|
Packit |
577717 |
/* This file attempts to test the unconditional branch instruction */
|
|
Packit |
577717 |
/* performance counter PAPI_BR_UCN */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* by Vince Weaver, <vincent.weaver@maine.edu> */
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include <stdlib.h>
|
|
Packit |
577717 |
#include <stdio.h>
|
|
Packit |
577717 |
#include <unistd.h>
|
|
Packit |
577717 |
#include <string.h>
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "papi.h"
|
|
Packit |
577717 |
#include "papi_test.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
#include "display_error.h"
|
|
Packit |
577717 |
#include "testcode.h"
|
|
Packit |
577717 |
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int main(int argc, char **argv) {
|
|
Packit |
577717 |
|
|
Packit |
577717 |
int num_runs=100,i;
|
|
Packit |
577717 |
long long high=0,low=0,average=0,expected=500000;
|
|
Packit |
577717 |
double error;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
long long count,total=0;
|
|
Packit |
577717 |
int quiet=0,retval,ins_result;
|
|
Packit |
577717 |
int eventset=PAPI_NULL;
|
|
Packit |
577717 |
|
|
Packit |
577717 |
quiet=tests_quiet(argc,argv);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!quiet) {
|
|
Packit |
577717 |
printf("\nTesting the PAPI_BR_UCN event.\n");
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
/* Init the PAPI library */
|
|
Packit |
577717 |
retval = PAPI_library_init( PAPI_VER_CURRENT );
|
|
Packit |
577717 |
if ( retval != PAPI_VER_CURRENT ) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval=PAPI_create_eventset(&eventset);
|
|
Packit |
577717 |
if (retval!=PAPI_OK) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval=PAPI_add_named_event(eventset,"PAPI_BR_UCN");
|
|
Packit |
577717 |
if (retval!=PAPI_OK) {
|
|
Packit |
577717 |
test_skip( __FILE__, __LINE__, "adding PAPI_BR_UCN", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!quiet) {
|
|
Packit |
577717 |
printf("Testing a loop with %lld unconditional branches (%d times):\n",
|
|
Packit |
577717 |
expected,num_runs);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
for(i=0;i
|
|
Packit |
577717 |
PAPI_reset(eventset);
|
|
Packit |
577717 |
PAPI_start(eventset);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
ins_result=branches_testcode();
|
|
Packit |
577717 |
|
|
Packit |
577717 |
retval=PAPI_stop(eventset,&count);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (ins_result==CODE_UNIMPLEMENTED) {
|
|
Packit |
577717 |
fprintf(stderr,"\tCode unimplemented\n");
|
|
Packit |
577717 |
test_skip( __FILE__, __LINE__, "unimplemented", 0);
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (retval!=PAPI_OK) {
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__,
|
|
Packit |
577717 |
"reading PAPI_TOT_INS", retval );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (count>high) high=count;
|
|
Packit |
577717 |
if ((low==0) || (count
|
|
Packit |
577717 |
total+=count;
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
average=(total/num_runs);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
error=display_error(average,high,low,expected,quiet);
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if ((error > 1.0) || (error<-1.0)) {
|
|
Packit |
577717 |
if (!quiet) printf("Instruction count off by more than 1%%\n");
|
|
Packit |
577717 |
test_fail( __FILE__, __LINE__, "Error too high", 1 );
|
|
Packit |
577717 |
}
|
|
Packit |
577717 |
|
|
Packit |
577717 |
if (!quiet) printf("\n");
|
|
Packit |
577717 |
|
|
Packit |
577717 |
test_pass( __FILE__ );
|
|
Packit |
577717 |
|
|
Packit |
577717 |
PAPI_shutdown();
|
|
Packit |
577717 |
|
|
Packit |
577717 |
return 0;
|
|
Packit |
577717 |
}
|