more Singeli renames: no more floor,ceil,abs,adds,subs,vshl

This commit is contained in:
dzaima 2025-04-23 23:51:15 +03:00
parent 2202726005
commit 7237ad1abb
9 changed files with 24 additions and 31 deletions

View File

@ -32,7 +32,7 @@ def andnot{a:T, b if primt{T} and knum{b}} = a & ~T~~b
oper &- ({v:T,m:(u1)} => v & -promote{T,m}) infix left 35 oper &- ({v:T,m:(u1)} => v & -promote{T,m}) infix left 35
oper // ({a,b}=>floor{a/b}) infix left 40 oper // ({a,b}=>__floor{a/b}) infix left 40
def ptr_add{E, ptr:P, am} = { ptr = P~~(am + *E~~ptr) } def ptr_add{E, ptr:P, am} = { ptr = P~~(am + *E~~ptr) }
@ -92,7 +92,6 @@ def all_same{{}} = 1
def try_same_type{_, default} = default def try_same_type{_, default} = default
def try_same_type{{h:T, ...t} if all{hastype{.,T}, t}, _} = T def try_same_type{{h:T, ...t} if all{hastype{.,T}, t}, _} = T
def broadcast{T, v if primt{T}} = v
def broadcast{n, v if knum{n}} = each{{_}=>v, range{n}} def broadcast{n, v if knum{n}} = each{{_}=>v, range{n}}
# type stats # type stats
@ -289,18 +288,12 @@ def cvt{T, x:[_]T} = x
def extract{V=[k]E, x:V, 0} = x def extract{V=[k]E, x:V, 0} = x
def store_narrow_relaxed{p:*DE, x:[k]E} = store{p, narrow{DE, x}, k} def store_narrow_relaxed{p:*DE, x:[k]E} = store{p, narrow{DE, x}, k}
def broadcast{T, v if primt{T}} = v
def broadcast{V=[_]T, v} = vec_broadcast{V, if (knum{v}) v else promote{T,v}} def broadcast{V=[_]T, v} = vec_broadcast{V, if (knum{v}) v else promote{T,v}}
def make{V=[_]_, ...xs} = vec_make{V, ...xs} def make{V=[_]_, ...xs} = vec_make{V, ...xs}
def iota{V=[k]_} = make{V, ...iota{k}} def iota{V=[k]_} = make{V, ...range{k}}
def absu{a:[_]_} = ty_u{abs{a}} def absu{a:[_]_} = ty_u{__abs{a}}
def shuf = vec_shuffle def shuf = vec_shuffle
def vshl = vec_merge_shift_right
def floor = __floor
def ceil = __ceil
def abs = __abs
def adds = __adds
def subs = __subs
@ -308,7 +301,7 @@ def subs = __subs
def __min{a, b if any_num{a} and any_num{b}} = tern{a<b, a, b} def __min{a, b if any_num{a} and any_num{b}} = tern{a<b, a, b}
def __max{a, b if any_num{a} and any_num{b}} = tern{a>b, a, b} def __max{a, b if any_num{a} and any_num{b}} = tern{a>b, a, b}
def cdiv{a,b} = (a+b-1)/b # ceiling divide def cdiv{a,b} = (a+b-1)/b # ceiling divide
def cdiv{a,b if knum{a} and knum{b}} = ceil{a/b} def cdiv{a,b if knum{a} and knum{b}} = __ceil{a/b}
def popc{x:T if isint{T} and width{T}==64} = emit{ux, '__builtin_popcountll', x} def popc{x:T if isint{T} and width{T}==64} = emit{ux, '__builtin_popcountll', x}
def popc{x:T if isint{T} and width{T}<=32} = emit{ux, '__builtin_popcount', x} def popc{x:T if isint{T} and width{T}<=32} = emit{ux, '__builtin_popcount', x}
def ctz{x:T if isint{T} and width{T}==64} = emit{ux, '__builtin_ctzll', x} def ctz{x:T if isint{T} and width{T}==64} = emit{ux, '__builtin_ctzll', x}

View File

@ -374,7 +374,7 @@ fn saturate{F,T,...up}(dst:*void, src:*void, n:u64) : void = {
def a = minvalue{T} def a = minvalue{T}
def b = maxvalue{T} def b = maxvalue{T}
@for (d in *T~~dst, xf in *F~~src over n) { @for (d in *T~~dst, xf in *F~~src over n) {
x := if (F==f64) (if (select{up,0}) floor else ceil){xf} else xf x := if (F==f64) (if (select{up,0}) __floor else __ceil){xf} else xf
d = cast_i{T, x} d = cast_i{T, x}
if (not x<b) d = b if (not x<b) d = b
if (x<a) d = a if (x<a) d = a

View File

@ -18,11 +18,11 @@ def eqne{op} = same{op,__eq} or same{op,__ne}
def pathAS{dst, len, T, op, x if issigned{T}} = { def pathAS{dst, len, T, op, x if issigned{T}} = {
def R{f if eqne{op}} = { def R{f if eqne{op}} = {
if (rare{floor{f}!=f}) fillbits{dst, len, op{0,1}, x} # also includes check for NaN/sNaN if (rare{__floor{f}!=f}) fillbits{dst, len, op{0,1}, x} # also includes check for NaN/sNaN
ftrunc{i64,f} ftrunc{i64,f}
} }
def R{f if same{op,__lt} or same{op,__ge}} = ftrunc{i64,ceil{f}} def R{f if same{op,__lt} or same{op,__ge}} = ftrunc{i64,__ceil{f}}
def R{f if same{op,__gt} or same{op,__le}} = ftrunc{i64,floor{f}} def R{f if same{op,__gt} or same{op,__le}} = ftrunc{i64,__floor{f}}
xf:f64 = interp_f64{x} xf:f64 = interp_f64{x}
xi64:i64 = R{xf} xi64:i64 = R{xf}

View File

@ -20,8 +20,8 @@ def bqn_or{a, b} = (a+b)-(a*b)
# + & - # + & -
# def arithChk1{(__add), M, w:T, x:T, r:T} = tup{'any_top', M{(w^r) & (x^r)}} # def arithChk1{(__add), M, w:T, x:T, r:T} = tup{'any_top', M{(w^r) & (x^r)}}
# def arithChk1{(__sub), M, w:T, x:T, r:T} = tup{'any_top', M{(w^x) & (w^r)}} # def arithChk1{(__sub), M, w:T, x:T, r:T} = tup{'any_top', M{(w^x) & (w^r)}}
def arithChk1{(__add), M, w:T=[_]E, x:T, r:T} = tup{'anyne', adds{w,x}, r} def arithChk1{(__add), M, w:T=[_]E, x:T, r:T} = tup{'anyne', __adds{w,x}, r}
def arithChk1{(__sub), M, w:T=[_]E, x:T, r:T} = tup{'anyne', subs{w,x}, r} def arithChk1{(__sub), M, w:T=[_]E, x:T, r:T} = tup{'anyne', __subs{w,x}, r}
def arithChk1{(__add), M, w:T, x:T, r:T if hasarch{'X86_64'} and width{T}<=256} = tup{'any_top', M{ty_s{w>r} ^ x}} def arithChk1{(__add), M, w:T, x:T, r:T if hasarch{'X86_64'} and width{T}<=256} = tup{'any_top', M{ty_s{w>r} ^ x}}
def arithChk1{(__sub), M, w:T, x:T, r:T if hasarch{'X86_64'} and width{T}<=256} = tup{'any_top', M{ty_s{x>w} ^ r}} def arithChk1{(__sub), M, w:T, x:T, r:T if hasarch{'X86_64'} and width{T}<=256} = tup{'any_top', M{ty_s{x>w} ^ r}}
@ -55,7 +55,7 @@ def arithChk2{F==__mul, M, w:T=[_](i32), x:T if hasarch{'X86_64'}} = {
max:= re_el{f32, (ty_u{T})**0x4efffffe} max:= re_el{f32, (ty_u{T})**0x4efffffe}
def cf32{x:X} = emit{re_el{f32,X}, tern{T==[8]i32, '_mm256_cvtepi32_ps', '_mm_cvtepi32_ps'}, x} def cf32{x:X} = emit{re_el{f32,X}, tern{T==[8]i32, '_mm256_cvtepi32_ps', '_mm_cvtepi32_ps'}, x}
f32mul:= cf32{w} * cf32{x} f32mul:= cf32{w} * cf32{x}
tup{w*x, tup{'any_hom', M{abs{f32mul} >= max}}} tup{w*x, tup{'any_hom', M{__abs{f32mul} >= max}}}
# TODO fallback to the below if the above fails # TODO fallback to the below if the above fails
# TODO don't do this, but instead shuffle one half, do math, unshuffle that half # TODO don't do this, but instead shuffle one half, do math, unshuffle that half
# def wp = mzip128{w, T**0} # def wp = mzip128{w, T**0}

View File

@ -1,6 +1,6 @@
def ceil{x:(f64)} = emit{f64, 'ceil', x} def __ceil{x:(f64)} = emit{f64, 'ceil', x}
def floor{x:(f64)} = emit{f64, 'floor', x} def __floor{x:(f64)} = emit{f64, 'floor', x}
def abs{x:(f64)} = emit{f64, 'fabs', x} def __abs{x:(f64)} = emit{f64, 'fabs', x}
def NaN = 0.0/0.0 def NaN = 0.0/0.0
def isNaN{x:(f64)} = x!=x def isNaN{x:(f64)} = x!=x

View File

@ -10,7 +10,7 @@ fn absFn{T}(r:*void, x:*void, len:u64) : u64 = {
def VT = [bulk]T def VT = [bulk]T
@for_mu{bulk, tern{T==f64, 2, 1}}(cx in tup{VT,*T~~x}, sr in tup{'g',*T~~r}, M in 'm' over is to len) { @for_mu{bulk, tern{T==f64, 2, 1}}(cx in tup{VT,*T~~x}, sr in tup{'g',*T~~r}, M in 'm' over is to len) {
if (T!=f64 and any_hom{M, ...eachx{==, cx, VT**minvalue{T}}}) return{select{is,0}*bulk} if (T!=f64 and any_hom{M, ...eachx{==, cx, VT**minvalue{T}}}) return{select{is,0}*bulk}
sr{each{abs, cx}} sr{each{__abs, cx}}
} }
len len
} }

View File

@ -507,7 +507,7 @@ def modperm_shuf_step{x:V=[_]T, l, m if l%8==0} = {
# Reverse each pair of elements # Reverse each pair of elements
def swap_elts{x:V=[k]_, el_bytes} = { def swap_elts{x:V=[k]_, el_bytes} = {
if (hasarch{'AARCH64'}) { if (hasarch{'AARCH64'}) {
if (el_bytes == 8) vshl{x, x, k/2} if (el_bytes == 8) vec_merge_shift_right{x, x, k/2}
else V~~reverse_units{2, re_el{ty_u{8*el_bytes}, x}} else V~~reverse_units{2, re_el{ty_u{8*el_bytes}, x}}
} else if (any_sel or (hasarch{'SSE2'} and el_bytes >= 2)) { } else if (any_sel or (hasarch{'SSE2'} and el_bytes >= 2)) {
def wd = __min{el_bytes, 8} def wd = __min{el_bytes, 8}
@ -664,7 +664,7 @@ def rep_const_bool_odd_mask4{
x:M = get_modperm_x{} x:M = get_modperm_x{}
def vrot1 = ifvec{{x} => { def vrot1 = ifvec{{x} => {
if (w256{M}) shuf{x, 3,0,1,2} if (w256{M}) shuf{x, 3,0,1,2}
else if (any_sel) vshl{x, x, vcount{type{x}}-1} else if (any_sel) vec_merge_shift_right{x, x, vcount{type{x}}-1}
else shuf{x, 1,0} else shuf{x, 1,0}
}} }}
xo := x<<k | vrot1{x>>(64-k)} xo := x<<k | vrot1{x>>(64-k)}

View File

@ -196,7 +196,7 @@ fn scan_stride_assoc{op, T, Ret, check_over}(xv:*void, rv:*void, ia:usz, l:usz)
def scan_stride_assoc{op, T} = scan_stride_assoc{op, T, void, {..._}=>{}} def scan_stride_assoc{op, T} = scan_stride_assoc{op, T, void, {..._}=>{}}
def check_add_over{_, w:T, x:T, r:T} = { if ((w^r) & (x^r) < 0) return{0} } def check_add_over{_, w:T, x:T, r:T} = { if ((w^r) & (x^r) < 0) return{0} }
def check_add_over{M, w:V=[_]E, x:V, r:V} = { def check_add_over{M, w:V=[_]E, x:V, r:V} = {
o:= (if (not hasarch{'X86_64'} or width{E}<=16) any_hom{M, subs{r,w} != x} o:= (if (not hasarch{'X86_64'} or width{E}<=16) any_hom{M, __subs{r,w} != x}
else any_top{M, (w^r) & (x^r)}) else any_top{M, (w^r) & (x^r)})
if (o) return{0} if (o) return{0}
} }
@ -373,7 +373,7 @@ def widenFull{E, xs} = {
}, xs}} }, xs}}
} }
def floor{x if knum{x}} = x - (x%1) def __floor{x if knum{x}} = x - (x%1)
def maxabsval{T if issigned{T}} = -minvalue{T} def maxabsval{T if issigned{T}} = -minvalue{T}
def maxsafeint{T if issigned{T}} = maxvalue{T} def maxsafeint{T if issigned{T}} = maxvalue{T}
def maxsafeint{T==f64} = 1<<53 def maxsafeint{T==f64} = 1<<53
@ -409,9 +409,9 @@ def simd_plus_scan_part{x:*X, c:R, r:*R, len:(u64), i:(u64)} = {
cv:= [arch_defvw/width{R}]R ** c cv:= [arch_defvw/width{R}]R ** c
if (R==f64 and c != floor{c}) goto{'end'} if (R==f64 and c != __floor{c}) goto{'end'}
while (1) { while (1) {
if (R==f64) { if (rare{abs{extract{cv,0}} >= maxFastA}) goto{'end'} } if (R==f64) { if (rare{__abs{extract{cv,0}} >= maxFastA}) goto{'end'} }
else { if (rare{extract{absu{half{cv,0}},0} > maxFastA}) goto{'end'} } else { if (rare{extract{absu{half{cv,0}},0} > maxFastA}) goto{'end'} }
i2:= i+bulk i2:= i+bulk

View File

@ -299,11 +299,11 @@ export{'simd_index_tab_u8', simd_index_tab_u8{usz}}
# following RangeFn's specification in calls.h, whether it's necessary to return 0 or otherwise accumulating & converting to i64 may produce incorrect results # following RangeFn's specification in calls.h, whether it's necessary to return 0 or otherwise accumulating & converting to i64 may produce incorrect results
def bad_float_i64{x:T=[_](f64)} = { def bad_float_i64{x:T=[_](f64)} = {
a:= abs{x} a:= __abs{x}
s:= T**(1<<53) s:= T**(1<<53)
__min{s,a} != s-(s-a) # ~ ((a<=s) & (a == s-(s-a))) __min{s,a} != s-(s-a) # ~ ((a<=s) & (a == s-(s-a)))
} }
def bad_float_i64{x:T=[_](f64) if hasarch{'SSE4.1'}} = (x!=floor{x}) | (abs{x}>T**(1<<53)) def bad_float_i64{x:T=[_](f64) if hasarch{'SSE4.1'}} = (x!=__floor{x}) | (__abs{x}>T**(1<<53))
def bad_float_i64{x:T=[_](f64) if hasarch{'AARCH64'}} = x != cvt{f64, cvt{i64, x}} def bad_float_i64{x:T=[_](f64) if hasarch{'AARCH64'}} = x != cvt{f64, cvt{i64, x}}
fn getRange{E}(x0:*void, res:*i64, n:u64) : u1 = { fn getRange{E}(x0:*void, res:*i64, n:u64) : u1 = {