PAPI  5.7.0.0
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 11 of file branches_testcode.c.

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

◆ 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 }
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
static long count
int i
Definition: fileop.c:140

◆ 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 }
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
static long count
int i
Definition: fileop.c:140

◆ 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 }
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
int i
Definition: fileop.c:140

◆ 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 }
static double array[ARRAYSIZE]
Definition: papi_l1_dca.c:23
int i
Definition: fileop.c:140

◆ 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
int gettimeofday(void *ptr1, void *ptr2)
int x
Definition: fileop.c:78
Here is the call graph for this function:

◆ 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
double c
Definition: multiplex.c:22
int quiet
Definition: rapl_overflow.c:18
volatile double a
int i
Definition: fileop.c:140

◆ 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 double b
double f(double a)
Definition: cpi.c:23
double c
Definition: multiplex.c:22
int one
int quiet
Definition: rapl_overflow.c:18
volatile double a
int x
Definition: fileop.c:78
int i
Definition: fileop.c:140
long long y
Definition: iozone.c:1335
Here is the call 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]
int rand()
int i
Definition: fileop.c:140
Here is the call 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++ ) {
112  double_mresult[i][j] += double_matrixa[i][k] * double_matrixb[k][j];
113  }
114  }
115  }
116 
117  return double_mresult[10][10];
118 }
#define COLUMNS
#define ROWS
static double double_mresult[ROWS][COLUMNS]
static double double_matrixb[ROWS][COLUMNS]
static double double_matrixa[ROWS][COLUMNS]
int i
Definition: fileop.c:140

◆ 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++) {
130  double_mresult[i][j] += double_matrixa[i][k] * double_matrixb[k][j];
131  }
132  }
133  }
134  return double_mresult[10][10];
135 }
#define COLUMNS
#define ROWS
static double double_mresult[ROWS][COLUMNS]
static double double_matrixb[ROWS][COLUMNS]
static double double_matrixa[ROWS][COLUMNS]
int i
Definition: fileop.c:140

◆ 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 }
#define COLUMNS
#define ROWS
static float float_matrixb[ROWS][COLUMNS]
int rand()
static float float_mresult[ROWS][COLUMNS]
static float float_matrixa[ROWS][COLUMNS]
int i
Definition: fileop.c:140
Here is the call 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 }
#define COLUMNS
#define ROWS
static float float_matrixb[ROWS][COLUMNS]
static float float_mresult[ROWS][COLUMNS]
static float float_matrixa[ROWS][COLUMNS]
int i
Definition: fileop.c:140

◆ 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 }
#define COLUMNS
#define ROWS
static float float_matrixb[ROWS][COLUMNS]
static float float_mresult[ROWS][COLUMNS]
static float float_matrixa[ROWS][COLUMNS]
int i
Definition: fileop.c:140

◆ 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  "big_loop:\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 big_loop # 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

◆ 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  "test_loop:\n"
14  " dec %%ecx\n"
15  " jnz test_loop\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  "test_loop:\n"
51  " deccc %%l0 ! decrement count\n"
52  " bnz test_loop ! 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,count @ set count\n"
61  " b test_loop\n"
62  "count: .word 333332\n"
63  "test_loop:\n"
64  " add r2,r2,#-1\n"
65  " cmp r2,#0\n"
66  " bne test_loop @ 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  "test_loop:\n"
75  " add x2,x2,#-1\n"
76  " cmp x2,#0\n"
77  " bne test_loop // 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 }
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2

◆ 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  "loadstore: # 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 loadstore\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  "loadstore: # 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 loadstore\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 }
#define CODE_UNIMPLEMENTED
Definition: testcode.h:2

◆ random_branches_testcode()

int random_branches_testcode ( int  number,
int  quiet 
)

Definition at line 109 of file branches_testcode.c.

109  {
110 
111  int j,junk=0;
112  double junk2=5.0;
113 
114  for(j=0;j<number;j++) {
115 
116  if (( ((random()>>2)^(random()>>4)) %1000)>500) goto label_false;
117 
118  junk++; /* can't just add, the optimizer is way too clever */
119 
120  junk2*=junk;
121 
122  //printf("T");
123  label_false:
124  //printf("F");
125  ;
126  }
127  if (!quiet) printf("%lf\n",junk2);
128 
129  return junk;
130 }
int junk
Definition: fileop.c:77
int quiet
Definition: rapl_overflow.c:18