1 //**************************************************************************
2 // Vector-Thread Vector-vector add benchmark
3 //--------------------------------------------------------------------------
5 // This benchmark uses adds to vectors and writes the results to a third
6 // vector. The input data (and reference data) should be generated using the
7 // vvadd_gendata.pl perl script and dumped to a file named dataset.h.
9 // Choose which implementation you wish to test... but leave only one on!
10 // (only the first one will be executed).
15 //--------------------------------------------------------------------------
16 // Input/Reference Data
18 //#include "dataset_test.h"
21 //--------------------------------------------------------------------------
24 int verify( int n
, float test
[], float correct
[] )
27 for ( i
= 0; i
< n
; i
++ ) {
28 // if ( test[i] != correct[i] ) {
29 if ( test
[i
] > 1.02*correct
[i
]
30 || test
[i
] < 0.98*correct
[i
]) {
32 printf(" test[%d] : %3.2f\n", i
, test
[i
]);
33 printf(" corr[%d] : %3.2f\n", i
, correct
[i
]);
35 // tell us which index fails + 2
36 // (so that if i==0,i==1 fails, we don't
37 // think it was a 'not-finished yet' or pass)
45 void finishTest( int correct
, long long num_cycles
, long long num_retired
)
47 int toHostValue
= correct
;
49 if ( toHostValue
== 1 )
50 printf( "*** PASSED ***\n" );
52 printf( "*** FAILED *** (tohost = %d)\n", toHostValue
);
55 // we no longer run in -testrun mode, which means we can't use
56 // the tohost register to communicate "test is done" and "test results"
57 // so instead we will communicate through print* functions!
60 printstr( "*** PASSED *** (num_cycles = 0x" );
62 printstr( ", num_inst_retired = 0x");
63 printhex(num_retired
);
68 printstr( "*** FAILED *** (num_cycles = 0x");
70 printstr( ", num_inst_retired = 0x");
71 printhex(num_retired
);
79 // deprecated - cr10/stats-enable register no longer exists
80 void setStats( int enable
)
82 #if ( !HOST_DEBUG && SET_STATS )
83 asm( "mtpcr %0, cr10" : : "r" (enable
) );
89 long long cycles
= 1337;
90 #if ( !HOST_DEBUG && SET_STATS )
91 __asm__
__volatile__( "rdcycle %0" : "=r" (cycles
) );
96 long long getInstRetired()
98 long long inst_retired
= 1338;
99 #if ( !HOST_DEBUG && SET_STATS )
100 __asm__
__volatile__( "rdinstret %0" : "=r" (inst_retired
) );
105 //--------------------------------------------------------------------------
108 // scalar C implementation
109 void vvadd( int n
, float a
[], float b
[], float c
[] )
112 for ( i
= 0; i
< n
; i
++ )
116 // assembly implementations can be found in *_asm.S
118 //--------------------------------------------------------------------------
121 int main( int argc
, char* argv
[] )
123 float results_data
[DATA_SIZE
];
124 long long start_cycles
= 0;
125 long long stop_cycles
= 0;
126 long long num_cycles
;
127 long long start_retired
= 0;
128 long long stop_retired
= 0;
129 long long num_retired
;
131 // Output the input array
134 printArray( "input1", DATA_SIZE
, input1_data
);
135 printArray( "input2", DATA_SIZE
, input2_data
);
136 printArray( "verify", DATA_SIZE
, verify_data
);
139 // --------------------------------------------------
140 // If needed we preallocate everything in the caches
145 vvadd( DATA_SIZE
, input1_data
, input2_data
, results_data
);
148 scalar_vvadd_asm( DATA_SIZE
, input1_data
, input2_data
, results_data
);
151 vt_vvadd_asm( DATA_SIZE
, input1_data
, input2_data
, results_data
);
158 // --------------------------------------------------
160 start_cycles
= getCycles();
161 start_retired
= getInstRetired();
164 vvadd( DATA_SIZE
, input1_data
, input2_data
, results_data
);
168 scalar_vvadd_asm( DATA_SIZE
, input1_data
, input2_data
, results_data
);
173 vt_vvadd_asm( DATA_SIZE
, input1_data
, input2_data
, results_data
);
179 stop_cycles
= getCycles();
180 stop_retired
= getInstRetired();
181 num_cycles
= stop_cycles
- start_cycles
;
182 num_retired
= stop_retired
- start_retired
;
184 // printstr("stop_cycles: "); printhex(stop_cycles); printstr("\n");
185 // printstr("star_cycles: "); printhex(start_cycles); printstr("\n");
187 // --------------------------------------------------
188 // Print out the results
191 printArray( "results", DATA_SIZE
, results_data
);
194 // --------------------------------------------------
196 int correct
= verify( DATA_SIZE
, results_data
, verify_data
);
197 finishTest(correct
, num_cycles
, num_retired
);