]> gitweb.factorcode.org Git - factor.git/commitdiff
checksums.superfast: reuse more code, slightly faster for non-byte-arrays.
authorJohn Benediktsson <mrjbq7@gmail.com>
Sun, 24 Nov 2013 17:58:02 +0000 (09:58 -0800)
committerJohn Benediktsson <mrjbq7@gmail.com>
Sun, 24 Nov 2013 17:58:02 +0000 (09:58 -0800)
basis/checksums/superfast/superfast.factor

index c883194e8522ee174ce034fb606755a09bf47a1b..44244928a17d718362f714cc53d883b00939165b 100644 (file)
@@ -12,24 +12,23 @@ C: <superfast> superfast
 
 <PRIVATE
 
+: 16-bit ( n -- n' ) 16 on-bits mask ; inline
+
 : 32-bit ( n -- n' ) 32 on-bits mask ; inline
 
-: (main-loop) ( hash m n -- hash' )
+: (main-loop) ( hash n -- hash' )
+    [ 16-bit ] [ -16 shift ] bi
     [ + ] [ 11 shift dupd bitxor ] bi*
     [ 16 shift ] [ bitxor ] bi* 32-bit
     [ -11 shift ] [ + ] bi ; inline
 
 : main-loop ( seq hash -- seq hash' )
     over byte-array? little-endian? and [
-        [ 0 over length 4 - 4 <range> ] dip [
-            pick <displaced-alien> int deref
-            [ 16 on-bits mask ] [ -16 shift ] bi
-            (main-loop)
-        ] reduce
+        [ 0 over length 4 - 4 <range> ] dip
+        [ pick <displaced-alien> int deref (main-loop) ] reduce
     ] [
-        [ dup length 4 mod dupd head-slice* 4 <groups> ] dip [
-            2 cut-slice [ le> ] bi@ (main-loop)
-        ] reduce
+        [ dup length 4 mod dupd head-slice* 4 <groups> ] dip
+        [ le> (main-loop) ] reduce
     ] if ; inline
 
 : end-case ( seq hash -- hash' )
@@ -52,12 +51,9 @@ C: <superfast> superfast
     } dispatch ; inline
 
 : avalanche ( hash -- hash' )
-    [ 3 shift ] [ bitxor ] bi 32-bit
-    [ -5 shift ] [ + ] bi
-    [ 4 shift ] [ bitxor ] bi 32-bit
-    [ -17 shift ] [ + ] bi
-    [ 25 shift ] [ bitxor ] bi 32-bit
-    [ -6 shift ] [ + ] bi ; inline
+    [ 3 shift ] [ bitxor ] bi 32-bit [ -5 shift ] [ + ] bi
+    [ 4 shift ] [ bitxor ] bi 32-bit [ -17 shift ] [ + ] bi
+    [ 25 shift ] [ bitxor ] bi 32-bit [ -6 shift ] [ + ] bi ; inline
 
 PRIVATE>