28 int num_random_branches=500000;
29 long long high=0,low=0,average=0,
expected=1500000;
30 long long expected_high,expected_low;
39 printf(
"\nTesting the PAPI_BR_PRC event.\n\n");
40 printf(
"This should measure predicted correctly conditional branches\n");
41 printf(
"If such a counter is not available, it may report predicted correctly\n");
42 printf(
"total branches instead.\n");
59 if (!
quiet) printf(
"Could not add PAPI_BR_CN\n");
64 if (!
quiet) printf(
"Could not add PAPI_BR_INS\n");
81 if (!
quiet) printf(
"Could not add PAPI_BR_PRC\n");
86 printf(
"\nPart 1: Testing that easy to predict loop has few misses\n");
87 printf(
"Testing a loop with %lld branches (%d times):\n",
89 printf(
"\tOn a simple loop like this, " 90 "hit rate should be very high.\n");
93 for(
i=0;
i<num_runs;
i++) {
103 fprintf(stderr,
"\tCode unimplemented\n");
104 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
109 "reading PAPI_TOT_INS",
retval );
117 average=(
total/num_runs);
119 if (!
quiet) printf(
"\tAverage number of branch hits: %lld\n",average);
122 if (!
quiet) printf(
"Branch miss rate too high\n");
123 test_fail( __FILE__, __LINE__,
"Error too high", 1 );
129 printf(
"\nPart 2\n");
132 high=0; low=0;
total=0;
134 for(
i=0;
i<num_runs;
i++) {
143 fprintf(stderr,
"\tCode unimplemented\n");
144 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
149 "reading PAPI_TOT_INS",
retval );
157 average=
total/num_runs;
161 printf(
"\nTesting a function that branches " 162 "based on a random number\n");
163 printf(
" The loop has %lld conditional branches.\n",
expected);
164 printf(
" %d are random branches.\n",num_random_branches);
167 high=0; low=0;
total=0;
169 for(
i=0;
i<num_runs;
i++) {
178 fprintf(stderr,
"\tCode unimplemented\n");
179 test_skip( __FILE__, __LINE__,
"unimplemented", 0);
184 "reading eventset",
retval );
192 average=
total/num_runs;
194 expected_low=
expected-((num_random_branches/4)*3);
195 expected_high=
expected-(num_random_branches/4);
198 printf(
"\nOut of %lld branches, " 199 "%lld were correctly predicted\n",
expected,average);
200 printf(
"Assuming a good random number generator and no " 202 printf(
"The mispredicts should be roughly " 203 "between %lld and %lld\n",
204 expected_low,expected_high);
208 if ( average < expected_low) {
209 if (!
quiet) printf(
"Branch hits too low\n");
210 test_fail( __FILE__, __LINE__,
"Error too low", 1 );
213 if (average > expected_high) {
214 if (!
quiet) printf(
"Branch hits too high\n");
215 test_fail( __FILE__, __LINE__,
"Error too high", 1 );
218 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
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 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)