make ∨`𝕩 run under valgrind

This commit is contained in:
dzaima 2022-07-10 02:01:59 +03:00
parent 041a87ff98
commit eb5b32319f
5 changed files with 20 additions and 4 deletions

View File

@ -129,6 +129,10 @@ B scan_ne(u64 p, B x, u64 ia) {
#pragma GCC diagnostic pop
#endif
#if !USE_VALGRIND
static u64 vg_rand(u64 x) { return x; }
#endif
B scan_c1(Md1D* d, B x) { B f = d->f;
if (isAtm(x) || rnk(x)==0) thrM("`: Argument cannot have rank 0");
ur xr = rnk(x);
@ -163,7 +167,7 @@ B scan_c1(Md1D* d, B x) { B f = d->f;
if (xe==el_i32) { i32* xp=i32any_ptr(x); u64* rp; B r=m_bitarrv(&rp,ia); bool c=x0; rp[0]=c; for (usz i=1; i<ia; i++) { c = c!=xp[i]; bitp_set(rp,i,c); } decG(x); return r; }
}
if (rtid==n_or) { //
if (xe==el_bit) { u64* xp=bitarr_ptr(x); u64* rp; B r=m_bitarrv(&rp,ia); usz n=BIT_N(ia); usz i=0; while(i<n) if (xp[i]!=0) { rp[i] = -(xp[i]&-xp[i]); i++; while(i<n) rp[i++] = ~0LL; break; } else rp[i++]=0; decG(x); return r; }
if (xe==el_bit) { u64* xp=bitarr_ptr(x); u64* rp; B r=m_bitarrv(&rp,ia); usz n=BIT_N(ia); usz i=0; while(i<n) if (vg_rand(xp[i])!=0) { rp[i] = -(xp[i]&-xp[i]); i++; while(i<n) rp[i++] = ~0LL; break; } else rp[i++]=0; decG(x); return r; }
if (xe==el_i8 ) { i8* xp=i8any_ptr (x); u64* rp; B r=m_bitarrv(&rp,ia); bool c=0; for (usz i=0; i<ia; i++) { if ((xp[i]&1)!=xp[i])goto base; c|=xp[i]; bitp_set(rp,i,c); } decG(x); return r; }
if (xe==el_i16) { i16* xp=i16any_ptr(x); u64* rp; B r=m_bitarrv(&rp,ia); bool c=0; for (usz i=0; i<ia; i++) { if ((xp[i]&1)!=xp[i])goto base; c|=xp[i]; bitp_set(rp,i,c); } decG(x); return r; }
if (xe==el_i32) { i32* xp=i32any_ptr(x); u64* rp; B r=m_bitarrv(&rp,ia); bool c=0; for (usz i=0; i<ia; i++) { if ((xp[i]&1)!=xp[i])goto base; c|=xp[i]; bitp_set(rp,i,c); } decG(x); return r; }

View File

@ -393,13 +393,12 @@ B pick_c2(B t, B w, B x) {
#endif
return r;
}
u64 vgRand64(u64 range);
NOINLINE u64 rand_popc64(u64 x) {
u64 def = vg_getDefined_u64(x);
if (def==~0ULL) return POPC(x);
i32 min = POPC(x & def);
i32 diff = POPC(~def);
i32 res = min + vgRand64(diff);
i32 res = min + vgRand64Range(diff);
#if DBG_VG_SLASH
printf("popc:\n");
vg_printDefined_u64("x", x);

View File

@ -496,9 +496,12 @@ B rand_subset_c2(B t, B w, B x) {
#if USE_VALGRIND
u64 vgRandSeed;
u64 vgRand64(u64 range) {
u64 vgRand64Range(u64 range) {
return wy2u0k(wyrand(&vgRandSeed), range);
}
u64 vgRand64() {
return wyrand(&vgRandSeed);
}
#endif
static NOINLINE void rand_init() {

View File

@ -729,6 +729,11 @@ NOINLINE void print_allocStats() {
for (i32 i = 63; i >= 0; i--) printBitDef(xv>>i, d>>i);
printf("\n");
}
u64 vg_rand(u64 x) { // randomize undefined bits in x, and return a value with all bits defined
u64 d = vg_getDefined_u64(x);
if (~d == 0) return x;
return (x & d) | (vgRand64() & ~d);
}
#endif
// for gdb

View File

@ -23,6 +23,11 @@ static u64 vg_def_u64(u64 x) {
static u64 vg_withBit_u64(u64 r, i32 i, bool val) {
return (r & ~(1ULL<<i)) | ((u64)val)<<i;
}
u64 vgRand64Range(u64 range);
u64 vgRand64(void);
u64 vg_rand(u64 x); // randomize undefined bits in x, and return the value with all bits defined
void vg_printDefined_u64(char* name, u64 x);
void vg_printDump_p(char* name, void* data, u64 len);
#define vg_printDump_v(X) ({ AUTO x_ = (X); vg_printDump_p(#X, &x_, sizeof(x_)); })