Separate transpose el_B case and fix dropped fill for shape 2‿n
This commit is contained in:
parent
dea063cb7b
commit
968bfd2fc6
@ -60,8 +60,7 @@ B transp_c1(B t, B x) {
|
||||
usz ia = IA(x);
|
||||
usz* xsh = SH(x);
|
||||
usz h = xsh[0];
|
||||
if (ia==0 || h==1) {
|
||||
no_reorder:;
|
||||
if (ia==0 || h==1 || h==ia /*w==1*/) {
|
||||
Arr* r = cpyWithShape(x);
|
||||
ShArr* sh = m_shArr(xr);
|
||||
shcpy(sh->a, xsh+1, xr-1);
|
||||
@ -70,45 +69,57 @@ B transp_c1(B t, B x) {
|
||||
return taga(r);
|
||||
}
|
||||
usz w = xsh[1] * shProd(xsh, 2, xr);
|
||||
if (w==1) goto no_reorder;
|
||||
|
||||
Arr* r;
|
||||
usz xi = 0;
|
||||
u8 xe = TI(x,elType);
|
||||
bool toBit = false;
|
||||
if (h==2) {
|
||||
if (xe==el_B) {
|
||||
B* xp = TO_BPTR(x);
|
||||
if (xe==el_B) {
|
||||
B xf = getFillR(x);
|
||||
B* xp = TO_BPTR(x);
|
||||
|
||||
HArr_p p = m_harrUp(ia);
|
||||
if (h==2) {
|
||||
B* x0 = xp; B* x1 = x0+w;
|
||||
HArr_p rp = m_harrUp(ia);
|
||||
for (usz i=0; i<w; i++) { rp.a[i*2] = inc(x0[i]); rp.a[i*2+1] = inc(x1[i]); }
|
||||
NOGC_E;
|
||||
r = (Arr*) rp.c;
|
||||
for (usz i=0; i<w; i++) { p.a[i*2] = inc(x0[i]); p.a[i*2+1] = inc(x1[i]); }
|
||||
} else {
|
||||
#ifndef __BMI2__
|
||||
if (xe==el_bit) { x = taga(cpyI8Arr(x)); xsh=SH(x); xe=el_i8; toBit=true; }
|
||||
void* rp = m_tyarrp(&r,elWidth(xe),ia,el2t(xe));
|
||||
#else
|
||||
void* rp = m_tyarrlbp(&r,elWidthLogBits(xe),ia,el2t(xe));
|
||||
#endif
|
||||
void* xp = tyany_ptr(x);
|
||||
switch(xe) { default: UD;
|
||||
#ifdef __BMI2__
|
||||
case el_bit:;
|
||||
u32* x0 = xp;
|
||||
Arr* x1o = TI(x,slice)(inc(x),w,w);
|
||||
u32* x1 = (u32*) ((TyArr*)x1o)->a;
|
||||
for (usz i=0; i<BIT_N(ia); i++) ((u64*)rp)[i] = _pdep_u64(x0[i], 0x5555555555555555) | _pdep_u64(x1[i], 0xAAAAAAAAAAAAAAAA);
|
||||
mm_free((Value*)x1o);
|
||||
break;
|
||||
#endif
|
||||
case el_i8: case el_c8: { u8* x0=xp; u8* x1=x0+w; for (usz i=0; i<w; i++) { ((u8* )rp)[i*2] = x0[i]; ((u8* )rp)[i*2+1] = x1[i]; } } break;
|
||||
case el_i16:case el_c16: { u16* x0=xp; u16* x1=x0+w; for (usz i=0; i<w; i++) { ((u16*)rp)[i*2] = x0[i]; ((u16*)rp)[i*2+1] = x1[i]; } } break;
|
||||
case el_i32:case el_c32: { u32* x0=xp; u32* x1=x0+w; for (usz i=0; i<w; i++) { ((u32*)rp)[i*2] = x0[i]; ((u32*)rp)[i*2+1] = x1[i]; } } break;
|
||||
case el_f64: { u64* x0=xp; u64* x1=x0+w; for (usz i=0; i<w; i++) { ((u64*)rp)[i*2] = x0[i]; ((u64*)rp)[i*2+1] = x1[i]; } } break;
|
||||
}
|
||||
for(usz y=0;y<h;y++) for(usz x=0;x<w;x++) p.a[x*h+y] = inc(xp[xi++]); // TODO inc afterwards, but don't when there's a method of freeing a HArr without freeing its elements
|
||||
}
|
||||
} else if (w==2 && xe!=el_B) {
|
||||
NOGC_E;
|
||||
|
||||
usz* rsh = arr_shAlloc((Arr*)p.c, xr);
|
||||
if (xr==2) {
|
||||
rsh[0] = w;
|
||||
rsh[1] = h;
|
||||
} else {
|
||||
shcpy(rsh, xsh+1, xr-1);
|
||||
rsh[xr-1] = h;
|
||||
}
|
||||
decG(x); return qWithFill(p.b, xf);
|
||||
} else if (h==2) {
|
||||
#ifndef __BMI2__
|
||||
if (xe==el_bit) { x = taga(cpyI8Arr(x)); xsh=SH(x); xe=el_i8; toBit=true; }
|
||||
void* rp = m_tyarrp(&r,elWidth(xe),ia,el2t(xe));
|
||||
#else
|
||||
void* rp = m_tyarrlbp(&r,elWidthLogBits(xe),ia,el2t(xe));
|
||||
#endif
|
||||
void* xp = tyany_ptr(x);
|
||||
switch(xe) { default: UD;
|
||||
#ifdef __BMI2__
|
||||
case el_bit:;
|
||||
u32* x0 = xp;
|
||||
Arr* x1o = TI(x,slice)(inc(x),w,w);
|
||||
u32* x1 = (u32*) ((TyArr*)x1o)->a;
|
||||
for (usz i=0; i<BIT_N(ia); i++) ((u64*)rp)[i] = _pdep_u64(x0[i], 0x5555555555555555) | _pdep_u64(x1[i], 0xAAAAAAAAAAAAAAAA);
|
||||
mm_free((Value*)x1o);
|
||||
break;
|
||||
#endif
|
||||
case el_i8: case el_c8: { u8* x0=xp; u8* x1=x0+w; for (usz i=0; i<w; i++) { ((u8* )rp)[i*2] = x0[i]; ((u8* )rp)[i*2+1] = x1[i]; } } break;
|
||||
case el_i16:case el_c16: { u16* x0=xp; u16* x1=x0+w; for (usz i=0; i<w; i++) { ((u16*)rp)[i*2] = x0[i]; ((u16*)rp)[i*2+1] = x1[i]; } } break;
|
||||
case el_i32:case el_c32: { u32* x0=xp; u32* x1=x0+w; for (usz i=0; i<w; i++) { ((u32*)rp)[i*2] = x0[i]; ((u32*)rp)[i*2+1] = x1[i]; } } break;
|
||||
case el_f64: { u64* x0=xp; u64* x1=x0+w; for (usz i=0; i<w; i++) { ((u64*)rp)[i*2] = x0[i]; ((u64*)rp)[i*2+1] = x1[i]; } } break;
|
||||
}
|
||||
} else if (w==2) {
|
||||
#ifndef __BMI2__
|
||||
if (xe==el_bit) { x = taga(cpyI8Arr(x)); xsh=SH(x); xe=el_i8; toBit=true; }
|
||||
#endif
|
||||
@ -139,24 +150,6 @@ B transp_c1(B t, B x) {
|
||||
case el_i16:case el_c16: { u16* xp=tyany_ptr(x); u16* rp = m_tyarrp(&r,2,ia,el2t(xe)); TRANSPOSE_SIMD(i16, rp, xp, w, h); break; }
|
||||
case el_i32:case el_c32: { u32* xp=tyany_ptr(x); u32* rp = m_tyarrp(&r,4,ia,el2t(xe)); TRANSPOSE_SIMD(i32, rp, xp, w, h); break; }
|
||||
case el_f64: { f64* xp=f64any_ptr(x); f64* rp; r=m_f64arrp(&rp,ia); TRANSPOSE_SIMD(i64, rp, xp, w, h); break; }
|
||||
case el_B: { // can't be bothered to implement a bitarr transpose
|
||||
B xf = getFillR(x);
|
||||
B* xp = TO_BPTR(x);
|
||||
|
||||
HArr_p p = m_harrUp(ia);
|
||||
for(usz y=0;y<h;y++) for(usz x=0;x<w;x++) p.a[x*h+y] = inc(xp[xi++]); // TODO inc afterwards, but don't when there's a method of freeing a HArr without freeing its elements
|
||||
NOGC_E;
|
||||
|
||||
usz* rsh = arr_shAlloc((Arr*)p.c, xr);
|
||||
if (xr==2) {
|
||||
rsh[0] = w;
|
||||
rsh[1] = h;
|
||||
} else {
|
||||
shcpy(rsh, xsh+1, xr-1);
|
||||
rsh[xr-1] = h;
|
||||
}
|
||||
decG(x); return qWithFill(p.b, xf);
|
||||
}
|
||||
}
|
||||
}
|
||||
usz* rsh = arr_shAlloc(r, xr);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user