ARR_BPTR_NEVER
This commit is contained in:
parent
ad16bc109a
commit
75c1b74ce1
@ -330,6 +330,9 @@ if (TI(x,elType)!=el_B) void* xp = tyany_ptr(x); // alternative equivalent check
|
||||
if (TY(x)==t_harr) B* xp = harr_ptr(x); // similarly, hslice_ptr, fillarrv_ptr, fillslicev_ptr for specific types
|
||||
B* xp = arr_bptr(x); // will return NULL if the array isn't backed by a contiguous B*
|
||||
// while currently there are no types with eltype el_B for which arr_bptr isn't NULL, that could change in the future and so should still be handled
|
||||
// testable with f=-DARR_BPTR_NEVER, which makes arr_bptr
|
||||
|
||||
// most arr_* fns have a arrv_* variant that takes an untagged pointer instead of B
|
||||
|
||||
// functions to convert arrays to a specific type array: (all consume their argument, and assume that the elements losslessly fit in the desired type)
|
||||
I8Arr* a = toI8Arr(x); // convert x to an I8Arr instance (returns the argument if it already is)
|
||||
|
||||
@ -1,17 +1,21 @@
|
||||
#pragma once
|
||||
|
||||
static B* arr_bptr(B x) { assert(isArr(x));
|
||||
if (TY(x)==t_harr) return harr_ptr(x);
|
||||
if (TY(x)==t_fillarr) return fillarrv_ptr(a(x));
|
||||
if (TY(x)==t_hslice) return hslice_ptr(x);
|
||||
if (TY(x)==t_fillslice) return fillslicev_ptr(a(x));
|
||||
#if !ARR_BPTR_NEVER
|
||||
if (TY(x)==t_harr) return harr_ptr(x);
|
||||
if (TY(x)==t_fillarr) return fillarrv_ptr(a(x));
|
||||
if (TY(x)==t_hslice) return hslice_ptr(x);
|
||||
if (TY(x)==t_fillslice) return fillslicev_ptr(a(x));
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
static B* arrV_bptr(Arr* x) {
|
||||
if (PTY(x)==t_harr) return harrv_ptr(x);
|
||||
if (PTY(x)==t_fillarr) return fillarrv_ptr(x);
|
||||
if (PTY(x)==t_hslice) return hslicev_ptr(x);
|
||||
if (PTY(x)==t_fillslice) return fillslicev_ptr(x);
|
||||
static B* arrv_bptr(Arr* x) {
|
||||
#if !ARR_BPTR_NEVER
|
||||
if (PTY(x)==t_harr) return harrv_ptr(x);
|
||||
if (PTY(x)==t_fillarr) return fillarrv_ptr(x);
|
||||
if (PTY(x)==t_hslice) return hslicev_ptr(x);
|
||||
if (PTY(x)==t_fillslice) return fillslicev_ptr(x);
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@ -295,11 +295,13 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x
|
||||
case t_c8arr: case t_c8slice: { u8* xp = c8any_ptr (x); vfor (usz i = 0; i < l; i++) mpo[i] = m_c32(xp[i+xs]); return; }
|
||||
case t_c16arr: case t_c16slice: { u16* xp = c16any_ptr(x); vfor (usz i = 0; i < l; i++) mpo[i] = m_c32(xp[i+xs]); return; }
|
||||
case t_c32arr: case t_c32slice: { u32* xp = c32any_ptr(x); vfor (usz i = 0; i < l; i++) mpo[i] = m_c32(xp[i+xs]); return; }
|
||||
#if !ARR_BPTR_NEVER
|
||||
case t_harr: case t_hslice: case t_fillarr: case t_fillslice:;
|
||||
B* xp = arr_bptr(x)+xs;
|
||||
for (usz i = 0; i < l; i++) inc(xp[i]);
|
||||
memcpy(mpo, xp, l*sizeof(B));
|
||||
return;
|
||||
#endif
|
||||
case t_f64arr: case t_f64slice:
|
||||
assert(sizeof(B)==sizeof(f64));
|
||||
memcpy(mpo, f64any_ptr(x)+xs, l*sizeof(B));
|
||||
@ -327,7 +329,7 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x
|
||||
for (usz i=0; i<ia; i++) WR(fn(xa,i)); \
|
||||
} \
|
||||
static void cpy##N##Arr_B(void* rp, void* xp, u64 ia, void* xRaw) { \
|
||||
Arr* xa = (Arr*)xRaw; B* bxp = arrV_bptr(xa); \
|
||||
Arr* xa = (Arr*)xRaw; B* bxp = arrv_bptr(xa); \
|
||||
if (bxp!=NULL && sizeof(B)==sizeof(f64)) H2T; \
|
||||
else cpy##N##Arr_BF(rp, xp, ia, xa); \
|
||||
} \
|
||||
|
||||
Loading…
Reference in New Issue
Block a user