Home

Resume

Blog

Teikitu


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


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

/* ---- MS_SETU_S16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 MS_SETU_S16_08( CPCU_TgSINT16 puiVal )
{
    return ((TgVEC_M_S16_08)_mm_loadu_si128( (const __m128i*)puiVal ));
}


/* ---- MS_SETA_S16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 MS_SETA_S16_08( CPCU_TgSINT16 puiVal )
{
    return ((TgVEC_M_S16_08)_mm_load_si128( (const __m128i*)puiVal ));
}


/* ---- MS_SET1_S16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 MS_SET1_S16_08( C_TgSINT16 uiVal )
{
    return ((TgVEC_M_S16_08)_mm_set1_epi16( (short)uiVal ));
}


/* ---- M_PERM_S16_08 --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_PERM_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight, C_TgVEC_M_S16_08 tuvMask )
{
    __m128i                             vX = { 0 };
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < 8; ++uiIndex)
    {
        C_TgSINT16                          byMask = tuvMask[uiIndex];
        C_TgSINT16                          i0 = tvLeft[byMask & 0x7];
        C_TgSINT16                          i1 = tvRight[byMask & 0x7];

        vX[uiIndex] = 0 == (byMask & KTgPERM_PARAM_SELECT_BIT) ? i0 : i1;
    };

    return ((TgVEC_M_S16_08)vX);
}


/* ---- M_SEL_S16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_SEL_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight, C_TgVEC_M_S16_08 tuvMask )
{
    return ((TgVEC_M_S16_08)_mm_or_si128( _mm_and_si128( (const __m128i)tvLeft, _mm_xor_si128( (const __m128i)KTgV_FFFF.m_i16_v08.m_mData, (const __m128i)tuvMask ) ), _mm_and_si128( (const __m128i)tvRight, (const __m128i)tuvMask ) ) );
}


/* ---- M_AND_S16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_AND_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_and_si128( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_OR_S16_08 ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_OR_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_or_si128( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_XOR_S16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_XOR_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_xor_si128( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_MAX_S16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_MAX_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_max_epi16( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_MIN_S16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_MIN_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_min_epi16( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_CMP_EQ_S16_08 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_CMP_EQ_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_cmpeq_epi16( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_CMP_NE_S16_08 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_CMP_NE_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_xor_si128( (const __m128i)KTgV_FFFF.m_i16_v08.m_mData, _mm_cmpeq_epi16( (const __m128i)tvLeft, (const __m128i)tvRight ) ));
}


/* ---- M_CMP_GE_S16_08 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_CMP_GE_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_xor_si128( (const __m128i)KTgV_FFFF.m_i16_v08.m_mData, _mm_cmpgt_epi16( (const __m128i)tvRight, (const __m128i)tvLeft ) ));
}


/* ---- M_CMP_GT_S16_08 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_CMP_GT_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_cmpgt_epi16( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_CMP_LE_S16_08 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_CMP_LE_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_xor_si128( (const __m128i)KTgV_FFFF.m_i16_v08.m_mData, _mm_cmpgt_epi16( (const __m128i)tvLeft, (const __m128i)tvRight ) ));
}


/* ---- TgVEC_M_S16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_CMP_LT_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_cmpgt_epi16( (const __m128i)tvRight, (const __m128i)tvLeft ));
}


/* ---- M_ADD_S_S16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_ADD_S_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_adds_epi16( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_ADD_M_S16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_ADD_M_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_add_epi16( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_SUB_S_S16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_SUB_S_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_subs_epi16( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_SUB_M_S16_08 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_SUB_M_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((TgVEC_M_S16_08)_mm_sub_epi16( (const __m128i)tvLeft, (const __m128i)tvRight ));
}


/* ---- M_AVG_S16_08 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S16_08 M_AVG_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (F_AVG_S16_08( (CP_TgVEC_S16_08)&tvLeft, (CP_TgVEC_S16_08)&tvRight ).m_mData);
}


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