Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save drchaos/a4941deee266acf272df74c5876686dc to your computer and use it in GitHub Desktop.
Save drchaos/a4941deee266acf272df74c5876686dc to your computer and use it in GitHub Desktop.
------------------ My code --------------------------
fnv1aHash32Word32# :: Word# -> Word# -> Word#
fnv1aHash32Word32# base word =
let b0 = word `and#` 0xFF##
b1 = (word `uncheckedShiftRL#` 8#) `and#` 0xFF##
b2 = (word `uncheckedShiftRL#` 16#) `and#` 0xFF##
b3 = (word `uncheckedShiftRL#` 24#) `and#` 0xFF##
in base <<>> b0 <<>> b1 <<>> b2 <<>> b3
where
(<<>>) = fnv1aHash32Base#
fnv1aHash32Base# :: Word# -> Word# -> Word#
fnv1aHash32Base# base byte = (base `xor#` byte) `timesWord#` fnvPrime32#
where fnvPrime32# = 16777619##
------------------ GHC code --------------------------
fnv1aHash32Word32# :: Word# -> Word# -> Word#
fnv1aHash32Word32#
= \ (base :: Word#) (word :: Word#) ->
timesWord#
(xor#
(timesWord#
(xor#
(timesWord#
(xor#
(timesWord# (xor# base (and# word 255##)) 16777619##)
(and# (uncheckedShiftRL# word 8#) 255##))
16777619##)
(and# (uncheckedShiftRL# word 16#) 255##))
16777619##)
(and# (uncheckedShiftRL# word 24#) 255##))
16777619##
------------------------- hashPlus generated code --------------------------
hashPlus :: Word32 -> Word32 -> Word32
hashPlus
= \ (l :: Word32) (r :: Word32) ->
case l of { W32# x#1 ->
case r of { W32# x#2 ->
W32#
(narrow32Word#
(timesWord#
(xor#
(narrow32Word#
(timesWord#
(xor#
(narrow32Word#
(timesWord#
(xor#
(narrow32Word#
(timesWord#
(xor#
(narrow32Word#
(timesWord#
(xor#
(narrow32Word#
(timesWord#
(xor#
(narrow32Word#
(timesWord#
(xor#
(narrow32Word#
(timesWord#
(xor#
2166136261##
(narrow8Word#
(and#
x#1 255##)))
16777619##))
(narrow8Word#
(and#
(uncheckedShiftRL#
x#1 8#)
255##)))
16777619##))
(narrow8Word#
(and#
(uncheckedShiftRL# x#1 16#)
255##)))
16777619##))
(narrow8Word#
(and# (uncheckedShiftRL# x#1 24#) 255##)))
16777619##))
(narrow8Word# (and# x#2 255##)))
16777619##))
(narrow8Word# (and# (uncheckedShiftRL# x#2 8#) 255##)))
16777619##))
(narrow8Word# (and# (uncheckedShiftRL# x#2 16#) 255##)))
16777619##))
(narrow8Word# (and# (uncheckedShiftRL# x#2 24#) 255##)))
16777619##))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment