Home

Resume

Blog

Teikitu


// =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= //
//  »Project«   Teikitu Gaming System (TgS) (∂)
//  »File«      TgS (WIN) Common - Math API [Vector] [S16].inl
//  »Author«    Andrew Aye (EMail: mailto:andrew.aye@gmail.com, Web: http://www.andrewaye.com)
//  »Version«   4.0
// ------------------------------------------------------------------------------------------------------------------------------ //
//  Copyright: © 2002-2010, 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: 
//    Redistributions of source code must retain this copyright notice, this list of conditions and the following disclaimers. 
//    Redistributions 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. 
//  Neither the names of the copyright owner nor the names of its contributors may 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_WIN_COMMON_MATH_API_VECTOR_S16_INL_)
#define _TGS_WIN_COMMON_MATH_API_VECTOR_S16_INL_
#pragma once


// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
// Vector [M]
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

// SIMD - LOAD/SET OPERATIONS --------------------------------------------------------------------------------------------------- //

TgINLINE TgVEC_M_S16_08 M_SETU_S16_08( CPCU_TgSINT16 puiVal )
{
    return (( _mm_loadu_si128( (__m128i*)puiVal ) ));
}


TgINLINE TgVEC_M_S16_08 M_SETA_S16_08( CPCU_TgSINT16 puiVal )
{
    return (( _mm_load_si128( (__m128i*)puiVal ) ));
}


TgINLINE TgVEC_M_S16_08 M_SET1_S16_08( C_TgSINT16 iVal )
{
    return (( _mm_set1_epi16( iVal ) ));
}




// SIMD - PERMUTE AND SELECT ---------------------------------------------------------------------------------------------------- //

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.m128i_i16[uiIndex] & 0x1F;
        C_TgSINT16                          i0 = tvLeft.m128i_i16[byMask & 0xF];
        C_TgSINT16                          i1 = tvRight.m128i_i16[byMask & 0xF];

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

    return (( vX ));
}


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 ((
        _mm_or_si128(
            _mm_and_si128( tvLeft, _mm_xor_si128( KTgV_FFFF.m_i16_v08.m_mData, tuvMask ) ),
            _mm_and_si128( tvRight, tuvMask )
        )
    ));
}




// SIMD - LOGICAL --------------------------------------------------------------------------------------------------------------- //

TgINLINE TgVEC_M_S16_08 M_AND_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_and_si128( tvLeft, tvRight ) ));
}


TgINLINE TgVEC_M_S16_08 M_OR_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_or_si128( tvLeft, tvRight ) ));
}


TgINLINE TgVEC_M_S16_08 M_XOR_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_xor_si128( tvLeft, tvRight ) ));
}




// SIMD - BOUNDS ---------------------------------------------------------------------------------------------------------------- //

TgINLINE TgVEC_M_S16_08 M_MAX_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_max_epi16( tvLeft, tvRight ) ));
}


TgINLINE TgVEC_M_S16_08 M_MIN_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_min_epi16( tvLeft, tvRight ) ));
}




// SIMD - COMPARISON OPERATORS -------------------------------------------------------------------------------------------------- //

TgINLINE TgVEC_M_S16_08 M_CMP_EQ_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_cmpeq_epi16( tvLeft, tvRight ) ));
}


TgINLINE TgVEC_M_S16_08 M_CMP_NE_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((
        _mm_xor_si128( KTgV_FFFF.m_i16_v08.m_mData, _mm_cmpeq_epi16( tvLeft, tvRight ) ) ));
}


TgINLINE TgVEC_M_S16_08 M_CMP_GE_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((
        _mm_xor_si128( KTgV_FFFF.m_i16_v08.m_mData, _mm_cmpgt_epi16( tvRight, tvLeft ) ) ));
}


TgINLINE TgVEC_M_S16_08 M_CMP_GT_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_cmpgt_epi16( tvLeft, tvRight ) ));
}


TgINLINE TgVEC_M_S16_08 M_CMP_LE_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return ((_mm_xor_si128( KTgV_FFFF.m_i16_v08.m_mData, _mm_cmpgt_epi16( tvLeft, tvRight ) ) ));
}


TgINLINE TgVEC_M_S16_08 M_CMP_LT_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_cmpgt_epi16( tvRight, tvLeft ) ));
}




// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //
// Vector [M] [I]
// -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. //

// SIMD - ARITHMETIC OPERATIONS ------------------------------------------------------------------------------------------------- //

TgINLINE TgVEC_M_S16_08 M_ADD_S_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_adds_epi16( tvLeft, tvRight ) ));
}


TgINLINE TgVEC_M_S16_08 M_ADD_M_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_add_epi16( tvLeft, tvRight ) ));
}


TgINLINE TgVEC_M_S16_08 M_SUB_S_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_subs_epi16( tvLeft, tvRight ) ));
}


TgINLINE TgVEC_M_S16_08 M_SUB_M_S16_08( C_TgVEC_M_S16_08 tvLeft, C_TgVEC_M_S16_08 tvRight )
{
    return (( _mm_sub_epi16( tvLeft, tvRight ) ));
}


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( (P_TgVEC_S16_08)&tvLeft, (P_TgVEC_S16_08)&tvRight ).m_mData);
}


#endif //  END  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////