Merge branch 'master' of github.com:ucb-bar/riscv-tests
[riscv-tests.git] / benchmarks / multiply / multiply_main.c
1 // *************************************************************************
2 // multiply filter bencmark
3 // -------------------------------------------------------------------------
4 //
5 // This benchmark tests the software multiply implemenation. The
6 // input data (and reference data) should be generated using the
7 // multiply_gendata.pl perl script and dumped to a file named
8 // dataset1.h You should not change anything except the
9 // HOST_DEBUG and VERIFY macros for your timing run.
10
11 #include "multiply.h"
12
13 int ncores = 1;
14 #include "util.h"
15
16 //--------------------------------------------------------------------------
17 // Macros
18
19 // Set HOST_DEBUG to 1 if you are going to compile this for a host
20 // machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
21 // to 0 if you are compiling with the smips-gcc toolchain.
22
23 #ifndef HOST_DEBUG
24 #define HOST_DEBUG 0
25 #endif
26
27 // Set PREALLOCATE to 1 if you want to preallocate the benchmark
28 // function before starting stats. If you have instruction/data
29 // caches and you don't want to count the overhead of misses, then
30 // you will need to use preallocation.
31
32 #ifndef PREALLOCATE
33 #define PREALLOCATE 0
34 #endif
35
36 // Set VERIFY to 1 if you want the program to check that the sort
37 // function returns the right answer. When you are doing your
38 // benchmarking you should set this to 0 so that the verification
39 // is not included in your timing.
40
41 #ifndef VERIFY
42 #define VERIFY 1
43 #endif
44
45 // Set SET_STATS to 1 if you want to carve out the piece that actually
46 // does the computation.
47
48 #ifndef SET_STATS
49 #define SET_STATS 0
50 #endif
51
52 //--------------------------------------------------------------------------
53 // Input/Reference Data
54
55 #include "dataset1.h"
56
57 //--------------------------------------------------------------------------
58 // Helper functions
59
60 int verify( int n, int test[], int correct[] )
61 {
62 int i;
63 for ( i = 0; i < n; i++ ) {
64 if ( test[i] != correct[i] ) {
65 return 2;
66 }
67 }
68 return 1;
69 }
70
71 #if HOST_DEBUG
72 void printArray( char name[], int n, int arr[] )
73 {
74 int i;
75 printf( " %10s :", name );
76 for ( i = 0; i < n; i++ )
77 printf( " %3d ", arr[i] );
78 printf( "\n" );
79 }
80 #endif
81
82 void setStats( int enable )
83 {
84 #if ( !HOST_DEBUG && SET_STATS )
85 asm( "mtpcr %0, cr10" : : "r" (enable) );
86 #endif
87 }
88
89 //--------------------------------------------------------------------------
90 // Main
91
92 int main( int argc, char* argv[] )
93 {
94 int i;
95 int results_data[DATA_SIZE];
96
97 // Output the input arrays
98
99 #if HOST_DEBUG
100 printArray( "input1", DATA_SIZE, input_data1 );
101 printArray( "input2", DATA_SIZE, input_data2 );
102 printArray( "verify", DATA_SIZE, verify_data );
103 #endif
104
105 #if ( !HOST_DEBUG && PREALLOCATE )
106 for (i = 0; i < DATA_SIZE; i++)
107 {
108 results_data[i] = multiply( input_data1[i], input_data2[i] );
109 }
110 #endif
111
112 #if HOST_DEBUG
113 for (i = 0; i < DATA_SIZE; i++)
114 {
115 results_data[i] = multiply( input_data1[i], input_data2[i] );
116 }
117 #else
118 setStats(1);
119 for (i = 0; i < DATA_SIZE; i++)
120 {
121 results_data[i] = multiply( input_data1[i], input_data2[i] );
122 }
123 setStats(0);
124 #endif
125
126 // Print out the results
127
128 #if HOST_DEBUG
129 printArray( "results", DATA_SIZE, results_data );
130 #endif
131
132 // Check the results
133
134 finishTest(verify( DATA_SIZE, results_data, verify_data ));
135
136 }