2 // Test_3x3transpose.cpp
5 // Copyright (c) 2011 Apple Inc.
9 #include "LinearMath/btScalar.h"
10 #if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON)
13 #include "Test_3x3transpose.h"
20 #include <LinearMath/btMatrix3x3.h>
22 #define LOOPCOUNT 1000
23 #define ARRAY_SIZE 1024
25 static inline btSimdFloat4 rand_f4(void)
27 return btAssign128( RANDF, RANDF, RANDF, BT_NAN ); // w channel NaN
30 static btMatrix3x3 Transpose( btMatrix3x3 &in )
32 btVector3 row0 = in.getRow(0);
33 btVector3 row1 = in.getRow(1);
34 btVector3 row2 = in.getRow(2);
35 btVector3 col0 = btAssign128(row0.x(), row1.x(), row2.x(), 0 );
36 btVector3 col1 = btAssign128(row0.y(), row1.y(), row2.y(), 0 );
37 btVector3 col2 = btAssign128(row0.z(), row1.z(), row2.z(), 0);
38 return btMatrix3x3( col0, col1, col2);
41 static int operator!= ( const btMatrix3x3 &a, const btMatrix3x3 &b )
43 if( a.getRow(0) != b.getRow(0) )
45 if( a.getRow(1) != b.getRow(1) )
47 if( a.getRow(2) != b.getRow(2) )
52 int Test_3x3transpose(void)
54 // Init an array flanked by guard pages
55 btMatrix3x3 in[ARRAY_SIZE];
56 btMatrix3x3 out[ARRAY_SIZE];
57 btMatrix3x3 out2[ARRAY_SIZE];
61 for( i = 0; i < ARRAY_SIZE; i++ )
63 in[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() );
65 out[i] = Transpose(in[i]);
66 out2[i] = in[i].transpose();
68 if( out[i] != out2[i] )
70 printf( "failure @ %ld\n", i);
75 uint64_t scalarTime, vectorTime;
76 uint64_t startTime, bestTime, currentTime;
79 for (j = 0; j < LOOPCOUNT; j++) {
80 startTime = ReadTicks();
81 for( i = 0; i < ARRAY_SIZE; i++ )
82 out[i] = Transpose(in[i]);
83 currentTime = ReadTicks() - startTime;
84 scalarTime += currentTime;
85 if( currentTime < bestTime )
86 bestTime = currentTime;
88 if( 0 == gReportAverageTimes )
89 scalarTime = bestTime;
91 scalarTime /= LOOPCOUNT;
95 for (j = 0; j < LOOPCOUNT; j++) {
96 startTime = ReadTicks();
97 for( i = 0; i < ARRAY_SIZE; i++ )
98 out[i] = in[i].transpose();
99 currentTime = ReadTicks() - startTime;
100 vectorTime += currentTime;
101 if( currentTime < bestTime )
102 bestTime = currentTime;
104 if( 0 == gReportAverageTimes )
105 vectorTime = bestTime;
107 vectorTime /= LOOPCOUNT;
110 vlog( "\t scalar\t vector\n" );
111 vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE );