]> arthur.barton.de Git - bup.git/commitdiff
_hashsplit.c: switch rollsum_roll() to a macro instead of an inline function.
authorAvery Pennarun <apenwarr@gmail.com>
Tue, 27 Jul 2010 07:06:26 +0000 (03:06 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Wed, 28 Jul 2010 04:43:55 +0000 (00:43 -0400)
gcc 4.3's optimizer manages to fail at optimizing the inline, but works okay
with the macro.

Mysteriously, if find_ofs() is *not* static (and therefore presumably
*harder* to optimize), the optimizer works either way.  But removing the
static is just wrong, so use the macro instead.

The difference in speed is about 53 megs/sec vs 80 megs/sec on my machine
for this command:

bup random 100M 2>/dev/null | bup split -N --bench

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
lib/bup/_hashsplit.c

index e5b7745f57d821a6e7488a00b15051c937643629..6994f42d36898c00887a548c0954e1d779819081 100644 (file)
@@ -31,12 +31,14 @@ static void rollsum_init(Rollsum *r)
 }
 
 
-static void rollsum_roll(Rollsum *r, uint8_t ch)
-{
-    rollsum_add(r, r->window[r->wofs], ch);
-    r->window[r->wofs] = ch;
-    r->wofs = (r->wofs + 1) % WINDOWSIZE;
-}
+// For some reason, gcc 4.3 (at least) optimizes badly if find_ofs()
+// is static and rollsum_roll is an inline function.  Let's use a macro
+// here instead to help out the optimizer.
+#define rollsum_roll(r, ch) do { \
+    rollsum_add((r), (r)->window[(r)->wofs], (ch)); \
+    (r)->window[(r)->wofs] = (ch); \
+    (r)->wofs = ((r)->wofs + 1) % WINDOWSIZE; \
+} while (0)
 
 
 static uint32_t rollsum_sum(uint8_t *buf, size_t ofs, size_t len)