MCPcopy Create free account
hub / github.com/EricLengyel/Terathon-Math-Library / InverseSqrt

Method InverseSqrt

TSMath.cpp:191–220  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191float Terathon::InverseSqrt(float x)
192{
193 #ifdef TERATHON_SSE
194
195 float result;
196
197 vec_float v = _mm_load_ss(&x);
198 vec_float mask = _mm_cmplt_ss(v, VecLoadScalarConstant<0x00800000>());
199
200 vec_float r = _mm_rsqrt_ss(v);
201 r = _mm_mul_ss(_mm_sub_ss(VecLoadScalarConstant<0x40400000>(), _mm_mul_ss(v, _mm_mul_ss(r, r))), _mm_mul_ss(r, VecLoadScalarConstant<0x3F000001>()));
202
203 _mm_store_ss(&result, _mm_or_ps(_mm_andnot_ps(mask, r), _mm_and_ps(mask, VecLoadScalarConstant<0x7F800000>())));
204 return (result);
205
206 #else
207
208 if (x < Math::min_float)
209 {
210 return (Math::infinity);
211 }
212
213 uint32 i = 0x5F375A86 - (asuint(x) >> 1);
214 float r = asfloat(i);
215 r = (0.5F * r) * (3.0F - x * r * r);
216 r = (0.5F * r) * (3.0F - x * r * r);
217 return (r);
218
219 #endif
220}
221
222float Terathon::Sin(float x)
223{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected