[base] Clean up. * src/base/ftcalc.c (FT_MOVE_SIGN): New macro for frequently used code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
diff --git a/ChangeLog b/ChangeLog
index f5666bc..4e26bde 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2014-09-30 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [base] Clean up.
+
+ * src/base/ftcalc.c (FT_MOVE_SIGN): New macro for frequently used
+ code.
+
2014-09-25 Alexei Podtelezhnikov <apodtele@gmail.com>
[base] Avoid unnecessary long division.
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index bee5170..13bd656 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -68,6 +68,16 @@
#define FT_COMPONENT trace_calc
+ /* transfer sign leaving a positive number */
+#define FT_MOVE_SIGN( x, s ) \
+ FT_BEGIN_STMNT \
+ if ( x < 0 ) \
+ { \
+ x = -x; \
+ s = -s; \
+ } \
+ FT_END_STMNT
+
/* The following three functions are available regardless of whether */
/* FT_LONG64 is defined. */
@@ -170,9 +180,9 @@
FT_Long d;
- if ( a < 0 ) { a = -a; s = -1; }
- if ( b < 0 ) { b = -b; s = -s; }
- if ( c < 0 ) { c = -c; s = -s; }
+ FT_MOVE_SIGN( a, s );
+ FT_MOVE_SIGN( b, s );
+ FT_MOVE_SIGN( c, s );
d = (FT_Long)( c > 0 ? ( (FT_Int64)a * b + ( c >> 1 ) ) / c
: 0x7FFFFFFFL );
@@ -192,9 +202,9 @@
FT_Long d;
- if ( a < 0 ) { a = -a; s = -1; }
- if ( b < 0 ) { b = -b; s = -s; }
- if ( c < 0 ) { c = -c; s = -s; }
+ FT_MOVE_SIGN( a, s );
+ FT_MOVE_SIGN( b, s );
+ FT_MOVE_SIGN( c, s );
d = (FT_Long)( c > 0 ? (FT_Int64)a * b / c
: 0x7FFFFFFFL );
@@ -219,8 +229,8 @@
FT_Long c;
- if ( a < 0 ) { a = -a; s = -1; }
- if ( b < 0 ) { b = -b; s = -s; }
+ FT_MOVE_SIGN( a, s );
+ FT_MOVE_SIGN( b, s );
c = (FT_Long)( ( (FT_Int64)a * b + 0x8000L ) >> 16 );
@@ -240,8 +250,8 @@
FT_Long q;
- if ( a < 0 ) { a = -a; s = -1; }
- if ( b < 0 ) { b = -b; s = -s; }
+ FT_MOVE_SIGN( a, s );
+ FT_MOVE_SIGN( b, s );
q = (FT_Long)( b > 0 ? ( ( (FT_UInt64)a << 16 ) + ( b >> 1 ) ) / b
: 0x7FFFFFFFL );
@@ -394,9 +404,9 @@
if ( a == 0 || b == c )
return a;
- if ( a < 0 ) { a = -a; s = -1; }
- if ( b < 0 ) { b = -b; s = -s; }
- if ( c < 0 ) { c = -c; s = -s; }
+ FT_MOVE_SIGN( a, s );
+ FT_MOVE_SIGN( b, s );
+ FT_MOVE_SIGN( c, s );
if ( c == 0 )
a = 0x7FFFFFFFL;
@@ -435,9 +445,9 @@
if ( a == 0 || b == c )
return a;
- if ( a < 0 ) { a = -a; s = -1; }
- if ( b < 0 ) { b = -b; s = -s; }
- if ( c < 0 ) { c = -c; s = -s; }
+ FT_MOVE_SIGN( a, s );
+ FT_MOVE_SIGN( b, s );
+ FT_MOVE_SIGN( c, s );
if ( c == 0 )
a = 0x7FFFFFFFL;
@@ -538,8 +548,8 @@
if ( a == 0 || b == 0x10000L )
return a;
- if ( a < 0 ) { a = -a; s = -1; }
- if ( b < 0 ) { b = -b; s = -s; }
+ FT_MOVE_SIGN( a, s );
+ FT_MOVE_SIGN( b, s );
ua = (FT_ULong)a;
ub = (FT_ULong)b;
@@ -573,8 +583,9 @@
/* XXX: this function does not allow 64-bit arguments */
- if ( a < 0 ) { a = -a; s = -1; }
- if ( b < 0 ) { b = -b; s = -s; }
+
+ FT_MOVE_SIGN( a, s );
+ FT_MOVE_SIGN( b, s );
if ( b == 0 )
{