[Mesa-dev] [PATCH] util: Use LONG_MAX instead of LONG_BIT.

Jose Fonseca jfonseca at vmware.com
Sun Aug 9 14:40:16 PDT 2015


More portable.  Based on Roland Scheidegger's idea.

Tested with roundevent_test on Linux, MinGW, and MSVC.

https://bugs.freedesktop.org/show_bug.cgi?id=91591
---
 src/util/rounding.h | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/src/util/rounding.h b/src/util/rounding.h
index 2d8f8d4..1116c31 100644
--- a/src/util/rounding.h
+++ b/src/util/rounding.h
@@ -28,6 +28,9 @@
 
 #include <math.h>
 #include <limits.h>
+#include <stdint.h>
+
+#include "macros.h" // STATIC_ASSERT
 
 /* SSE2 is supported on: all x86_64 targets, on x86 targets when -msse2 is
  * passed to GCC, and should also be enabled on all Windows builds. */
@@ -106,9 +109,11 @@ static inline long
 _mesa_lroundevenf(float x)
 {
 #ifdef HAVE_SSE2
-#if LONG_BIT == 64
+#if LONG_MAX == INT64_MAX
+   STATIC_ASSERT(sizeof(long) == 8);
    return _mm_cvtss_si64(_mm_load_ss(&x));
-#elif LONG_BIT == 32 || defined(_WIN32)
+#elif LONG_MAX == INT32_MAX
+   STATIC_ASSERT(sizeof(long) == 4);
    return _mm_cvtss_si32(_mm_load_ss(&x));
 #else
 #error "Unsupported or undefined LONG_BIT"
@@ -126,9 +131,11 @@ static inline long
 _mesa_lroundeven(double x)
 {
 #ifdef HAVE_SSE2
-#if LONG_BIT == 64
+#if LONG_MAX == INT64_MAX
+   STATIC_ASSERT(sizeof(long) == 8);
    return _mm_cvtsd_si64(_mm_load_sd(&x));
-#elif LONG_BIT == 32 || defined(_WIN32)
+#elif LONG_MAX == INT32_MAX
+   STATIC_ASSERT(sizeof(long) == 4);
    return _mm_cvtsd_si32(_mm_load_sd(&x));
 #else
 #error "Unsupported or undefined LONG_BIT"
-- 
2.1.4



More information about the mesa-dev mailing list