- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- Class List
- Class Hierarchy
- Class Members

Public Member Functions

# HWVector Struct Reference

Search for all occurrences

## Detailed Description

This class represents a four dimensional vector stored in the SSE registers.

Definition at line 58 of file SSE.h.

`#include <SSE.h>`

List of all members.

## Public Member Functions
| HWVector (void)
void | setZero (void)
| HWVector (float f)
| HWVector (const mudbox::Vector &h)
| HWVector (float x, float y, float z, float w=0)
void | Fill (const mudbox::Vector &vVector)
| HWVector (const float a[4])
HWVector | ShiftLeft (void) const
void | ShiftLeft (HWVector &result)
void | ShiftLeftInPlace ()
HWVector | ShiftRight (void) const
void | ShiftRight (HWVector &result)
HWVector | operator& (HWVector &o)
HWVector | operator| (const HWVector &o) const
HWVector | Length (void) const
HWVector | LengthSquared (void) const
float | DistanceFromLine (const HWVector &vStart, const HWVector &vEnd) const
void | Normalize (void)
HWVector | Floor (void)
HWVector | Minimum (const HWVector &o) const
HWVector | Maximum (const HWVector &o) const
HWVector | operator+ (const HWVector &o) const
HWVector | operator- (const HWVector &o) const
void | operator+= (const HWVector &o)
void | operator-= (const HWVector &o)
void | operator*= (const HWVector &o)
void | operator/= (const HWVector &o)
HWVector | operator* (const HWVector &o) const
HWVector | operator* (float f) const
HWVector | operator/ (const HWVector &o) const
void | operator*= (float f)
void | Store (float *p)
void | Load (float f)
void | StoreNormalAsInt (int *pBuffer) const
void | StoreAsInt (int *pBuffer) const
| operator float (void) const
| operator mudbox::Vector (void) const
| operator mudbox::Vector4 (void) const
| MB_SSE_ALIGN16_VAR (__m128 v)

## Constructor & Destructor Documentation

HWVector | ( | void |  | ) | `[inline]`

Definition at line 60 of file SSE.h.

    {};

HWVector | ( | float | f | ) | `[inline]`

Definition at line 67 of file SSE.h.

        {
            v = _mm_set_ps1( f );
        }

HWVector | ( | const mudbox::Vector & | h | ) | `[inline]`

Definition at line 72 of file SSE.h.

        {
            v = _mm_set_ps( h.x, h.y, h.z, 0);
        };

HWVector | ( | float | x,
|  | float | y,
|  | float | z,
|  | float | w = `0`
| ) |  | `[inline]`

Definition at line 76 of file SSE.h.

        {
            v = _mm_set_ps( x,y,z,w );
        };

HWVector | ( | const float | a[4] | ) | `[inline]`

Definition at line 81 of file SSE.h.

        {
            v = _mm_loadu_ps( a );
        };

## Member Function Documentation

void setZero | ( | void |  | ) | `[inline]`

Search for all occurrences

Definition at line 62 of file SSE.h.

        {
            v = _mm_setzero_ps();
        }

void Fill | ( | const mudbox::Vector & | vVector | ) |

Search for all occurrences

HWVector ShiftLeft | ( | void |  | ) | const `[inline]`

Search for all occurrences

Definition at line 85 of file SSE.h.

    { HWVector r; r.v = _mm_shuffle_ps(v,v,_MM_SHUFFLE(2,1,3,0)); return r; };

void ShiftLeft | ( | HWVector & | result | ) | `[inline]`

Search for all occurrences

Definition at line 86 of file SSE.h.

    { result.v = _mm_shuffle_ps(v,v,_MM_SHUFFLE(2,1,3,0)); }

void ShiftLeftInPlace | ( |  | ) | `[inline]`

Search for all occurrences

Definition at line 87 of file SSE.h.

    { v = _mm_shuffle_ps(v,v,_MM_SHUFFLE(2,1,3,0)); }

HWVector ShiftRight | ( | void |  | ) | const `[inline]`

Search for all occurrences

Definition at line 88 of file SSE.h.

    { HWVector r; r.v = _mm_shuffle_ps(v,v,_MM_SHUFFLE(1,3,2,0)); return r; };

void ShiftRight | ( | HWVector & | result | ) | `[inline]`

Search for all occurrences

Definition at line 89 of file SSE.h.

    { result.v = _mm_shuffle_ps(v,v,_MM_SHUFFLE(1,3,2,0)); };

HWVector operator& | ( | HWVector & | o | ) | `[inline]`

Definition at line 90 of file SSE.h.

        {
            //HWVector al = (*this).ShiftLeft(), bl = o.ShiftLeft(), ar = (*this).ShiftRight(), br = o.ShiftRight();
            HWVector al, bl, ar, br;
            ShiftLeft(al);
            o.ShiftLeft(bl);
            ShiftRight(ar);
            o.ShiftRight(br);

            return al*br-ar*bl;
        };

HWVector operator| | ( | const HWVector & | o | ) | const `[inline]`

Definition at line 102 of file SSE.h.

        {
            HWVector r;
            r.v = _mm_mul_ps( v, o.v );
            // Requires SSE3
            r.v = _mm_hadd_ps( r.v, r.v );
            r.v = _mm_hadd_ps( r.v, r.v );
            return r;
        };

HWVector Length | ( | void |  | ) | const `[inline]`

Search for all occurrences

Definition at line 112 of file SSE.h.

        {
            HWVector r = operator |( *this );
            r.v = _mm_sqrt_ss( r.v );
            return r;
        };

HWVector LengthSquared | ( | void |  | ) | const `[inline]`

Search for all occurrences

Definition at line 119 of file SSE.h.

        {
            HWVector r = operator |( *this );
            return r;
        };

float DistanceFromLine | ( | const HWVector & | vStart,
|  | const HWVector & | vEnd
| ) |  | const `[inline]`

Search for all occurrences

Definition at line 125 of file SSE.h.

        {
            HWVector n = vEnd - vStart;
            HWVector m = (*this)-vStart;
            HWVector h = n&m;
            HWVector d = n&h;
            d.Normalize();
            float fDistance = (d|(*this))-(d|vStart);
            return fDistance>0?fDistance:(-fDistance);
        }

void Normalize | ( | void |  | ) | `[inline]`

Search for all occurrences

Definition at line 136 of file SSE.h.

        {
            HWVector f = operator |( *this );
            f.v = _mm_rsqrt_ps( f.v );
            v = _mm_mul_ps( f.v, v );
        };

HWVector Floor | ( | void |  | ) | `[inline]`

Search for all occurrences

Definition at line 143 of file SSE.h.

        {
            static unsigned int a = 1<<23;
            static float twoTo23AsFloat = (float)a;
            static const __m128 twoTo23 = _mm_set_ps( twoTo23AsFloat,twoTo23AsFloat,twoTo23AsFloat,twoTo23AsFloat );
            // b = fabs(v)
            __m128 b = _mm_castsi128_ps(_mm_srli_epi32( _mm_slli_epi32( _mm_castps_si128(v),1 ), 1 ));
            // The essence of the floor routine
            __m128 d = _mm_sub_ps( _mm_add_ps( _mm_add_ps( _mm_sub_ps( v,twoTo23 ), twoTo23 ),twoTo23 ), twoTo23 );
            // �1 if v >= 2**23
            __m128 largeMaskE = _mm_cmpgt_ps( b, twoTo23 );
            // Check for possible off by one error
            __m128 g = _mm_cmplt_ps( v, d );
            // Convert positive check result to -1.0, negative to 0.0
            __m128 h = _mm_cvtepi32_ps( _mm_castps_si128(g) );
            // Add in the error if there is one
            __m128 t = _mm_add_ps( d, h );
            //Select between output result and input value based on v >= 2**23
            __m128 w = _mm_and_ps( v, largeMaskE );
            t = _mm_andnot_ps( largeMaskE, t );
            HWVector vResult;
            vResult.v = _mm_or_ps( t, w );
            return vResult;
        };

HWVector Minimum | ( | const HWVector & | o | ) | const `[inline]`

Search for all occurrences

Definition at line 168 of file SSE.h.

    { HWVector r; r.v = _mm_min_ps( v, o.v ); return r; };

HWVector Maximum | ( | const HWVector & | o | ) | const `[inline]`

Search for all occurrences

Definition at line 169 of file SSE.h.

    { HWVector r; r.v = _mm_max_ps( v, o.v ); return r; };

HWVector operator+ | ( | const HWVector & | o | ) | const `[inline]`

Definition at line 170 of file SSE.h.

    { HWVector r; r.v = _mm_add_ps( v, o.v ); return r; };

HWVector operator- | ( | const HWVector & | o | ) | const `[inline]`

Definition at line 171 of file SSE.h.

    { HWVector r; r.v = _mm_sub_ps( v, o.v ); return r; };

void operator+= | ( | const HWVector & | o | ) | `[inline]`

Definition at line 172 of file SSE.h.

    { v = _mm_add_ps( v, o.v ); };

void operator-= | ( | const HWVector & | o | ) | `[inline]`

Definition at line 173 of file SSE.h.

    { v = _mm_sub_ps( v, o.v ); };

void operator*= | ( | const HWVector & | o | ) | `[inline]`

Definition at line 174 of file SSE.h.

    { v = _mm_mul_ps( v, o.v ); };

void operator/= | ( | const HWVector & | o | ) | `[inline]`

Definition at line 175 of file SSE.h.

    { v = _mm_div_ps( v, o.v ); };

HWVector operator* | ( | const HWVector & | o | ) | const `[inline]`

Definition at line 176 of file SSE.h.

    { HWVector r; r.v = _mm_mul_ps( v, o.v ); return r; };

HWVector operator* | ( | float | f | ) | const `[inline]`

Definition at line 177 of file SSE.h.

    { HWVector r; r.v = _mm_mul_ps( v, _mm_set1_ps( f ) ); return r; };

HWVector operator/ | ( | const HWVector & | o | ) | const `[inline]`

Definition at line 178 of file SSE.h.

    { HWVector r; r.v = _mm_div_ps( v, o.v ); return r; };

void operator*= | ( | float | f | ) | `[inline]`

Definition at line 179 of file SSE.h.

    { v = _mm_mul_ps( v, _mm_set1_ps(f ) ); };

void Store | ( | float * | p | ) | `[inline]`

Search for all occurrences

Definition at line 180 of file SSE.h.

    { _mm_storeu_ps( p, v ); };

void Load | ( | float | f | ) | `[inline]`

Search for all occurrences

Definition at line 181 of file SSE.h.

    { v = _mm_set_ps1( f ); };

void StoreNormalAsInt | ( | int * | pBuffer | ) | const `[inline]`

Search for all occurrences

Definition at line 182 of file SSE.h.

        {
            //static __declspec(align(16)) float c[4] = { 32766.0f, 32766.0f, 32766.0f, 32766.0f };
            // instead of the correct value, we use a little bit smaller number, because after
            // normalization a component can be a littlebit bigger than 1.0. in that case storing it in
            // a 16 bit integer would overflow, and artifacts on the surface would appear.
            static const MB_SSE_ALIGN16_VAR(float c[4]) = { 32740.0f, 32740.0f, 32740.0f, 32740.0f };

            __m128 f = _mm_load_ps( c );
            f = _mm_mul_ps( f, v );
            __m128i i = _mm_cvtps_epi32( f );
            _mm_storeu_si128( (__m128i *)pBuffer, i );
        };

void StoreAsInt | ( | int * | pBuffer | ) | const `[inline]`

Search for all occurrences

Definition at line 195 of file SSE.h.

        {
            __m128i i = _mm_cvtps_epi32( v );
            _mm_storeu_si128( (__m128i *)pBuffer, i );
        };

operator float | ( | void |  | ) | const `[inline]`

Definition at line 200 of file SSE.h.

        {
            MB_SSE_ALIGN16_VAR(float f);
            _mm_store_ss( &f, v );
            return f;
        };

operator mudbox::Vector | ( | void |  | ) | const `[inline]`

Search for all occurrences

Definition at line 206 of file SSE.h.

        {
            mudbox::Vector r;
            __m128 t = _mm_shuffle_ps( v, v, _MM_SHUFFLE(2,1,0,3) );
            _mm_store_ss( &r.x, t );
            t = _mm_shuffle_ps( t, t, _MM_SHUFFLE(2,1,0,3) );
            _mm_store_ss( &r.y, t );
            t = _mm_shuffle_ps( t, t, _MM_SHUFFLE(2,1,0,3) );
            _mm_store_ss( &r.z, t );
            return r;
        };

operator mudbox::Vector4 | ( | void |  | ) | const `[inline]`

Search for all occurrences

Definition at line 217 of file SSE.h.

        {
            mudbox::Vector4 r;
            __m128 t = _mm_shuffle_ps( v, v, _MM_SHUFFLE(2,1,0,3) );
            _mm_store_ss( &r.x, t );
            t = _mm_shuffle_ps( t, t, _MM_SHUFFLE(2,1,0,3) );
            _mm_store_ss( &r.y, t );
            t = _mm_shuffle_ps( t, t, _MM_SHUFFLE(2,1,0,3) );
            _mm_store_ss( &r.z, t );
            t = _mm_shuffle_ps( t, t, _MM_SHUFFLE(2,1,0,3) );
            _mm_store_ss( &r.w, t );
            return r;
        };

MB_SSE_ALIGN16_VAR | ( | __m128 | v | ) |

Search for all occurrences

The documentation for this struct was generated from the following file:

- Mudbox/SSE.h