aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar David Leverton <levertond@googlemail.com> 2010-01-01 15:18:45 +0000
committerAvatar David Leverton <levertond@googlemail.com> 2010-01-01 15:42:00 +0000
commite296bb507b7bd09ff844ec3607cdde4b6c4ba3ae (patch)
tree275aa4963397e0c01d1986d2aabb091b3fae3758
parent3993ba5b86f8a68e9ea64723198e4a06cbc1d8ff (diff)
downloadpaludis-e296bb507b7bd09ff844ec3607cdde4b6c4ba3ae.tar.gz
paludis-e296bb507b7bd09ff844ec3607cdde4b6c4ba3ae.tar.xz
Speed up SHA1 somewhat
On a ~300 megabyte file, g++ 4.3.4: Old version, -march=core2 -O2: ~5.0 seconds New version, -march=core2 -O2: ~3.95 seconds Old version, -march=core2 -O3: ~4.4 seconds New version, -march=core2 -O3: ~3.3 seconds For comparison: sha1sum, coreutils 7.5, -march=core2 -O2: ~2.75 seconds OpenSSL 0.9.8l, -march=core2 -O2: ~2.15 seconds so there's still some way to go yet
-rw-r--r--paludis/util/sha1.cc26
1 files changed, 16 insertions, 10 deletions
diff --git a/paludis/util/sha1.cc b/paludis/util/sha1.cc
index e3df4f8..fc2b54f 100644
--- a/paludis/util/sha1.cc
+++ b/paludis/util/sha1.cc
@@ -104,7 +104,7 @@ namespace
static const uint32_t k = 0xCA62C1D6U;
};
- template <int t_, int u_>
+ template <int t_, int u_, int i_ = t_>
struct ProcessChunk : ChunkParams<t_, u_>
{
using ChunkParams<t_, u_>::f;
@@ -112,15 +112,21 @@ namespace
static void process(uint32_t * w, uint32_t & a, uint32_t & b, uint32_t & c, uint32_t & d, uint32_t & e)
{
- for (int t = t_; t < u_; ++t)
- {
- uint32_t temp(s<5>(a) + f(b, c, d) + e + w[t] + k);
- e = d;
- d = c;
- c = s<30>(b);
- b = a;
- a = temp;
- }
+ uint32_t temp(s<5>(a) + f(b, c, d) + e + w[i_] + k);
+ e = d;
+ d = c;
+ c = s<30>(b);
+ b = a;
+ a = temp;
+ ProcessChunk<t_, u_, i_ + 1>::process(w, a, b, c, d, e);
+ }
+ };
+
+ template <int t_, int u_>
+ struct ProcessChunk<t_, u_, u_>
+ {
+ static void process(uint32_t *, uint32_t &, uint32_t &, uint32_t &, uint32_t &, uint32_t &)
+ {
}
};
}