Make sure value in store{} has an appropriate type

This commit is contained in:
Marshall Lochbaum 2023-12-26 22:36:06 -05:00
parent 629a7602b3
commit dcb031d142
3 changed files with 15 additions and 14 deletions

View File

@ -85,7 +85,7 @@ fn write_indices{I,T}(t:*I, w:*T, n:u64) : void = {
id := i+d id := i+d
wi := undefined{T} wi := undefined{T}
if (id >= n) { if (id >= n) {
@for (w over j from i to n) store{t, w, cast_i{i64, j+1}} @for (w over j from i to n) store{t, w, cast_i{I, j+1}}
goto{break} goto{break}
} else if ((wi = load{w, i}) == load{w, id}) { } else if ((wi = load{w, i}) == load{w, id}) {
# Gallop # Gallop
@ -102,14 +102,14 @@ fn write_indices{I,T}(t:*I, w:*T, n:u64) : void = {
l -= h l -= h
} }
} else { } else {
@unroll (j to 8) store{t, load{w, i+j}, cast_i{i64, i+j+1}} @unroll (j to 8) store{t, load{w, i+j}, cast_i{I, i+j+1}}
i += 8 i += 8
} }
} }
setlabel{break} setlabel{break}
} }
fn write_indices{I,T & width{I}==8}(t:*I, w:*T, n:u64) : void = { fn write_indices{I,T & width{I}==8}(t:*I, w:*T, n:u64) : void = {
@for (w over j to n) store{t, w, j+1} @for (w over j to n) store{t, w, cast_i{I, j+1}}
} }
def bins_lookup{I, T, up, w:*T, wn:u64, x:*T, xn:u64, rp:*void} = { def bins_lookup{I, T, up, w:*T, wn:u64, x:*T, xn:u64, rp:*void} = {
# Build table # Build table

View File

@ -149,7 +149,7 @@ def do_bittab{x0:*void, n:u64, tab:*void, u:u8, t, mode, r0} = {
btab:= *i8~~tab btab:= *i8~~tab
def settab_sub{x, v, i} = { def settab_sub{x, v, i} = {
if (rval) store{*u8~~r0, u, x} if (rval) store{*u8~~r0, u, x}
if (rind and v!=t) store{r0, x, i} if (rind and v!=t) store{r0, x, cast_i{u32, i}}
u+= u8~~i8~~(t - v) # u tracks the total of btab u+= u8~~i8~~(t - v) # u tracks the total of btab
store{btab, x, t} store{btab, x, t}
v v
@ -324,8 +324,8 @@ fn getRange{E}(x0:*void, res:*i64, n:u64) : u1 = {
max1 = max{max1, x} max1 = max{max1, x}
} }
} }
store{res, 0, min1} store{res, 0, cast_i{i64, min1}}
store{res, 1, max1} store{res, 1, cast_i{i64, max1}}
1 1
} }
@ -337,13 +337,13 @@ oper &- ({v:T,m} => v & -promote{T,m}) infix left 35
def rty{name} = if (to_prim{name}=='∊') i8 else i32 def rty{name} = if (to_prim{name}=='∊') i8 else i32
def ity{name} = (to_prim{name}=='⊒')**(*u32) def ity{name} = (to_prim{name}=='⊒')**(*u32)
fn hashtab{T, name}(rp:*rty{name}, iv:*void, mi:usz, fv:*void, ni:usz, links:ity{name}) = { fn hashtab{T, name}(rpi:*rty{name}, iv:*void, mi:usz, fv:*void, ni:usz, links:ity{name}) = {
# iv,mi/ip,m - searched-in; fv,ni/fp,n - searched-for; may get swapped around & back # iv,mi/ip,m - searched-in; fv,ni/fp,n - searched-for; may get swapped around & back
def prim = to_prim{name} def prim = to_prim{name}
def U = if (prim=='∊') usz else u32 def U = if (prim=='∊') usz else u32
m := cast_i{U,mi}; n := cast_i{U,ni} m := cast_i{U,mi}; n := cast_i{U,ni}
def wt = width{T} def wt = width{T}
ip := *T~~iv; fp := *T~~fv ip := *T~~iv; fp := *T~~fv; rp := if (prim=='∊') rpi else *u32~~rpi
def swap_sides{} = each{{a,b}=>{t:=a; a=b; b=t}, tup{ip,m}, tup{fp,n}} def swap_sides{} = each{{a,b}=>{t:=a; a=b; b=t}, tup{ip,m}, tup{fp,n}}
swap:u1 = n+(1024*(prim!='⊒')) < (if (prim!='∊') m else m-m/4) swap:u1 = n+(1024*(prim!='⊒')) < (if (prim!='∊') m else m-m/4)
if (swap) swap_sides{} if (swap) swap_sides{}
@ -541,18 +541,18 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, mi:usz, fv:*void, ni:usz, links:ity
} }
insert_all{set, set_maxh, dup} insert_all{set, set_maxh, dup}
store{inds, get_end{}, (m-ind_maxh) &- has_maxh} store{inds, get_end{}, (m-ind_maxh) &- has_maxh}
lookup_all{{found, j} => i32~~(m - (load{inds, j} &- found))} lookup_all{{found, j} => m - (load{inds, j} &- found)}
} else { # swap } else { # swap
# After insert_all, position i in rp contains: # After insert_all, position i in rp contains:
# - ≠𝕨, if i is the first occurrence of its value in 𝕩, or # - ≠𝕨, if i is the first occurrence of its value in 𝕩, or
# - j-≠𝕩, where j<i is the index of the first occurrence # - j-≠𝕩, where j<i is the index of the first occurrence
uniq:usz = 0 uniq:usz = 0
has_maxh:u1 = 0 has_maxh:u1 = 0
ri:i32 = 0 # Placed in rp (should be scoped to insert_all loop body) ri:u32 = 0 # Placed in rp (should be scoped to insert_all loop body)
def dup = makelabel{} def dup = makelabel{}
def set_maxh{found, i, j} = { def set_maxh{found, i, j} = {
sequester_maxh{j, found} sequester_maxh{j, found}
ri = cast_i{i32, n} # Initialize to not-found ri = cast_i{u32, n} # Initialize to not-found
if (found & has_maxh) goto{dup} if (found & has_maxh) goto{dup}
has_maxh |= found has_maxh |= found
} }
@ -560,7 +560,7 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, mi:usz, fv:*void, ni:usz, links:ity
store{inds, j, i} store{inds, j, i}
if (u1~~0) { if (u1~~0) {
setlabel{dup} setlabel{dup}
ri = i32~~(load{inds, j} - m) ri = load{inds, j} - m
} }
store{rp, i, ri} store{rp, i, ri}
} }

View File

@ -4,11 +4,12 @@ include './hashtab'
# Resizing hash table, with fallback # Resizing hash table, with fallback
def rty{name} = if (to_prim{name}=='∊') i8 else i32 def rty{name} = if (to_prim{name}=='∊') i8 else i32
fn selfhashtab{T, name}(rp:*rty{name}, xp:*T, n:usz) = { fn selfhashtab{T, name}(rpi:*rty{name}, xp:*T, n:usz) = {
def wt = width{T} def wt = width{T}
def prim = to_prim{name} def prim = to_prim{name}
def has_radix = if (prim=='⊐') 0 else wt==32 def has_radix = if (prim=='⊐') 0 else wt==32
n64 := promote{u64,n} n64 := promote{u64,n}
rp := if (prim=='∊') rpi else *u32~~rpi
def {res0,cc_stop} = if (prim=='∊') tup{1,n64>>has_radix} else tup{0,2*n64} def {res0,cc_stop} = if (prim=='∊') tup{1,n64>>has_radix} else tup{0,2*n64}
log := clzc{n} log := clzc{n}
@ -30,7 +31,7 @@ fn selfhashtab{T, name}(rp:*rty{name}, xp:*T, n:usz) = {
} }
def {output, write_res} = match (prim) { def {output, write_res} = match (prim) {
{('∊')} => tup{{b}=>b, {j,h,k,x0} => { hash<-{j}h; k!=h }} {('∊')} => tup{{b}=>b, {j,h,k,x0} => { hash<-{j}h; promote{i8,k!=h} }}
{('⊒')} => { {('⊒')} => {
ctr0:u32 = 1; def {val} = vals ctr0:u32 = 1; def {val} = vals
def res{j,h,k,x0} = { def res{j,h,k,x0} = {