Commit c7022467d244f93a0848b39d1eb2c8506b66bc85

Alexei Podtelezhnikov 2014-08-14T23:01:01

Turn FT_MSB into a macro when using gcc builtins. * src/base/ftcalc.c, include/internal/ftcalc.h: Updated.

diff --git a/ChangeLog b/ChangeLog
index b6c5228..32aa534 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2014-08-13  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
+	Turn FT_MSB into a macro when using gcc builtins.
+
+	* src/base/ftcalc.c, include/internal/ftcalc.h: Updated.
+
 2014-08-12  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
 	[base] Avoid undefined FT_MSB in `BBox_Cubic_Check'.
diff --git a/include/internal/ftcalc.h b/include/internal/ftcalc.h
index ff4e611..b3cd618 100644
--- a/include/internal/ftcalc.h
+++ b/include/internal/ftcalc.h
@@ -261,22 +261,6 @@ FT_BEGIN_HEADER
 
 #endif /* __GNUC__ && __x86_64__ */
 
-#if defined( __GNUC__ )
-#if ( __GNUC__ > 3 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 4 ) )
-
-#if FT_SIZEOF_INT == 4
-
-#define FT_MSB_BUILTIN( x )  ( 31 - __builtin_clz( x ) )
-
-#elif FT_SIZEOF_LONG == 4
-
-#define FT_MSB_BUILTIN( x )  ( 31 - __builtin_clzl( x ) )
-
-#endif
-
-#endif
-#endif /* __GNUC__ */
-
 #endif /* !FT_CONFIG_OPTION_NO_ASSEMBLER */
 
 
@@ -367,9 +351,32 @@ FT_BEGIN_HEADER
   /*
    *  Return the most significant bit index.
    */
+
+#ifndef  FT_CONFIG_OPTION_NO_ASSEMBLER
+#if defined( __GNUC__ )
+#if ( __GNUC__ > 3 ) || ( ( __GNUC__ == 3 ) && ( __GNUC_MINOR__ >= 4 ) )
+
+#if FT_SIZEOF_INT == 4
+
+#define FT_MSB( x )  ( 31 - __builtin_clz( x ) )
+
+#elif FT_SIZEOF_LONG == 4
+
+#define FT_MSB( x )  ( 31 - __builtin_clzl( x ) )
+
+#endif
+
+#endif
+#endif /* __GNUC__ */
+#endif /* !FT_CONFIG_OPTION_NO_ASSEMBLER */
+
+#ifndef FT_MSB
+
   FT_BASE( FT_Int )
   FT_MSB( FT_UInt32  z );
 
+#endif
+
 
   /*
    *  Return sqrt(x*x+y*y), which is the same as `FT_Vector_Length' but uses
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index d12a981..9188e2c 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -100,16 +100,11 @@
                       : -((-a) & ~0xFFFFL );
   }
 
+#ifndef FT_MSB
 
   FT_BASE_DEF ( FT_Int )
   FT_MSB( FT_UInt32 z )
   {
-#ifdef FT_MSB_BUILTIN
-
-    return FT_MSB_BUILTIN( z );
-
-#else
-
     FT_Int shift = 0;
 
     /* determine msb bit index in `shift' */
@@ -140,10 +135,10 @@
     }
 
     return shift;
-
-#endif /* FT_MSB_BUILTIN */
   }
 
+#endif /* !FT_MSB */
+
 
   /* documentation is in ftcalc.h */