Commit 869fb8c49ddf292d6daf4826172a308973d3e11f

Alexei Podtelezhnikov 2013-01-23T19:43:28

[base] Split out MSB function. * src/base/fttrigon.c (ft_trig_prenorm): Borrow from here. * include/freetype/internal/ftcalc.h (FT_MSB): Declare here. * src/base/ftcalc.c (FT_MSB): Define here.

diff --git a/ChangeLog b/ChangeLog
index 114ddfb..01db3c4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-01-23  Alexei Podtelezhnikov  <apodtele@gmail.com>
+
+	[base] Split out MSB function.
+
+	* src/base/fttrigon.c (ft_trig_prenorm): Borrow from here.
+	* include/freetype/internal/ftcalc.h (FT_MSB): Declare here.
+	* src/base/ftcalc.c (FT_MSB): Define here.
+
 2013-01-22  Werner Lemberg  <wl@gnu.org>
 
 	[truetype] Fix font height.
diff --git a/include/freetype/internal/ftcalc.h b/include/freetype/internal/ftcalc.h
index 56aa07c..e4924d0 100644
--- a/include/freetype/internal/ftcalc.h
+++ b/include/freetype/internal/ftcalc.h
@@ -125,7 +125,6 @@ FT_BEGIN_HEADER
    *  A variant of FT_Vector_Transform.  See comments for
    *  FT_Matrix_Multiply_Scaled.
    */
-
   FT_BASE( void )
   FT_Vector_Transform_Scaled( FT_Vector*        vector,
                               const FT_Matrix*  matrix,
@@ -156,6 +155,13 @@ FT_BEGIN_HEADER
                      FT_Pos  out_y );
 
 
+  /*
+   *  Return the most significant bit index.
+   */  
+  FT_BASE( FT_Int )
+  FT_MSB( FT_UInt32 z );
+
+
 #define INT_TO_F26DOT6( x )    ( (FT_Long)(x) << 6  )
 #define INT_TO_F2DOT14( x )    ( (FT_Long)(x) << 14 )
 #define INT_TO_FIXED( x )      ( (FT_Long)(x) << 16 )
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index 2aeea04..4122fda 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -103,6 +103,42 @@
   }
 
 
+  FT_BASE_DEF ( FT_Int )
+  FT_MSB( FT_UInt32 z )
+  {
+    FT_Int shift = 0;
+
+    /* determine msb bit index in `shift' */
+    if ( z >= ( 1L << 16 ) )
+    {
+      z     >>= 16;
+      shift  += 16;
+    }
+    if ( z >= ( 1L << 8 ) )
+    {
+      z     >>= 8;
+      shift  += 8;
+    }
+    if ( z >= ( 1L << 4 ) )
+    {
+      z     >>= 4;
+      shift  += 4;
+    }
+    if ( z >= ( 1L << 2 ) )
+    {
+      z     >>= 2;
+      shift  += 2;
+    }
+    if ( z >= ( 1L << 1 ) )
+    {
+      z     >>= 1;
+      shift  += 1;
+    }
+
+    return shift;
+  }
+
+
 #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
 
   /* documentation is in ftcalc.h */
diff --git a/src/base/fttrigon.c b/src/base/fttrigon.c
index 4bd4320..e8cc3e3 100644
--- a/src/base/fttrigon.c
+++ b/src/base/fttrigon.c
@@ -118,42 +118,14 @@
   static FT_Int
   ft_trig_prenorm( FT_Vector*  vec )
   {
-    FT_Fixed  x, y, z;
+    FT_Fixed  x, y;
     FT_Int    shift;
 
 
     x = vec->x;
     y = vec->y;
 
-    z     = FT_ABS( x ) | FT_ABS( y );
-    shift = 0;
-
-    /* determine msb bit index in `shift' */
-    if ( z >= ( 1L << 16 ) )
-    {
-      z     >>= 16;
-      shift  += 16;
-    }
-    if ( z >= ( 1L << 8 ) )
-    {
-      z     >>= 8;
-      shift  += 8;
-    }
-    if ( z >= ( 1L << 4 ) )
-    {
-      z     >>= 4;
-      shift  += 4;
-    }
-    if ( z >= ( 1L << 2 ) )
-    {
-      z     >>= 2;
-      shift  += 2;
-    }
-    if ( z >= ( 1L << 1 ) )
-    {
-      z    >>= 1;
-      shift += 1;
-    }
+    shift = FT_MSB( FT_ABS( x ) | FT_ABS( y ) );
 
     if ( shift <= FT_TRIG_SAFE_MSB )
     {