Home

Resume

Blog

Teikitu


/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/*  »Project«   Teikitu Gaming System (TgS) (∂)
    »File«      TgS Common - Math API [Vector].i_inc
    »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".                                                   */
/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */

MSVC_WARN_DISABLE_PUSH( 4701 )


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

/* ---- V(F_SETU) ------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_SETU)( const TYPE * __restrict const pty )
{
    TgCOMPILER_ASSERT( sizeof( V(TgVEC) ) == DIM*sizeof( TYPE ), 0 );

    V(TgVEC)                            vResult;

    TgMEMCPY( &vResult, sizeof(vResult), pty, DIM*sizeof( TYPE ) );

    MSVC_WARN_SUPPRESS( 6001 )
    return (vResult);
}


/* ---- V(F_SETA) ------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_SETA)( const TYPE * __restrict const pty )
{
    TgCOMPILER_ASSERT( sizeof( V(TgVEC) ) == DIM*sizeof( TYPE ), 0 );

    V(TgVEC)                            vResult;

    memcpy( &vResult, pty, DIM*sizeof( TYPE ) );

    MSVC_WARN_SUPPRESS( 6001 )
    return (vResult);
}


/* ---- V(FS_SET1) ------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(FS_SET1)( const TYPE fX )
{
    #define EQN(A) fX
    VEC_ASSIGN_EQN
    #undef EQN
}


/* ---- V(F_PERM) ------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_PERM)( V(CPC_TgVEC) pv0, V(CPC_TgVEC) pv1, CPCU_TgUINT08 puiMask )
{
    TgCOMPILER_ASSERT( sizeof( V(TgVEC) ) == DIM*sizeof( TYPE ), 0 );
    TgCOMPILER_ASSERT( sizeof( V(TgVEC) ) <= KTgPERM_PARAM_SELECT_BIT, 0 );
    TgCOMPILER_ASSERT( sizeof( TYPE ) == TYPE_SIZE, 0 );

    union V(F_PERM_DATA_ALIAS_OUTPUT)
    {
        V(TgVEC)                                    v;
        TgUINT08                                    i[sizeof( V(TgVEC) )];
    }                                   uOut0;

    union V(F_PERM_DATA_ALIAS_INPUT)
    {
        V(CP_TgVEC)                                 pv;
        CP_TgUINT08                                 pi;
    }                                   uIn0, uIn1;

    TgUINT32                            uiIndex, uiIndex_Element;

    uIn0.pv = pv0;
    uIn1.pv = pv1;

    for (uiIndex = 0; uiIndex < DIM; ++uiIndex)
    {
        C_TgUINT08                          byMask = puiMask[uiIndex];
        C_TgUINT08                          uiData_Index = sizeof( TYPE ) * (byMask & (KTgPERM_PARAM_SELECT_BIT - 1));
        CP_TgUINT08                         pvData = (0 == (byMask & KTgPERM_PARAM_SELECT_BIT)) ? uIn0.pi : uIn1.pi;

        for (uiIndex_Element = 0; uiIndex_Element < sizeof( TYPE ); ++uiIndex_Element)
        {
            uOut0.i[uiIndex_Element + uiIndex * sizeof( TYPE )] = pvData[uiData_Index + uiIndex_Element];
        };
    };

    return (uOut0.v);
}


/* ---- V(F_SEL) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_SEL)( V(CPC_TgVEC) pv0, V(CPC_TgVEC) pv1, CPCU_TgUINT32 puiMask )
{
    TgCOMPILER_ASSERT( 0 == (sizeof( V(TgVEC) ) % sizeof( TgUINT32 )), 0 );
    TgCOMPILER_ASSERT( sizeof( V(TgVEC) ) == DIM*sizeof( TYPE ), 0 );
    TgCOMPILER_ASSERT( sizeof( TYPE ) == TYPE_SIZE, 0 );

    union V(F_SEL_DATA_ALIAS_OUTPUT)
    {
        V(TgVEC)                                    v;
        TgUINT32                                    i[sizeof( V(TgVEC) ) / sizeof( TgUINT32 )];
    }                                   uOut0;

    union V(F_SEL_DATA_ALIAS_INPUT)
    {
        V(CP_TgVEC)                                 pv;
        CP_TgUINT32                                 pi;
    }                                   uIn0, uIn1;

    TgUINT32                            uiIndex;

    uIn0.pv = pv0;
    uIn1.pv = pv1;

    for (uiIndex = 0; uiIndex*sizeof( TgUINT32 ) < DIM*sizeof( TYPE ); ++uiIndex)
    {
        uOut0.i[uiIndex] = (uIn0.pi[uiIndex] & ~(puiMask[uiIndex])) | (uIn1.pi[uiIndex] & puiMask[uiIndex]);
    };

    return (uOut0.v);
}


/* ---- V(F_AND) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_AND)( V(CPC_TgVEC) pv0, V(CPC_TgVEC) pv1 )
{
    TgCOMPILER_ASSERT( 0 == (sizeof( V(TgVEC) ) % sizeof( TgUINT32 )), 0 );
    TgCOMPILER_ASSERT( sizeof( V(TgVEC) ) == DIM*sizeof( TYPE ), 0 );
    TgCOMPILER_ASSERT( sizeof( TYPE ) == TYPE_SIZE, 0 );

    union V(F_AND_DATA_ALIAS_OUTPUT)
    {
        V(TgVEC)                                    v;
        TgUINT32                                    i[sizeof( V(TgVEC) ) / sizeof( TgUINT32 )];
    }                                   uOut0;

    TgCOMPILER_ASSERT( sizeof( uOut0.v ) == sizeof( uOut0.i ), 0 );

    union V(F_AND_DATA_ALIAS_INPUT)
    {
        V(CP_TgVEC)                                 pv;
        CP_TgUINT32                                 pi;
    }                                   uIn0, uIn1;

    TgUINT32                            uiIndex;

    uIn0.pv = pv0;
    uIn1.pv = pv1;

    for (uiIndex = 0; uiIndex < sizeof( uOut0.i ) / sizeof( uOut0.i[0] ); ++uiIndex)
    {
        uOut0.i[uiIndex] = uIn0.pi[uiIndex] & uIn1.pi[uiIndex];
    };

    return (uOut0.v);
}


/* ---- V(F_OR) --------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_OR)( V(CPC_TgVEC) pv0, V(CPC_TgVEC) pv1 )
{
    TgCOMPILER_ASSERT( 0 == (sizeof( V(TgVEC) ) % sizeof( TgUINT32 )), 0 );
    TgCOMPILER_ASSERT( sizeof( V(TgVEC) ) == DIM*sizeof( TYPE ), 0 );
    TgCOMPILER_ASSERT( sizeof( TYPE ) == TYPE_SIZE, 0 );

    union V(F_OR_DATA_ALIAS_OUTPUT)
    {
        V(TgVEC)                                    v;
        TgUINT32                                    i[sizeof( V(TgVEC) ) / sizeof( TgUINT32 )];
    }                                   uOut0;

    TgCOMPILER_ASSERT( sizeof( uOut0.v ) == sizeof( uOut0.i ), 0 );

    union V(F_OR_DATA_ALIAS_INPUT)
    {
        V(CP_TgVEC)                                 pv;
        CP_TgUINT32                                 pi;
    }                                   uIn0, uIn1;

    TgUINT32                            uiIndex;

    uIn0.pv = pv0;
    uIn1.pv = pv1;

    for (uiIndex = 0; uiIndex < sizeof( uOut0.i ) / sizeof( uOut0.i[0] ); ++uiIndex)
    {
        uOut0.i[uiIndex] = uIn0.pi[uiIndex] | uIn1.pi[uiIndex];
    };

    return (uOut0.v);
}


/* ---- V(F_XOR) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_XOR)( V(CPC_TgVEC) pv0, V(CPC_TgVEC) pv1 )
{
    TgCOMPILER_ASSERT( 0 == (sizeof( V(TgVEC) ) % sizeof( TgUINT32 )), 0 );
    TgCOMPILER_ASSERT( sizeof( V(TgVEC) ) == DIM*sizeof( TYPE ), 0 );
    TgCOMPILER_ASSERT( sizeof( TYPE ) == TYPE_SIZE, 0 );

    union V(F_XOR_DATA_ALIAS_OUTPUT)
    {
        V(TgVEC)                                    v;
        TgUINT32                                    i[sizeof( V(TgVEC) ) / sizeof( TgUINT32 )];
    }                                   uOut0;

    TgCOMPILER_ASSERT( sizeof( uOut0.v ) == sizeof( uOut0.i ), 0 );

    union V(F_XOR_DATA_ALIAS_INPUT)
    {
        V(CP_TgVEC)                                 pv;
        CP_TgUINT32                                 pi;
    }                                   uIn0, uIn1;

    TgUINT32                            uiIndex;

    uIn0.pv = pv0;
    uIn1.pv = pv1;

    for (uiIndex = 0; uiIndex < sizeof( uOut0.i ) / sizeof( uOut0.i[0] ); ++uiIndex)
    {
        uOut0.i[uiIndex] = uIn0.pi[uiIndex] ^ uIn1.pi[uiIndex];
    };

    return (uOut0.v);
}


/* ---- V(F_MAX) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_MAX)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    #define EQN(A) T(tgCM_MAX)( pv0->m_aData[A], pv1->m_aData[A] )
    VEC_ASSIGN_EQN
    #undef EQN
}


/* ---- V(F_MIN) -------------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_MIN)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    #define EQN(A) T(tgCM_MIN)( pv0->m_aData[A], pv1->m_aData[A] )
    VEC_ASSIGN_EQN
    #undef EQN
}


/* ---- V(F_CMP_EQ_M) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
CLANG_WARN_DISABLE_PUSH(float-equal)
TgINLINE V(TgVEC) V(F_CMP_EQ_M)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    #define EQN(A) (TYPE)((pv0->m_aData[A] == pv1->m_aData[A]) ? TYPE_MASK : 0)
    VEC_ASSIGN_EQN
    #undef EQN
}
CLANG_WARN_DISABLE_POP(float-equal)


/* ---- V(F_CMP_NE_M) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
CLANG_WARN_DISABLE_PUSH(float-equal)
TgINLINE V(TgVEC) V(F_CMP_NE_M)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    #define EQN(A) (TYPE)((pv0->m_aData[A] != pv1->m_aData[A]) ? TYPE_MASK : 0)
    VEC_ASSIGN_EQN
    #undef EQN
}
CLANG_WARN_DISABLE_POP(float-equal)


/* ---- V(F_CMP_GE_M) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_CMP_GE_M)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    #define EQN(A) (TYPE)((pv0->m_aData[A] >= pv1->m_aData[A]) ? TYPE_MASK : 0)
    VEC_ASSIGN_EQN
    #undef EQN
}


/* ---- V(F_CMP_GT_M) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_CMP_GT_M)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    #define EQN(A) (TYPE)((pv0->m_aData[A] >  pv1->m_aData[A]) ? TYPE_MASK : 0)
    VEC_ASSIGN_EQN
    #undef EQN
}


/* ---- V(F_CMP_LE_M) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_CMP_LE_M)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    #define EQN(A) (TYPE)((pv0->m_aData[A] <= pv1->m_aData[A]) ? TYPE_MASK : 0)
    VEC_ASSIGN_EQN
    #undef EQN
}


/* ---- V(F_CMP_LT_M) --------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE V(TgVEC) V(F_CMP_LT_M)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    #define EQN(A) (TYPE)(pv0->m_aData[A] <  pv1->m_aData[A] ? TYPE_MASK : 0)
    VEC_ASSIGN_EQN
    #undef EQN
}


/* ---- V(F_CMP_EQ) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
CLANG_WARN_DISABLE_PUSH(float-equal)
TgINLINE TgBOOL V(F_CMP_EQ)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < DIM; ++uiIndex)
    {
        if (!(pv0->m_aData[uiIndex] == pv1->m_aData[uiIndex]))
        {
            return (TgFALSE);
        };
    };

    return (TgTRUE);
}
CLANG_WARN_DISABLE_POP(float-equal)


/* ---- V(F_CMP_NE) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
CLANG_WARN_DISABLE_PUSH(float-equal)
TgINLINE TgBOOL V(F_CMP_NE)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < DIM; ++uiIndex)
    {
        if (!(pv0->m_aData[uiIndex] != pv1->m_aData[uiIndex]))
        {
            return (TgFALSE);
        };
    };

    return (TgTRUE);
}
CLANG_WARN_DISABLE_POP(float-equal)


/* ---- V(F_CMP_GE) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(F_CMP_GE)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < DIM; ++uiIndex)
    {
        if (!(pv0->m_aData[uiIndex] >= pv1->m_aData[uiIndex]))
        {
            return (TgFALSE);
        };
    };

    return (TgTRUE);
}


/* ---- V(F_CMP_GT) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(F_CMP_GT)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < DIM; ++uiIndex)
    {
        if (!(pv0->m_aData[uiIndex] > pv1->m_aData[uiIndex]))
        {
            return (TgFALSE);
        };
    };

    return (TgTRUE);
}


/* ---- V(F_CMP_LE) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(F_CMP_LE)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < DIM; ++uiIndex)
    {
        if (!(pv0->m_aData[uiIndex] <= pv1->m_aData[uiIndex]))
        {
            return (TgFALSE);
        };
    };

    return (TgTRUE);
}


/* ---- V(F_CMP_LT) ----------------------------------------------------------------------------------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
TgINLINE TgBOOL V(F_CMP_LT)( V(CPCU_TgVEC) pv0, V(CPCU_TgVEC) pv1 )
{
    TgUINT32                            uiIndex;

    for (uiIndex = 0; uiIndex < DIM; ++uiIndex)
    {
        if (!(pv0->m_aData[uiIndex] < pv1->m_aData[uiIndex]))
        {
            return (TgFALSE);
        };
    };

    return (TgTRUE);
}

MSVC_WARN_DISABLE_POP()