fast bitarr×intarr

This commit is contained in:
dzaima 2022-09-06 22:47:16 +03:00
parent a90e7de997
commit 1c279a0a20
4 changed files with 29 additions and 16 deletions

View File

@ -47,3 +47,16 @@ def b_setBatch{sz, x:*u64, n:(Size), v & sz== 8} = store{*u8 ~~ x, n, cast_i{u8
def b_setBatch{sz, x:*u64, n:(Size), v & sz==16} = store{*u16 ~~ x, n, cast_i{u16,v}}
def b_setBatch{sz, x:*u64, n:(Size), v & sz==32} = store{*u32 ~~ x, n, cast_i{u32,v}}
def b_setBatch{sz, x:*u64, n:(Size), v & sz==64} = store{ x, n, cast_i{u64,v}}
def spreadBits{T==[32]u8, a:u32} = {
def idxs = iota{32}
b:= broadcast{[8]u32, a}
c:= [32]u8~~b
d:= sel{[16]u8, c, make{[32]i8, idxs>>3 + bit{4, idxs}}}
e:= make{[32]u8, 1<<tail{3, idxs}}
e == (d&e)
}
def spreadBits{T, a & vcount{T} <= width{eltype{T}} & w256u{T}} = {
b:= make{T, 1<<iota{vcount{T}}}
b == (b & broadcast{T, a})
}

View File

@ -6,20 +6,6 @@ include './mask'
include './cbqnDefs'
include './bitops'
def spreadBits{T==[32]u8, a:u32} = {
def idxs = iota{32}
b:= broadcast{[8]u32, a}
c:= [32]u8~~b
d:= sel{[16]u8, c, make{[32]i8, idxs>>3 + bit{4, idxs}}}
e:= make{[32]u8, 1<<tail{3, idxs}}
e == (d&e)
}
def spreadBits{T, a & vcount{T} <= width{eltype{T}} & w256u{T}} = {
b:= make{T, 1<<iota{vcount{T}}}
b == (b & broadcast{T, a})
}
def copyFromBits{T, xp: *u64, rp: *eltype{T}, l:u64} = {
def bulk = vcount{T}
def TU = ty_u{T}

View File

@ -25,6 +25,10 @@ def rootty{T & isvec{T}} = eltype{T}
def is_s{X} = issigned{rootty{X}}
def is_u{X} = isunsigned{rootty{X}}
def loadBatchBit{T, x:*u64, n:(Size)} = {
spreadBits{T, b_getBatch{vcount{T}, x, n}}
}
def ty_sc{O, R} = R # keep floats as-is
def ty_sc{O, R & is_s{O} & is_u{R}} = ty_s{R}
def ty_sc{O, R & is_u{O} & is_s{R}} = ty_u{R}
@ -123,6 +127,16 @@ def arithAAimpl{vw, mode, F, W, X, R, w, x, r, len} = {
cx:= loadBatch{*u64~~x, i, TY}
storeBatch{*u64~~r, i, F{cw, cx}, M}
}}
} else if (match{F,__mul} and W!=u1 and X==u1 and W==R) { # 0‿1‿1‿1‿1‿0‿1‿1×3‿1‿4‿1‿5‿9‿2‿6
def bulk = vw / width{W}
def TU = ty_u{R}
def TV = [bulk]TU
maskedLoop{bulk, len, {i, M} => {
cw:= loadBatch{*TU~~w, i, TV}
cx:= loadBatchBit{TV, *u64~~x, i}
storeBatch{*TU~~r, i, cw&cx, M}
}}
} else {
def bulk = vw / max{max{width{W}, width{X}}, width{R}}
def overflow = tern{mode==1, {i}=>return{i}, tern{mode==2, {i}=>return{1}, 0}}

View File

@ -213,8 +213,8 @@ Make ← {𝕊ns:
}
Make¨ { reprcbqn:
commutative1 reprcbqn si"__mul" id"mul"
aa_a bitandc_numDiag # ∾⟨u‿bit‿i8‿i8, u‿bit‿i16‿i16, u‿bit‿i32‿i32, u‿bit‿f64‿f64⟩
aa_b w_numDiag # TODO readd ↑
aa_a bitandc_numDiagubiti8i8, ubiti16i16, ubiti32i32 # no u‿bit‿f64‿f64 because 0×∞ etc
aa_b w_numDiag
sa"iii" overflowEq1
}¨ "×""mul", "∧""and"
Make {