1 //**************************************************************************
2 // Double-precision general matrix multiplication benchmark
3 //--------------------------------------------------------------------------
5 //--------------------------------------------------------------------------
8 // Set HOST_DEBUG to 1 if you are going to compile this for a host
9 // machine (ie Athena/Linux) for debug purposes and set HOST_DEBUG
10 // to 0 if you are compiling with the smips-gcc toolchain.
16 // Set PREALLOCATE to 1 if you want to preallocate the benchmark
17 // function before starting stats. If you have instruction/data
18 // caches and you don't want to count the overhead of misses, then
19 // you will need to use preallocation.
25 // Set SET_STATS to 1 if you want to carve out the piece that actually
26 // does the computation.
32 //--------------------------------------------------------------------------
33 // Input/Reference Data
37 //--------------------------------------------------------------------------
40 int verify( long n
, const double test
[], const double correct
[] )
43 for ( i
= 0; i
< n
; i
++ ) {
44 if ( test
[i
] != correct
[i
] ) {
54 void printArray( char name
[], long n
, const double arr
[] )
57 printf( " %10s :", name
);
58 for ( i
= 0; i
< n
; i
++ )
59 printf( " %8.1f ", arr
[i
] );
64 void finishTest( int toHostValue
)
67 if ( toHostValue
== 1 )
68 printf( "*** PASSED ***\n" );
70 printf( "*** FAILED *** (tohost = %d)\n", toHostValue
);
73 asm( "mtpcr %0, tohost" : : "r" (toHostValue
) );
78 void setStats( int enable
)
80 #if ( !HOST_DEBUG && SET_STATS )
81 asm( "mtpcr %0, cr10" : : "r" (enable
) );
85 void spmv(int r
, const double* val
, const int* idx
, const double* x
,
86 const int* ptr
, double* y
)
88 for (int i
= 0; i
< r
; i
++)
91 double yi0
= 0, yi1
= 0, yi2
= 0, yi3
= 0;
92 for (k
= ptr
[i
]; k
< ptr
[i
+1]-3; k
+=4)
94 yi0
+= val
[k
+0]*x
[idx
[k
+0]];
95 yi1
+= val
[k
+1]*x
[idx
[k
+1]];
96 yi2
+= val
[k
+2]*x
[idx
[k
+2]];
97 yi3
+= val
[k
+3]*x
[idx
[k
+3]];
99 for ( ; k
< ptr
[i
+1]; k
++)
101 yi0
+= val
[k
]*x
[idx
[k
]];
103 y
[i
] = (yi0
+yi1
)+(yi2
+yi3
);
107 //--------------------------------------------------------------------------
110 int main( int argc
, char* argv
[] )
115 spmv(R
, val
, idx
, x
, ptr
, y
);
119 spmv(R
, val
, idx
, x
, ptr
, y
);
122 finishTest(verify(R
, y
, verify_data
));