introduce bitany_ptr

+ more general typed arr pointer getting functions
This commit is contained in:
dzaima 2024-08-15 17:28:25 +03:00
parent 00a64101e9
commit 88de336516
4 changed files with 23 additions and 11 deletions

View File

@ -157,7 +157,7 @@ static Arr* transpose_noshape(B* px, usz ia, usz w, usz h) {
if (h==2) {
u64* rp; r=m_bitarrp(&rp, ia);
Arr* x1o = TI(x,slice)(inc(x),w,w);
interleave_bits(rp, bitarr_ptr(x), ((TyArr*)x1o)->a, ia);
interleave_bits(rp, bitarr_ptr(x), bitanyv_ptr(x1o), ia);
mm_free((Value*)x1o);
#ifdef __BMI2__
} else if (w==2) {

View File

@ -14,12 +14,22 @@ static B* arrV_bptr(Arr* x) {
if (PTY(x)==t_fillslice) return ((FillSlice*)x)->a;
return NULL;
}
static void* tyarr_ptr(B x) { assert(IS_ANY_ARR(TY(x)) && !IS_SLICE(TY(x))); return c(TyArr,x)->a; }
static void* tyslice_ptr(B x) { assert(IS_ANY_ARR(TY(x)) && IS_SLICE(TY(x))); return c(TySlice,x)->a; }
static void* tyany_ptr(B x) {
assert(IS_ANY_ARR(TY(x)));
return IS_SLICE(TY(x))? c(TySlice,x)->a : c(TyArr,x)->a;
static void* tyarrv_ptr(TyArr* x) {
assert(IS_ANY_ARR(PTY(x)) && !IS_SLICE(PTY(x)));
return x->a;
}
static void* tyanyv_ptr(Arr* x) {
assert(IS_ANY_ARR(PTY(x)));
return IS_SLICE(PTY(x))? ((TySlice*)x)->a : ((TyArr*)x)->a;
}
static void* tyslicev_ptr(Arr* x) {
assert(IS_SLICE(PTY(x)));
return ((TySlice*)x)->a;
}
static void* tyarr_ptr(B x) { return tyarrv_ptr(c(TyArr,x)); }
static void* tyany_ptr(B x) { return tyanyv_ptr(a(x)); }
#define M_TYARR(WM, OVER, MID, RV, PRE) { PRE \
Arr* r = m_arr((offsetof(TyArr, a) + ( \

View File

@ -89,8 +89,10 @@ static Arr* m_bitarrp(u64** p, usz ia) {
*p = (u64*)r->a;
return (Arr*)r;
}
static u64* bitarr_ptr(B x) { VTY(x, t_bitarr); return (u64*)c(BitArr,x)->a; }
static u64* bitarrv_ptr(TyArr* x) { return (u64*)x->a; }
static u64* bitarrv_ptr(TyArr* x) { VTY(taga(x), t_bitarr); return (u64*)((BitArr*)x)->a; }
static u64* bitanyv_ptr(Arr* x) { VTY(taga(x), t_bitarr); return (u64*)((BitArr*)x)->a; }
static u64* bitarr_ptr(B x) { return bitarrv_ptr(c(TyArr,x)); }
static u64* bitany_ptr(B x) { return bitanyv_ptr(a(x)); }
Arr* cpyI8Arr (B x); // consumes

View File

@ -184,13 +184,13 @@ static bool eqShape(B w, B x) { assert(isArr(w) && isArr(x)); return ptr_eqShape
B bit_sel(B b, B e0, B e1); // consumes b; b must be bitarr; b⊏e0‿e1
Arr* allZeroes(usz ia); // ia⥊0 with undefined shape
Arr* allOnes(usz ia); // ia⥊1 with undefined shape
Arr* allZeroes(usz ia); // ia⥊0 with undefined shape; always produces new array
Arr* allOnes(usz ia); // ia⥊1 with undefined shape; always produces new array
Arr* reshape_one(usz nia, B x); // nia⥊<x with undefined shape; consumes x
B i64EachDec(i64 v, B x); // v¨ x; consumes x
B bit_negate(B x); // consumes
B bit_negate(B x); // consumes; always produces new array
void bit_negatePtr(u64* rp, u64* xp, usz count); // count is number of u64-s
B widenBitArr(B x, ur axis); // consumes x, assumes bitarr; returns some array with cell size padded to the nearest of 8,16,32,64 if ≤64 bits, or a multiple of 64 bits otherwise
B narrowWidenedBitArr(B x, ur axis, ur cr, usz* csh); // consumes x.val; undoes widenBitArr, overriding shape past axis to cr↑csh