[Mesa-dev] [PATCH] util: Use LONG_MAX instead of LONG_BIT.
Jose Fonseca
jfonseca at vmware.com
Sun Aug 9 14:51:08 PDT 2015
Indeed, given these are Mesa internal functions, we could indeed have
then return int32 or int64 and side-step this problem completely.
Especially because the callers of these function might care about those
things too.
Nothing prevents we do that in the medium term, but in the short term
this change gets everything building and running again.
Jose
On 09/08/15 22:44, Roland Scheidegger wrote:
> Looks good to me. Would have been much less trouble if we'd just
> returned an int, to hell with lrintf's long return type no callers will
> care about the long returned anyway...
>
> Reviewed-by: Roland Scheidegger <sroland at vmware.com>
>
>
> Am 09.08.2015 um 23:40 schrieb Jose Fonseca:
>> 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 bare/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"
>>
>
More information about the mesa-dev
mailing list