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