[PATCH 2/5] checksum: Optimize add32() for PowerPC

Joakim Tjernlund Joakim.Tjernlund at transmode.se
Sun Apr 25 11:41:19 CEST 2010


PowerPC does not recognize add32() as an "add with carry"
operation so use inline assembler instead.

Signed-off-by: Joakim Tjernlund <Joakim.Tjernlund at transmode.se>
---
 lib/checksum.c |   12 +++++++++++-
 1 files changed, 11 insertions(+), 1 deletions(-)

diff --git a/lib/checksum.c b/lib/checksum.c
index bf70cab..cd0fefd 100644
--- a/lib/checksum.c
+++ b/lib/checksum.c
@@ -21,7 +21,16 @@ add16(u16 sum, u16 x)
   u16 z = sum + x;
   return z + (z < sum);
 }
-
+#ifdef __powerpc__
+static
+u32
+add32(u32 sum, u32 x)
+{
+    /* add and set carry; add carry */
+    asm ("addc %0, %0, %1; addze %0, %0": "+r"(sum): "r" (x): "xer");
+    return sum;
+}
+#else
 static u32
 add32(u32 sum, u32 x)
 {
@@ -30,6 +39,7 @@ add32(u32 sum, u32 x)
       z++;
   return z;
 }
+#endif
 
 static u16
 ipsum_calc_block(u16 *x, unsigned len, u16 sum)
-- 
1.6.4.4




More information about the Bird-users mailing list