2
0

mMatrixTest.cpp 3.1 KB

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