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_3x3mulMV.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_01, RANDF_01, RANDF_01, BT_NAN ); // w channel NaN
31 static btVector3 M3x3mulMV_ref( const btMatrix3x3 &m, const btVector3 &v )
33 return btVector3(m[0].dot(v), m[1].dot(v), m[2].dot(v));
36 int Test_3x3mulMV(void)
38 // Init an array flanked by guard pages
39 btMatrix3x3 in1[ARRAY_SIZE];
40 btVector3 in2[ARRAY_SIZE];
41 btVector3 out[ARRAY_SIZE];
42 btVector3 out2[ARRAY_SIZE];
46 for( i = 0; i < ARRAY_SIZE; i++ )
48 in1[i] = btMatrix3x3(rand_f4(), rand_f4(), rand_f4() );
49 in2[i] = btVector3(rand_f4());
51 out[i] = M3x3mulMV_ref(in1[i], in2[i]);
52 out2[i] = (in1[i] * in2[i]);
54 if( fabsf(out[i].m_floats[0] - out2[i].m_floats[0]) +
55 fabsf(out[i].m_floats[1] - out2[i].m_floats[1]) +
56 fabsf(out[i].m_floats[2] - out2[i].m_floats[2]) +
57 fabsf(out[i].m_floats[3] - out2[i].m_floats[3]) > FLT_EPSILON*4 )
59 vlog( "Error - M3x3mulMV result error! ");
60 vlog( "failure @ %ld\n", i);
61 vlog( "\ncorrect = (%10.4f, %10.4f, %10.4f, %10.4f) "
62 "\ntested = (%10.4f, %10.4f, %10.4f, %10.4f) \n",
63 out[i].m_floats[0], out[i].m_floats[1], out[i].m_floats[2], out[i].m_floats[3],
64 out2[i].m_floats[0], out2[i].m_floats[1], out2[i].m_floats[2], out2[i].m_floats[3]);
70 uint64_t scalarTime, vectorTime;
71 uint64_t startTime, bestTime, currentTime;
74 for (j = 0; j < LOOPCOUNT; j++)
76 startTime = ReadTicks();
77 for( i = 0; i < ARRAY_SIZE; i++ )
78 out[i] = M3x3mulMV_ref(in1[i], in2[i]);
79 currentTime = ReadTicks() - startTime;
80 scalarTime += currentTime;
81 if( currentTime < bestTime )
82 bestTime = currentTime;
84 if( 0 == gReportAverageTimes )
85 scalarTime = bestTime;
87 scalarTime /= LOOPCOUNT;
91 for (j = 0; j < LOOPCOUNT; j++)
93 startTime = ReadTicks();
94 for( i = 0; i < ARRAY_SIZE; i++ )
95 out2[i] = (in1[i] * in2[i]);
96 currentTime = ReadTicks() - startTime;
97 vectorTime += currentTime;
98 if( currentTime < bestTime )
99 bestTime = currentTime;
101 if( 0 == gReportAverageTimes )
102 vectorTime = bestTime;
104 vectorTime /= LOOPCOUNT;
107 vlog( "\t scalar\t vector\n" );
108 vlog( "\t%10.2f\t%10.2f\n", TicksToCycles( scalarTime ) / ARRAY_SIZE, TicksToCycles( vectorTime ) / ARRAY_SIZE );