checksums.superfast: reuse code and make a bit faster.
parent
df47ff8289
commit
405e543f92
basis/checksums/superfast
|
@ -1,10 +1,9 @@
|
|||
! Copyright (C) 2013 John Benediktsson.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
|
||||
USING: accessors alien alien.data byte-arrays checksums
|
||||
combinators fry grouping io.binary kernel math math.bitwise
|
||||
math.ranges sequences sequences.private ;
|
||||
QUALIFIED-WITH: alien.c-types c
|
||||
USING: accessors alien alien.c-types alien.data byte-arrays
|
||||
checksums combinators fry grouping io.binary kernel math
|
||||
math.bitwise math.ranges sequences sequences.private ;
|
||||
|
||||
IN: checksums.superfast
|
||||
|
||||
|
@ -15,23 +14,21 @@ C: <superfast> superfast
|
|||
|
||||
: 32-bit ( n -- n' ) 32 on-bits mask ; inline
|
||||
|
||||
: (main-loop) ( hash m n -- hash' )
|
||||
[ + ] [ 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> c:short deref ]
|
||||
[ [ 2 + ] dip <displaced-alien> c:short deref ] 2bi
|
||||
[ + ] [ 11 shift dupd bitxor ] bi*
|
||||
[ 16 shift ] [ bitxor ] bi* 32-bit
|
||||
[ -11 shift ] [ + ] bi
|
||||
[ 0 over length 4 - 4 <range> ] dip [
|
||||
pick <displaced-alien> int deref
|
||||
[ 16 on-bits mask ] [ -16 shift ] bi
|
||||
(main-loop)
|
||||
] reduce
|
||||
] [
|
||||
[ dup length 4 mod dupd head-slice* 4 <groups> ] dip [
|
||||
2 cut-slice
|
||||
[ le> + ] [ le> 11 shift dupd bitxor ] bi*
|
||||
[ 16 shift ] [ bitxor ] bi* 32-bit
|
||||
[ -11 shift ] [ + ] bi
|
||||
2 cut-slice [ le> ] bi@ (main-loop)
|
||||
] reduce
|
||||
] if ; inline
|
||||
|
||||
|
|
Loading…
Reference in New Issue