|
|
a2eaef |
diff -up papi-5.2.0/src/papi_internal.c.postfix papi-5.2.0/src/papi_internal.c
|
|
|
a2eaef |
--- papi-5.2.0/src/papi_internal.c.postfix 2016-07-25 14:25:09.331487358 -0400
|
|
|
a2eaef |
+++ papi-5.2.0/src/papi_internal.c 2016-07-25 14:27:17.271715363 -0400
|
|
|
a2eaef |
@@ -32,6 +32,7 @@
|
|
|
a2eaef |
#include <errno.h>
|
|
|
a2eaef |
#include <string.h>
|
|
|
a2eaef |
#include <ctype.h>
|
|
|
a2eaef |
+#include <assert.h>
|
|
|
a2eaef |
|
|
|
a2eaef |
#include "papi.h"
|
|
|
a2eaef |
#include "papi_internal.h"
|
|
|
a2eaef |
@@ -1840,89 +1841,90 @@ handle_derived_add_ps( int *position, lo
|
|
|
a2eaef |
/* this function implement postfix calculation, it reads in a string where I use:
|
|
|
a2eaef |
| as delimiter
|
|
|
a2eaef |
N2 indicate No. 2 native event in the derived preset
|
|
|
a2eaef |
- +, -, *, /, % as operator
|
|
|
a2eaef |
+ +, -, *, / as operator
|
|
|
a2eaef |
# as MHZ(million hz) got from _papi_hwi_system_info.hw_info.cpu_max_mhz*1000000.0
|
|
|
a2eaef |
|
|
|
a2eaef |
Haihang (you@cs.utk.edu)
|
|
|
a2eaef |
*/
|
|
|
a2eaef |
-static long long
|
|
|
a2eaef |
-_papi_hwi_postfix_calc( EventInfo_t * evi, long long *hw_counter )
|
|
|
a2eaef |
-{
|
|
|
a2eaef |
- char *point = evi->ops, operand[16];
|
|
|
a2eaef |
- double stack[PAPI_EVENTS_IN_DERIVED_EVENT];
|
|
|
a2eaef |
- int i, top = 0;
|
|
|
a2eaef |
-
|
|
|
a2eaef |
- memset(&stack,0,PAPI_EVENTS_IN_DERIVED_EVENT*sizeof(double));
|
|
|
a2eaef |
-
|
|
|
a2eaef |
- while ( *point != '\0' ) {
|
|
|
a2eaef |
- if ( *point == 'N' ) { /* to get count for each native event */
|
|
|
a2eaef |
- i = 0;
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- do {
|
|
|
a2eaef |
- operand[i] = *point;
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- i++;
|
|
|
a2eaef |
- } while ( *point != '|' );
|
|
|
a2eaef |
- operand[i] = '\0';
|
|
|
a2eaef |
- stack[top] = ( double ) hw_counter[evi->pos[atoi( operand )]];
|
|
|
a2eaef |
- top++;
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } else if ( *point == '#' ) { /* to get mhz, ignore the rest char's */
|
|
|
a2eaef |
- stack[top] = _papi_hwi_system_info.hw_info.cpu_max_mhz * 1000000.0;
|
|
|
a2eaef |
- top++;
|
|
|
a2eaef |
- do {
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } while ( *point != '|' );
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } else if ( isdigit( *point ) ) { /* to get integer, I suppose only integer will be used,
|
|
|
a2eaef |
- no error check here, please only use integer */
|
|
|
a2eaef |
- i = 0;
|
|
|
a2eaef |
- do {
|
|
|
a2eaef |
- operand[i] = *point;
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- i++;
|
|
|
a2eaef |
- } while ( *point != '|' );
|
|
|
a2eaef |
- operand[i] = '\0';
|
|
|
a2eaef |
- stack[top] = atoi( operand );
|
|
|
a2eaef |
- top++;
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } else if ( *point == '+' ) { /* + calculation */
|
|
|
a2eaef |
- stack[top - 2] += stack[top - 1];
|
|
|
a2eaef |
- top--;
|
|
|
a2eaef |
- do {
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } while ( *point != '|' );
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } else if ( *point == '-' ) { /* - calculation */
|
|
|
a2eaef |
- stack[top - 2] -= stack[top - 1];
|
|
|
a2eaef |
- top--;
|
|
|
a2eaef |
- do {
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } while ( *point != '|' );
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } else if ( *point == '*' ) { /* * calculation */
|
|
|
a2eaef |
- stack[top - 2] *= stack[top - 1];
|
|
|
a2eaef |
- top--;
|
|
|
a2eaef |
- do {
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } while ( *point != '|' );
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } else if ( *point == '/' ) { /* / calculation */
|
|
|
a2eaef |
- stack[top - 2] /= stack[top - 1];
|
|
|
a2eaef |
- top--;
|
|
|
a2eaef |
- do {
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } while ( *point != '|' );
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } else { /* do nothing */
|
|
|
a2eaef |
- do {
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- } while ( *point != '|' );
|
|
|
a2eaef |
- point++;
|
|
|
a2eaef |
- }
|
|
|
a2eaef |
- }
|
|
|
a2eaef |
- return ( long long ) stack[0];
|
|
|
a2eaef |
-}
|
|
|
a2eaef |
+ static long long
|
|
|
a2eaef |
+ _papi_hwi_postfix_calc( EventInfo_t * evi, long long *hw_counter )
|
|
|
a2eaef |
+ {
|
|
|
a2eaef |
+ char *point = evi->ops, operand[16];
|
|
|
a2eaef |
+ double stack[PAPI_EVENTS_IN_DERIVED_EVENT];
|
|
|
a2eaef |
+ int i, val, top = 0;
|
|
|
a2eaef |
+
|
|
|
a2eaef |
+ INTDBG("ENTER: evi: %p, evi->ops: %p (%s), evi->pos[0]: %d, evi->pos[1]: %d, hw_counter: %p (%lld %lld)\n",
|
|
|
a2eaef |
+ evi, evi->ops, evi->ops, evi->pos[0], evi->pos[1], hw_counter, hw_counter[0], hw_counter[1]);
|
|
|
a2eaef |
+
|
|
|
a2eaef |
+ memset(&stack,0,PAPI_EVENTS_IN_DERIVED_EVENT*sizeof(double));
|
|
|
a2eaef |
+
|
|
|
a2eaef |
+ while ( *point != '\0' ) {
|
|
|
a2eaef |
+ if ( *point == '|' ) { /* consume '|' characters */
|
|
|
a2eaef |
+ point++;
|
|
|
a2eaef |
+ } else if ( *point == 'N' ) { /* to get count for each native event */
|
|
|
a2eaef |
+ point++;
|
|
|
a2eaef |
+ i = 0;
|
|
|
a2eaef |
+ while ( isdigit(*point) ) {
|
|
|
a2eaef |
+ assert(i<16);
|
|
|
a2eaef |
+ operand[i] = *point;
|
|
|
a2eaef |
+ point++;
|
|
|
a2eaef |
+ i++;
|
|
|
a2eaef |
+ }
|
|
|
a2eaef |
+ assert(0
|
|
|
a2eaef |
+ operand[i] = '\0';
|
|
|
a2eaef |
+ val = atoi( operand );
|
|
|
a2eaef |
+ assert( top < PAPI_EVENTS_IN_DERIVED_EVENT );
|
|
|
a2eaef |
+ assert( 0 <= val && val < PAPI_EVENTS_IN_DERIVED_EVENT );
|
|
|
a2eaef |
+ stack[top] = ( double ) hw_counter[evi->pos[val]];
|
|
|
a2eaef |
+ top++;
|
|
|
a2eaef |
+ } else if ( *point == '#' ) { /* to get mhz */
|
|
|
a2eaef |
+ point++;
|
|
|
a2eaef |
+ assert( top < PAPI_EVENTS_IN_DERIVED_EVENT );
|
|
|
a2eaef |
+ stack[top] = _papi_hwi_system_info.hw_info.cpu_max_mhz * 1000000.0;
|
|
|
a2eaef |
+ top++;
|
|
|
a2eaef |
+ } else if ( isdigit( *point ) ) {
|
|
|
a2eaef |
+ i = 0;
|
|
|
a2eaef |
+ while ( isdigit(*point) ) {
|
|
|
a2eaef |
+ assert(i<16);
|
|
|
a2eaef |
+ operand[i] = *point;
|
|
|
a2eaef |
+ point++;
|
|
|
a2eaef |
+ i++;
|
|
|
a2eaef |
+ }
|
|
|
a2eaef |
+ assert(0
|
|
|
a2eaef |
+ operand[i] = '\0';
|
|
|
a2eaef |
+ assert( top < PAPI_EVENTS_IN_DERIVED_EVENT );
|
|
|
a2eaef |
+ stack[top] = atoi( operand );
|
|
|
a2eaef |
+ top++;
|
|
|
a2eaef |
+ } else if ( *point == '+' ) { /* + calculation */
|
|
|
a2eaef |
+ point++;
|
|
|
a2eaef |
+ assert(top >= 2);
|
|
|
a2eaef |
+ stack[top - 2] += stack[top - 1];
|
|
|
a2eaef |
+ top--;
|
|
|
a2eaef |
+ } else if ( *point == '-' ) { /* - calculation */
|
|
|
a2eaef |
+ point++;
|
|
|
a2eaef |
+ assert(top >= 2);
|
|
|
a2eaef |
+ stack[top - 2] -= stack[top - 1];
|
|
|
a2eaef |
+ top--;
|
|
|
a2eaef |
+ } else if ( *point == '*' ) { /* * calculation */
|
|
|
a2eaef |
+ point++;
|
|
|
a2eaef |
+ assert(top >= 2);
|
|
|
a2eaef |
+ stack[top - 2] *= stack[top - 1];
|
|
|
a2eaef |
+ top--;
|
|
|
a2eaef |
+ } else if ( *point == '/' ) { /* / calculation */
|
|
|
a2eaef |
+ point++;
|
|
|
a2eaef |
+ assert(top >= 2);
|
|
|
a2eaef |
+ /* FIXME should handle runtime divide by zero */
|
|
|
a2eaef |
+ stack[top - 2] /= stack[top - 1];
|
|
|
a2eaef |
+ top--;
|
|
|
a2eaef |
+ } else { /* flag an error parsing the preset */
|
|
|
a2eaef |
+ PAPIERROR( "BUG! Unable to parse \"%s\"", evi->ops );
|
|
|
a2eaef |
+ return ( long long ) stack[0];
|
|
|
a2eaef |
+ }
|
|
|
a2eaef |
+ }
|
|
|
a2eaef |
+ assert(top == 1);
|
|
|
a2eaef |
+ INTDBG("EXIT: stack[0]: %lld\n", (long long)stack[0]);
|
|
|
a2eaef |
+ return ( long long ) stack[0];
|
|
|
a2eaef |
+ }
|
|
|
a2eaef |
|
|
|
a2eaef |
static long long
|
|
|
a2eaef |
handle_derived( EventInfo_t * evi, long long *from )
|