20int main(
int argc,
char **argv) {
23 int num_random_branches=500000;
24 long long high=0,low=0,average=0,
expected=1500000;
33 printf(
"\nTesting the PAPI_BR_MSP event.\n");
50 if (!
quiet) printf(
"Could not add PAPI_BR_INS\n");
66 printf(
"\nPart 1: Testing that easy to predict loop has few misses\n");
67 printf(
"Testing a loop with %lld branches (%d times):\n",
69 printf(
"\tOn a simple loop like this, "
70 "miss rate should be very small.\n");
73 for(
i=0;
i<num_runs;
i++) {
83 fprintf(
stderr,
"\tCode unimplemented\n");
84 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
89 "reading PAPI_TOT_INS",
retval );
97 average=(
total/num_runs);
99 if (!
quiet) printf(
"\tAverage number of branch misses: %lld\n",average);
102 if (!
quiet) printf(
"Branch miss rate too high\n");
103 test_fail( __FILE__, __LINE__,
"Error too high", 1 );
109 printf(
"\nPart 2\n");
112 high=0; low=0;
total=0;
114 for(
i=0;
i<num_runs;
i++) {
123 fprintf(
stderr,
"\tCode unimplemented\n");
124 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
129 "reading PAPI_TOT_INS",
retval );
137 average=
total/num_runs;
141 printf(
"\nTesting a function that branches "
142 "based on a random number\n");
143 printf(
" The loop has %lld branches\n",
expected);
144 printf(
" %d are random branches.\n",num_random_branches);
147 high=0; low=0;
total=0;
149 for(
i=0;
i<num_runs;
i++) {
158 fprintf(
stderr,
"\tCode unimplemented\n");
159 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
164 "reading eventset",
retval );
172 average=
total/num_runs;
175 double rate = 100.0*(double)average/(
double)num_random_branches;
176 printf(
"\nOut of %d random branches %lld were mispredicted,\n",num_random_branches,average);
177 printf(
"resulting in a misprediction rate = %.1lf%%.\n",rate);
178 printf(
"Assuming a good random number generator and no freaky luck\n");
179 printf(
"the misprediction rate should be around 50%%, and the\n");
180 printf(
"mispredicts should at least be between %d and %d.\n",
181 num_random_branches/4,(num_random_branches/4)*3);
184 if ( average < (num_random_branches/4)) {
185 if (!
quiet) printf(
"Mispredicts too low\n");
186 test_fail( __FILE__, __LINE__,
"Error too low", 1 );
189 if (average > (num_random_branches/4)*3) {
190 if (!
quiet) printf(
"Mispredicts too high\n");
191 test_fail( __FILE__, __LINE__,
"Error too high", 1 );
194 if (!
quiet) printf(
"\n");
int branches_testcode(void)
int random_branches_testcode(int number, int quiet)
add PAPI preset or native hardware event by name to an EventSet
Create a new empty PAPI EventSet.
initialize the PAPI library.
Reset the hardware event counts in an event set.
Finish using PAPI and free all related resources.
Start counting hardware events in an event set.
Stop counting hardware events in an event set.
static int expected[NUM_THREADS]
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
void PAPI_NORETURN test_pass(const char *filename)
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
#define CODE_UNIMPLEMENTED