Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS (MSVC-X86) Common - Math API [Vector] [M] [U08].inl
    »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
    »Version«   4.51 / »GUID« A9981407-3EC9-42AF-8B6F-8BE6DD919615                                                                                                        */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
/*  Copyright: © 2002-2017, Andrew Aye.  All Rights Reserved.
    This software is free for non-commercial use.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
    following conditions are met:
    Redistribution of source code must retain this copyright notice, this list of conditions and the following disclaimers.
    Redistribution in binary form must reproduce this copyright notice, this list of conditions and the following disclaimers in the documentation and other materials
    provided with the distribution.
    The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.
    The intellectual property rights of the algorithms used reside with Andrew Aye.
    You may not use this software, in whole or in part, in support of any commercial product without the express written consent of the author.
    There is no warranty or other guarantee of fitness of this software for any purpose. It is provided solely "as is".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
#if !defined(TGS_COMMON_MATH_API_VECTOR_M_U08_INL)
#define TGS_COMMON_MATH_API_VECTOR_M_U08_INL
#pragma once


/* == Common ============================================================================================================================================================ */

/* ---- SCALAR- LOAD/SET OPERATIONS ------------------------------------------------------------------------------------------------------------------------------------- */

/* ---- MS_SETU_U08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 MS_SETU_U08_16( CPCU_TgUINT08 puiVal )
{
    return (_mm_loadu_si128( (__m128i*)puiVal ));
}


/* ---- MS_SETA_U08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 MS_SETA_U08_16( CPCU_TgUINT08 puiVal )
{
    return (_mm_load_si128( (__m128i*)puiVal ));
}


/* ---- MS_SET1_U08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 MS_SET1_U08_16( C_TgUINT08 uiVal )
{
    return (_mm_set1_epi8( (int)uiVal ));
}


/* ---- M_PERM_U08_16 --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_PERM_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight, C_TgVEC_M_U08_16 tuvMask )
{
    __m128i                             vX = { 0 };
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < 16; ++uiIndex)
    {
        C_TgUINT08                          byMask = tuvMask.m128i_u8[uiIndex];
        C_TgUINT08                          ui0 = tvLeft.m128i_u8[byMask & 0xF];
        C_TgUINT08                          ui1 = tvRight.m128i_u8[byMask & 0xF];

        vX.m128i_u8[uiIndex] = 0 == (byMask & KTgPERM_PARAM_SELECT_BIT) ? ui0 : ui1;
    };

    return (vX);
}


/* ---- M_SEL_U08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_SEL_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight, C_TgVEC_M_U08_16 tuvMask )
{
    return ( _mm_or_si128( _mm_and_si128( tvLeft, _mm_xor_si128( KTgV_FFFF.m_u08_v16.m_mData, tuvMask ) ), _mm_and_si128( tvRight, tuvMask ) ));
}


/* ---- M_AND_U08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_AND_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_and_si128( tvLeft, tvRight ));
}


/* ---- M_OR_U08_16 ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_OR_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_or_si128( tvLeft, tvRight ));
}


/* ---- M_XOR_U08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_XOR_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_xor_si128( tvLeft, tvRight ));
}


/* ---- M_MAX_U08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_MAX_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_max_epu8( tvLeft, tvRight ));
}


/* ---- M_MIN_U08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_MIN_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_min_epu8( tvLeft, tvRight ));
}


/* ---- M_CMP_EQ_U08_16 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_CMP_EQ_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_cmpeq_epi8( tvLeft, tvRight ));
}


/* ---- M_CMP_NE_U08_16 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_CMP_NE_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_xor_si128( KTgV_FFFF.m_u08_v16.m_mData, _mm_cmpeq_epi8( tvLeft, tvRight ) ));
}


/* ---- M_CMP_GE_U08_16 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_CMP_GE_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_xor_si128( KTgV_FFFF.m_u08_v16.m_mData, M_CMP_GT_U08_16( tvRight, tvLeft ) ));
}


/* ---- M_CMP_GT_U08_16 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_CMP_GT_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    __m128i                             vX1;

    vX1.m128i_u8[0] = tvLeft.m128i_u8[0] > tvRight.m128i_u8[0] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[1] = tvLeft.m128i_u8[1] > tvRight.m128i_u8[1] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[2] = tvLeft.m128i_u8[2] > tvRight.m128i_u8[2] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[3] = tvLeft.m128i_u8[3] > tvRight.m128i_u8[3] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[4] = tvLeft.m128i_u8[4] > tvRight.m128i_u8[4] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[5] = tvLeft.m128i_u8[5] > tvRight.m128i_u8[5] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[6] = tvLeft.m128i_u8[6] > tvRight.m128i_u8[6] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[7] = tvLeft.m128i_u8[7] > tvRight.m128i_u8[7] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[8] = tvLeft.m128i_u8[8] > tvRight.m128i_u8[8] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[9] = tvLeft.m128i_u8[9] > tvRight.m128i_u8[9] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[10] = tvLeft.m128i_u8[10] > tvRight.m128i_u8[10] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[11] = tvLeft.m128i_u8[11] > tvRight.m128i_u8[11] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[12] = tvLeft.m128i_u8[12] > tvRight.m128i_u8[12] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[13] = tvLeft.m128i_u8[13] > tvRight.m128i_u8[13] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[14] = tvLeft.m128i_u8[14] > tvRight.m128i_u8[14] ? 0xFFui8 : 0x00ui8;
    vX1.m128i_u8[15] = tvLeft.m128i_u8[15] > tvRight.m128i_u8[15] ? 0xFFui8 : 0x00ui8;

    return (vX1);
}


/* ---- M_CMP_LE_U08_16 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_CMP_LE_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_xor_si128( KTgV_FFFF.m_u08_v16.m_mData, M_CMP_GT_U08_16( tvLeft, tvRight ) ));
}


/* ---- TgVEC_M_U08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_CMP_LT_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return M_CMP_GT_U08_16( tvRight, tvLeft );
}


/* ---- M_ADD_S_U08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_ADD_S_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_adds_epu8( tvLeft, tvRight ));
}


/* ---- M_ADD_M_U08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_ADD_M_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (F_ADD_M_U08_16( (P_TgVEC_U08_16)&tvLeft, (P_TgVEC_U08_16)&tvRight ).m_mData);
}


/* ---- M_SUB_S_U08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_SUB_S_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_subs_epu8( tvLeft, tvRight ));
}


/* ---- M_SUB_M_U08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_SUB_M_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (F_SUB_M_U08_16( (P_TgVEC_U08_16)&tvLeft, (P_TgVEC_U08_16)&tvRight ).m_mData);
}


/* ---- M_AVG_U08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U08_16 M_AVG_U08_16( C_TgVEC_M_U08_16 tvLeft, C_TgVEC_M_U08_16 tvRight )
{
    return (_mm_avg_epu8( tvLeft, tvRight ));
}


/* ====================================================================================================================================================================== */
#endif