MUT_APPEND
This commit is contained in:
parent
390ee503fb
commit
a3d74c6af2
@ -338,7 +338,7 @@ B fold_rows(Md1D* fd, B x) {
|
|||||||
usz *sh = SH(x); usz n = sh[0]; usz m = sh[1];
|
usz *sh = SH(x); usz n = sh[0]; usz m = sh[1];
|
||||||
usz b = (block + m - 1) / m; // Normal block length
|
usz b = (block + m - 1) / m; // Normal block length
|
||||||
usz b_max = b + b/4; // Last block max length
|
usz b_max = b + b/4; // Last block max length
|
||||||
MAKE_MUT(r, n);
|
MAKE_MUT(r, n); MUT_APPEND_INIT(r);
|
||||||
BSS2A slice = TI(x,slice);
|
BSS2A slice = TI(x,slice);
|
||||||
for (usz i=0, im=0; i<n; ) {
|
for (usz i=0, im=0; i<n; ) {
|
||||||
usz l = n-i; if (l > b_max) { incG(x); l = b; }
|
usz l = n-i; if (l > b_max) { incG(x); l = b; }
|
||||||
@ -348,7 +348,7 @@ B fold_rows(Md1D* fd, B x) {
|
|||||||
ssh[0] = l;
|
ssh[0] = l;
|
||||||
ssh[1] = m;
|
ssh[1] = m;
|
||||||
B sr = insert_c1(fd, C1(transp, taga(sl)));
|
B sr = insert_c1(fd, C1(transp, taga(sl)));
|
||||||
mut_copy(r, i, sr, 0, l);
|
MUT_APPEND(r, sr, 0, l);
|
||||||
decG(sr);
|
decG(sr);
|
||||||
i += l; im += sia;
|
i += l; im += sia;
|
||||||
}
|
}
|
||||||
|
|||||||
4
src/h.h
4
src/h.h
@ -236,7 +236,7 @@ typedef union B {
|
|||||||
#if defined(OBJ_TRACK)
|
#if defined(OBJ_TRACK)
|
||||||
#define OBJ_COUNTER 1
|
#define OBJ_COUNTER 1
|
||||||
#endif
|
#endif
|
||||||
#if DEBUG && !defined(VERIFY_TAIL) && MM!=2
|
#if DEBUG && !defined(VERIFY_TAIL) && MM==1
|
||||||
#define VERIFY_TAIL 64
|
#define VERIFY_TAIL 64
|
||||||
#endif
|
#endif
|
||||||
#if ALLOC_STAT || VERIFY_TAIL
|
#if ALLOC_STAT || VERIFY_TAIL
|
||||||
@ -322,6 +322,7 @@ typedef struct Arr {
|
|||||||
#define UD assert(false);
|
#define UD assert(false);
|
||||||
extern bool cbqn_noAlloc;
|
extern bool cbqn_noAlloc;
|
||||||
NOINLINE void cbqn_NOGC_start(); // function to allow breakpointing
|
NOINLINE void cbqn_NOGC_start(); // function to allow breakpointing
|
||||||
|
#define NOGC_CHECK if (cbqn_noAlloc && !gc_depth) err("allocating during noalloc");
|
||||||
#define NOGC_S cbqn_NOGC_start()
|
#define NOGC_S cbqn_NOGC_start()
|
||||||
#define NOGC_E cbqn_noAlloc=false
|
#define NOGC_E cbqn_noAlloc=false
|
||||||
#else
|
#else
|
||||||
@ -331,6 +332,7 @@ typedef struct Arr {
|
|||||||
#define UD __builtin_unreachable();
|
#define UD __builtin_unreachable();
|
||||||
#define NOGC_S
|
#define NOGC_S
|
||||||
#define NOGC_E
|
#define NOGC_E
|
||||||
|
#define NOGC_CHECK
|
||||||
#endif
|
#endif
|
||||||
#if WARN_SLOW
|
#if WARN_SLOW
|
||||||
void warn_slow1(char* s, B x);
|
void warn_slow1(char* s, B x);
|
||||||
|
|||||||
@ -23,10 +23,8 @@ extern EmptyValue* mm_buckets[64];
|
|||||||
#if !ALLOC_NOINLINE || ALLOC_IMPL || ALLOC_IMPL_MMX
|
#if !ALLOC_NOINLINE || ALLOC_IMPL || ALLOC_IMPL_MMX
|
||||||
ALLOC_FN void* mm_alloc(u64 sz, u8 type) {
|
ALLOC_FN void* mm_alloc(u64 sz, u8 type) {
|
||||||
assert(sz>=16);
|
assert(sz>=16);
|
||||||
|
NOGC_CHECK;
|
||||||
preAlloc(sz, type);
|
preAlloc(sz, type);
|
||||||
#if DEBUG
|
|
||||||
if (cbqn_noAlloc && !gc_depth) err("allocating during noAlloc");
|
|
||||||
#endif
|
|
||||||
#if VERIFY_TAIL
|
#if VERIFY_TAIL
|
||||||
i64 logAlloc = LOG2(sz + VERIFY_TAIL);
|
i64 logAlloc = LOG2(sz + VERIFY_TAIL);
|
||||||
#else
|
#else
|
||||||
|
|||||||
@ -25,6 +25,7 @@ static void mm_visitP(void* x) { }
|
|||||||
|
|
||||||
bool gc_maybeGC(bool);
|
bool gc_maybeGC(bool);
|
||||||
void gc_forceGC(bool);
|
void gc_forceGC(bool);
|
||||||
|
#define gc_depth 0
|
||||||
void mm_forHeap(V2v f);
|
void mm_forHeap(V2v f);
|
||||||
void mm_dumpHeap(FILE* f);
|
void mm_dumpHeap(FILE* f);
|
||||||
|
|
||||||
|
|||||||
@ -46,27 +46,27 @@ void mut_to(Mut* m, u8 n);
|
|||||||
#define MAKE_MUT(N, IA) Mut N##_val; N##_val.fns = &mutFns[el_MAX]; N##_val.ia = (IA); Mut* N = &N##_val;
|
#define MAKE_MUT(N, IA) Mut N##_val; N##_val.fns = &mutFns[el_MAX]; N##_val.ia = (IA); Mut* N = &N##_val;
|
||||||
|
|
||||||
static B mut_fv(Mut* m) { assert(m->fns->elType!=el_MAX);
|
static B mut_fv(Mut* m) { assert(m->fns->elType!=el_MAX);
|
||||||
NOGC_E;
|
NOGC_E; assert(m->ia == m->val->ia);
|
||||||
Arr* a = m->val;
|
Arr* a = m->val;
|
||||||
a->sh = &a->ia;
|
a->sh = &a->ia;
|
||||||
SPRNK(a, 1);
|
SPRNK(a, 1);
|
||||||
return taga(a);
|
return taga(a);
|
||||||
}
|
}
|
||||||
static B mut_fc(Mut* m, B x) { assert(m->fns->elType!=el_MAX); // doesn't consume x
|
static B mut_fc(Mut* m, B x) { assert(m->fns->elType!=el_MAX); // doesn't consume x
|
||||||
NOGC_E;
|
NOGC_E; assert(m->ia == m->val->ia);
|
||||||
Arr* a = m->val;
|
Arr* a = m->val;
|
||||||
arr_shCopy(a, x);
|
arr_shCopy(a, x);
|
||||||
return taga(a);
|
return taga(a);
|
||||||
}
|
}
|
||||||
static B mut_fcd(Mut* m, B x) { assert(m->fns->elType!=el_MAX); // consumes x
|
static B mut_fcd(Mut* m, B x) { assert(m->fns->elType!=el_MAX); // consumes x
|
||||||
NOGC_E;
|
NOGC_E; assert(m->ia == m->val->ia);
|
||||||
Arr* a = m->val;
|
Arr* a = m->val;
|
||||||
arr_shCopy(a, x);
|
arr_shCopy(a, x);
|
||||||
decG(x);
|
decG(x);
|
||||||
return taga(a);
|
return taga(a);
|
||||||
}
|
}
|
||||||
static Arr* mut_fp(Mut* m) { assert(m->fns->elType!=el_MAX);
|
static Arr* mut_fp(Mut* m) { assert(m->fns->elType!=el_MAX);
|
||||||
NOGC_E;
|
NOGC_E; assert(m->ia == m->val->ia);
|
||||||
return m->val;
|
return m->val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +93,15 @@ static void mut_fill(Mut* m, usz ms, B x, usz l) { m->fns->m_fill(m, ms, x, l);
|
|||||||
// doesn't consume; expects x to be an array, each position must be written to precisely once
|
// doesn't consume; expects x to be an array, each position must be written to precisely once
|
||||||
static void mut_copy(Mut* m, usz ms, B x, usz xs, usz l) { assert(isArr(x)); m->fns->m_copy(m, ms, x, xs, l); }
|
static void mut_copy(Mut* m, usz ms, B x, usz xs, usz l) { assert(isArr(x)); m->fns->m_copy(m, ms, x, xs, l); }
|
||||||
|
|
||||||
|
// MUT_APPEND_INIT must be called immediately after MAKE_MUT or MAKE_MUT_INIT
|
||||||
|
// after that, the only valid operation on the Mut will be MUT_APPEND
|
||||||
|
// using this append system will no longer prevent allocations from being done during the lifetime of the Mut
|
||||||
|
#define MUT_APPEND_INIT(N) ux N##_ci = 0; NOGC_E;
|
||||||
|
#define MUT_APPEND(N, X, XS, L) ({ ux l_ = (L); NOGC_CHECK; \
|
||||||
|
mut_copy(N, N##_ci, X, XS, l_); \
|
||||||
|
N##_ci+= l_; \
|
||||||
|
if (PTY(N->val) == t_harr) { NOGC_E; N->val->ia = N##_ci; } \
|
||||||
|
})
|
||||||
|
|
||||||
#define MUTG_INIT(N) MutFns N##_mutfns = *N->fns; void* N##_mutarr = N->a
|
#define MUTG_INIT(N) MutFns N##_mutfns = *N->fns; void* N##_mutarr = N->a
|
||||||
// these methods function as the non-G-postfixed ones, except that
|
// these methods function as the non-G-postfixed ones, except that
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user