2 /* Test of origin tracking through floating point code and in the case
3 where there are large amounts of uninitialised data floating
4 around. This program creates 3 matrices of 2300x2300 doubles,
5 makes one value in them undefined, does arithmetic, and tests the
6 result, which is then undefined.
8 This also tests the secondary otag cache (ocacheL2), since the
9 amount of uninitialised data is somewhat over 43MB and it appears
10 that quite a lot of non-zero-otag lines are pushed into ocacheL2.
12 This program needs to be compiled with -O.
18 #include "../memcheck.h"
21 double** alloc_square_array ( int nArr
)
26 vec
= malloc(nArr
* sizeof(double*));
28 for (i
= 0; i
< nArr
; i
++) {
29 vec
[i
] = malloc(nArr
* sizeof(double));
35 double** do3x3smooth ( double** arr
, int nArr
)
40 out
= alloc_square_array(nArr
- 2);
42 for (i
= 1; i
< nArr
-1; i
++) {
43 for (j
= 1; j
< nArr
-1; j
++) {
44 double s
= arr
[i
-1][j
-1] + arr
[i
-1][j
] + arr
[i
-1][j
+1]
45 + arr
[i
][j
-1] + arr
[i
][j
] + arr
[i
][j
+1]
46 + arr
[i
+1][j
-1] + arr
[i
+1][j
] + arr
[i
+1][j
+1];
47 out
[i
-1][j
-1] = s
/ 9.0;
53 double sum ( double** arr
, int nArr
)
58 for (i
= 0; i
< nArr
; i
++) {
59 for (j
= 0; j
< nArr
; j
++) {
66 void setup_arr ( /*OUT*/double** arr
, int nArr
)
70 for (i
= 0; i
< nArr
; i
++) {
71 for (j
= 0; j
< nArr
; j
++) {
72 arr
[i
][j
] = (double)(i
* j
);
73 if (i
== nArr
/2 && j
== nArr
/2) {
74 unsigned char* p
= (unsigned char*)&arr
[i
][j
];
75 (void) VALGRIND_MAKE_MEM_UNDEFINED(p
, 1);
85 double r
, **arr
, **arr2
, **arr3
;
86 arr
= alloc_square_array(nArr
);
87 setup_arr( arr
, nArr
);
88 arr2
= do3x3smooth( arr
, nArr
);
89 arr3
= do3x3smooth( arr2
, nArr
-2 );
90 r
= sum( arr3
, nArr
-4 );
91 /* Convert answer to int before testing it, so as to
92 guarantee there's only one conditional branch. */
93 if (0) fprintf(stderr
, "r = %g\n", r
);
96 if (0) fprintf(stderr
, "ri = %d\n", ri
);
97 if (ri
== 696565111) {
98 fprintf(stderr
, "Test succeeded.\n");
100 fprintf(stderr
, "Test FAILED !\n");