Torque3D Documentation / _generateds / mMatrixTest.cpp

mMatrixTest.cpp

Engine/source/math/test/mMatrixTest.cpp

More...

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2014 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifdef TORQUE_TESTS_ENABLED
 25#include "testing/unitTesting.h"
 26#include "platform/platform.h"
 27#include "math/mMatrix.h"
 28#include "math/mRandom.h"
 29
 30extern void default_matF_x_matF_C(const F32 *a, const F32 *b, F32 *mresult);
 31extern void mInstallLibrary_ASM();
 32
 33// If we're x86 and not Mac, then include these. There's probably a better way to do this.
 34#if defined(WIN32) && defined(TORQUE_CPU_X86)
 35void Athlon_MatrixF_x_MatrixF(const F32 *matA, const F32 *matB, F32 *result);
 36void SSE_MatrixF_x_MatrixF(const F32 *matA, const F32 *matB, F32 *result);
 37#endif
 38
 39#if defined( __VEC__ )
 40extern void vec_MatrixF_x_MatrixF(const F32 *matA, const F32 *matB, F32 *result);
 41#endif
 42
 43TEST(MatrixF, MultiplyImplmentations)
 44{
 45   F32 m1[16], m2[16], mrC[16];
 46
 47   // I am not positive that the best way to do this is to use random numbers
 48   // but I think that using some kind of standard matrix may not always catch
 49   // all problems.
 50   for (S32 i = 0; i < 16; i++)
 51   {
 52      m1[i] = gRandGen.randF();
 53      m2[i] = gRandGen.randF();
 54   }
 55
 56   // C will be the baseline
 57   default_matF_x_matF_C(m1, m2, mrC);
 58
 59#if defined(WIN32) && defined(TORQUE_CPU_X86)
 60   // Check the CPU info
 61   U32 cpuProperties = Platform::SystemInfo.processor.properties;
 62   bool same;
 63
 64   // Test 3D NOW! if it is available
 65   F32 mrAMD[16];
 66   if (cpuProperties & CPU_PROP_3DNOW)
 67   {
 68      Athlon_MatrixF_x_MatrixF(m1, m2, mrAMD);
 69
 70      same = true;
 71      for (S32 i = 0; i < 16; i++)
 72         same &= mIsEqual(mrC[i], mrAMD[i]);
 73
 74      EXPECT_TRUE(same) << "Matrix multiplication verification failed. (C vs. 3D NOW!)";
 75   }
 76
 77   // Test SSE if it is available
 78   F32 mrSSE[16];
 79   if (cpuProperties & CPU_PROP_SSE)
 80   {
 81      SSE_MatrixF_x_MatrixF(m1, m2, mrSSE);
 82
 83      same = true;
 84      for (S32 i = 0; i < 16; i++)
 85         same &= mIsEqual(mrC[i], mrSSE[i]);
 86
 87      EXPECT_TRUE(same) << "Matrix multiplication verification failed. (C vs. SSE)";
 88   }
 89
 90   same = true;
 91#endif
 92
 93   // If Altivec exists, test it!
 94#if defined(__VEC__)
 95   bool same = false;
 96   F32 mrVEC[16];
 97
 98   vec_MatrixF_x_MatrixF(m1, m2, mrVEC);
 99
100   for (S32 i = 0; i < 16; i++)
101      same &= isEqual(mrC[i], mrVEC[i]);
102
103   EXPECT_TRUE(same) << "Matrix multiplication verification failed. (C vs. Altivec)";
104#endif
105}
106
107#endif
108