don't overflow-check widening array-scalar cases when not needed

This commit is contained in:
dzaima 2023-04-15 01:06:59 +03:00
parent 04ccf9fd49
commit bbb9e7f0ed
2 changed files with 19 additions and 15 deletions

View File

@ -190,7 +190,7 @@ def arithAA{mode, F, W, X, R} = {
else arithAAu{vw, mode, F, W, X, R}
}
# mode: 0:overflow-checked, needed; 1:overflow-erroring; 2: overflow-checked, not needed
# mode: 0:overflow-checked, needed; 1:overflow-erroring; 2: overflow-checked, not needed; 3: overflow-erroring, not needed
fn arithSAf{vw, mode, F, swap, W, X, R}(r:*void, w:u64, x:*void, len:u64) : u64 = {
# show{F, swap, mode, W, X, R}
assert{len>0}
@ -198,19 +198,19 @@ fn arithSAf{vw, mode, F, swap, W, X, R}(r:*void, w:u64, x:*void, len:u64) : u64
def TY = [bulk]R
def overflow = tern{mode==1, {i}=>return{1}, {i}=>return{i}}
def run = runner{(R==f64) | (mode==2), R, F}
def run = runner{(R==f64) | (mode>=2), R, F}
def getW{v} = trunc{W, v}
def getW{v & W==f64} = interp_f64{v}
cw:= ty_sc{W, TY}**getW{w}
def unr = tern{mode==2, 2, 1} # same as in arithAAimpl
def unr = tern{mode>=2, 2, 1} # same as in arithAAimpl
muLoop{bulk, unr, len, {is, M} => {
def cx = loadBatch{*X~~x, is, ty_sc{X, TY}}
def cws = tuplen{is}**cw
storeBatch{*R~~r, is, arithProcess{F, run, overflow, M, is, tern{swap,cx,cws}, tern{swap,cws,cx}, TY}, M}
}}
if (mode==1) 0
if (mode==1 or mode==3) 0
else len
}

View File

@ -136,13 +136,15 @@ Make ← {𝕊ns:
{ 𝕊 swap:
choices swap(2)¨ ns.sa
hadChrArr 0
ResMap {{(2¨𝕩)((2¨𝕩)) 22@} 'c'=𝕩}
_tyMap {(𝔽 𝕩)((2¨𝕩='c')) 22@}
ResMap ('c'=2¨) _tyMap
{
0𝕩? @;
charAtm 'c' 𝕩
hasNumArr 'i' 1¨𝕩
hasChrArr 'c' 1¨𝕩
resChr ResMap 𝕩
uncheckedMap (¨'u'¨) _tyMap 𝕩
argarr swap "SA"
canOverflow "f64"¨ tyName
P {"{",𝕨,",",𝕩,"}"}´
@ -158,12 +160,13 @@ Make ← {𝕊ns:
charArr numisc
¬ (charAtm¬numcanOverflow) (onlyFirst 𝕨=2) (¬hasChrArr)charArr?
currRes charAtmcharArrresChr
unchFn2 charAtmcharArruncheckedMap
currRes@?
twnumcharAtmtyityc txnumtyName tr𝕩currRestyityc
tr@?
siName id, argarr, 𝕨"?ce", '_'¨ twtxtr
𝕨 { 𝕊:
siSrc "export{'", siName, "', arithSA{", '0'+ 𝕨@, onlyFirst02, 1, ',', si, ',', '0'+swap, (',' 'u'('c'))¨ twtxtr, "}}", nl
siSrc "export{'", siName, "', arithSA{", '0'+ 𝕨@, onlyFirst02, unchFn213, ',', si, ',', '0'+swap, (',' 'u'('c'))¨ twtxtr, "}}", nl
singeliASFns <siName
} ¬(<siName)singeliASFns
siName;
@ -189,11 +192,12 @@ Make ← {𝕊ns:
# TODO unify sub u‿c32‿c32‿i32 and c‿i32‿i32‿i32?
# TODO when there's singeli div/sqrt, use scalar for like 1-2 tail elements
{ # definitions
# ⟨mode, w, x, r⟩
# definitions
{
# TODO when there's singeli div/sqrt, use scalar for like 1-2 tail elements
# aa_a/aa_b: list of ⟨mode, w, x, r⟩
# sa: list of "wxr", with an appended "u" if widened case can't error
c_numDiag ci8i8i8, ci16i16i16, ci32i32i32, uf64f64f64
u_numDiag ui8i8i8, ui16i16i16, ui32i32i32, uf64f64f64
w_numDiag ui8i8i16, ui16i16i32, ui32i32f64
@ -203,19 +207,19 @@ Make ← {𝕊ns:
commutative1 repr"+" cbqn"add" si"__add" id"add"
aa_a c_numDiagci8c8c8, ci16c16c16, ei32c32c32, xsqc8f64@, xsqc16f64@, xsqc32f64@ci8i16i16, ci8i32i32, ci16i32i32
aa_b w_numDiagei8c8c16, ei16c16c32
sa"iii""icc""cic" overflowEq1
sa"iiiu""icc""cic" overflowEq1
}
Make {
commutative0 repr"-" cbqn"sub" si"__sub" id"sub"
aa_a c_numDiagcc8c8i8, cc16c16i16, uc32c32i32cc8i8c8, cc16i16c16, ec32i32c32xsqc8f64@, xsqc16f64@, xsqc32f64@
aa_b w_numDiaguc8c8i16, uc16c16i32 ec8i8c16, ec16i16c32
sa"iii""cic""cci" overflowEq1
sa"iiiu""cic""cciu" overflowEq1
}
Make¨ { reprcbqn:
commutative1 reprcbqn si"__mul" id"mul"
aa_a bitandc_numDiagubiti8i8, ubiti16i16, ubiti32i32 # no u‿bit‿f64‿f64 because 0×∞ etc
aa_b w_numDiag
sa"iii" overflowEq1
sa"iiiu" overflowEq1
}¨ "×""mul", "∧""and"
Make {
commutative1 repr"" cbqn"or" si"bqn_or" id"or"
@ -226,12 +230,12 @@ Make ← {𝕊ns:
Make {
commutative1 repr"⌊" cbqn"floor" si"min" id"min"
aa_a bitandu_numDiag aa_b
sa"iii" overflowEq0
sa"iiiu" overflowEq0
}
Make {
commutative1 repr"⌈" cbqn"ceil" si"max" id"max"
aa_a bitoru_numDiag aa_b
sa"iii" overflowEq0
sa"iiiu" overflowEq0
}
# Make¨ { repr‿cbqn‿si:
# commutative⇐0 ⋄ repr‿cbqn‿si⇐ ⋄ id⇐cbqn