HWVector Struct Reference

HWVector Struct Reference

#include <SSE.h>

Class Description

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

Definition at line 64 of file SSE.h.

Public Member Functions

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

Constructor & Destructor Documentation

HWVector ( void  )
inline

Definition at line 66 of file SSE.h.

66 {};
HWVector ( float  f)
inline

Definition at line 73 of file SSE.h.

74  {
75  v = _mm_set_ps1( f );
76  }
const GLdouble * v
Definition: GLee.h:1174
GLclampf f
Definition: GLee.h:9303
HWVector ( const mudbox::Vector h)
inline

Definition at line 78 of file SSE.h.

79  {
80  v = _mm_set_ps( h.x, h.y, h.z, 0);
81  };
float z
Definition: math.h:340
float y
Definition: math.h:340
const GLdouble * v
Definition: GLee.h:1174
float x
Definition: math.h:340
HWVector ( float  x,
float  y,
float  z,
float  w = 0 
)
inline

Definition at line 82 of file SSE.h.

83  {
84  v = _mm_set_ps( x,y,z,w );
85  };
GLenum GLint GLint y
Definition: GLee.h:876
GLdouble GLdouble z
Definition: GLee.h:1393
GLenum GLint x
Definition: GLee.h:876
const GLdouble * v
Definition: GLee.h:1174
GLubyte GLubyte GLubyte GLubyte w
Definition: GLee.h:1775
HWVector ( const float  a[4])
inline

Definition at line 87 of file SSE.h.

88  {
89  v = _mm_loadu_ps( a );
90  };
const GLdouble * v
Definition: GLee.h:1174
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404

Member Function Documentation

void setZero ( void  )
inline

Definition at line 68 of file SSE.h.

69  {
70  v = _mm_setzero_ps();
71  }
const GLdouble * v
Definition: GLee.h:1174
void Fill ( const mudbox::Vector vVector)
HWVector ShiftLeft ( void  ) const
inline

Definition at line 91 of file SSE.h.

91 { HWVector r; r.v = _mm_shuffle_ps(v,v,_MM_SHUFFLE(2,1,3,0)); return r; };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
void ShiftLeft ( HWVector result)
inline

Definition at line 92 of file SSE.h.

92 { result.v = _mm_shuffle_ps(v,v,_MM_SHUFFLE(2,1,3,0)); }
const GLdouble * v
Definition: GLee.h:1174
void ShiftLeftInPlace ( )
inline

Definition at line 93 of file SSE.h.

93 { v = _mm_shuffle_ps(v,v,_MM_SHUFFLE(2,1,3,0)); }
const GLdouble * v
Definition: GLee.h:1174
HWVector ShiftRight ( void  ) const
inline

Definition at line 94 of file SSE.h.

94 { HWVector r; r.v = _mm_shuffle_ps(v,v,_MM_SHUFFLE(1,3,2,0)); return r; };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
void ShiftRight ( HWVector result)
inline

Definition at line 95 of file SSE.h.

95 { result.v = _mm_shuffle_ps(v,v,_MM_SHUFFLE(1,3,2,0)); };
const GLdouble * v
Definition: GLee.h:1174
HWVector operator& ( HWVector o)
inline

Definition at line 96 of file SSE.h.

97  {
98  //HWVector al = (*this).ShiftLeft(), bl = o.ShiftLeft(), ar = (*this).ShiftRight(), br = o.ShiftRight();
99  HWVector al, bl, ar, br;
100  ShiftLeft(al);
101  o.ShiftLeft(bl);
102  ShiftRight(ar);
103  o.ShiftRight(br);
104 
105  return al*br-ar*bl;
106  };
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
HWVector ShiftLeft(void) const __attribute__((always_inline))
Definition: SSE.h:91
HWVector ShiftRight(void) const __attribute__((always_inline))
Definition: SSE.h:94
HWVector operator| ( const HWVector o) const
inline

Definition at line 108 of file SSE.h.

109  {
110  HWVector r;
111  r.v = _mm_mul_ps( v, o.v );
112  // Requires SSE3
113  r.v = _mm_hadd_ps( r.v, r.v );
114  r.v = _mm_hadd_ps( r.v, r.v );
115  return r;
116  };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
HWVector Length ( void  ) const
inline

Definition at line 118 of file SSE.h.

119  {
120  HWVector r = operator |( *this );
121  r.v = _mm_sqrt_ss( r.v );
122  return r;
123  };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
HWVector operator|(const HWVector &o) const __attribute__((always_inline))
Definition: SSE.h:108
HWVector LengthSquared ( void  ) const
inline

Definition at line 125 of file SSE.h.

126  {
127  HWVector r = operator |( *this );
128  return r;
129  };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
HWVector operator|(const HWVector &o) const __attribute__((always_inline))
Definition: SSE.h:108
float DistanceFromLine ( const HWVector vStart,
const HWVector vEnd 
) const
inline

Definition at line 131 of file SSE.h.

132  {
133  HWVector n = vEnd - vStart;
134  HWVector m = (*this)-vStart;
135  HWVector h = n&m;
136  HWVector d = n&h;
137  d.Normalize();
138  float fDistance = (d|(*this))-(d|vStart);
139  return fDistance>0?fDistance:(-fDistance);
140  }
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
GLenum GLsizei n
Definition: GLee.h:3432
void Normalize(void) __attribute__((always_inline))
Definition: SSE.h:142
int int int int int int h
Definition: GLee.h:10534
void Normalize ( void  )
inline

Definition at line 142 of file SSE.h.

143  {
144  HWVector f = operator |( *this );
145  f.v = _mm_rsqrt_ps( f.v );
146  v = _mm_mul_ps( f.v, v );
147  };
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
HWVector operator|(const HWVector &o) const __attribute__((always_inline))
Definition: SSE.h:108
GLclampf f
Definition: GLee.h:9303
HWVector Floor ( void  )
inline

Definition at line 149 of file SSE.h.

150  {
151  static const unsigned int a = (1 << 23);
152  static const float twoTo23AsFloat = (float)a;
153  static const __m128 twoTo23 = _mm_set_ps( twoTo23AsFloat, twoTo23AsFloat, twoTo23AsFloat, twoTo23AsFloat );
154  // b = fabs(v)
155  __m128 b = _mm_castsi128_ps(_mm_srli_epi32( _mm_slli_epi32( _mm_castps_si128(v),1 ), 1 ));
156  // The essence of the floor routine
157  __m128 d = _mm_sub_ps( _mm_add_ps( _mm_add_ps( _mm_sub_ps( v, twoTo23 ), twoTo23 ), twoTo23 ), twoTo23 );
158  // set mask to all 1s if v >= 2**23
159  __m128 largeMaskE = _mm_cmpgt_ps( b, twoTo23 );
160  // Check for possible off by one error
161  __m128 g = _mm_cmplt_ps( v, d );
162  // Convert positive check result to -1.0, negative to 0.0
163  __m128 h = _mm_cvtepi32_ps( _mm_castps_si128(g) );
164  // Add in the error if there is one
165  __m128 t = _mm_add_ps( d, h );
166  // Select between output result and input value based on v >= 2**23
167  __m128 w = _mm_and_ps( v, largeMaskE );
168  t = _mm_andnot_ps( largeMaskE, t );
169  HWVector vResult;
170  vResult.v = _mm_or_ps( t, w );
171  return vResult;
172  };
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
GLubyte g
Definition: GLee.h:5404
const GLdouble * v
Definition: GLee.h:1174
GLubyte GLubyte b
Definition: GLee.h:5404
int int int int int int h
Definition: GLee.h:10534
GLubyte GLubyte GLubyte a
Definition: GLee.h:5404
GLubyte GLubyte GLubyte GLubyte w
Definition: GLee.h:1775
GLdouble GLdouble t
Definition: GLee.h:1181
HWVector Minimum ( const HWVector o) const
inline

Definition at line 174 of file SSE.h.

174 { HWVector r; r.v = _mm_min_ps( v, o.v ); return r; };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
HWVector Maximum ( const HWVector o) const
inline

Definition at line 175 of file SSE.h.

175 { HWVector r; r.v = _mm_max_ps( v, o.v ); return r; };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
HWVector operator+ ( const HWVector o) const
inline

Definition at line 176 of file SSE.h.

176 { HWVector r; r.v = _mm_add_ps( v, o.v ); return r; };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
HWVector operator- ( const HWVector o) const
inline

Definition at line 177 of file SSE.h.

177 { HWVector r; r.v = _mm_sub_ps( v, o.v ); return r; };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
void operator+= ( const HWVector o)
inline

Definition at line 178 of file SSE.h.

178 { v = _mm_add_ps( v, o.v ); };
const GLdouble * v
Definition: GLee.h:1174
void operator-= ( const HWVector o)
inline

Definition at line 179 of file SSE.h.

179 { v = _mm_sub_ps( v, o.v ); };
const GLdouble * v
Definition: GLee.h:1174
void operator*= ( const HWVector o)
inline

Definition at line 180 of file SSE.h.

180 { v = _mm_mul_ps( v, o.v ); };
const GLdouble * v
Definition: GLee.h:1174
void operator/= ( const HWVector o)
inline

Definition at line 181 of file SSE.h.

181 { v = _mm_div_ps( v, o.v ); };
const GLdouble * v
Definition: GLee.h:1174
HWVector operator* ( const HWVector o) const
inline

Definition at line 182 of file SSE.h.

182 { HWVector r; r.v = _mm_mul_ps( v, o.v ); return r; };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
HWVector operator* ( float  f) const
inline

Definition at line 183 of file SSE.h.

183 { HWVector r; r.v = _mm_mul_ps( v, _mm_set1_ps( f ) ); return r; };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
GLclampf f
Definition: GLee.h:9303
HWVector operator/ ( const HWVector o) const
inline

Definition at line 184 of file SSE.h.

184 { HWVector r; r.v = _mm_div_ps( v, o.v ); return r; };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
This class represents a four dimensional vector stored in the SSE registers.
Definition: SSE.h:64
const GLdouble * v
Definition: GLee.h:1174
void operator*= ( float  f)
inline

Definition at line 185 of file SSE.h.

185 { v = _mm_mul_ps( v, _mm_set1_ps(f ) ); };
const GLdouble * v
Definition: GLee.h:1174
GLclampf f
Definition: GLee.h:9303
void Store ( float *  p)
inline

Definition at line 186 of file SSE.h.

186 { _mm_storeu_ps( p, v ); };
const GLdouble * v
Definition: GLee.h:1174
GLfloat GLfloat p
Definition: GLee.h:5416
void Load ( float  f)
inline

Definition at line 187 of file SSE.h.

187 { v = _mm_set_ps1( f ); };
const GLdouble * v
Definition: GLee.h:1174
GLclampf f
Definition: GLee.h:9303
void StoreNormalAsInt ( int pBuffer) const
inline

Definition at line 188 of file SSE.h.

189  {
190  //static __declspec(align(16)) float c[4] = { 32766.0f, 32766.0f, 32766.0f, 32766.0f };
191  // instead of the correct value, we use a little bit smaller number, because after
192  // normalization a component can be a littlebit bigger than 1.0. in that case storing it in
193  // a 16 bit integer would overflow, and artifacts on the surface would appear.
194  static const MB_SSE_ALIGN16_VAR(float c[4]) = { 32740.0f, 32740.0f, 32740.0f, 32740.0f };
195 
196  __m128 f = _mm_load_ps( c );
197  f = _mm_mul_ps( f, v );
198  __m128i i = _mm_cvtps_epi32( f );
199  _mm_storeu_si128( (__m128i *)pBuffer, i );
200  };
MB_SSE_ALIGN16_VAR(__m128 v)
const GLdouble * v
Definition: GLee.h:1174
const GLubyte * c
Definition: GLee.h:5419
GLclampf f
Definition: GLee.h:9303
void StoreAsInt ( int pBuffer) const
inline

Definition at line 201 of file SSE.h.

202  {
203  __m128i i = _mm_cvtps_epi32( v );
204  _mm_storeu_si128( (__m128i *)pBuffer, i );
205  };
const GLdouble * v
Definition: GLee.h:1174
void StoreAsIntTruncate ( int pBuffer) const
inline

Definition at line 206 of file SSE.h.

207  {
208  __m128i i = _mm_cvttps_epi32( v );
209  _mm_storeu_si128( (__m128i *)pBuffer, i );
210  };
const GLdouble * v
Definition: GLee.h:1174
operator float ( void  ) const
inline

Definition at line 211 of file SSE.h.

212  {
213  MB_SSE_ALIGN16_VAR(float f);
214  _mm_store_ss( &f, v );
215  return f;
216  };
MB_SSE_ALIGN16_VAR(__m128 v)
const GLdouble * v
Definition: GLee.h:1174
GLclampf f
Definition: GLee.h:9303
operator mudbox::Vector ( void  ) const
inline

Definition at line 217 of file SSE.h.

218  {
220  __m128 t = _mm_shuffle_ps( v, v, _MM_SHUFFLE(2,1,0,3) );
221  _mm_store_ss( &r.x, t );
222  t = _mm_shuffle_ps( t, t, _MM_SHUFFLE(2,1,0,3) );
223  _mm_store_ss( &r.y, t );
224  t = _mm_shuffle_ps( t, t, _MM_SHUFFLE(2,1,0,3) );
225  _mm_store_ss( &r.z, t );
226  return r;
227  };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
float z
Definition: math.h:340
Represents a 3D vector or point with S23E8 floating point elements.
Definition: math.h:35
float y
Definition: math.h:340
const GLdouble * v
Definition: GLee.h:1174
GLdouble GLdouble t
Definition: GLee.h:1181
float x
Definition: math.h:340
operator mudbox::Vector4 ( void  ) const
inline

Definition at line 228 of file SSE.h.

229  {
231  __m128 t = _mm_shuffle_ps( v, v, _MM_SHUFFLE(2,1,0,3) );
232  _mm_store_ss( &r.x, t );
233  t = _mm_shuffle_ps( t, t, _MM_SHUFFLE(2,1,0,3) );
234  _mm_store_ss( &r.y, t );
235  t = _mm_shuffle_ps( t, t, _MM_SHUFFLE(2,1,0,3) );
236  _mm_store_ss( &r.z, t );
237  t = _mm_shuffle_ps( t, t, _MM_SHUFFLE(2,1,0,3) );
238  _mm_store_ss( &r.w, t );
239  return r;
240  };
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
float z
Definition: math.h:632
float y
Definition: math.h:632
float w
Definition: math.h:632
A four dimensionsional vector (X, Y, Z, and W)
Definition: math.h:617
const GLdouble * v
Definition: GLee.h:1174
float x
Definition: math.h:632
GLdouble GLdouble t
Definition: GLee.h:1181
MB_SSE_ALIGN16_VAR ( __m128  v)

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