simpler vg_pext_u64 tail handling
that makes it not get SIMD-mangled when optimizations are enabled, thus allowing valgrind to preserve vbits
This commit is contained in:
parent
aabaac977b
commit
0b155e4416
@ -363,14 +363,14 @@ B pick_c2(B t, B w, B x) {
|
||||
if (!(maskD&c) && undefMask==0) undefMask = (~0ULL)<<ri;
|
||||
if (vg_def_u64(mask&c)) r = vg_withBit_u64(r, ri++, (c&src)!=0);
|
||||
}
|
||||
while (ri<64) r = vg_withBit_u64(r, ri++, 0);
|
||||
if (ri<64) r = r & (1ULL<<ri)-1;
|
||||
r = vg_withDefined_u64(r, vg_getDefined_u64(r) & ~undefMask);
|
||||
#if DBG_VG_SLASH
|
||||
printf("pext:\n");
|
||||
vg_printDefined_u64("src", src);
|
||||
vg_printDefined_u64("msk", mask);
|
||||
vg_printDefined_u64("res", r);
|
||||
vg_printDefined_u64("exp", _pext_u64(src, mask));
|
||||
vg_printDefined_u64("exp", _pext_u64(src, mask));
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
@ -706,7 +706,7 @@ NOINLINE void print_allocStats() {
|
||||
u8 vbits[len];
|
||||
int r = VALGRIND_GET_VBITS(data, vbits, len);
|
||||
|
||||
printf("%s:\n", name);
|
||||
if(name!=NULL) printf("%s:\n", name);
|
||||
if (r!=1) printf("(failed to get vbits)\n");
|
||||
|
||||
for (u64 i = 0; i < len; i++) {
|
||||
@ -721,7 +721,7 @@ NOINLINE void print_allocStats() {
|
||||
putchar('\n');
|
||||
}
|
||||
void vg_printDefined_u64(char* name, u64 x) {
|
||||
printf("%s: ", name);
|
||||
if(name!=NULL) printf("%s: ", name);
|
||||
u64 d = vg_getDefined_u64(x);
|
||||
u64 xv = x;
|
||||
VALGRIND_MAKE_MEM_DEFINED(&xv, 8);
|
||||
@ -734,6 +734,43 @@ NOINLINE void print_allocStats() {
|
||||
if (~d == 0) return x;
|
||||
return (x & d) | (vgRand64() & ~d);
|
||||
}
|
||||
B vg_validateResult(B x) {
|
||||
if (!isArr(x)) return x;
|
||||
void* data;
|
||||
u64 len;
|
||||
u8 xe = TI(x,elType);
|
||||
u64 ia = a(x)->ia;
|
||||
if (xe!=el_B) {
|
||||
data = tyany_ptr(x);
|
||||
if (xe==el_bit) {
|
||||
i32 left = ia&63;
|
||||
len = (ia>>6)*8;
|
||||
if (left) {
|
||||
u64 last = ((u64*)data)[len/8];
|
||||
u64 exp = (1ULL<<left) - 1;
|
||||
u64 got = vg_getDefined_u64(last);
|
||||
if ((got&exp) != exp) {
|
||||
printf("Expected %d defined trailing bits, got:\n", left);
|
||||
vg_printDefined_u64(NULL, last);
|
||||
err("");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
len = elWidth(xe) * ia;
|
||||
}
|
||||
} else {
|
||||
B* xp = arr_bptr(x);
|
||||
if (xp==NULL) return x; // can't check unknown type array
|
||||
data = xp;
|
||||
len = sizeof(B) * ia;
|
||||
}
|
||||
if (VALGRIND_CHECK_MEM_IS_DEFINED(data, len)) {
|
||||
printf("Expected "N64d" defined bytes, got:\n", len);
|
||||
vg_printDump_p(NULL, data, len);
|
||||
err("");
|
||||
}
|
||||
return x;
|
||||
}
|
||||
#endif
|
||||
|
||||
// for gdb
|
||||
|
||||
16
src/h.h
16
src/h.h
@ -278,9 +278,9 @@ typedef struct Arr {
|
||||
Value* VALIDATEP(Value* x);
|
||||
#define UD assert(false);
|
||||
#else
|
||||
#define assert(x) {if (!(x)) __builtin_unreachable();}
|
||||
#define VALIDATE(x) (x)
|
||||
#define VALIDATEP(x) (x)
|
||||
#define assert(X) {if (!(X)) __builtin_unreachable();}
|
||||
#define VALIDATE(X) (X)
|
||||
#define VALIDATEP(X) (X)
|
||||
#define UD __builtin_unreachable();
|
||||
#endif
|
||||
#if WARN_SLOW==1
|
||||
@ -593,15 +593,21 @@ typedef struct Fun {
|
||||
BBB2B c2;
|
||||
} Fun;
|
||||
|
||||
#if USE_VALGRIND
|
||||
B vg_validateResult(B x);
|
||||
#define VRES(X) vg_validateResult(X)
|
||||
#else
|
||||
#define VRES(X) X
|
||||
#endif
|
||||
|
||||
B c1F(B f, B x);
|
||||
B c2F(B f, B w, B x);
|
||||
static B c1(B f, B x) { // BQN-call f monadically; consumes x
|
||||
if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, x));
|
||||
if (isFun(f)) return VALIDATE(VRES(c(Fun,f)->c1(f, x)));
|
||||
return c1F(f, x);
|
||||
}
|
||||
static B c2(B f, B w, B x) { // BQN-call f dyadically; consumes w,x
|
||||
if (isFun(f)) return VALIDATE(c(Fun,f)->c2(f, w, x));
|
||||
if (isFun(f)) return VALIDATE(VRES(c(Fun,f)->c2(f, w, x)));
|
||||
return c2F(f, w, x);
|
||||
}
|
||||
static void errMd(B x) { if(RARE(isMd(x))) thrM("Calling a modifier"); }
|
||||
|
||||
Loading…
Reference in New Issue
Block a user