builtins: restore nicer hash code for Dict

This commit is contained in:
Brian Carroll 2023-01-23 22:09:29 +00:00
parent 28d6d000ec
commit a249e14ee5
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
2 changed files with 20 additions and 42 deletions

View file

@ -993,33 +993,11 @@ wymix = \a, b ->
wymum : U64, U64 -> { lower : U64, upper : U64 }
wymum = \a, b ->
# uint64_t ha=*A>>32, hb=*B>>32, la=(uint32_t)*A, lb=(uint32_t)*B, hi, lo;
# uint64_t rh=ha*hb, rm0=ha*lb, rm1=hb*la, rl=la*lb, t=rl+(rm0<<32), c=t<rl;
# lo=t+(rm1<<32); c+=lo<t; hi=rh+(rm0>>32)+(rm1>>32)+c;
ha = Num.shiftRightZfBy a 32
hb = Num.shiftRightZfBy b 32
la = Num.bitwiseAnd a 0x0000_0000_FFFF_FFFF
lb = Num.bitwiseAnd b 0x0000_0000_FFFF_FFFF
rh = ha * hb
rm0 = ha * lb
rm1 = hb * la
rl = la * lb
t = Num.addWrap rl (Num.shiftLeftBy rm0 32)
c = if t < rl then 1 else 0
lower = Num.addWrap t (Num.shiftLeftBy rm1 32)
c2 = c + (if lower < t then 1 else 0)
upper =
rh
|> Num.addWrap (Num.shiftRightZfBy rm0 32)
|> Num.addWrap (Num.shiftRightZfBy rm1 32)
|> Num.addWrap c2
r = Num.toU128 a * Num.toU128 b
lower = Num.toU64 r
upper = Num.shiftRightZfBy r 64 |> Num.toU64
# TODO: switch back to this once wasm supports bit shifting a U128.
# The above code is manually doing the 128bit multiplication.
# r = Num.toU128 a * Num.toU128 b
# lower = Num.toU64 r
# upper = Num.shiftRightZfBy r 64 |> Num.toU64
# This is the more robust form.
# This is the more robust form, which we may look into later
# { lower: Num.bitwiseXor a lower, upper: Num.bitwiseXor b upper }
{ lower, upper }

View file

@ -1,22 +1,22 @@
procedure Dict.1 (Dict.518):
let Dict.521 : List {[], []} = Array [];
let Dict.528 : U64 = 0i64;
let Dict.529 : U64 = 8i64;
let Dict.522 : List U64 = CallByName List.11 Dict.528 Dict.529;
let Dict.525 : I8 = CallByName Dict.34;
let Dict.526 : U64 = 8i64;
let Dict.523 : List I8 = CallByName List.11 Dict.525 Dict.526;
let Dict.524 : U64 = 0i64;
let Dict.520 : {List {[], []}, List U64, List I8, U64} = Struct {Dict.521, Dict.522, Dict.523, Dict.524};
ret Dict.520;
procedure Dict.1 (Dict.508):
let Dict.511 : List {[], []} = Array [];
let Dict.518 : U64 = 0i64;
let Dict.519 : U64 = 8i64;
let Dict.512 : List U64 = CallByName List.11 Dict.518 Dict.519;
let Dict.515 : I8 = CallByName Dict.34;
let Dict.516 : U64 = 8i64;
let Dict.513 : List I8 = CallByName List.11 Dict.515 Dict.516;
let Dict.514 : U64 = 0i64;
let Dict.510 : {List {[], []}, List U64, List I8, U64} = Struct {Dict.511, Dict.512, Dict.513, Dict.514};
ret Dict.510;
procedure Dict.34 ():
let Dict.527 : I8 = -128i64;
ret Dict.527;
let Dict.517 : I8 = -128i64;
ret Dict.517;
procedure Dict.4 (Dict.507):
let Dict.85 : U64 = StructAtIndex 3 Dict.507;
dec Dict.507;
procedure Dict.4 (Dict.497):
let Dict.85 : U64 = StructAtIndex 3 Dict.497;
dec Dict.497;
ret Dict.85;
procedure List.11 (List.114, List.115):