better ARR_BPTR_NEVER
This commit is contained in:
parent
41785cb4bf
commit
da29b285dd
@ -330,7 +330,8 @@ 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
|
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*
|
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
|
// 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
|
// testable with f=-DARR_BPTR_NEVER, which makes arr_bptr & arrv_bptr always return NULL
|
||||||
|
// use arr_bptrG & arrv_bptrG if you know that the input is B*-backed and want to rely on it (never returns NULL; unaffected by ARR_BPTR_NEVER)
|
||||||
|
|
||||||
// most arr_* fns have a arrv_* variant that takes an untagged pointer instead of B
|
// most arr_* fns have a arrv_* variant that takes an untagged pointer instead of B
|
||||||
|
|
||||||
|
|||||||
@ -1,24 +1,23 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
static B* arr_bptr(B x) { assert(isArr(x));
|
#define ARRV_BPTR_BODY switch (PTY(xa)) { \
|
||||||
#if !ARR_BPTR_NEVER
|
case t_harr: return harrv_ptr(xa); \
|
||||||
if (TY(x)==t_harr) return harr_ptr(x);
|
case t_fillarr: return fillarrv_ptr(xa); \
|
||||||
if (TY(x)==t_fillarr) return fillarrv_ptr(a(x));
|
case t_hslice: return hslicev_ptr(xa); \
|
||||||
if (TY(x)==t_hslice) return hslice_ptr(x);
|
case t_fillslice: return fillslicev_ptr(xa); \
|
||||||
if (TY(x)==t_fillslice) return fillslicev_ptr(a(x));
|
|
||||||
#endif
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static B* arrv_bptrG(Arr* xa) { ARRV_BPTR_BODY; UD; }
|
||||||
|
static B* arr_bptrG(B x) { Arr* xa=a(x); ARRV_BPTR_BODY; UD; }
|
||||||
|
|
||||||
|
#if ARR_BPTR_NEVER
|
||||||
|
static B* arr_bptr(B x) { return NULL; }
|
||||||
|
static B* arrv_bptr(Arr* x) { return NULL; }
|
||||||
|
#else
|
||||||
|
static B* arr_bptr(B x) { Arr* xa=a(x); ARRV_BPTR_BODY; return NULL; }
|
||||||
|
static B* arrv_bptr(Arr* xa) { ARRV_BPTR_BODY; return NULL; }
|
||||||
|
#endif
|
||||||
|
|
||||||
static void* tyarrv_ptr(TyArr* x) {
|
static void* tyarrv_ptr(TyArr* x) {
|
||||||
assert(IS_ANY_ARR(PTY(x)) && !IS_SLICE(PTY(x)));
|
assert(IS_ANY_ARR(PTY(x)) && !IS_SLICE(PTY(x)));
|
||||||
return x->a;
|
return x->a;
|
||||||
|
|||||||
@ -112,7 +112,7 @@ static B toI8Any (B x) { u8 t=TY(x); return t==t_i8arr || t==t_i8slice ? x : ta
|
|||||||
static B toI16Any(B x) { u8 t=TY(x); return t==t_i16arr || t==t_i16slice? x : taga(cpyI16Arr(x)); }
|
static B toI16Any(B x) { u8 t=TY(x); return t==t_i16arr || t==t_i16slice? x : taga(cpyI16Arr(x)); }
|
||||||
static B toI32Any(B x) { u8 t=TY(x); return t==t_i32arr || t==t_i32slice? x : taga(cpyI32Arr(x)); }
|
static B toI32Any(B x) { u8 t=TY(x); return t==t_i32arr || t==t_i32slice? x : taga(cpyI32Arr(x)); }
|
||||||
static B toF64Any(B x) { u8 t=TY(x); return t==t_f64arr || t==t_f64slice? x : taga(cpyF64Arr(x)); }
|
static B toF64Any(B x) { u8 t=TY(x); return t==t_f64arr || t==t_f64slice? x : taga(cpyF64Arr(x)); }
|
||||||
|
static B toBitAny(B x) { return taga(toBitArr(x)); }
|
||||||
|
|
||||||
B m_cai32(usz ia, i32* a);
|
B m_cai32(usz ia, i32* a);
|
||||||
B m_caf64(usz sz, f64* a);
|
B m_caf64(usz sz, f64* a);
|
||||||
|
|||||||
@ -295,13 +295,11 @@ 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_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_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; }
|
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:;
|
case t_harr: case t_hslice: case t_fillarr: case t_fillslice:;
|
||||||
B* xp = arr_bptr(x)+xs;
|
B* xp = arr_bptrG(x)+xs;
|
||||||
for (usz i = 0; i < l; i++) inc(xp[i]);
|
for (usz i = 0; i < l; i++) inc(xp[i]);
|
||||||
memcpy(mpo, xp, l*sizeof(B));
|
memcpy(mpo, xp, l*sizeof(B));
|
||||||
return;
|
return;
|
||||||
#endif
|
|
||||||
case t_f64arr: case t_f64slice:
|
case t_f64arr: case t_f64slice:
|
||||||
assert(sizeof(B)==sizeof(f64));
|
assert(sizeof(B)==sizeof(f64));
|
||||||
memcpy(mpo, f64any_ptr(x)+xs, l*sizeof(B));
|
memcpy(mpo, f64any_ptr(x)+xs, l*sizeof(B));
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user