70b3f75e1116c5d3ae7dcf8890771420e6bbeccb
1 //**************************************************************************
2 // Vector-vector add benchmark
3 //--------------------------------------------------------------------------
5 // This benchmark uses adds to vectors and writes the results to a
6 // third vector. The input data (and reference data) should be
7 // generated using the vvadd_gendata.pl perl script and dumped
8 // to a file named dataset1.h The smips-gcc toolchain does not
9 // support system calls so printf's can only be used on a host system,
10 // not on the smips processor simulator itself. You should not change
11 // anything except the HOST_DEBUG and PREALLOCATE macros for your timing
14 //--------------------------------------------------------------------------
17 // Set HOST_DEBUG to 1 if you are going to compile this for a host
18 // machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
19 // to 0 if you are compiling with the smips-gcc toolchain.
25 // Set PREALLOCATE to 1 if you want to preallocate the benchmark
26 // function before starting stats. If you have instruction/data
27 // caches and you don't want to count the overhead of misses, then
28 // you will need to use preallocation.
34 // Set SET_STATS to 1 if you want to carve out the piece that actually
35 // does the computation.
41 //--------------------------------------------------------------------------
42 // Input/Reference Data
46 //--------------------------------------------------------------------------
49 int verify( int n
, int test
[], int correct
[] )
52 for ( i
= 0; i
< n
; i
++ ) {
53 if ( test
[i
] != correct
[i
] ) {
61 void printArray( char name
[], int n
, int arr
[] )
64 printf( " %10s :", name
);
65 for ( i
= 0; i
< n
; i
++ )
66 printf( " %3d ", arr
[i
] );
71 void finishTest( int toHostValue
)
74 if ( toHostValue
== 1 )
75 printf( "*** PASSED ***\n" );
77 printf( "*** FAILED *** (tohost = %d)\n", toHostValue
);
80 asm( "mtpcr %0, tohost" : : "r" (toHostValue
) );
85 void setStats( int enable
)
87 #if ( !HOST_DEBUG && SET_STATS )
88 asm( "mtpcr %0, cr10" : : "r" (enable
) );
92 //--------------------------------------------------------------------------
95 void vvadd( int n
, int a
[], int b
[], int c
[] )
98 for ( i
= 0; i
< n
; i
++ )
102 //--------------------------------------------------------------------------
105 int main( int argc
, char* argv
[] )
107 int results_data
[DATA_SIZE
];
109 // Output the input array
112 printArray( "input1", DATA_SIZE
, input1_data
);
113 printArray( "input2", DATA_SIZE
, input2_data
);
114 printArray( "verify", DATA_SIZE
, verify_data
);
117 // If needed we preallocate everything in the caches
120 vvadd( DATA_SIZE
, input1_data
, input2_data
, results_data
);
126 vvadd( DATA_SIZE
, input1_data
, input2_data
, results_data
);
129 // Print out the results
132 printArray( "results", DATA_SIZE
, results_data
);
137 finishTest(verify( DATA_SIZE
, results_data
, verify_data
));