2 // Test_3x3timesTranspose.cpp
5 // Copyright (c) 2011 Apple Inc.
10 #include "LinearMath/btScalar.h"
11 #if defined (BT_USE_SSE_IN_API) || defined (BT_USE_NEON)
14 #include "Test_3x3timesTranspose.h"
21 #include <LinearMath/btMatrix3x3.h>
23 #define LOOPCOUNT 1000
24 #define ARRAY_SIZE 128
26 static inline btSimdFloat4 rand_f4(void)
28 return btAssign128( RANDF, RANDF, RANDF, BT_NAN ); // w channel NaN
31 static btMatrix3x3 timesTranspose( const btMatrix3x3 &in, const btMatrix3x3 &m )
33 btVector3 m_el[3] = { in[0], in[1], in[2] };
35 m_el[0].dot(m[0]), m_el[0].dot(m[1]), m_el[0].dot(m[2]),
36 m_el[1].dot(m[0]), m_el[1].dot(m[1]), m_el[1].dot(m[2]),
37 m_el[2].dot(m[0]), m_el[2].dot(m[1]), m_el[2].dot(m[2]));
40 static int operator!= ( const btMatrix3x3 &a, const btMatrix3x3 &b )
42 if( a.getRow(0) != b.getRow(0) )
44 if( a.getRow(1) != b.getRow(1) )
46 if( a.getRow(2) != b.getRow(2) )
51 int Test_3x3timesTranspose(void)
53 // Init an array flanked by guard pages
54 btMatrix3x3 in1[ARRAY_SIZE];
55 btMatrix3x3 in2[ARRAY_SIZE];
56 btMatrix3x3 out[ARRAY_SIZE];
57 btMatrix3x3 out2[ARRAY_SIZE];
61 for( i = 0; i < ARRAY_SIZE; i++ )
63 in1[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() );
64 in2[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() );
66 out[i] = timesTranspose(in1[i], in2[i]);
67 out2[i] = in1[i].timesTranspose(in2[i]);
69 if( out[i] != out2[i] )
71 printf( "failure @ %ld\n", i);
76 uint64_t scalarTime, vectorTime;
77 uint64_t startTime, bestTime, currentTime;
80 for (j = 0; j < LOOPCOUNT; j++) {
81 startTime = ReadTicks();
82 for( i = 0; i < ARRAY_SIZE; i++ )
83 out[i] = timesTranspose(in1[i], in2[i]);
84 currentTime = ReadTicks() - startTime;
85 scalarTime += currentTime;
86 if( currentTime < bestTime )
87 bestTime = currentTime;
89 if( 0 == gReportAverageTimes )
90 scalarTime = bestTime;
92 scalarTime /= LOOPCOUNT;
96 for (j = 0; j < LOOPCOUNT; j++) {
97 startTime = ReadTicks();
98 for( i = 0; i < ARRAY_SIZE; i++ )
99 out[i] = in1[i].timesTranspose(in2[i]);
100 currentTime = ReadTicks() - startTime;
101 vectorTime += currentTime;
102 if( currentTime < bestTime )
103 bestTime = currentTime;
105 if( 0 == gReportAverageTimes )
106 vectorTime = bestTime;
108 vectorTime /= LOOPCOUNT;
111 vlog( "\t scalar\t vector\n" );
112 vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE );