[PATCH 1/5] checksum: improve add32

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


Gcc does not recognize z + (z < sum) as an "add with carry"
However, x86 recognizes if (z < x) z++ as an
"add with carry" operation so lets use that instead.

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

diff --git a/lib/checksum.c b/lib/checksum.c
index 33cb386..bf70cab 100644
--- a/lib/checksum.c
+++ b/lib/checksum.c
@@ -26,7 +26,9 @@ static u32
 add32(u32 sum, u32 x)
 {
   u32 z = sum + x;
-  return z + (z < sum);
+  if (z < x)
+      z++;
+  return z;
 }
 
 static u16
-- 
1.6.4.4




More information about the Bird-users mailing list