-
Notifications
You must be signed in to change notification settings - Fork 1
/
check.c
51 lines (45 loc) · 1.1 KB
/
check.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <stdio.h>
#include <stddef.h>
#include "trans.h"
TYPE A[N][M];
TYPE B[M][N];
static void init(TYPE A[N][M], TYPE B[M][N])
{
for (size_t i=0; i<N; i++) {
for (size_t j=0; j<M; j++) {
A[i][j] = i * M + j;
B[j][i] = -1;
}
}
}
static void check(const char *str, const TYPE B[M][N])
{
for (size_t j=0; j<M; j++) {
for (size_t i=0; i<N; i++) {
const TYPE exp = i * M + j;
if (exp != B[j][i]) {
fprintf(stderr, "%s: B[%zu][%zu] == %g != %g\n",
str, j, i, (double)B[j][i], exp);
}
}
}
}
int main(void)
{
#define CHECK_(f, a, b, c) \
do { \
void *A_ = (a), *B_ = (b), *C_ = (c); \
init(A_, B_); \
f(A_, B_); \
check(# f, C_); \
} while(0)
#define CHECK(f, a, b) CHECK_(f, (a), (b), (b))
CHECK(trans_REF, A, B);
CHECK(trans_UNROLL, A, B);
CHECK(trans_UNROLL_AND_JAM, A, B);
CHECK(trans_BLOCK, A, B);
CHECK(trans_LINEAR, A, B);
CHECK(trans_LINEAR_UNROLL, A, B);
CHECK_(trans_INPLACE, A, B, A);
return 0;
}