1 // See LICENSE for license details.
3 //**************************************************************************
4 // Vector-Thread Vector-vector add benchmark
5 //--------------------------------------------------------------------------
7 // This benchmark uses adds to vectors and writes the results to a third
8 // vector. The input data (and reference data) should be generated using the
9 // vvadd_gendata.pl perl script and dumped to a file named dataset.h.
11 // Choose which implementation you wish to test... but leave only one on!
12 // (only the first one will be executed).
17 //--------------------------------------------------------------------------
18 // Input/Reference Data
20 //#include "dataset_test.h"
23 //--------------------------------------------------------------------------
26 int verify( int n
, float test
[], float correct
[] )
29 for ( i
= 0; i
< n
; i
++ ) {
30 // if ( test[i] != correct[i] ) {
31 if ( test
[i
] > 1.02*correct
[i
]
32 || test
[i
] < 0.98*correct
[i
]) {
34 printf(" test[%d] : %3.2f\n", i
, test
[i
]);
35 printf(" corr[%d] : %3.2f\n", i
, correct
[i
]);
37 // tell us which index fails + 2
38 // (so that if i==0,i==1 fails, we don't
39 // think it was a 'not-finished yet' or pass)
47 void finishTest( int correct
, long long num_cycles
, long long num_retired
)
49 int toHostValue
= correct
;
51 if ( toHostValue
== 1 )
52 printf( "*** PASSED ***\n" );
54 printf( "*** FAILED *** (tohost = %d)\n", toHostValue
);
57 // we no longer run in -testrun mode, which means we can't use
58 // the tohost register to communicate "test is done" and "test results"
59 // so instead we will communicate through print* functions!
62 printstr( "*** PASSED *** (num_cycles = 0x" );
64 printstr( ", num_inst_retired = 0x");
65 printhex(num_retired
);
70 printstr( "*** FAILED *** (num_cycles = 0x");
72 printstr( ", num_inst_retired = 0x");
73 printhex(num_retired
);
81 // deprecated - cr10/stats-enable register no longer exists
82 void setStats( int enable
)
84 #if ( !HOST_DEBUG && SET_STATS )
85 asm( "mtpcr %0, cr10" : : "r" (enable
) );
91 long long cycles
= 1337;
92 #if ( !HOST_DEBUG && SET_STATS )
93 __asm__
__volatile__( "rdcycle %0" : "=r" (cycles
) );
98 long long getInstRetired()
100 long long inst_retired
= 1338;
101 #if ( !HOST_DEBUG && SET_STATS )
102 __asm__
__volatile__( "rdinstret %0" : "=r" (inst_retired
) );
107 //--------------------------------------------------------------------------
110 // scalar C implementation
111 void vvadd( int n
, float a
[], float b
[], float c
[] )
114 for ( i
= 0; i
< n
; i
++ )
118 // assembly implementations can be found in *_asm.S
120 //--------------------------------------------------------------------------
123 int main( int argc
, char* argv
[] )
125 float results_data
[DATA_SIZE
];
126 long long start_cycles
= 0;
127 long long stop_cycles
= 0;
128 long long num_cycles
;
129 long long start_retired
= 0;
130 long long stop_retired
= 0;
131 long long num_retired
;
133 // Output the input array
136 printArray( "input1", DATA_SIZE
, input1_data
);
137 printArray( "input2", DATA_SIZE
, input2_data
);
138 printArray( "verify", DATA_SIZE
, verify_data
);
141 // --------------------------------------------------
142 // If needed we preallocate everything in the caches
147 vvadd( DATA_SIZE
, input1_data
, input2_data
, results_data
);
150 scalar_vvadd_asm( DATA_SIZE
, input1_data
, input2_data
, results_data
);
153 vt_vvadd_asm( DATA_SIZE
, input1_data
, input2_data
, results_data
);
160 // --------------------------------------------------
162 start_cycles
= getCycles();
163 start_retired
= getInstRetired();
166 vvadd( DATA_SIZE
, input1_data
, input2_data
, results_data
);
170 scalar_vvadd_asm( DATA_SIZE
, input1_data
, input2_data
, results_data
);
175 vt_vvadd_asm( DATA_SIZE
, input1_data
, input2_data
, results_data
);
181 stop_cycles
= getCycles();
182 stop_retired
= getInstRetired();
183 num_cycles
= stop_cycles
- start_cycles
;
184 num_retired
= stop_retired
- start_retired
;
186 // printstr("stop_cycles: "); printhex(stop_cycles); printstr("\n");
187 // printstr("star_cycles: "); printhex(start_cycles); printstr("\n");
189 // --------------------------------------------------
190 // Print out the results
193 printArray( "results", DATA_SIZE
, results_data
);
196 // --------------------------------------------------
198 int correct
= verify( DATA_SIZE
, results_data
, verify_data
);
199 finishTest(correct
, num_cycles
, num_retired
);