Monday, March 19, 2007

A Small Start on SHA1 Performance Part IV

Using apfelmus' suggestions saves a bit more time but the improvement isn't dramatic. The code is here.

dom@heisenberg:~/sha11/sha1> time ./perfTest ../../sha1/eg
737be686da2aac4bbfb4cee3fc7dfa825f1d48a3
Success

real 0m2.225s
user 0m2.180s
sys 0m0.036s


The function which consumes most of the time is shown below but it's difficult to see how it can be improved.


oneBlock ss xs = tt
where
us :: Array Int Word32
us =
accumArray (curry snd) 0 (0,79) (zip [0..15] xs ++ map (\(x,y) -> (x, rotL 1 y))[(i, xxor i) | i<-[16..79]])
where
xxor i = us ! (i-16) `xor` us ! (i-3) `xor` us ! (i-8) `xor` us ! (i-14)
g (AccAndWord160 n (Word160 a b c d e)) w =
AccAndWord160 (n+1) (Word160 ((rotL 5 a) + (f n b c d) + e + w + (k n)) a (rotL 30 b) c d)
(AccAndWord160 _ tt) = foldl' g (AccAndWord160 0 ss) (elems us)


If you are going to build the code then here is the appropriate command line.


ghc -fglasgow-exts --make perfTest.hs -o perfTest -O -fvia-C -funbox-strict-fields

No comments: