Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS (MSVC-X86) Common - Math API [Vector] [M] [U16].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_U16_INL)
#define TGS_COMMON_MATH_API_VECTOR_M_U16_INL
#pragma once


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

/* ---- MS_SETU_U16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 MS_SETU_U16_08( CPCU_TgUINT16 puiVal )
{
    return (_mm_loadu_si128( (__m128i*)puiVal ));
}


/* ---- MS_SETA_U16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 MS_SETA_U16_08( CPCU_TgUINT16 puiVal )
{
    return (_mm_load_si128( (__m128i*)puiVal ));
}


/* ---- MS_SET1_U16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 MS_SET1_U16_08( C_TgUINT16 uiVal )
{
    return (_mm_set1_epi16( (int)uiVal ));
}


/* ---- M_PERM_U16_08 --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_PERM_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight, C_TgVEC_M_U16_08 tuvMask )
{
    __m128i                             vX = { 0 };
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < 8; ++uiIndex)
    {
        C_TgUINT08                          byMask = tuvMask.m128i_u8[uiIndex];
        C_TgUINT16                          ui0 = tvLeft.m128i_u16[byMask & 0x7];
        C_TgUINT16                          ui1 = tvRight.m128i_u16[byMask & 0x7];

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

    return (vX);
}


/* ---- M_SEL_U16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_SEL_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight, C_TgVEC_M_U16_08 tuvMask )
{
    return ( _mm_or_si128( _mm_and_si128( tvLeft, _mm_xor_si128( KTgV_FFFF.m_u16_v08.m_mData, tuvMask ) ), _mm_and_si128( tvRight, tuvMask ) ));
}


/* ---- M_AND_U16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_AND_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_and_si128( tvLeft, tvRight ));
}


/* ---- M_OR_U16_08 ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_OR_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_or_si128( tvLeft, tvRight ));
}


/* ---- M_XOR_U16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_XOR_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_xor_si128( tvLeft, tvRight ));
}


/* ---- M_MAX_U16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_MAX_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_max_epu16( tvLeft, tvRight ));
}


/* ---- M_MIN_U16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_MIN_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_min_epu16( tvLeft, tvRight ));
}


/* ---- M_CMP_EQ_U16_08 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_CMP_EQ_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_cmpeq_epi16( tvLeft, tvRight ));
}


/* ---- M_CMP_NE_U16_08 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_CMP_NE_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_xor_si128( KTgV_FFFF.m_u16_v08.m_mData, _mm_cmpeq_epi16( tvLeft, tvRight ) ));
}


/* ---- M_CMP_GE_U16_08 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_CMP_GE_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_xor_si128( KTgV_FFFF.m_u16_v08.m_mData, M_CMP_GT_U16_08( tvRight, tvLeft ) ));
}


/* ---- M_CMP_GT_U16_08 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_CMP_GT_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    __m128i                             vX1;

    vX1.m128i_u16[0] = tvLeft.m128i_u16[0] > tvRight.m128i_u16[0] ? 0xFFFFui16 : 0x0000ui16;
    vX1.m128i_u16[1] = tvLeft.m128i_u16[1] > tvRight.m128i_u16[1] ? 0xFFFFui16 : 0x0000ui16;
    vX1.m128i_u16[2] = tvLeft.m128i_u16[2] > tvRight.m128i_u16[2] ? 0xFFFFui16 : 0x0000ui16;
    vX1.m128i_u16[3] = tvLeft.m128i_u16[3] > tvRight.m128i_u16[3] ? 0xFFFFui16 : 0x0000ui16;
    vX1.m128i_u16[4] = tvLeft.m128i_u16[4] > tvRight.m128i_u16[4] ? 0xFFFFui16 : 0x0000ui16;
    vX1.m128i_u16[5] = tvLeft.m128i_u16[5] > tvRight.m128i_u16[5] ? 0xFFFFui16 : 0x0000ui16;
    vX1.m128i_u16[6] = tvLeft.m128i_u16[6] > tvRight.m128i_u16[6] ? 0xFFFFui16 : 0x0000ui16;
    vX1.m128i_u16[7] = tvLeft.m128i_u16[7] > tvRight.m128i_u16[7] ? 0xFFFFui16 : 0x0000ui16;

    return (vX1);
}


/* ---- M_CMP_LE_U16_08 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_CMP_LE_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_xor_si128( KTgV_FFFF.m_u16_v08.m_mData, M_CMP_GT_U16_08( tvLeft, tvRight ) ));
}


/* ---- TgVEC_M_U16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_CMP_LT_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (M_CMP_GT_U16_08( tvRight, tvLeft ));
}


/* ---- M_ADD_S_U16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_ADD_S_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_adds_epu16( tvLeft, tvRight ));
}


/* ---- M_ADD_M_U16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_ADD_M_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (F_ADD_M_U16_08( (P_TgVEC_U16_08)&tvLeft, (P_TgVEC_U16_08)&tvRight ).m_mData);
}


/* ---- M_SUB_S_U16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_SUB_S_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_subs_epu16( tvLeft, tvRight ));
}


/* ---- M_SUB_M_U16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_SUB_M_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (F_SUB_M_U16_08( (P_TgVEC_U16_08)&tvLeft, (P_TgVEC_U16_08)&tvRight ).m_mData);
}


/* ---- M_AVG_U16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_U16_08 M_AVG_U16_08( C_TgVEC_M_U16_08 tvLeft, C_TgVEC_M_U16_08 tvRight )
{
    return (_mm_avg_epu16( tvLeft, tvRight ));
}


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