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_qtmul.h"
21 #include <LinearMath/btQuaternion.h>
23 #define BT_OP(a, b) ((a) *= (b))
24 // reference code for testing purposes
25 static inline btQuaternion& qtmul_ref(btQuaternion& q1, btQuaternion& q2);
27 static inline btQuaternion& qtmul_ref(btQuaternion& q1, btQuaternion& q2)
30 x = q1.w() * q2.x() + q1.x() * q2.w() + q1.y() * q2.z() - q1.z() * q2.y(),
31 y = q1.w() * q2.y() + q1.y() * q2.w() + q1.z() * q2.x() - q1.x() * q2.z(),
32 z = q1.w() * q2.z() + q1.z() * q2.w() + q1.x() * q2.y() - q1.y() * q2.x(),
33 w = q1.w() * q2.w() - q1.x() * q2.x() - q1.y() * q2.y() - q1.z() * q2.z();
35 q1.setValue(x, y, z, w);
39 #define LOOPCOUNT 1024
40 #define NUM_CYCLES 1000
44 btQuaternion q1, q2, q3;
46 float x, y, z, w, vNaN;
53 vNaN = BT_NAN; // w channel NaN
64 btQuaternion correct_res, test_res;
68 correct_res.setValue(vNaN, vNaN, vNaN, vNaN);
69 test_res.setValue(vNaN, vNaN, vNaN, vNaN);
70 correct_res = qtmul_ref(q1, q2);
71 test_res = BT_OP(q3,q2);
73 if( fabsf(correct_res.x() - test_res.x()) +
74 fabsf(correct_res.y() - test_res.y()) +
75 fabsf(correct_res.z() - test_res.z()) +
76 fabsf(correct_res.w() - test_res.w()) > FLT_EPSILON*10 )
78 vlog( "Error - qtmul result error! "
79 "\ncorrect = (%10.4f, %10.4f, %10.4f, %10.4f) "
80 "\ntested = (%10.4f, %10.4f, %10.4f, %10.4f) \n",
81 correct_res.x(), correct_res.y(),
82 correct_res.z(), correct_res.w(),
83 test_res.x(), test_res.y(),
84 test_res.z(), test_res.w());
90 #define DATA_SIZE LOOPCOUNT
92 btQuaternion qt_arr1[DATA_SIZE];
93 btQuaternion qt_arr2[DATA_SIZE];
100 uint64_t startTime, bestTime, currentTime;
104 for (j = 0; j < NUM_CYCLES; j++)
106 for( k = 0; k < DATA_SIZE; k++ )
112 qt_arr1[k].setValue(x,y,z,w);
118 qt_arr2[k].setValue(x,y,z,w);
121 startTime = ReadTicks();
122 for( k = 0; k < LOOPCOUNT; k++ )
124 qt_arr1[k] = qtmul_ref(qt_arr1[k], qt_arr2[k]);
126 currentTime = ReadTicks() - startTime;
127 scalarTime += currentTime;
128 if( currentTime < bestTime )
129 bestTime = currentTime;
131 if( 0 == gReportAverageTimes )
132 scalarTime = bestTime;
134 scalarTime /= NUM_CYCLES;
138 uint64_t startTime, bestTime, currentTime;
142 for (j = 0; j < NUM_CYCLES; j++)
144 for( k = 0; k < DATA_SIZE; k++ )
150 qt_arr1[k].setValue(x,y,z,w);
156 qt_arr2[k].setValue(x,y,z,w);
159 startTime = ReadTicks();
160 for( k = 0; k < LOOPCOUNT; k++ )
162 qt_arr1[k] = BT_OP(qt_arr1[k], qt_arr2[k]);
164 currentTime = ReadTicks() - startTime;
165 vectorTime += currentTime;
166 if( currentTime < bestTime )
167 bestTime = currentTime;
169 if( 0 == gReportAverageTimes )
170 vectorTime = bestTime;
172 vectorTime /= NUM_CYCLES;
176 vlog( " \t scalar\t vector\n" );
177 vlog( " \t%10.4f\t%10.4f\n", TicksToCycles( scalarTime ) / LOOPCOUNT,
178 TicksToCycles( vectorTime ) / LOOPCOUNT );