minor code cleanup

This commit is contained in:
dzaima 2024-02-27 00:40:16 +02:00
parent fef984b6fd
commit 694920c273
2 changed files with 21 additions and 17 deletions

View File

@ -178,16 +178,17 @@ B fold_c1(Md1D* d, B x) { B f = d->f;
u64* xp = bitarr_ptr(x);
f64 r;
switch (rtid) { default: goto base;
case n_add: r = bit_sum (xp, ia); break;
case n_sub: r = bit_diff(xp, ia); break;
case n_and: case n_mul: case n_floor: r = bit_has (xp, ia, 0) ^ 1; break;
case n_or: case n_ceil: r = bit_has (xp, ia, 1) ; break;
case n_ne: r = fold_ne (xp, ia) ; break;
case n_eq: r = fold_ne (xp, ia) ^ (1&~ia); break;
case n_lt: r = bit_find(xp, ia, 1) == ia-1; break;
case n_le: r = bit_find(xp, ia, 0) != ia-1; break;
case n_gt: r = bit_find(xp, ia, 0) & 1; break;
case n_ge: r =~bit_find(xp, ia, 1) & 1; break;
case n_mul:
case n_and:case n_floor: r = bit_has (xp, ia, 0) ^ 1; break;
case n_or: case n_ceil: r = bit_has (xp, ia, 1); break;
case n_add: r = bit_sum (xp, ia); break;
case n_sub: r = bit_diff(xp, ia); break;
case n_ne: r = fold_ne (xp, ia); break;
case n_eq: r = fold_ne (xp, ia) ^ (1&~ia); break;
case n_lt: r = bit_find(xp, ia, 1) == ia-1; break;
case n_le: r = bit_find(xp, ia, 0) != ia-1; break;
case n_gt: r = bit_find(xp, ia, 0) & 1; break;
case n_ge: r =~bit_find(xp, ia, 1) & 1; break;
}
decG(x); return m_f64(r);
}
@ -203,6 +204,7 @@ B fold_c1(Md1D* d, B x) { B f = d->f;
if (rtid==n_ceil ) { f64 r=max_fns[xe-el_i8](tyany_ptr(x), ia); decG(x); return m_f64(r); } // ⌈
if (rtid==n_mul | rtid==n_and) { // ×/∧
void *xv = tyany_ptr(x);
assert(xe >= el_i8);
u8 sel = xe - el_i8;
f64 r = xe<=el_i32 ? prod_int_fns[sel](xv, ia, 1)
: prod_fns[sel](xv, ia, 1);

View File

@ -1263,13 +1263,15 @@ static B pick_replaceOne(B fn, usz pos, B x, usz xia) {
if (reusable(x) && TI(x,canStore)(rep)) { REUSE(x);
u8 xt = TY(x);
void* xp = tyany_ptr(x);
if (xt==t_i8arr ) { ((i8* )xp)[pos] = o2iG(rep); return x; }
else if (xt==t_i16arr) { ((i16*)xp)[pos] = o2iG(rep); return x; }
else if (xt==t_i32arr) { ((i32*)xp)[pos] = o2iG(rep); return x; }
else if (xt==t_f64arr) { ((f64*)xp)[pos] = o2fG(rep); return x; }
else if (xt==t_c8arr ) { ((u8* )xp)[pos] = o2cG(rep); return x; }
else if (xt==t_c16arr) { ((u16*)xp)[pos] = o2cG(rep); return x; }
else if (xt==t_c32arr) { ((u32*)xp)[pos] = o2cG(rep); return x; }
switch (xt) {
case t_i8arr: ((i8* )xp)[pos] = o2iG(rep); return x;
case t_i16arr: ((i16*)xp)[pos] = o2iG(rep); return x;
case t_i32arr: ((i32*)xp)[pos] = o2iG(rep); return x;
case t_f64arr: ((f64*)xp)[pos] = o2fG(rep); return x;
case t_c8arr: ((u8* )xp)[pos] = o2cG(rep); return x;
case t_c16arr: ((u16*)xp)[pos] = o2cG(rep); return x;
case t_c32arr: ((u32*)xp)[pos] = o2cG(rep); return x;
}
}
MAKE_MUT_INIT(r, xia, el_or(TI(x,elType), selfElType(rep))); MUTG_INIT(r);
mut_setG(r, pos, rep);