Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Alternate PR to nim-lang#15915 to
resolve the problem mentioned there (`hash() == 0`) as well as
to close nim-lang#15624

* Address nim-lang#15937 (comment)
{ though this was only a move from 2 copies to 3 copies. ;-) }
  • Loading branch information
c-blake authored and irdassis committed Feb 12, 2021
1 parent 8ac81ed commit ad8bf8a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/pure/hashes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,12 @@ proc hashWangYi1*(x: int64|uint64|Hash): Hash {.inline.} =
const P0 = 0xa0761d6478bd642f'u64
const P1 = 0xe7037ed1a0b428db'u64
const P58 = 0xeb44accab455d165'u64 xor 8'u64
template h(x): untyped = hiXorLo(hiXorLo(P0, uint64(x) xor P1), P58)
when nimvm:
cast[Hash](hiXorLo(hiXorLo(P0, uint64(x) xor P1), P58))
when defined(js): # Nim int64<->JS Number & VM match => JS gets 32-bit hash
result = cast[Hash](h(x)) and cast[Hash](0xFFFFFFFF)
else:
result = cast[Hash](h(x))
else:
when defined(js):
asm """
Expand All @@ -132,8 +136,9 @@ proc hashWangYi1*(x: int64|uint64|Hash): Hash {.inline.} =
var res = hi_xor_lo_js(hi_xor_lo_js(P0, BigInt(`x`) ^ P1), P58);
`result` = Number(res & ((BigInt(1) << BigInt(53)) - BigInt(1)));
}"""
result = result and cast[Hash](0xFFFFFFFF)
else:
cast[Hash](hiXorLo(hiXorLo(P0, uint64(x) xor P1), P58))
result = cast[Hash](h(x))

proc hashData*(data: pointer, size: int): Hash =
## Hashes an array of bytes of size `size`.
Expand Down

0 comments on commit ad8bf8a

Please sign in to comment.