diff options
author | H. Peter Anvin <hpa@zytor.com> | 2007-09-02 14:46:00 +0000 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2007-09-02 14:46:00 +0000 |
commit | e17a3cb29dc0a532a2ea7258e3fd57583c01699e (patch) | |
tree | ab277c8de4464f4f8e61c873cfc3bd1de91d1c83 /perllib | |
parent | 4768f5f6f272328522a792e572672cf229d91ea6 (diff) | |
download | nasm-e17a3cb29dc0a532a2ea7258e3fd57583c01699e.tar.gz nasm-e17a3cb29dc0a532a2ea7258e3fd57583c01699e.tar.bz2 nasm-e17a3cb29dc0a532a2ea7258e3fd57583c01699e.zip |
phash.ph: yet another attempt at getting Perl to behave, arithmetically
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/phash.ph | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/perllib/phash.ph b/perllib/phash.ph index 5021c2f..d5a06ce 100644 --- a/perllib/phash.ph +++ b/perllib/phash.ph @@ -10,13 +10,22 @@ use Graph::Undirected; require 'random_sv_vectors.ph'; # +# Truncate to 32-bit integer +# +sub int32($) { + my($x) = @_; + + return int($x) % 4294967296; +} + +# # 32-bit rotate # sub rot($$) { - use integer; my($v,$s) = @_; - return (($v << $s)+($v >> (32-$s))) & 0xffffffff; + $v = int32($v); + return int32(($v << $s)|($v >> (32-$s))); } # @@ -25,17 +34,16 @@ sub rot($$) { # prehash(key, sv, N) # sub prehash($$$) { - use integer; my($key, $n, $sv) = @_; my $c; my $k1 = 0, $k2 = 0; - my $kn1, $kn2; + my $ko1, $ko2; my($s0, $s1, $s2, $s3) = @{$sv}; foreach $c (unpack("C*", $key)) { - $kn1 = (rot($k1,$s0)-rot($k2, $s1)+$c) & 0xffffffff; - $kn2 = (rot($k2,$s2)-rot($k1, $s3)+$c) & 0xffffffff; - $k1 = $kn1; $k2 = $kn2; + $ko1 = $k1; $ko2 = $k2; + $k1 = int32(rot($ko1,$s0)-rot($ko2, $s1)+$c); + $k2 = int32(rot($ko2,$s2)-rot($ko1, $s3)+$c); } # Create a bipartite graph... |