Fix various sentinel bugs

This commit is contained in:
Marshall Lochbaum 2023-11-09 20:24:46 -05:00
parent 7b79dfc94e
commit e1b0c53c92

View File

@ -348,9 +348,9 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, m:usz, fv:*void, n:usz, links:ity{n
log := clzc{m} log := clzc{m}
# Max size # Max size
msl := max{clzc{m+m/2}+1, min{ux~~14,clzc{m+n/4}}} msl := max{clzc{(m+m/2)|4}+1, min{ux~~14,clzc{m+n/4}}}
msz := usz~~1 << msl msz := usz~~1 << msl
# Starting log-size # Starting log-size (try_vec_memb requires size>4)
sl := msl; if (msl>=14) sl = 12+(msl&1) sl := msl; if (msl>=14) sl = 12+(msl&1)
b:usz = 64 # Block size b:usz = 64 # Block size
@ -504,8 +504,8 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, m:usz, fv:*void, n:usz, links:ity{n
} }
try_vec_memb{T, hash, sz, sh, maxh, has_maxh, swap, rp, fp, n, abort} try_vec_memb{T, hash, sz, sh, maxh, has_maxh, swap, rp, fp, n, abort}
end := maxh>>sh # Clip trailing maxh if it shouldn't be in the table end := maxh>>sh # Clip trailing maxh if it shouldn't be in the table
if (has_maxh) { while (load{hash,end}!=maxh) ++end } while (load{hash,end}!=maxh) ++end
else end += promote{T,ext} # Unreachable if (has_maxh) ++end # Don't clip
lookup_all{{found, j} => promote{i8, swap ^ (found & (j<end))}} lookup_all{{found, j} => promote{i8, swap ^ (found & (j<end))}}
} }
@ -522,10 +522,8 @@ fn hashtab{T, name}(rp:*rty{name}, iv:*void, m:usz, fv:*void, n:usz, links:ity{n
has_maxh |= found has_maxh |= found
} }
insert_all{set, set_maxh, dup} insert_all{set, set_maxh, dup}
if (has_maxh) { end := maxh>>sh; while (load{hash,end}!=maxh) ++end
end := maxh>>sh; while (load{hash,end}!=maxh) ++end store{inds, end, (m-ind_maxh) &- has_maxh}
store{inds, end, ind_maxh}
}
lookup_all{{found, j} => i32~~(m - (load{inds, j} &- found))} lookup_all{{found, j} => i32~~(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:
@ -596,6 +594,7 @@ def try_vec_memb{T, hash, sz, sh, maxh, has_maxh, swap, rp, fp, n, done
# i-h>>sh = i+((1<<sh-1)-h)>>sh = (((i+1)<<sh-1)-h)>>sh # i-h>>sh = i+((1<<sh-1)-h)>>sh = (((i+1)<<sh-1)-h)>>sh
# We maintain io = (i+1)<<sh-1 # We maintain io = (i+1)<<sh-1
def vl = 4; def V = [vl]T def vl = 4; def V = [vl]T
assert{sz > 4}
assert{sz%vl == 0} assert{sz%vl == 0}
io := make{V, each{{k} => T~~k<<sh - 1, 1+iota{vl}}} io := make{V, each{{k} => T~~k<<sh - 1, 1+iota{vl}}}
id := V**(T~~vl<<sh) id := V**(T~~vl<<sh)