20 int 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 printf(
"\nOut of %lld branches, %lld were mispredicted\n",
expected,average);
176 printf(
"Assuming a good random number generator and no freaky luck\n");
177 printf(
"The mispredicts should be roughly between %d and %d\n",
178 num_random_branches/4,(num_random_branches/4)*3);
181 if ( average < (num_random_branches/4)) {
182 if (!
quiet) printf(
"Mispredicts too low\n");
183 test_fail( __FILE__, __LINE__,
"Error too low", 1 );
186 if (average > (num_random_branches/4)*3) {
187 if (!
quiet) printf(
"Mispredicts too high\n");
188 test_fail( __FILE__, __LINE__,
"Error too high", 1 );
191 if (!
quiet) printf(
"\n");
int PAPI_stop(int EventSet, long long *values)
int random_branches_testcode(int number, int quiet)
void test_pass(const char *filename)
static int expected[NUM_THREADS]
int PAPI_reset(int EventSet)
#define CODE_UNIMPLEMENTED
Return codes and api definitions.
void test_skip(const char *file, int line, const char *call, int retval)
int PAPI_add_named_event(int EventSet, const char *EventName)
int PAPI_library_init(int version)
int main(int argc, char **argv)
int PAPI_create_eventset(int *EventSet)
int branches_testcode(void)
int tests_quiet(int argc, char **argv)
void test_fail(const char *file, int line, const char *call, int retval)
int PAPI_start(int EventSet)