finish separating arr_shAlloc
This commit is contained in:
parent
6d5c04e62a
commit
76dbabb03d
@ -16,8 +16,10 @@ B m_c32arrc(B x) { assert(isArr(x));
|
|||||||
arr_shCopy(r, x);
|
arr_shCopy(r, x);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
B m_c32arrp(usz ia) { // doesn't write any shape/size info! be careful!
|
B m_c32arrp(usz ia) { // doesn't write shape/rank
|
||||||
return m_arr(fsizeof(C32Arr,a,u32,ia), t_c32arr);
|
B r = m_arr(fsizeof(C32Arr,a,u32,ia), t_c32arr);
|
||||||
|
a(r)->ia = ia;
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -89,12 +89,12 @@ B m_unit(B x) {
|
|||||||
B xf = asFill(inc(x));
|
B xf = asFill(inc(x));
|
||||||
if (noFill(xf)) {
|
if (noFill(xf)) {
|
||||||
HArr_p r = m_harrp(1);
|
HArr_p r = m_harrp(1);
|
||||||
arr_shAlloc(r.b, 1, 0);
|
arr_shAllocR(r.b, 0);
|
||||||
r.a[0] = x;
|
r.a[0] = x;
|
||||||
return r.b;
|
return r.b;
|
||||||
}
|
}
|
||||||
B r = m_arr(fsizeof(FillArr,a,B,1), t_fillarr);
|
B r = m_arr(fsizeof(FillArr,a,B,1), t_fillarr);
|
||||||
arr_shAlloc(r, 1, 0);
|
arr_shAllocI(r, 1, 0);
|
||||||
c(FillArr,r)->fill = xf;
|
c(FillArr,r)->fill = xf;
|
||||||
c(FillArr,r)->a[0] = x;
|
c(FillArr,r)->a[0] = x;
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
27
src/h.h
27
src/h.h
@ -32,16 +32,6 @@
|
|||||||
#define CTR_PRINT(N) printf(#N ": %lu\n", N);
|
#define CTR_PRINT(N) printf(#N ": %lu\n", N);
|
||||||
CTR_FOR(CTR_DEF)
|
CTR_FOR(CTR_DEF)
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
#include<assert.h>
|
|
||||||
B VALIDATE(B x);
|
|
||||||
Value* VALIDATEP(Value* x);
|
|
||||||
#else
|
|
||||||
#define assert(x) {if (!(x)) __builtin_unreachable();}
|
|
||||||
#define VALIDATE(x) (x)
|
|
||||||
#define VALIDATEP(x) (x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define fsizeof(T,F,E,n) (offsetof(T, F) + sizeof(E)*(n)) // type, flexible array member name, flexible array member type, item amount
|
#define fsizeof(T,F,E,n) (offsetof(T, F) + sizeof(E)*(n)) // type, flexible array member name, flexible array member type, item amount
|
||||||
#define ftag(x) ((u64)(x) << 48)
|
#define ftag(x) ((u64)(x) << 48)
|
||||||
#define tag(v, t) b(((u64)(v)) | ftag(t))
|
#define tag(v, t) b(((u64)(v)) | ftag(t))
|
||||||
@ -161,6 +151,16 @@ typedef struct Arr {
|
|||||||
usz* sh;
|
usz* sh;
|
||||||
} Arr;
|
} Arr;
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#include<assert.h>
|
||||||
|
B VALIDATE(B x);
|
||||||
|
Value* VALIDATEP(Value* x);
|
||||||
|
#else
|
||||||
|
#define assert(x) {if (!(x)) __builtin_unreachable();}
|
||||||
|
#define VALIDATE(x) (x)
|
||||||
|
#define VALIDATEP(x) (x)
|
||||||
|
#endif
|
||||||
|
|
||||||
// memory manager
|
// memory manager
|
||||||
typedef void (*V2v)(Value*);
|
typedef void (*V2v)(Value*);
|
||||||
typedef void (*vfn)();
|
typedef void (*vfn)();
|
||||||
@ -187,6 +187,7 @@ B mm_alloc(usz sz, u8 type, u64 tag) {
|
|||||||
return b((u64)mm_allocN(sz,type) | tag);
|
return b((u64)mm_allocN(sz,type) | tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// some primitive actions
|
// some primitive actions
|
||||||
void dec(B x);
|
void dec(B x);
|
||||||
B inc(B x);
|
B inc(B x);
|
||||||
@ -278,14 +279,14 @@ void arr_shVec(B x, usz ia) {
|
|||||||
a(x)->sh = &a(x)->ia;
|
a(x)->sh = &a(x)->ia;
|
||||||
}
|
}
|
||||||
bool gotShape[t_COUNT];
|
bool gotShape[t_COUNT];
|
||||||
usz* arr_shAlloc(B x, usz ia, ur r) {
|
usz* arr_shAllocI(B x, usz ia, ur r) {
|
||||||
a(x)->ia = ia;
|
a(x)->ia = ia;
|
||||||
srnk(x,r);
|
srnk(x,r);
|
||||||
if (r>1) return a(x)->sh = ((ShArr*)mm_allocN(fsizeof(ShArr, a, usz, r), t_shape))->a;
|
if (r>1) return a(x)->sh = ((ShArr*)mm_allocN(fsizeof(ShArr, a, usz, r), t_shape))->a;
|
||||||
a(x)->sh = &a(x)->ia;
|
a(x)->sh = &a(x)->ia;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
usz* arr_shAllocR(B x, ur r) { // allocates shape, leaves ia unchanged
|
usz* arr_shAllocR(B x, ur r) { // allocates shape, sets rank, leaves ia unchanged
|
||||||
srnk(x,r);
|
srnk(x,r);
|
||||||
if (r>1) return a(x)->sh = ((ShArr*)mm_allocN(fsizeof(ShArr, a, usz, r), t_shape))->a;
|
if (r>1) return a(x)->sh = ((ShArr*)mm_allocN(fsizeof(ShArr, a, usz, r), t_shape))->a;
|
||||||
a(x)->sh = &a(x)->ia;
|
a(x)->sh = &a(x)->ia;
|
||||||
@ -467,7 +468,7 @@ B m_atop( B g, B h);
|
|||||||
|
|
||||||
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
u64 nsTime() {
|
static inline u64 nsTime() {
|
||||||
struct timespec t;
|
struct timespec t;
|
||||||
timespec_get(&t, TIME_UTC);
|
timespec_get(&t, TIME_UTC);
|
||||||
// clock_gettime(CLOCK_REALTIME, &t);
|
// clock_gettime(CLOCK_REALTIME, &t);
|
||||||
|
|||||||
@ -28,8 +28,10 @@ HArr_p m_harrc(B x) { assert(isArr(x));
|
|||||||
return harr_parts(r);
|
return harr_parts(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
HArr_p m_harrp(usz ia) { // doesn't write any shape/size info! be careful!
|
HArr_p m_harrp(usz ia) { // doesn't write shape/rank
|
||||||
return harr_parts(m_arr(fsizeof(HArr,a,B,ia), t_harr));
|
B r = m_arr(fsizeof(HArr,a,B,ia), t_harr);
|
||||||
|
a(r)->ia = ia;
|
||||||
|
return harr_parts(r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -16,8 +16,10 @@ B m_i32arrc(B x) { assert(isArr(x));
|
|||||||
arr_shCopy(r, x);
|
arr_shCopy(r, x);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
B m_i32arrp(usz ia) { // doesn't write any shape/size info! be careful!
|
B m_i32arrp(usz ia) { // doesn't write shape/rank
|
||||||
return m_arr(fsizeof(I32Arr,a,i32,ia), t_i32arr);
|
B r = m_arr(fsizeof(I32Arr,a,i32,ia), t_i32arr);
|
||||||
|
a(r)->ia = ia;
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -52,7 +52,7 @@ Block* ca3(B b) {
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t getline(char** __lineptr, size_t* n, FILE* stream);
|
ssize_t getline(char** line, size_t* n, FILE* stream);
|
||||||
|
|
||||||
|
|
||||||
void printAllocStats() {
|
void printAllocStats() {
|
||||||
|
|||||||
@ -13,7 +13,7 @@ B tbl_c2(B d, B w, B x) { B f = c(Md1D,d)->f;
|
|||||||
usz ria = wia*xia; ur rr = wr+xr;
|
usz ria = wia*xia; ur rr = wr+xr;
|
||||||
if (rr<xr) thrM("⌜: Required result rank too large");
|
if (rr<xr) thrM("⌜: Required result rank too large");
|
||||||
HArr_p r = m_harrp(ria);
|
HArr_p r = m_harrp(ria);
|
||||||
usz* rsh = arr_shAlloc(r.b, ria, rr);
|
usz* rsh = arr_shAllocR(r.b, rr);
|
||||||
if (rsh) {
|
if (rsh) {
|
||||||
memcpy(rsh , a(w)->sh, wr*sizeof(usz));
|
memcpy(rsh , a(w)->sh, wr*sizeof(usz));
|
||||||
memcpy(rsh+wr, a(x)->sh, xr*sizeof(usz));
|
memcpy(rsh+wr, a(x)->sh, xr*sizeof(usz));
|
||||||
|
|||||||
@ -156,7 +156,7 @@ B shape_c2(B t, B w, B x) {
|
|||||||
B r;
|
B r;
|
||||||
if (reusable(x)) { r = x; decSh(x); }
|
if (reusable(x)) { r = x; decSh(x); }
|
||||||
else r = TI(x).slice(x, 0);
|
else r = TI(x).slice(x, 0);
|
||||||
usz* sh = arr_shAlloc(r, nia, nr);
|
usz* sh = arr_shAllocI(r, nia, nr);
|
||||||
if (sh) for (i32 i = 0; i < nr; i++) sh[i] = o2s(wget(w,i));
|
if (sh) for (i32 i = 0; i < nr; i++) sh[i] = o2s(wget(w,i));
|
||||||
dec(w);
|
dec(w);
|
||||||
return r;
|
return r;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user