[Mesa-dev] Mesa (master): Use signbit() in IS_NEGATIVE and DIFFERENT_SIGNS

Matt Turner mattst88 at gmail.com
Mon Sep 24 11:43:55 PDT 2012


On Mon, Sep 24, 2012 at 11:02 AM, Brian Paul <brianp at vmware.com> wrote:
> On 09/24/2012 10:49 AM, Matt Turner wrote:
>>
>> Module: Mesa
>> Branch: master
>> Commit: 0f3ba405eada72e1ab4371948315b28608903927
>> URL:
>> http://cgit.freedesktop.org/mesa/mesa/commit/?id=0f3ba405eada72e1ab4371948315b28608903927
>>
>> Author: Matt Turner<mattst88 at gmail.com>
>> Date:   Fri Sep 14 16:04:40 2012 -0700
>>
>> Use signbit() in IS_NEGATIVE and DIFFERENT_SIGNS
>>
>> signbit() appears to be available everywhere (even MSVC according to
>> MSDN), so let's use it instead of open-coding some messy and confusing
>> bit twiddling macros.
>>
>> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54805
>> Reviewed-by: Paul Berry<stereotype441 at gmail.com>
>> Suggested-by: Ian Romanick<ian.d.romanick at intel.com>
>>
>> ---
>>
>>   configure.ac           |    7 +++++++
>>   src/mesa/main/macros.h |   21 ++-------------------
>>   2 files changed, 9 insertions(+), 19 deletions(-)
>>
>> diff --git a/configure.ac b/configure.ac
>> index 4193496..cb65467 100644
>> --- a/configure.ac
>> +++ b/configure.ac
>> @@ -499,6 +499,13 @@ AC_SUBST([DLOPEN_LIBS])
>>   dnl See if posix_memalign is available
>>   AC_CHECK_FUNC([posix_memalign], [DEFINES="$DEFINES
>> -DHAVE_POSIX_MEMALIGN"])
>>
>> +dnl signbit() is a macro in glibc's math.h, so AC_CHECK_FUNC fails. To
>> handle
>> +dnl this, use AC_CHECK_DECLS and fallback to AC_CHECK_FUNC in case it
>> fails.
>> +AC_CHECK_DECLS([signbit],[],
>> +               AC_CHECK_FUNC([signbit],[],
>> +                             AC_MSG_ERROR([could not find signbit()])),
>> +               [#include<math.h>])
>> +
>>   dnl SELinux awareness.
>>   AC_ARG_ENABLE([selinux],
>>       [AS_HELP_STRING([--enable-selinux],
>> diff --git a/src/mesa/main/macros.h b/src/mesa/main/macros.h
>> index 04d59d7..7b7fd1b 100644
>> --- a/src/mesa/main/macros.h
>> +++ b/src/mesa/main/macros.h
>> @@ -693,31 +693,14 @@ NORMALIZE_3FV(GLfloat v[3])
>>   static inline GLboolean
>>   IS_NEGATIVE(float x)
>>   {
>> -#if defined(USE_IEEE)
>> -   fi_type fi;
>> -   fi.f = x;
>> -   return fi.i<  0;
>> -#else
>> -   return x<  0.0F;
>> -#endif
>> +   return signbit(x) != 0;
>>   }
>>
>> -
>>   /** Test two floats have opposite signs */
>>   static inline GLboolean
>>   DIFFERENT_SIGNS(GLfloat x, GLfloat y)
>>   {
>> -#if defined(USE_IEEE)
>> -   fi_type xfi, yfi;
>> -   xfi.f = x;
>> -   yfi.f = y;
>> -   return !!((xfi.i ^ yfi.i)&  (1u<<  31));
>> -#else
>> -   /* Could just use (x*y<0) except for the flatshading requirements.
>> -    * Maybe there's a better way?
>> -    */
>> -   return ((x) * (y)<= 0.0F&&  (x) - (y) != 0.0F);
>> -#endif
>> +   return signbit(x) != signbit(y);
>>   }
>>
>>
>
> Looks like we don't have signbit() on Windows.  We build with scons there so
> the autoconf check isn't applicable.  I'll post a patch in a bit.
>
> -Brian

MSDN claims that Windows does have signbit():
http://msdn.microsoft.com/en-us/library/hh308342.aspx


More information about the mesa-dev mailing list