comparison test/suite_aggrs/globals.c @ 457:90b1d927912a

- suite_aggrs: make sure random memory used doesn't ever result in NaN fp values (for every possible address), as this messes with result comparison
author Tassilo Philipp
date Fri, 28 Jan 2022 14:11:21 +0100
parents a3b2afc35730
children 1c18c2377c24
comparison
equal deleted inserted replaced
456:20fa684221a1 457:90b1d927912a
30 DEF_TYPES 30 DEF_TYPES
31 #undef X 31 #undef X
32 32
33 #define AGGR_MISALIGN 0 33 #define AGGR_MISALIGN 0
34 34
35 static double rand_d() { return ( ( (double) rand() ) / ( (double) RAND_MAX ) ); } 35 static double rand_d() { return ( ( (double) rand() ) / ( (double) RAND_MAX ) ); }
36 static void rand_mem(void* p, size_t s) { int i; for(i=0; i<s; ++i) ((char*)p)[i] = (char)rand(); } /* byte by byte is slow, but whatev */ 36
37 /* fill mem with random values, make sure no float aligned memory location
38 * results in a NaN, as they always compare to false; so avaid all ones in
39 * exporent (for simplicity we just look at first 7 exponent bits and make sure
40 * they aren't all set, which would work for all IEEE754 precision formats) */
41 static void rand_mem__fp_friendly(void* p, size_t s)
42 {
43 int i;
44 for(i = 0; i<s; ++i) {
45 char* c = (char*)p;
46 c[i] = (char)rand(); /* slowish, byte by byte, but whatev */
47 if((c[i]&0x7f) == 0x7f)
48 c[i] ^= 1;
49 }
50 }
37 51
38 static int calc_max_aggr_size() 52 static int calc_max_aggr_size()
39 { 53 {
40 int i, s = 0; 54 int i, s = 0;
41 for(i=0; i<G_naggs; ++i) 55 for(i=0; i<G_naggs; ++i)
60 K_l[i] = (long long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2))); 74 K_l[i] = (long long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2)));
61 K_p[i] = (void*) (long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(void*)*8-1))); 75 K_p[i] = (void*) (long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(void*)*8-1)));
62 K_f[i] = (float) (rand_d() * FLT_MAX); 76 K_f[i] = (float) (rand_d() * FLT_MAX);
63 K_d[i] = (double) (((rand_d()-0.5)*2) * DBL_MAX); 77 K_d[i] = (double) (((rand_d()-0.5)*2) * DBL_MAX);
64 K_a[i] = malloc(maxaggrsize+AGGR_MISALIGN); 78 K_a[i] = malloc(maxaggrsize+AGGR_MISALIGN);
65 rand_mem(K_a[i], maxaggrsize+AGGR_MISALIGN); 79 rand_mem__fp_friendly(K_a[i], maxaggrsize+AGGR_MISALIGN);
66 K_a[i] = (char*)K_a[i]+AGGR_MISALIGN; 80 K_a[i] = (char*)K_a[i]+AGGR_MISALIGN;
67 } 81 }
68 } 82 }
69 83
70 void clear_V() 84 void clear_V()