Check for AVX2 in Singeli transpose so it can build on non-x86 architectures

This commit is contained in:
Marshall Lochbaum 2023-03-25 15:27:25 -04:00
parent bf04b3aab0
commit 410d51501d
3 changed files with 20 additions and 17 deletions

View File

@ -576,7 +576,7 @@ cachedBin‿linkerCache ← {
"xa""src/builtins/arithd.c""dyarith", "xa""src/builtins/cmp.c""cmp", "xa""src/builtins/squeeze.c""squeeze"
"x.""src/builtins/select.c""select", "x.""src/builtins/fold.c""fold", "x.""src/builtins/scan.c""scan"
"x.""src/builtins/scan.c""neq", "x.""src/builtins/slash.c""slash", "x.""src/builtins/slash.c""constrep"
"x.""src/builtins/transpose.c""transpose"
"xa""src/builtins/transpose.c""transpose"
objs

View File

@ -35,7 +35,7 @@
#define TRANSPOSE_LOOP( DST, SRC, W, H) PLAINLOOP for(usz y=0,xi=0;y< H;y++) NOVECTORIZE for(usz x=0;x< W;x++) DST[x*H+y] = SRC[xi++]
#define TRANSPOSE_BLOCK(DST, SRC, BW, BH, W, H) PLAINLOOP for(usz y=0 ;y<BH;y++) NOVECTORIZE for(usz x=0;x<BW;x++) DST[x*H+y] = SRC[y*W+x]
#if SINGELI_X86_64
#if SINGELI
#define DECL_BASE(T) \
static NOINLINE void base_transpose_##T(T* rp, T* xp, u64 bw, u64 bh, u64 w, u64 h) { \
TRANSPOSE_BLOCK(rp, xp, bw, bh, w, h); \

View File

@ -65,20 +65,7 @@ def for_mult_max{k, m}{vars,begin,end,block} = {
}
}
fn transpose{T, k, kh}(r0:*void, x0:*void, w:u64, h:u64) : void = {
# Scalar transpose defined in C
def ts = if (T==i8) 'i8' else if (T==i16) 'i16' else if (T==i32) 'i32' else 'i64'
def call_base{...a} = emit{void, merge{'base_transpose_',ts}, ...a, w, h}
rp:*T = *T~~r0
xp:*T = *T~~x0
if (w<k or h<k) {
if (h==2) @for (x0 in xp, x1 in xp+w over i to w) { store{rp, i*2, x0}; store{rp, i*2+1, x1} }
else if (w==2) @for (r0 in rp, r1 in rp+h over i to h) { r0 = load{xp, i*2}; r1 = load{xp, i*2+1} }
else call_base{rp, xp, w, h}
return{}
}
def transpose_with_kernel{T, k, kh, call_base, rp:*T, xp:*T, w, h} = {
def at{x,y} = tup{xp + y*w + x, rp + x*h + y}
# Cache line info
@ -130,7 +117,7 @@ fn transpose{T, k, kh}(r0:*void, x0:*void, w:u64, h:u64) : void = {
def vt{i} = transpose_square{VT, k, each{loadx, k*i + iota{k}}}
each{tup, ...each{vt, iota{line_vecs}}}
}
ro := tail{6, -u64~~r0} / (width{T}/8) # Offset to align within cache line; assume elt-aligned
ro := tail{6, -u64~~rp} / (width{T}/8) # Offset to align within cache line; assume elt-aligned
wh := w*h
yn := h
if (ro != 0) {
@ -170,6 +157,22 @@ fn transpose{T, k, kh}(r0:*void, x0:*void, w:u64, h:u64) : void = {
}
}
fn transpose{T, k, kh}(r0:*void, x0:*void, w:u64, h:u64) : void = {
# Scalar transpose defined in C
def ts = if (T==i8) 'i8' else if (T==i16) 'i16' else if (T==i32) 'i32' else 'i64'
def call_base{...a} = emit{void, merge{'base_transpose_',ts}, ...a, w, h}
rp:*T = *T~~r0
xp:*T = *T~~x0
if (hasarch{'X86_64'} and w>=k and h>=k) {
transpose_with_kernel{T, k, kh, call_base, rp, xp, w, h}
} else {
if (h==2) @for (x0 in xp, x1 in xp+w over i to w) { store{rp, i*2, x0}; store{rp, i*2+1, x1} }
else if (w==2) @for (r0 in rp, r1 in rp+h over i to h) { r0 = load{xp, i*2}; r1 = load{xp, i*2+1} }
else call_base{rp, xp, w, h}
}
}
def transpose{T, k} = transpose{T, k, k}
export{'simd_transpose_i8', transpose{i8 , 16}}