mirror of
https://github.com/visualboyadvance-m/visualboyadvance-m
synced 2025-10-05 23:52:49 +02:00
Add fast-inverse SSE1 sqrt() from Quake 3 Arena
Add the Quake 3 Arena fast-inverse `sqrt()` using SSE1 intrinsics to third_party. Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
committed by
Rafael Kitover
parent
44aa859e6d
commit
d36f80b5e6
12
third_party/quake3-sqrt/quake3-sqrt.h
vendored
Normal file
12
third_party/quake3-sqrt/quake3-sqrt.h
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
// From Quake 3 Arena.
|
||||
|
||||
#include <immintrin.h>
|
||||
|
||||
inline float quake3_sqrt(float x) {
|
||||
__m128 y = _mm_set_ss(x);
|
||||
__m128 approx = _mm_rsqrt_ss(y);
|
||||
__m128 half_x = _mm_mul_ss(y, _mm_set_ss(0.5f));
|
||||
__m128 three_half = _mm_set_ss(1.5f);
|
||||
__m128 refined = _mm_mul_ss(approx, _mm_sub_ss(three_half, _mm_mul_ss(half_x, _mm_mul_ss(approx, approx))));
|
||||
return _mm_cvtss_f32(_mm_mul_ss(refined, y));
|
||||
}
|
Reference in New Issue
Block a user