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