PAPI 7.1.0.0
Loading...
Searching...
No Matches
testcode.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ALL_OK   0
 
#define CODE_UNIMPLEMENTED   -1
 
#define ERROR_RESULT   -2
 

Functions

int instructions_million (void)
 
int instructions_fldcw (void)
 
int instructions_rep (void)
 
int branches_testcode (void)
 
int random_branches_testcode (int number, int quiet)
 
int flops_float_init_matrix (void)
 
float flops_float_matrix_matrix_multiply (void)
 
float flops_float_swapped_matrix_matrix_multiply (void)
 
int flops_double_init_matrix (void)
 
double flops_double_matrix_matrix_multiply (void)
 
double flops_double_swapped_matrix_matrix_multiply (void)
 
double do_flops3 (double x, int iters, int quiet)
 
double do_flops (int n, int quiet)
 
int cache_write_test (double *array, int size)
 
double cache_read_test (double *array, int size)
 
int cache_random_write_test (double *array, int size, int count)
 
double cache_random_read_test (double *array, int size, int count)
 
double do_cycles (int minimum_time)
 

Macro Definition Documentation

◆ ALL_OK

#define ALL_OK   0

Definition at line 1 of file testcode.h.

◆ CODE_UNIMPLEMENTED

#define CODE_UNIMPLEMENTED   -1

Definition at line 2 of file testcode.h.

◆ ERROR_RESULT

#define ERROR_RESULT   -2

Definition at line 3 of file testcode.h.

Function Documentation

◆ branches_testcode()

int branches_testcode ( void  )

Definition at line 23 of file branches_testcode.c.

23 {
24
25#if defined(__i386__) || (defined __x86_64__)
26 asm( "\txor %%ecx,%%ecx\n"
27 "\tmov $500000,%%ecx\n"
28 "test_loop:\n"
29 "\tjmp test_jmp\n"
30 "\tnop\n"
31 "test_jmp:\n"
32 "\txor %%eax,%%eax\n"
33 "\tjnz test_jmp2\n"
34 "\tinc %%eax\n"
35 "test_jmp2:\n"
36 "\tdec %%ecx\n"
37 "\tjnz test_loop\n"
38 : /* no output registers */
39 : /* no inputs */
40 : "cc", "%ecx", "%eax" /* clobbered */
41 );
42 return 0;
43
44#elif defined(__arm__)
45 /* Initial code contributed by sam wang linux.swang _at_ gmail.com */
46 asm( "\teor r3,r3,r3\n"
47 "\tldr r3,=500000\n"
48 "test_loop:\n"
49 "\tB test_jmp\n"
50 "\tnop\n"
51 "test_jmp:\n"
52 "\teor r2,r2,r2\n"
53 "\tcmp r2,#1\n"
54 "\tbge test_jmp2\n"
55 "\tnop\n"
56 "\tadd r2,r2,#1\n"
57 "test_jmp2:\n"
58 "\tsub r3,r3,#1\n"
59 "\tcmp r3,#1\n"
60 "\tbgt test_loop\n"
61 : /* no output registers */
62 : /* no inputs */
63 : "cc", "r2", "r3" /* clobbered */
64 );
65
66 return 0;
67#elif defined(__aarch64__)
68 asm( "\teor x3,x3,x3\n"
69 "\tldr x3,=500000\n"
70 "test_loop:\n"
71 "\tB test_jmp\n"
72 "\tnop\n"
73 "test_jmp:\n"
74 "\teor x2,x2,x2\n"
75 "\tcmp x2,#1\n"
76 "\tbge test_jmp2\n"
77 "\tnop\n"
78 "\tadd x2,x2,#1\n"
79 "test_jmp2:\n"
80 "\tsub x3,x3,#1\n"
81 "\tcmp x3,#1\n"
82 "\tbgt test_loop\n"
83 : /* no output registers */
84 : /* no inputs */
85 : "cc", "x2", "x3" /* clobbered */
86 );
87
88 return 0;
89#elif defined(__powerpc__)
90 /* Not really optimized */
91
92 asm( "\txor 3,3,3\n"
93 "\tlis 3,500000@ha\n"
94 "\taddi 3,3,500000@l\n"
95 "test_loop:\n"
96 "\tb test_jmp\n"
97 "\tnop\n"
98 "test_jmp:\n"
99 "\txor 4,4,4\n"
100 "\tcmpwi cr0,4,1\n"
101 "\tbge test_jmp2\n"
102 "\tnop\n"
103 "\taddi 4,4,1\n"
104 "test_jmp2:\n"
105 "\taddi 3,3,-1\n"
106 "\tcmpwi cr0,3,1\n"
107 "\tbgt test_loop\n"
108 : /* no output registers */
109 : /* no inputs */
110 : "cr0", "r3", "r4" /* clobbered */
111 );
112
113 return 0;
114#endif
115
116 return -1;
117
118}
Here is the caller graph for this function:

◆ cache_random_read_test()

double cache_random_read_test ( double *  array,
int  size,
int  count 
)

Definition at line 38 of file cache_testcode.c.

38 {
39
40 int i;
41 double sum=0;
42
43 for(i=0; i<count; i++) {
44 sum+= array[random()%size];
45 }
46
47 return sum;
48}
int i
static long count
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
Here is the caller graph for this function:

◆ cache_random_write_test()

int cache_random_write_test ( double *  array,
int  size,
int  count 
)

Definition at line 28 of file cache_testcode.c.

28 {
29 int i;
30
31 for(i=0; i<count; i++) {
32 array[random()%size]=(double)i;
33 }
34
35 return 0;
36}
Here is the caller graph for this function:

◆ cache_read_test()

double cache_read_test ( double *  array,
int  size 
)

Definition at line 16 of file cache_testcode.c.

16 {
17
18 int i;
19 double sum=0;
20
21 for(i=0; i<size; i++) {
22 sum+= array[i];
23 }
24
25 return sum;
26}
Here is the caller graph for this function:

◆ cache_write_test()

int cache_write_test ( double *  array,
int  size 
)

Definition at line 6 of file cache_testcode.c.

6 {
7 int i;
8
9 for(i=0; i<size; i++) {
10 array[i]=(double)i;
11 }
12
13 return 0;
14}
Here is the caller graph for this function:

◆ do_cycles()

double do_cycles ( int  minimum_time)

Definition at line 8 of file busy_work.c.

9{
10 struct timeval start, now;
11 double x, sum;
12
13 gettimeofday( &start, NULL );
14
15 for ( ;; ) {
16 sum = 1.0;
17 for ( x = 1.0; x < 250000.0; x += 1.0 ) {
18 sum += x;
19 }
20 if ( sum < 0.0 ) {
21 printf( "==>> SUM IS NEGATIVE !! <<==\n" );
22 }
23
24 gettimeofday( &now, NULL );
25 if ( now.tv_sec >= start.tv_sec + minimum_time ) {
26 break;
27 }
28 }
29 return sum;
30}
static struct timeval start
__time_t tv_sec
volatile double x

◆ do_flops()

double do_flops ( int  n,
int  quiet 
)

Definition at line 184 of file flops_testcode.c.

185{
186 int i;
187 double c = 0.11;
188
189 for ( i = 0; i < n; i++ ) {
190 c += a * b;
191 }
192
193 if (!quiet) printf("%lf\n",c);
194
195 return c;
196}
volatile double b
volatile double a
static double c[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:40
int quiet
Definition: rapl_overflow.c:19

◆ do_flops3()

double do_flops3 ( double  x,
int  iters,
int  quiet 
)

Definition at line 142 of file flops_testcode.c.

143{
144 int i;
145 double w, y, z, a, b, c, d, e, f, g, h;
146 double result;
147 double one;
148 one = 1.0;
149 w = x;
150 y = x;
151 z = x;
152 a = x;
153 b = x;
154 c = x;
155 d = x;
156 e = x;
157 f = x;
158 g = x;
159 h = x;
160 for ( i = 1; i <= iters; i++ ) {
161 w = w * 1.000000000001 + one;
162 y = y * 1.000000000002 + one;
163 z = z * 1.000000000003 + one;
164 a = a * 1.000000000004 + one;
165 b = b * 1.000000000005 + one;
166 c = c * 0.999999999999 + one;
167 d = d * 0.999999999998 + one;
168 e = e * 0.999999999997 + one;
169 f = f * 0.999999999996 + one;
170 g = h * 0.999999999995 + one;
171 h = h * 1.000000000006 + one;
172 }
173 result = 2.0 * ( a + b + c + d + e + f + w + x + y + z + g + h );
174
175 if (!quiet) printf("Result = %lf\n", result);
176
177 return result;
178}
volatile int result
double f(double a)
Definition: cpi.c:23
volatile double y
Here is the call graph for this function:
Here is the caller graph for this function:

◆ flops_double_init_matrix()

int flops_double_init_matrix ( void  )

Definition at line 81 of file flops_testcode.c.

81 {
82
83 int i,j;
84
85 /* Initialize the Matrix arrays */
86 /* Non-optimail row major. Intentional? */
87 for ( i = 0; i < ROWS; i++ ) {
88 for ( j = 0; j < COLUMNS; j++) {
89 double_mresult[j][i] = 0.0;
90 double_matrixa[j][i] = ( double ) rand() * ( double ) 1.1;
91 double_matrixb[j][i] = ( double ) rand() * ( double ) 1.1;
92 }
93 }
94
95#if defined(__powerpc__)
96 /* has fused multiply-add */
97 return ROWS*ROWS*ROWS;
98#else
99 return ROWS*ROWS*ROWS*2;
100#endif
101
102}
#define COLUMNS
#define ROWS
static double double_mresult[ROWS][COLUMNS]
static double double_matrixb[ROWS][COLUMNS]
static double double_matrixa[ROWS][COLUMNS]
Here is the caller graph for this function:

◆ flops_double_matrix_matrix_multiply()

double flops_double_matrix_matrix_multiply ( void  )

Definition at line 104 of file flops_testcode.c.

104 {
105
106 int i,j,k;
107
108 /* Matrix-Matrix multiply */
109 for ( i = 0; i < ROWS; i++ ) {
110 for ( j = 0; j < COLUMNS; j++ ) {
111 for ( k = 0; k < COLUMNS; k++ ) {
113 }
114 }
115 }
116
117 return double_mresult[10][10];
118}
Here is the caller graph for this function:

◆ flops_double_swapped_matrix_matrix_multiply()

double flops_double_swapped_matrix_matrix_multiply ( void  )

Definition at line 120 of file flops_testcode.c.

120 {
121
122 int i, j, k;
123
124 /* Matrix-Matrix multiply */
125 /* With inner loops swapped */
126
127 for (i = 0; i < ROWS; i++) {
128 for (k = 0; k < COLUMNS; k++) {
129 for (j = 0; j < COLUMNS; j++) {
131 }
132 }
133 }
134 return double_mresult[10][10];
135}

◆ flops_float_init_matrix()

int flops_float_init_matrix ( void  )

Definition at line 23 of file flops_testcode.c.

23 {
24
25 int i,j;
26
27 /* Initialize the Matrix arrays */
28 /* Non-optimail row major. Intentional? */
29 for ( i = 0; i < ROWS; i++ ) {
30 for ( j = 0; j < COLUMNS; j++) {
31 float_mresult[j][i] = 0.0;
32 float_matrixa[j][i] = ( float ) rand() * ( float ) 1.1;
33 float_matrixb[j][i] = ( float ) rand() * ( float ) 1.1;
34 }
35 }
36
37#if defined(__powerpc__)
38 /* Has fused multiply-add */
39 return ROWS*ROWS*ROWS;
40#else
41 return ROWS*ROWS*ROWS*2;
42#endif
43
44}
static float float_matrixa[ROWS][COLUMNS]
static float float_matrixb[ROWS][COLUMNS]
static float float_mresult[ROWS][COLUMNS]
Here is the caller graph for this function:

◆ flops_float_matrix_matrix_multiply()

float flops_float_matrix_matrix_multiply ( void  )

Definition at line 46 of file flops_testcode.c.

46 {
47
48 int i,j,k;
49
50 /* Matrix-Matrix multiply */
51 for ( i = 0; i < ROWS; i++ ) {
52 for ( j = 0; j < COLUMNS; j++ ) {
53 for ( k = 0; k < COLUMNS; k++ ) {
54 float_mresult[i][j] += float_matrixa[i][k] * float_matrixb[k][j];
55 }
56 }
57 }
58
59 return float_mresult[10][10];
60}
Here is the caller graph for this function:

◆ flops_float_swapped_matrix_matrix_multiply()

float flops_float_swapped_matrix_matrix_multiply ( void  )

Definition at line 62 of file flops_testcode.c.

62 {
63
64 int i, j, k;
65
66 /* Matrix-Matrix multiply */
67 /* With inner loops swapped */
68
69 for (i = 0; i < ROWS; i++) {
70 for (k = 0; k < COLUMNS; k++) {
71 for (j = 0; j < COLUMNS; j++) {
72 float_mresult[i][j] += float_matrixa[i][k] * float_matrixb[k][j];
73 }
74 }
75 }
76 return float_mresult[10][10];
77}
Here is the caller graph for this function:

◆ instructions_fldcw()

int instructions_fldcw ( void  )

Definition at line 92 of file instructions_testcode.c.

92 {
93
94#if defined(__i386__) || (defined __x86_64__)
95
96 int saved_cw,result,cw;
97 double three=3.0;
98
99 asm( " mov $100000,%%ecx\n"
100 "44:\n"
101 " fldl %1 # load value onto fp stack\n"
102 " fnstcw %0 # store control word to mem\n"
103 " movzwl %0, %%eax # load cw from mem, zero extending\n"
104 " movb $12, %%ah # set cw for \"round to zero\"\n"
105 " movw %%ax, %3 # store back to memory\n"
106 " fldcw %3 # save new rounding mode\n"
107 " fistpl %2 # save stack value as integer to mem\n"
108 " fldcw %0 # restore old cw\n"
109 " loop 44b # loop to make the count more obvious\n"
110 : /* no output registers */
111 : "m"(saved_cw), "m"(three), "m"(result), "m"(cw) /* inputs */
112 : "cc", "%ecx","%eax" /* clobbered */
113 );
114 return 0;
115#endif
116
117 return CODE_UNIMPLEMENTED;
118}
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2
Here is the caller graph for this function:

◆ instructions_million()

int instructions_million ( void  )

Definition at line 8 of file instructions_testcode.c.

8 {
9
10#if defined(__i386__) || (defined __x86_64__)
11 asm( " xor %%ecx,%%ecx\n"
12 " mov $499999,%%ecx\n"
13 "55:\n"
14 " dec %%ecx\n"
15 " jnz 55b\n"
16 : /* no output registers */
17 : /* no inputs */
18 : "cc", "%ecx" /* clobbered */
19 );
20 return 0;
21#elif defined(__PPC__)
22 asm( " nop # to give us an even million\n"
23 " lis 15,499997@ha # load high 16-bits of counter\n"
24 " addi 15,15,499997@l # load low 16-bits of counter\n"
25 "55:\n"
26 " addic. 15,15,-1 # decrement counter\n"
27 " bne 0,55b # loop until zero\n"
28 : /* no output registers */
29 : /* no inputs */
30 : "cc", "15" /* clobbered */
31 );
32 return 0;
33#elif defined(__ia64__)
34
35 asm( " mov loc6=166666 // below is 6 instr.\n"
36 " ;; // because of that we count 4 too few\n"
37 "55:\n"
38 " add loc6=-1,loc6 // decrement count\n"
39 " ;;\n"
40 " cmp.ne p2,p3=0,loc6\n"
41 "(p2) br.cond.dptk 55b // if not zero, loop\n"
42 : /* no output registers */
43 : /* no inputs */
44 : "p2", "loc6" /* clobbered */
45 );
46 return 0;
47#elif defined(__sparc__)
48 asm( " sethi %%hi(333333), %%l0\n"
49 " or %%l0,%%lo(333333),%%l0\n"
50 "55:\n"
51 " deccc %%l0 ! decrement count\n"
52 " bnz 55b ! repeat until zero\n"
53 " nop ! branch delay slot\n"
54 : /* no output registers */
55 : /* no inputs */
56 : "cc", "l0" /* clobbered */
57 );
58 return 0;
59#elif defined(__arm__)
60 asm( " ldr r2,42f @ set count\n"
61 " b 55f\n"
62 "42: .word 333332\n"
63 "55:\n"
64 " add r2,r2,#-1\n"
65 " cmp r2,#0\n"
66 " bne 55b @ repeat till zero\n"
67 : /* no output registers */
68 : /* no inputs */
69 : "cc", "r2" /* clobbered */
70 );
71 return 0;
72#elif defined(__aarch64__)
73 asm( " ldr x2,=333332 // set count\n"
74 "55:\n"
75 " add x2,x2,#-1\n"
76 " cmp x2,#0\n"
77 " bne 55b // repeat till zero\n"
78 : /* no output registers */
79 : /* no inputs */
80 : "cc", "r2" /* clobbered */
81 );
82 return 0;
83#endif
84
85 return CODE_UNIMPLEMENTED;
86
87}
Here is the caller graph for this function:

◆ instructions_rep()

int instructions_rep ( void  )

Definition at line 124 of file instructions_testcode.c.

124 {
125
126#if defined(__i386__) || defined(__ILP32__)
127
128 char buffer_out[16384];
129
130 asm( " mov $1000,%%edx\n"
131 " cld\n"
132 "66: # test 8-bit store\n"
133 " mov $0xd, %%al # set eax to d\n"
134 " mov $16384, %%ecx\n"
135 " mov %0, %%edi # set destination\n"
136 " rep stosb # store d 16384 times, auto-increment\n"
137 " dec %%edx\n"
138 " jnz 66b\n"
139 : /* outputs */
140 : "rm" (buffer_out) /* inputs */
141 : "cc", "%esi","%edi","%edx","%ecx","%eax","memory" /* clobbered */
142 );
143 return 0;
144#elif defined (__x86_64__)
145
146 char buffer_out[16384];
147
148 asm( " mov $1000,%%edx\n"
149 " cld\n"
150 "66: # test 8-bit store\n"
151 " mov $0xd, %%al # set eax to d\n"
152 " mov $16384, %%ecx\n"
153 " mov %0, %%rdi # set destination\n"
154 " rep stosb # store d 16384 times, auto-increment\n"
155 " dec %%edx\n"
156 " jnz 66b\n"
157 : /* outputs */
158 : "rm" (buffer_out) /* inputs */
159 : "cc", "%esi","%edi","%edx","%ecx","%eax","memory" /* clobbered */
160 );
161 return 0;
162#endif
163
164 return CODE_UNIMPLEMENTED;
165
166}
Here is the caller graph for this function:

◆ random_branches_testcode()

int random_branches_testcode ( int  number,
int  quiet 
)

Definition at line 121 of file branches_testcode.c.

121 {
122
123 int j,junk=0;
124 double junk2=5.0;
125 long int b,z1,z2,z3,z4,result;
126 z1=236;
127 z2=347;
128 z3=458;
129 z4=9751;
130
131 for(j=0;j<number;j++) {
132
133 BRNG();
134 if( (result%2)==0 ){
135 junk = result + j;
136 junk = 1 + j/junk;
137 junk2 *= (double)junk;
138 }
139 BRNG();
140 junk = result + j;
141 junk = 1 + j/junk;
142 junk2 *= (double)junk;
143 }
144 if (!quiet) printf("%lf\n",junk2);
145
146 return junk;
147}
volatile unsigned int z1
volatile unsigned int z2
volatile unsigned int z3
volatile unsigned int z4
#define BRNG()
static double b[MATRIX_SIZE][MATRIX_SIZE]
Definition: libmsr_basic.c:39
Here is the caller graph for this function: