Shuffle-based 4-byte vector binary search

This commit is contained in:
Marshall Lochbaum 2023-07-08 13:28:26 -04:00
parent af5ba0a2d2
commit fc57e0012d

View File

@ -299,8 +299,10 @@ def bin_search_vec{T, up, w:*T, wn, x:*T, xn, rp, maxwn & hasarch{'AVX2'}} = {
r += c r += c
} }
r -= off r -= off
rn := if (T==i8) r else half{narrow{u8, r}, 0} rn := if (T==i8) r
store{*[vl]i8~~(*i8~~rp+j), 0, rn} else if (T==i16) half{narrow{u8, r}, 0}
else extract{to_el{i64, narrow{u8, r}}, 0}
store{*type{rn}~~(*i8~~rp+j), 0, rn}
} }
} }
} }
@ -345,8 +347,8 @@ fn bins{T, up}(w:*void, wn:u64, x:*void, xn:u64, rp:*void, rty:u8) : void = {
else if (k+1 < tuplen{rtypes}) lookup{k+1} else if (k+1 < tuplen{rtypes}) lookup{k+1}
} }
# For >=8 i8 values, vector bit-table is as good as binary search # For >=8 i8 values, vector bit-table is as good as binary search
def wn_vec = if (T==i8) 8 else 32 def wn_vec = if (T==i8) 8 else 2*256/width{T}
if (hasarch{'AVX2'} and T<=i16 and wn < wn_vec and xn >= 256/width{T}) { if (hasarch{'AVX2'} and T<=i32 and wn < wn_vec and xn >= 256/width{T}) {
bin_search_vec{T, ...param, wn_vec} bin_search_vec{T, ...param, wn_vec}
# Lookup table threshold has to account for cost of # Lookup table threshold has to account for cost of
# populating the table (proportional to wn until it's large), and # populating the table (proportional to wn until it's large), and