Home

Resume

Blog

Teikitu


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


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

/* ---- MS_SETU_S08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 MS_SETU_S08_16( CPCU_TgSINT08 puiVal )
{
    return (_mm_loadu_si128( (__m128i*)puiVal ));
}


/* ---- MS_SETA_S08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 MS_SETA_S08_16( CPCU_TgSINT08 puiVal )
{
    return (_mm_load_si128( (__m128i*)puiVal ));
}


/* ---- MS_SET1_S08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 MS_SET1_S08_16( C_TgSINT08 uiVal )
{
    return (_mm_set1_epi8( (int)uiVal ));
}


/* ---- M_PERM_S08_16 --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_PERM_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight, C_TgVEC_M_S08_16 tuvMask )
{
    __m128i                             vX = { 0 };
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < 16; ++uiIndex)
    {
        C_TgUINT08                          byMask = tuvMask.m128i_u8[uiIndex];
        C_TgSINT08                          i0 = tvLeft.m128i_i8[byMask & 0xF];
        C_TgSINT08                          i1 = tvRight.m128i_i8[byMask & 0xF];

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

    return (vX);
}


/* ---- M_SEL_S08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_SEL_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight, C_TgVEC_M_S08_16 tuvMask )
{
    return (_mm_or_si128( _mm_and_si128( tvLeft, _mm_xor_si128( KTgV_FFFF.m_i08_v16.m_mData, tuvMask ) ), _mm_and_si128( tvRight, tuvMask ) ) );
}


/* ---- M_AND_S08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_AND_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_and_si128( tvLeft, tvRight ));
}


/* ---- M_OR_S08_16 ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_OR_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_or_si128( tvLeft, tvRight ));
}


/* ---- M_XOR_S08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_XOR_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_xor_si128( tvLeft, tvRight ));
}


/* ---- M_MAX_S08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_MAX_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_max_epi8( tvLeft, tvRight ));
}


/* ---- M_MIN_S08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_MIN_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_min_epi8( tvLeft, tvRight ));
}


/* ---- M_CMP_EQ_S08_16 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_CMP_EQ_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_cmpeq_epi8( tvLeft, tvRight ));
}


/* ---- M_CMP_NE_S08_16 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_CMP_NE_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_xor_si128( KTgV_FFFF.m_i08_v16.m_mData, _mm_cmpeq_epi8( tvLeft, tvRight ) ));
}


/* ---- M_CMP_GE_S08_16 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_CMP_GE_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_xor_si128( KTgV_FFFF.m_i08_v16.m_mData, _mm_cmpgt_epi8( tvRight, tvLeft ) ));
}


/* ---- M_CMP_GT_S08_16 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_CMP_GT_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_cmpgt_epi8( tvLeft, tvRight ));
}


/* ---- M_CMP_LE_S08_16 ------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_CMP_LE_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_xor_si128( KTgV_FFFF.m_i08_v16.m_mData, _mm_cmpgt_epi8( tvLeft, tvRight ) ));
}


/* ---- TgVEC_M_S08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_CMP_LT_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_cmpgt_epi8( tvRight, tvLeft ));
}


/* ---- M_ADD_S_S08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_ADD_S_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_adds_epi8( tvLeft, tvRight ));
}


/* ---- M_ADD_M_S08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_ADD_M_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_add_epi8( tvLeft, tvRight ));
}


/* ---- M_SUB_S_S08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_SUB_S_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_subs_epi8( tvLeft, tvRight ));
}


/* ---- M_SUB_M_S08_16 -------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_SUB_M_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (_mm_sub_epi8( tvLeft, tvRight ));
}


/* ---- M_AVG_S08_16 ---------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgVEC_M_S08_16 M_AVG_S08_16( C_TgVEC_M_S08_16 tvLeft, C_TgVEC_M_S08_16 tvRight )
{
    return (F_AVG_S08_16( (P_TgVEC_S08_16)&tvLeft, (P_TgVEC_S08_16)&tvRight ).m_mData);
}


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