@@ -51,6 +51,12 @@ Index of this file:
51
51
#include < math.h> // sqrtf, fabsf, fmodf, powf, floorf, ceilf, cosf, sinf
52
52
#include < limits.h> // INT_MIN, INT_MAX
53
53
54
+ // Enable SSE intrinsics if available
55
+ #if defined __SSE__ || defined __x86_64__ || defined _M_X64
56
+ #define IMGUI_ENABLE_SSE
57
+ #include < immintrin.h>
58
+ #endif
59
+
54
60
// Visual Studio warnings
55
61
#ifdef _MSC_VER
56
62
#pragma warning (push)
@@ -390,6 +396,12 @@ static inline float ImAbs(float x) { return fabsf(x); }
390
396
static inline double ImAbs (double x) { return fabs (x); }
391
397
static inline float ImSign (float x) { return (x < 0 .0f ) ? -1 .0f : ((x > 0 .0f ) ? 1 .0f : 0 .0f ); } // Sign operator - returns -1, 0 or 1 based on sign of argument
392
398
static inline double ImSign (double x) { return (x < 0.0 ) ? -1.0 : ((x > 0.0 ) ? 1.0 : 0.0 ); }
399
+ #ifdef IMGUI_ENABLE_SSE
400
+ static inline float ImRsqrt (float x) { return _mm_cvtss_f32 (_mm_rsqrt_ss (_mm_set_ss (x))); }
401
+ #else
402
+ static inline float ImRsqrt (float x) { return 1 .0f / sqrtf (x); }
403
+ #endif
404
+ static inline double ImRsqrt (double x) { return 1.0 / sqrt (x); }
393
405
#endif
394
406
// - ImMin/ImMax/ImClamp/ImLerp/ImSwap are used by widgets which support variety of types: signed/unsigned int/long long float/double
395
407
// (Exceptionally using templates here but we could also redefine them for those types)
@@ -410,7 +422,7 @@ static inline ImVec4 ImLerp(const ImVec4& a, const ImVec4& b, float t)
410
422
static inline float ImSaturate (float f) { return (f < 0 .0f ) ? 0 .0f : (f > 1 .0f ) ? 1 .0f : f; }
411
423
static inline float ImLengthSqr (const ImVec2& lhs) { return (lhs.x * lhs.x ) + (lhs.y * lhs.y ); }
412
424
static inline float ImLengthSqr (const ImVec4& lhs) { return (lhs.x * lhs.x ) + (lhs.y * lhs.y ) + (lhs.z * lhs.z ) + (lhs.w * lhs.w ); }
413
- static inline float ImInvLength (const ImVec2& lhs, float fail_value) { float d = (lhs.x * lhs.x ) + (lhs.y * lhs.y ); if (d > 0 .0f ) return 1 . 0f / ImSqrt (d); return fail_value; }
425
+ static inline float ImInvLength (const ImVec2& lhs, float fail_value) { float d = (lhs.x * lhs.x ) + (lhs.y * lhs.y ); if (d > 0 .0f ) return ImRsqrt (d); return fail_value; }
414
426
static inline float ImFloor (float f) { return (float )(int )(f); }
415
427
static inline float ImFloorSigned (float f) { return (float )((f >= 0 || (int )f == f) ? (int )f : (int )f - 1 ); } // Decent replacement for floorf()
416
428
static inline ImVec2 ImFloor (const ImVec2& v) { return ImVec2 ((float )(int )(v.x ), (float )(int )(v.y )); }
0 commit comments