freetype-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ft-devel] [PATCH] Improve FT_MulFix


From: James Cloos
Subject: [ft-devel] [PATCH] Improve FT_MulFix
Date: Mon, 04 Apr 2011 12:03:49 -0400
User-agent: Gnus/5.110016 (No Gnus v0.16) Emacs/24.0.50 (gnu/linux)

Please consider pulling the master branch of:

git://anongit.freedesktop.org/~cloos/freetype2.git

to receive the patch below.

I tested a wide array of gcc cross compilers as well as clang/llvm.
In each case the machine code this version produces is as good as
the hand-tuned assembly and uses the trick that adding 0x7FFF when
the product is negative causes the same round-away-from-zero that
the current code does.

commit 94dc0c20554f3a3d709711f2c43ac65ab7c68afe
Author: James Cloos <address@hidden>
Date:   Mon Apr 4 11:35:39 2011 -0400

Improve the version of FT_MulFix() which is used when a sixty-four bit
interger type is available.

Signed-off-by: James Cloos <address@hidden>
---
 ChangeLog         |    4 ++++
 src/base/ftcalc.c |   20 +++-----------------
 2 files changed, 7 insertions(+), 17 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0744fa5..af3c908 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2011-04-04  James Cloos  <address@hidden>
+       * src/base/ftcalc.c (FT_MulFix): Produce more efficient
+       assembly.
+
 2011-04-04  Werner Lemberg  <address@hidden>
 
        Fix formatting of autofit debug dumps.
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index 3892fab..b7866ab 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -202,25 +202,11 @@
 
 #else
 
-    FT_Int   s = 1;
-    FT_Long  c;
+    FT_Int64  c;
 
+    c = (FT_Int64)a * b;
 
-    if ( a < 0 )
-    {
-      a = -a;
-      s = -1;
-    }
-
-    if ( b < 0 )
-    {
-      b = -b;
-      s = -s;
-    }
-
-    c = (FT_Long)( ( (FT_Int64)a * b + 0x8000L ) >> 16 );
-
-    return ( s > 0 ) ? c : -c;
+    return (FT_Long)((c + 0x8000 - (c < 0)) >> 16);
 
 #endif /* FT_MULFIX_ASSEMBLER */
   }
-- 
1.7.4.1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]