1 //**************************************************************************
2 // Double-precision general matrix multiplication benchmark
3 //--------------------------------------------------------------------------
8 //--------------------------------------------------------------------------
11 // Set HOST_DEBUG to 1 if you are going to compile this for a host
12 // machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
13 // to 0 if you are compiling with the smips-gcc toolchain.
19 // Set PREALLOCATE to 1 if you want to preallocate the benchmark
20 // function before starting stats. If you have instruction/data
21 // caches and you don't want to count the overhead of misses, then
22 // you will need to use preallocation.
28 // Set SET_STATS to 1 if you want to carve out the piece that actually
29 // does the computation.
35 //--------------------------------------------------------------------------
36 // Input/Reference Data
40 //--------------------------------------------------------------------------
43 int verify( long n
, const double test
[], const double correct
[] )
46 for ( i
= 0; i
< n
; i
++ ) {
47 if ( test
[i
] != correct
[i
] ) {
57 void printArray( char name
[], long n
, const double arr
[] )
60 printf( " %10s :", name
);
61 for ( i
= 0; i
< n
; i
++ )
62 printf( " %8.1f ", arr
[i
] );
67 void setStats( int enable
)
69 #if ( !HOST_DEBUG && SET_STATS )
70 asm( "mtpcr %0, cr10" : : "r" (enable
) );
74 void spmv(int r
, const double* val
, const int* idx
, const double* x
,
75 const int* ptr
, double* y
)
77 for (int i
= 0; i
< r
; i
++)
80 double yi0
= 0, yi1
= 0, yi2
= 0, yi3
= 0;
81 for (k
= ptr
[i
]; k
< ptr
[i
+1]-3; k
+=4)
83 yi0
+= val
[k
+0]*x
[idx
[k
+0]];
84 yi1
+= val
[k
+1]*x
[idx
[k
+1]];
85 yi2
+= val
[k
+2]*x
[idx
[k
+2]];
86 yi3
+= val
[k
+3]*x
[idx
[k
+3]];
88 for ( ; k
< ptr
[i
+1]; k
++)
90 yi0
+= val
[k
]*x
[idx
[k
]];
92 y
[i
] = (yi0
+yi1
)+(yi2
+yi3
);
96 //--------------------------------------------------------------------------
99 int main( int argc
, char* argv
[] )
104 spmv(R
, val
, idx
, x
, ptr
, y
);
108 spmv(R
, val
, idx
, x
, ptr
, y
);
111 finishTest(verify(R
, y
, verify_data
));