move makeOptBranch to base.singeli, use in search

This commit is contained in:
dzaima 2023-04-15 12:32:14 +03:00
parent 147d4530c1
commit 722107e470
3 changed files with 17 additions and 15 deletions

View File

@ -255,6 +255,17 @@ def forXUnroll{unr}{vars,begin,end,block} = {
}
def makeBranch{Ts, F} = {
def args = undef{Ts}
def skip = makelabel{}; goto{skip}
def start = setlabel{}
F{...args}
setlabel{skip}
{...vs} => { each{=, args, vs}; goto{start} }
}
def makeOptBranch{enable, Ts, F} = if (enable) makeBranch{Ts, F} else 'not defined'
def tree_fold{F, x} = {
def h = tuplen{x}>>1
F{tree_fold{F, slice{x,0,h}}, tree_fold{F, slice{x,h,tuplen{x}}}}

View File

@ -29,13 +29,18 @@ fn search{A, E}(l:*void, e0:A, n:u64) : u64 = {
def e = if (A==E) e0 else cast_i{E, e0}
def bulk = arch_defvw/width{E}
def VT = [bulk]E
def end = makeBranch{
tup{u64, ty_u{VT}},
{i,c} => return{i*bulk + promote{u64, ctz{homMask{c}}}}
}
muLoop{bulk, tern{arch_defvw>=256, 1, 2}, n, {is, M} => {
eq:= eachx{==, loadBatch{*E~~l, is, VT}, VT**e}
if (homAny{M{tree_fold{|, eq}}}) {
findFirst{
{i,c} => homAny{c},
{i,c} => tup{i,c},
{i,c} => return{i*bulk + promote{u64, ctz{homMask{c}}}},
end,
is, eq
}
}

View File

@ -42,20 +42,6 @@ def anyNonChar{M, x:T & isvec{T} & hasarch{'X86_64'}} = {
}
def makeOptBranch{enable, Ts, F} = {
if (enable) {
def args = undef{Ts}
def skip = makelabel{}; goto{skip}
def start = setlabel{}
F{...args}
setlabel{skip}
{...vs} => { each{=, args, vs}; goto{start} }
} else {
'not defined'
}
}
def cvtNarrow{T, x:X & width{T}==elwidth{X}} = cvt{T, x}
def cvtNarrow{T, x:X & width{T}< elwidth{X}} = narrow{T, x}
def cvtWiden{T, x:X & elwidth{T}==elwidth{X}} = cvt{eltype{T}, x}