SimdMathTests.cpp 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <AzCore/Math/Internal/MathTypes.h>
  9. #include <AzCore/Math/Quaternion.h>
  10. #include <AzCore/UnitTest/TestTypes.h>
  11. using namespace AZ;
  12. namespace UnitTest
  13. {
  14. template<typename VectorType>
  15. void TestToVec1()
  16. {
  17. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  18. float testStoreValues[4] = { -1.0f, -1.0f, -1.0f, -1.0f };
  19. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  20. Simd::Vec1::FloatType testVec1 = VectorType::ToVec1(testVector);
  21. Simd::Vec1::StoreUnaligned(testStoreValues, testVec1);
  22. for (int32_t i = 0; i < Simd::Vec1::ElementCount; ++i)
  23. {
  24. EXPECT_NEAR(testLoadValues[i], testStoreValues[i], AZ::Constants::Tolerance);
  25. }
  26. }
  27. template<typename VectorType>
  28. void TestFromVec1()
  29. {
  30. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  31. float testStoreValues[4] = { -1.0f, -1.0f, -1.0f, -1.0f };
  32. Simd::Vec1::FloatType testVec1 = Simd::Vec1::LoadUnaligned(testLoadValues);
  33. typename VectorType::FloatType testVector = VectorType::FromVec1(testVec1);
  34. VectorType::StoreUnaligned(testStoreValues, testVector);
  35. // All the elements must be set to the Vec1.x value
  36. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  37. {
  38. EXPECT_NEAR(testLoadValues[0], testStoreValues[i], AZ::Constants::Tolerance);
  39. }
  40. }
  41. template<typename VectorType>
  42. void TestToVec2()
  43. {
  44. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  45. float testStoreValues[4] = { -1.0f, -1.0f, -1.0f, -1.0f };
  46. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  47. Simd::Vec2::FloatType testVec2 = VectorType::ToVec2(testVector);
  48. Simd::Vec2::StoreUnaligned(testStoreValues, testVec2);
  49. for (int32_t i = 0; i < Simd::Vec2::ElementCount; ++i)
  50. {
  51. EXPECT_NEAR(testLoadValues[i], testStoreValues[i], AZ::Constants::Tolerance);
  52. }
  53. }
  54. template<typename VectorType>
  55. void TestFromVec2()
  56. {
  57. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  58. float testStoreValues[4] = { -1.0f, -1.0f, -1.0f, -1.0f };
  59. Simd::Vec2::FloatType testVec2 = Simd::Vec2::LoadUnaligned(testLoadValues);
  60. typename VectorType::FloatType testVector = VectorType::FromVec2(testVec2);
  61. VectorType::StoreUnaligned(testStoreValues, testVector);
  62. // The first 2 elements must be set to (Vec2.x, Vec2.y)
  63. for (int32_t i = 0; i < Simd::Vec2::ElementCount; ++i)
  64. {
  65. EXPECT_NEAR(testLoadValues[i], testStoreValues[i], AZ::Constants::Tolerance);
  66. }
  67. // The rest of elements must be set to zero
  68. for (int32_t i = Simd::Vec2::ElementCount; i < VectorType::ElementCount; ++i)
  69. {
  70. EXPECT_NEAR(0.0f, testStoreValues[i], AZ::Constants::Tolerance);
  71. }
  72. }
  73. template <typename VectorType>
  74. void TestLoadStoreFloat()
  75. {
  76. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  77. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  78. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  79. VectorType::StoreUnaligned(testStoreValues, testVector);
  80. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  81. {
  82. EXPECT_NEAR(testLoadValues[i], testStoreValues[i], AZ::Constants::Tolerance);
  83. }
  84. }
  85. template <typename VectorType>
  86. void TestLoadStoreInt()
  87. {
  88. int32_t testLoadValues[4] = { 1, 2, 3, 4 };
  89. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  90. typename VectorType::Int32Type testVector = VectorType::LoadUnaligned(testLoadValues);
  91. VectorType::StoreUnaligned(testStoreValues, testVector);
  92. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  93. {
  94. EXPECT_NEAR(testLoadValues[i], testStoreValues[i], AZ::Constants::Tolerance);
  95. }
  96. }
  97. template <typename VectorType>
  98. void TestSelectFirst()
  99. {
  100. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  101. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  102. const float selectedValue = VectorType::SelectIndex0(testVector);
  103. EXPECT_NEAR(testLoadValues[0], selectedValue, AZ::Constants::Tolerance);
  104. }
  105. template <typename VectorType>
  106. void TestSelectSecond()
  107. {
  108. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  109. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  110. const float selectedValue = VectorType::SelectIndex1(testVector);
  111. EXPECT_NEAR(testLoadValues[1], selectedValue, AZ::Constants::Tolerance);
  112. }
  113. template <typename VectorType>
  114. void TestSelectThird()
  115. {
  116. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  117. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  118. const float selectedValue = VectorType::SelectIndex2(testVector);
  119. EXPECT_NEAR(testLoadValues[2], selectedValue, AZ::Constants::Tolerance);
  120. }
  121. template <typename VectorType>
  122. void TestSelectFourth()
  123. {
  124. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  125. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  126. const float selectedValue = VectorType::SelectIndex3(testVector);
  127. EXPECT_NEAR(testLoadValues[3], selectedValue, AZ::Constants::Tolerance);
  128. }
  129. template <typename VectorType>
  130. void ValidateReplaceResults(const float* testLoadValues1, const float* testLoadValues2, typename VectorType::FloatArgType result, uint32_t replaceIndex)
  131. {
  132. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  133. VectorType::StoreUnaligned(testStoreValues, result);
  134. for (uint32_t i = 0; i < VectorType::ElementCount; ++i)
  135. {
  136. if (i == replaceIndex)
  137. {
  138. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(testLoadValues2[i], AZ::Constants::Tolerance));
  139. }
  140. else
  141. {
  142. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(testLoadValues1[i], AZ::Constants::Tolerance));
  143. }
  144. }
  145. }
  146. template <typename VectorType>
  147. void TestReplaceFirst()
  148. {
  149. float testLoadValues1[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  150. const typename VectorType::FloatType testVector1 = VectorType::LoadUnaligned(testLoadValues1);
  151. float testLoadValues2[4] = { -1.0f, -2.0f, -3.0f, -4.0f };
  152. const typename VectorType::FloatType testVector2 = VectorType::LoadUnaligned(testLoadValues2);
  153. typename VectorType::FloatType result1 = VectorType::ReplaceFirst(testVector1, testVector2);
  154. ValidateReplaceResults<VectorType>(testLoadValues1, testLoadValues2, result1, 0);
  155. typename VectorType::FloatType result2 = VectorType::ReplaceFirst(testVector1, testLoadValues2[0]);
  156. ValidateReplaceResults<VectorType>(testLoadValues1, testLoadValues2, result2, 0);
  157. }
  158. template <typename VectorType>
  159. void TestReplaceSecond()
  160. {
  161. float testLoadValues1[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  162. const typename VectorType::FloatType testVector1 = VectorType::LoadUnaligned(testLoadValues1);
  163. float testLoadValues2[4] = { -1.0f, -2.0f, -3.0f, -4.0f };
  164. const typename VectorType::FloatType testVector2 = VectorType::LoadUnaligned(testLoadValues2);
  165. typename VectorType::FloatType result1 = VectorType::ReplaceSecond(testVector1, testVector2);
  166. ValidateReplaceResults<VectorType>(testLoadValues1, testLoadValues2, result1, 1);
  167. typename VectorType::FloatType result2 = VectorType::ReplaceSecond(testVector1, testLoadValues2[1]);
  168. ValidateReplaceResults<VectorType>(testLoadValues1, testLoadValues2, result2, 1);
  169. }
  170. template <typename VectorType>
  171. void TestReplaceThird()
  172. {
  173. float testLoadValues1[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  174. const typename VectorType::FloatType testVector1 = VectorType::LoadUnaligned(testLoadValues1);
  175. float testLoadValues2[4] = { -1.0f, -2.0f, -3.0f, -4.0f };
  176. const typename VectorType::FloatType testVector2 = VectorType::LoadUnaligned(testLoadValues2);
  177. typename VectorType::FloatType result1 = VectorType::ReplaceThird(testVector1, testVector2);
  178. ValidateReplaceResults<VectorType>(testLoadValues1, testLoadValues2, result1, 2);
  179. typename VectorType::FloatType result2 = VectorType::ReplaceThird(testVector1, testLoadValues2[2]);
  180. ValidateReplaceResults<VectorType>(testLoadValues1, testLoadValues2, result2, 2);
  181. }
  182. template <typename VectorType>
  183. void TestReplaceFourth()
  184. {
  185. float testLoadValues1[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  186. const typename VectorType::FloatType testVector1 = VectorType::LoadUnaligned(testLoadValues1);
  187. float testLoadValues2[4] = { -1.0f, -2.0f, -3.0f, -4.0f };
  188. const typename VectorType::FloatType testVector2 = VectorType::LoadUnaligned(testLoadValues2);
  189. typename VectorType::FloatType result1 = VectorType::ReplaceFourth(testVector1, testVector2);
  190. ValidateReplaceResults<VectorType>(testLoadValues1, testLoadValues2, result1, 3);
  191. typename VectorType::FloatType result2 = VectorType::ReplaceFourth(testVector1, testLoadValues2[3]);
  192. ValidateReplaceResults<VectorType>(testLoadValues1, testLoadValues2, result2, 3);
  193. }
  194. template <typename VectorType>
  195. void TestSplatFloat()
  196. {
  197. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  198. typename VectorType::FloatType testVector = VectorType::Splat(1.0f);
  199. VectorType::StoreUnaligned(testStoreValues, testVector);
  200. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  201. {
  202. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(1.0f, AZ::Constants::Tolerance));
  203. }
  204. }
  205. template <typename VectorType>
  206. void TestSplatInt()
  207. {
  208. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  209. typename VectorType::Int32Type testVector = VectorType::Splat(1);
  210. VectorType::StoreUnaligned(testStoreValues, testVector);
  211. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  212. {
  213. EXPECT_THAT(testStoreValues[i], ::testing::Eq(1));
  214. }
  215. }
  216. template<typename VectorType>
  217. void TestSplatFirst()
  218. {
  219. float testLoadValues[4] = { 3.5f, 0.0f, 0.0f, 0.0f };
  220. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  221. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  222. testVector = VectorType::SplatIndex0(testVector);
  223. VectorType::StoreUnaligned(testStoreValues, testVector);
  224. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  225. {
  226. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(3.5f, AZ::Constants::Tolerance));
  227. }
  228. }
  229. template<typename VectorType>
  230. void TestSplatSecond()
  231. {
  232. float testLoadValues[4] = { 0.0f, 3.5f, 0.0f, 0.0f };
  233. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  234. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  235. testVector = VectorType::SplatIndex1(testVector);
  236. VectorType::StoreUnaligned(testStoreValues, testVector);
  237. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  238. {
  239. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(3.5f, AZ::Constants::Tolerance));
  240. }
  241. }
  242. template<typename VectorType>
  243. void TestSplatThird()
  244. {
  245. float testLoadValues[4] = { 0.0f, 0.0f, 3.5f, 0.0f };
  246. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  247. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  248. testVector = VectorType::SplatIndex2(testVector);
  249. VectorType::StoreUnaligned(testStoreValues, testVector);
  250. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  251. {
  252. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(3.5f, AZ::Constants::Tolerance));
  253. }
  254. }
  255. template<typename VectorType>
  256. void TestSplatFourth()
  257. {
  258. float testLoadValues[4] = { 0.0f, 0.0f, 0.0f, 3.5f };
  259. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  260. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  261. testVector = VectorType::SplatIndex3(testVector);
  262. VectorType::StoreUnaligned(testStoreValues, testVector);
  263. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  264. {
  265. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(3.5f, AZ::Constants::Tolerance));
  266. }
  267. }
  268. template <typename VectorType>
  269. void TestLoadImmediateFloat()
  270. {
  271. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  272. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  273. typename VectorType::FloatType testVector = VectorType::LoadUnaligned(testLoadValues);
  274. VectorType::StoreUnaligned(testStoreValues, testVector);
  275. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  276. {
  277. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(testLoadValues[i], AZ::Constants::Tolerance));
  278. }
  279. }
  280. template <typename VectorType>
  281. void TestLoadImmediateInt()
  282. {
  283. int32_t testLoadValues[4] = { 1, 2, 3, 4 };
  284. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  285. typename VectorType::Int32Type testVector = VectorType::LoadUnaligned(testLoadValues);
  286. VectorType::StoreUnaligned(testStoreValues, testVector);
  287. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  288. {
  289. EXPECT_THAT(testStoreValues[i], ::testing::Eq(testLoadValues[i]));
  290. }
  291. }
  292. template <typename VectorType>
  293. void TestAddSubMulDivFloat()
  294. {
  295. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  296. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  297. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  298. // Add
  299. {
  300. float results[4] = { 2.0f, 4.0f, 6.0f, 8.0f };
  301. typename VectorType::FloatType testVector = VectorType::Add(sourceVector, sourceVector);
  302. VectorType::StoreUnaligned(testStoreValues, testVector);
  303. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  304. {
  305. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  306. }
  307. }
  308. // Sub
  309. {
  310. float results[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  311. typename VectorType::FloatType testVector = VectorType::Sub(VectorType::Add(sourceVector, sourceVector), sourceVector);
  312. VectorType::StoreUnaligned(testStoreValues, testVector);
  313. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  314. {
  315. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  316. }
  317. }
  318. // Mul
  319. {
  320. float results[4] = { 1.0f, 4.0f, 9.0f, 16.0f };
  321. typename VectorType::FloatType testVector = VectorType::Mul(sourceVector, sourceVector);
  322. VectorType::StoreUnaligned(testStoreValues, testVector);
  323. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  324. {
  325. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  326. }
  327. }
  328. // Div
  329. {
  330. float results[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
  331. typename VectorType::FloatType testVector = VectorType::Div(sourceVector, sourceVector);
  332. VectorType::StoreUnaligned(testStoreValues, testVector);
  333. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  334. {
  335. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  336. }
  337. }
  338. }
  339. template <typename VectorType>
  340. void TestAddSubMulInt()
  341. {
  342. int32_t testLoadValues[4] = { 1, 2, 3, 4 };
  343. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  344. typename VectorType::Int32Type sourceVector = VectorType::LoadUnaligned(testLoadValues);
  345. // Add
  346. {
  347. int32_t results[4] = { 2, 4, 6, 8 };
  348. typename VectorType::Int32Type testVector = VectorType::Add(sourceVector, sourceVector);
  349. VectorType::StoreUnaligned(testStoreValues, testVector);
  350. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  351. {
  352. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  353. }
  354. }
  355. // Sub
  356. {
  357. int32_t results[4] = { 1, 2, 3, 4 };
  358. typename VectorType::Int32Type testVector = VectorType::Sub(VectorType::Add(sourceVector, sourceVector), sourceVector);
  359. VectorType::StoreUnaligned(testStoreValues, testVector);
  360. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  361. {
  362. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  363. }
  364. }
  365. // Mul
  366. {
  367. int32_t results[4] = { 1, 4, 9, 16 };
  368. typename VectorType::Int32Type testVector = VectorType::Mul(sourceVector, sourceVector);
  369. VectorType::StoreUnaligned(testStoreValues, testVector);
  370. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  371. {
  372. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  373. }
  374. }
  375. }
  376. template <typename VectorType>
  377. void TestNotFloat()
  378. {
  379. float testLoadValues[4] = { 0.0f, 1.0f, -0.0f, -1.0f };
  380. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  381. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  382. typename VectorType::FloatType testVector = VectorType::Not(sourceVector);
  383. VectorType::StoreUnaligned(testStoreValues, testVector);
  384. switch (VectorType::ElementCount)
  385. {
  386. case 4:
  387. EXPECT_NEAR(testStoreValues[3], 4.0f, 0.01f);
  388. case 3:
  389. EXPECT_TRUE(AZStd::isnan(testStoreValues[2]));
  390. case 2:
  391. EXPECT_NEAR(testStoreValues[1], -4.0f, 0.01f);
  392. case 1:
  393. EXPECT_TRUE(AZStd::isnan(testStoreValues[0]));
  394. break;
  395. }
  396. }
  397. template <typename VectorType>
  398. void TestAndAndnotOrFloat()
  399. {
  400. float testLoadValues[4] = { 1.0f, 2.0f, -3.0f, -4.0f };
  401. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  402. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  403. // And
  404. {
  405. float results[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  406. typename VectorType::FloatType testVector = VectorType::And(sourceVector, VectorType::ZeroFloat());
  407. VectorType::StoreUnaligned(testStoreValues, testVector);
  408. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  409. {
  410. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  411. }
  412. }
  413. // AndNot
  414. {
  415. typename VectorType::FloatType testVector = VectorType::AndNot(VectorType::ZeroFloat(), sourceVector);
  416. VectorType::StoreUnaligned(testStoreValues, testVector);
  417. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  418. {
  419. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(testLoadValues[i], AZ::Constants::Tolerance));
  420. }
  421. }
  422. // Or
  423. {
  424. float results[4] = { 1.0f, 2.0f, -3.0f, -4.0f };
  425. typename VectorType::FloatType testVector = VectorType::Or(sourceVector, VectorType::ZeroFloat());
  426. VectorType::StoreUnaligned(testStoreValues, testVector);
  427. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  428. {
  429. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  430. }
  431. }
  432. }
  433. template <typename VectorType>
  434. void TestXorFloat()
  435. {
  436. float testLoadValues[4] = { 1.0f, 2.0f, -3.0f, -4.0f };
  437. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  438. typename VectorType::Int32Type mask = VectorType::Splat(static_cast<int32_t>(0x80000000));
  439. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  440. typename VectorType::FloatType testVector = VectorType::Xor(sourceVector, VectorType::CastToFloat(mask));
  441. VectorType::StoreUnaligned(testStoreValues, testVector);
  442. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  443. {
  444. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(-testLoadValues[i], AZ::Constants::Tolerance));
  445. }
  446. }
  447. template <typename VectorType>
  448. void TestNotInt()
  449. {
  450. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  451. typename VectorType::Int32Type sourceVector = VectorType::Splat(static_cast<int32_t>(0x80000000));
  452. typename VectorType::Int32Type testVector = VectorType::Not(sourceVector);
  453. VectorType::StoreUnaligned(testStoreValues, testVector);
  454. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  455. {
  456. EXPECT_THAT(testStoreValues[i], ::testing::Eq(0x7FFFFFFF));
  457. }
  458. }
  459. template <typename VectorType>
  460. void TestAndAndnotOrInt()
  461. {
  462. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  463. typename VectorType::Int32Type sourceVector1 = VectorType::Splat(static_cast<int32_t>(0xFFFF0000));
  464. typename VectorType::Int32Type sourceVector2 = VectorType::Splat(static_cast<int32_t>(0x0000FFFF));
  465. // And
  466. {
  467. typename VectorType::Int32Type testVector = VectorType::And(sourceVector1, sourceVector2);
  468. VectorType::StoreUnaligned(testStoreValues, testVector);
  469. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  470. {
  471. EXPECT_THAT(testStoreValues[i], ::testing::Eq(0));
  472. }
  473. }
  474. // AndNot
  475. {
  476. typename VectorType::Int32Type testVector = VectorType::AndNot(sourceVector1, sourceVector2);
  477. VectorType::StoreUnaligned(testStoreValues, testVector);
  478. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  479. {
  480. EXPECT_THAT(testStoreValues[i], ::testing::Eq(0x0000FFFF));
  481. }
  482. }
  483. // Or
  484. {
  485. typename VectorType::Int32Type testVector = VectorType::Or(sourceVector1, sourceVector2);
  486. VectorType::StoreUnaligned(testStoreValues, testVector);
  487. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  488. {
  489. EXPECT_THAT(testStoreValues[i], ::testing::Eq(0xFFFFFFFF));
  490. }
  491. }
  492. }
  493. template <typename VectorType>
  494. void TestXorInt()
  495. {
  496. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  497. typename VectorType::Int32Type sourceVector1 = VectorType::Splat(static_cast<int32_t>(0xFFFFF000));
  498. typename VectorType::Int32Type sourceVector2 = VectorType::Splat(static_cast<int32_t>(0x000FFFFF));
  499. typename VectorType::Int32Type testVector = VectorType::Xor(sourceVector1, sourceVector2);
  500. VectorType::StoreUnaligned(testStoreValues, testVector);
  501. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  502. {
  503. EXPECT_THAT(testStoreValues[i], ::testing::Eq(0xFFF00FFF));
  504. }
  505. }
  506. template <typename VectorType>
  507. void TestMinMaxInt()
  508. {
  509. int32_t testLoadValues1[4] = { 0, 1, -1, 0 };
  510. int32_t testLoadValues2[4] = { -1, 0, 0, 1 };
  511. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  512. typename VectorType::Int32Type sourceVector1 = VectorType::LoadUnaligned(testLoadValues1);
  513. typename VectorType::Int32Type sourceVector2 = VectorType::LoadUnaligned(testLoadValues2);
  514. // Min
  515. {
  516. int32_t results[4] = { -1, 0, -1, 0 };
  517. typename VectorType::Int32Type testVector = VectorType::Min(sourceVector1, sourceVector2);
  518. VectorType::StoreUnaligned(testStoreValues, testVector);
  519. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  520. {
  521. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  522. }
  523. }
  524. // Max
  525. {
  526. int32_t results[4] = { 0, 1, 0, 1 };
  527. typename VectorType::Int32Type testVector = VectorType::Max(sourceVector1, sourceVector2);
  528. VectorType::StoreUnaligned(testStoreValues, testVector);
  529. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  530. {
  531. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  532. }
  533. }
  534. }
  535. template <typename VectorType>
  536. void TestClampInt()
  537. {
  538. int32_t testLoadValues[4] = { -10, 10, -5, 5 };
  539. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  540. typename VectorType::Int32Type sourceVector1 = VectorType::LoadUnaligned(testLoadValues);
  541. typename VectorType::Int32Type sourceVector2 = VectorType::Splat(-8);
  542. typename VectorType::Int32Type sourceVector3 = VectorType::Splat( 8);
  543. typename VectorType::Int32Type testVector = VectorType::Clamp(sourceVector1, sourceVector2, sourceVector3);
  544. VectorType::StoreUnaligned(testStoreValues, testVector);
  545. int32_t results[4] = { -8, 8, -5, 5 };
  546. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  547. {
  548. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  549. }
  550. }
  551. template <typename VectorType>
  552. void TestFloorFloat()
  553. {
  554. // Positive values
  555. float testLoadValues[4] = { 0.2f, 0.4f, 0.6f, 0.8f };
  556. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  557. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  558. {
  559. typename VectorType::FloatType testVector = VectorType::Floor(sourceVector);
  560. VectorType::StoreUnaligned(testStoreValues, testVector);
  561. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  562. {
  563. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(0.0f, AZ::Constants::Tolerance));
  564. }
  565. }
  566. // Negative values
  567. float testNegativeLoadValues[4] = { -0.2f, -0.4f, -0.6f, -0.8f };
  568. sourceVector = VectorType::LoadUnaligned(testNegativeLoadValues);
  569. {
  570. typename VectorType::FloatType testVector = VectorType::Floor(sourceVector);
  571. VectorType::StoreUnaligned(testStoreValues, testVector);
  572. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  573. {
  574. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(-1.0f, AZ::Constants::Tolerance));
  575. }
  576. }
  577. // Equidistant values
  578. float testEquidistantLoadValues[4] = { 0.5f, -0.5f, 1.5f, -1.5f };
  579. sourceVector = VectorType::LoadUnaligned(testEquidistantLoadValues);
  580. {
  581. typename VectorType::FloatType testVector = VectorType::Floor(sourceVector);
  582. VectorType::StoreUnaligned(testStoreValues, testVector);
  583. float results[4] = { 0.0f, -1.0f, 1.0f, -2.0f };
  584. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  585. {
  586. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  587. }
  588. }
  589. // Whole values
  590. float testWholeLoadValues[4] = { 0.0f, 1.0f, -1.0f, 2.0f };
  591. sourceVector = VectorType::LoadUnaligned(testWholeLoadValues);
  592. {
  593. typename VectorType::FloatType testVector = VectorType::Floor(sourceVector);
  594. VectorType::StoreUnaligned(testStoreValues, testVector);
  595. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  596. {
  597. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(testWholeLoadValues[i], AZ::Constants::Tolerance));
  598. }
  599. }
  600. }
  601. template <typename VectorType>
  602. void TestCeilFloat()
  603. {
  604. // Positive values
  605. float testLoadValues[4] = { 0.2f, 0.4f, 0.6f, 0.8f };
  606. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  607. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  608. {
  609. typename VectorType::FloatType testVector = VectorType::Ceil(sourceVector);
  610. VectorType::StoreUnaligned(testStoreValues, testVector);
  611. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  612. {
  613. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(1.0f, AZ::Constants::Tolerance));
  614. }
  615. }
  616. // Negative values
  617. float testNegativeLoadValues[4] = { -0.2f, -0.4f, -0.6f, -0.8f };
  618. sourceVector = VectorType::LoadUnaligned(testNegativeLoadValues);
  619. {
  620. typename VectorType::FloatType testVector = VectorType::Ceil(sourceVector);
  621. VectorType::StoreUnaligned(testStoreValues, testVector);
  622. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  623. {
  624. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(0.0f, AZ::Constants::Tolerance));
  625. }
  626. }
  627. // Equidistant values
  628. float testEquidistantLoadValues[4] = { 0.5f, -0.5f, 1.5f, -1.5f };
  629. sourceVector = VectorType::LoadUnaligned(testEquidistantLoadValues);
  630. {
  631. typename VectorType::FloatType testVector = VectorType::Ceil(sourceVector);
  632. VectorType::StoreUnaligned(testStoreValues, testVector);
  633. float results[4] = { 1.0f, 0.0f, 2.0f, -1.0f };
  634. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  635. {
  636. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  637. }
  638. }
  639. // Whole values
  640. float testWholeLoadValues[4] = { 0.0f, 1.0f, -1.0f, 2.0f };
  641. sourceVector = VectorType::LoadUnaligned(testWholeLoadValues);
  642. {
  643. typename VectorType::FloatType testVector = VectorType::Ceil(sourceVector);
  644. VectorType::StoreUnaligned(testStoreValues, testVector);
  645. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  646. {
  647. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(testWholeLoadValues[i], AZ::Constants::Tolerance));
  648. }
  649. }
  650. }
  651. template <typename VectorType>
  652. void TestRoundFloat()
  653. {
  654. // Positive values
  655. float testLoadValues[4] = { 0.2f, 0.4f, 0.6f, 0.8f };
  656. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  657. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  658. {
  659. typename VectorType::FloatType testVector = VectorType::Round(sourceVector);
  660. VectorType::StoreUnaligned(testStoreValues, testVector);
  661. float results[4] = { 0.0f, 0.0f, 1.0f, 1.0f };
  662. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  663. {
  664. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  665. }
  666. }
  667. // Negative values
  668. float testNegativeLoadValues[4] = { -0.2f, -0.4f, -0.6f, -0.8f };
  669. sourceVector = VectorType::LoadUnaligned(testNegativeLoadValues);
  670. {
  671. typename VectorType::FloatType testVector = VectorType::Round(sourceVector);
  672. VectorType::StoreUnaligned(testStoreValues, testVector);
  673. float results[4] = { 0.0f, 0.0f, -1.0f, -1.0f };
  674. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  675. {
  676. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  677. }
  678. }
  679. // Equidistant values
  680. float testEquidistantLoadValues[4] = { 0.5f, -0.5f, 1.5f, -1.5f };
  681. sourceVector = VectorType::LoadUnaligned(testEquidistantLoadValues);
  682. {
  683. typename VectorType::FloatType testVector = VectorType::Round(sourceVector);
  684. VectorType::StoreUnaligned(testStoreValues, testVector);
  685. // The expected behaviour is ties to even (banker's rounding)
  686. float results[4] = { 0.0f, 0.0f, 2.0f, -2.0f };
  687. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  688. {
  689. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  690. }
  691. }
  692. // Whole values
  693. float testWholeLoadValues[4] = { 0.0f, 1.0f, -1.0f, 2.0f };
  694. sourceVector = VectorType::LoadUnaligned(testWholeLoadValues);
  695. {
  696. typename VectorType::FloatType testVector = VectorType::Round(sourceVector);
  697. VectorType::StoreUnaligned(testStoreValues, testVector);
  698. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  699. {
  700. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(testWholeLoadValues[i], AZ::Constants::Tolerance));
  701. }
  702. }
  703. }
  704. template <typename VectorType>
  705. void TestTruncateFloat()
  706. {
  707. // Positive values
  708. float testLoadValues[4] = { 0.2f, 0.4f, 0.6f, 0.8f };
  709. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  710. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  711. {
  712. typename VectorType::FloatType testVector = VectorType::Truncate(sourceVector);
  713. VectorType::StoreUnaligned(testStoreValues, testVector);
  714. float results[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  715. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  716. {
  717. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  718. }
  719. }
  720. // Negative values
  721. float testNegativeLoadValues[4] = { -0.2f, -0.4f, -0.6f, -0.8f };
  722. sourceVector = VectorType::LoadUnaligned(testNegativeLoadValues);
  723. {
  724. typename VectorType::FloatType testVector = VectorType::Truncate(sourceVector);
  725. VectorType::StoreUnaligned(testStoreValues, testVector);
  726. float results[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  727. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  728. {
  729. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  730. }
  731. }
  732. // Equidistant values
  733. float testEquidistantLoadValues[4] = { 0.5f, -0.5f, 1.5f, -1.5f };
  734. sourceVector = VectorType::LoadUnaligned(testEquidistantLoadValues);
  735. {
  736. typename VectorType::FloatType testVector = VectorType::Truncate(sourceVector);
  737. VectorType::StoreUnaligned(testStoreValues, testVector);
  738. float results[4] = { 0.0f, 0.0f, 1.0f, -1.0f };
  739. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  740. {
  741. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  742. }
  743. }
  744. // Whole values
  745. float testWholeLoadValues[4] = { 0.0f, 1.0f, -1.0f, 2.0f };
  746. sourceVector = VectorType::LoadUnaligned(testWholeLoadValues);
  747. {
  748. typename VectorType::FloatType testVector = VectorType::Truncate(sourceVector);
  749. VectorType::StoreUnaligned(testStoreValues, testVector);
  750. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  751. {
  752. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(testWholeLoadValues[i], AZ::Constants::Tolerance));
  753. }
  754. }
  755. }
  756. template <typename VectorType>
  757. void TestMinMaxFloat()
  758. {
  759. float testLoadValues1[4] = { 0.0f, 1.0f, -1.0f, 0.0f };
  760. float testLoadValues2[4] = { -1.0f, 0.0f, 0.0f, 1.0f };
  761. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  762. typename VectorType::FloatType sourceVector1 = VectorType::LoadUnaligned(testLoadValues1);
  763. typename VectorType::FloatType sourceVector2 = VectorType::LoadUnaligned(testLoadValues2);
  764. // Min
  765. {
  766. typename VectorType::FloatType testVector = VectorType::Min(sourceVector1, sourceVector2);
  767. VectorType::StoreUnaligned(testStoreValues, testVector);
  768. float results[4] = { -1.0f, 0.0f, -1.0f, 0.0f };
  769. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  770. {
  771. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  772. }
  773. }
  774. // Max
  775. {
  776. typename VectorType::FloatType testVector = VectorType::Max(sourceVector1, sourceVector2);
  777. VectorType::StoreUnaligned(testStoreValues, testVector);
  778. float results[4] = { 0.0f, 1.0f, 0.0f, 1.0f };
  779. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  780. {
  781. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  782. }
  783. }
  784. }
  785. template <typename VectorType>
  786. void TestClampFloat()
  787. {
  788. float testLoadValues[4] = { -10.0f, 10.0f, -5.0f, 5.0f };
  789. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  790. typename VectorType::FloatType sourceVector1 = VectorType::LoadUnaligned(testLoadValues);
  791. typename VectorType::FloatType sourceVector2 = VectorType::Splat(-8.0f);
  792. typename VectorType::FloatType sourceVector3 = VectorType::Splat(8.0f);
  793. typename VectorType::FloatType testVector = VectorType::Clamp(sourceVector1, sourceVector2, sourceVector3);
  794. VectorType::StoreUnaligned(testStoreValues, testVector);
  795. float results[4] = { -8.0f, 8.0f, -5.0f, 5.0f };
  796. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  797. {
  798. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(results[i], AZ::Constants::Tolerance));
  799. }
  800. }
  801. template <typename VectorType>
  802. void TestCompareFloat()
  803. {
  804. float testLoadValues1[4] = { -10.1f, 10.0f, -5.0f, 5.1f };
  805. float testLoadValues2[4] = { -10.0f, 0.0f, -5.0f, 5.1f };
  806. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  807. typename VectorType::FloatType sourceVector1 = VectorType::LoadUnaligned(testLoadValues1);
  808. typename VectorType::FloatType sourceVector2 = VectorType::LoadUnaligned(testLoadValues2);
  809. // CmpEq
  810. {
  811. typename VectorType::FloatType testVector = VectorType::CmpEq(sourceVector1, sourceVector2);
  812. VectorType::StoreUnaligned(testStoreValues, VectorType::CastToInt(testVector));
  813. int32_t results[4] = { 0, 0, -1, -1 };
  814. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  815. {
  816. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  817. }
  818. }
  819. // CmpNeq
  820. {
  821. typename VectorType::FloatType testVector = VectorType::CmpNeq(sourceVector1, sourceVector2);
  822. VectorType::StoreUnaligned(testStoreValues, VectorType::CastToInt(testVector));
  823. int32_t results[4] = { -1, -1, 0, 0 };
  824. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  825. {
  826. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  827. }
  828. }
  829. // CmpGt
  830. {
  831. typename VectorType::FloatType testVector = VectorType::CmpGt(sourceVector1, sourceVector2);
  832. VectorType::StoreUnaligned(testStoreValues, VectorType::CastToInt(testVector));
  833. int32_t results[4] = { 0, -1, 0, 0 };
  834. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  835. {
  836. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  837. }
  838. }
  839. // CmpGte
  840. {
  841. typename VectorType::FloatType testVector = VectorType::CmpGtEq(sourceVector1, sourceVector2);
  842. VectorType::StoreUnaligned(testStoreValues, VectorType::CastToInt(testVector));
  843. int32_t results[4] = { 0, -1, -1, -1 };
  844. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  845. {
  846. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  847. }
  848. }
  849. // CmpLt
  850. {
  851. typename VectorType::FloatType testVector = VectorType::CmpLt(sourceVector1, sourceVector2);
  852. VectorType::StoreUnaligned(testStoreValues, VectorType::CastToInt(testVector));
  853. int32_t results[4] = { -1, 0, 0, 0 };
  854. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  855. {
  856. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  857. }
  858. }
  859. // CmpLte
  860. {
  861. typename VectorType::FloatType testVector = VectorType::CmpLtEq(sourceVector1, sourceVector2);
  862. VectorType::StoreUnaligned(testStoreValues, VectorType::CastToInt(testVector));
  863. int32_t results[4] = { -1, 0, -1, -1 };
  864. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  865. {
  866. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  867. }
  868. }
  869. }
  870. template <typename VectorType>
  871. void TestCompareAllFloat()
  872. {
  873. float testLoadValues1[4] = { -10.1f, 10.0f, -5.1f, 5.0f };
  874. float testLoadValues2[4] = { -10.0f, 10.1f, -5.0f, 5.1f };
  875. typename VectorType::FloatType sourceVector1 = VectorType::LoadUnaligned(testLoadValues1);
  876. typename VectorType::FloatType sourceVector2 = VectorType::LoadUnaligned(testLoadValues2);
  877. EXPECT_FALSE(VectorType::CmpAllEq(sourceVector1, sourceVector2));
  878. EXPECT_TRUE (VectorType::CmpAllLt(sourceVector1, sourceVector2));
  879. EXPECT_TRUE (VectorType::CmpAllLtEq(sourceVector1, sourceVector2));
  880. EXPECT_FALSE(VectorType::CmpAllGt(sourceVector1, sourceVector2));
  881. EXPECT_FALSE(VectorType::CmpAllGtEq(sourceVector1, sourceVector2));
  882. EXPECT_TRUE(VectorType::CmpAllEq(sourceVector1, sourceVector1));
  883. EXPECT_TRUE(VectorType::CmpAllEq(sourceVector2, sourceVector2));
  884. EXPECT_FALSE(VectorType::CmpAllLt(sourceVector1, sourceVector1));
  885. EXPECT_FALSE(VectorType::CmpAllGt(sourceVector1, sourceVector1));
  886. EXPECT_FALSE(VectorType::CmpAllLt(sourceVector2, sourceVector2));
  887. EXPECT_FALSE(VectorType::CmpAllGt(sourceVector2, sourceVector2));
  888. EXPECT_TRUE(VectorType::CmpAllLtEq(sourceVector1, sourceVector1));
  889. EXPECT_TRUE(VectorType::CmpAllGtEq(sourceVector1, sourceVector1));
  890. EXPECT_TRUE(VectorType::CmpAllLtEq(sourceVector2, sourceVector2));
  891. EXPECT_TRUE(VectorType::CmpAllGtEq(sourceVector2, sourceVector2));
  892. }
  893. template <typename VectorType>
  894. void TestCompareInt()
  895. {
  896. int32_t testLoadValues1[4] = { -11, 10, -5, 6 };
  897. int32_t testLoadValues2[4] = { -10, 0, -5, 6 };
  898. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  899. typename VectorType::Int32Type sourceVector1 = VectorType::LoadUnaligned(testLoadValues1);
  900. typename VectorType::Int32Type sourceVector2 = VectorType::LoadUnaligned(testLoadValues2);
  901. // CmpEq
  902. {
  903. typename VectorType::Int32Type testVector = VectorType::CmpEq(sourceVector1, sourceVector2);
  904. VectorType::StoreUnaligned(testStoreValues, testVector);
  905. int32_t results[4] = { 0, 0, -1, -1 };
  906. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  907. {
  908. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  909. }
  910. }
  911. // CmpNeq
  912. {
  913. typename VectorType::Int32Type testVector = VectorType::CmpNeq(sourceVector1, sourceVector2);
  914. VectorType::StoreUnaligned(testStoreValues, testVector);
  915. int32_t results[4] = { -1, -1, 0, 0 };
  916. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  917. {
  918. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  919. }
  920. }
  921. // CmpGt
  922. {
  923. typename VectorType::Int32Type testVector = VectorType::CmpGt(sourceVector1, sourceVector2);
  924. VectorType::StoreUnaligned(testStoreValues, testVector);
  925. int32_t results[4] = { 0, -1, 0, 0 };
  926. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  927. {
  928. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  929. }
  930. }
  931. // CmpGte
  932. {
  933. typename VectorType::Int32Type testVector = VectorType::CmpGtEq(sourceVector1, sourceVector2);
  934. VectorType::StoreUnaligned(testStoreValues, testVector);
  935. int32_t results[4] = { 0, -1, -1, -1 };
  936. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  937. {
  938. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  939. }
  940. }
  941. // CmpLt
  942. {
  943. typename VectorType::Int32Type testVector = VectorType::CmpLt(sourceVector1, sourceVector2);
  944. VectorType::StoreUnaligned(testStoreValues, testVector);
  945. int32_t results[4] = { -1, 0, 0, 0 };
  946. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  947. {
  948. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  949. }
  950. }
  951. // CmpLte
  952. {
  953. typename VectorType::Int32Type testVector = VectorType::CmpLtEq(sourceVector1, sourceVector2);
  954. VectorType::StoreUnaligned(testStoreValues, testVector);
  955. int32_t results[4] = { -1, 0, -1, -1 };
  956. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  957. {
  958. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  959. }
  960. }
  961. }
  962. template <typename VectorType>
  963. void TestCompareAllInt()
  964. {
  965. int32_t testLoadValues1[4] = { -10, 11, -4, 6 };
  966. int32_t testLoadValues2[4] = { -11, 10, -5, 5 };
  967. typename VectorType::Int32Type sourceVector1 = VectorType::LoadUnaligned(testLoadValues1);
  968. typename VectorType::Int32Type sourceVector2 = VectorType::LoadUnaligned(testLoadValues2);
  969. EXPECT_FALSE(VectorType::CmpAllEq(sourceVector1, sourceVector2));
  970. EXPECT_TRUE(VectorType::CmpAllEq(sourceVector1, sourceVector1));
  971. EXPECT_TRUE(VectorType::CmpAllEq(sourceVector2, sourceVector2));
  972. }
  973. template <typename VectorType>
  974. void TestReciprocalFloat()
  975. {
  976. float testLoadValues[4] = { 2.0f, 4.0f, 8.0f, 1.0f };
  977. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  978. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  979. // Reciprocal
  980. {
  981. typename VectorType::FloatType testVector = VectorType::Reciprocal(sourceVector);
  982. VectorType::StoreUnaligned(testStoreValues, testVector);
  983. float results[4] = { 0.5f, 0.25f, 0.125f, 1.0f };
  984. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  985. {
  986. EXPECT_NEAR(testStoreValues[i], results[i], 0.01f);
  987. }
  988. }
  989. // ReciprocalEstimate
  990. {
  991. typename VectorType::FloatType testVector = VectorType::ReciprocalEstimate(sourceVector);
  992. VectorType::StoreUnaligned(testStoreValues, testVector);
  993. float results[4] = { 0.5f, 0.25f, 0.125f, 1.0f };
  994. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  995. {
  996. EXPECT_NEAR(testStoreValues[i], results[i], 0.01f);
  997. }
  998. }
  999. }
  1000. template <typename VectorType>
  1001. void TestSqrtInvSqrtFloat()
  1002. {
  1003. float testLoadValues[4] = { -1.0f, 16.0f, 1.0f, 0.0f };
  1004. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1005. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  1006. // Sqrt
  1007. {
  1008. typename VectorType::FloatType testVector = VectorType::Sqrt(sourceVector);
  1009. VectorType::StoreUnaligned(testStoreValues, testVector);
  1010. switch (VectorType::ElementCount)
  1011. {
  1012. case 4:
  1013. EXPECT_NEAR(testStoreValues[3], 0.0f, 0.002f);
  1014. case 3:
  1015. EXPECT_NEAR(testStoreValues[2], 1.0f, 0.002f);
  1016. case 2:
  1017. EXPECT_NEAR(testStoreValues[1], 4.0f, 0.002f);
  1018. case 1:
  1019. EXPECT_TRUE(AZStd::isnan(testStoreValues[0]));
  1020. break;
  1021. }
  1022. }
  1023. // InvSqrt
  1024. {
  1025. typename VectorType::FloatType testVector = VectorType::SqrtInv(sourceVector);
  1026. VectorType::StoreUnaligned(testStoreValues, testVector);
  1027. switch (VectorType::ElementCount)
  1028. {
  1029. case 4:
  1030. EXPECT_TRUE(AZStd::isnan(testStoreValues[3]) || AZStd::isinf(testStoreValues[3]));
  1031. case 3:
  1032. EXPECT_NEAR(testStoreValues[2], 1.0f, 0.002f);
  1033. case 2:
  1034. EXPECT_NEAR(testStoreValues[1], 0.25f, 0.002f);
  1035. case 1:
  1036. EXPECT_TRUE(AZStd::isnan(testStoreValues[0]));
  1037. break;
  1038. }
  1039. }
  1040. }
  1041. template <typename VectorType>
  1042. void TestSin()
  1043. {
  1044. float testLoadValues1[4] = { 0.0f, 0.523598775598f, 1.5707963267949f, 3.141594f };
  1045. float testLoadValues2[4] = { 21.991148575f, 4.18879020479f, -1.5707963267949f, -3.1415926f };
  1046. float testStoreValues1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1047. float testStoreValues2[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1048. float precision = 0.000002f;
  1049. typename VectorType::FloatType sourceVector1 = VectorType::LoadUnaligned(testLoadValues1);
  1050. typename VectorType::FloatType sourceVector2 = VectorType::LoadUnaligned(testLoadValues2);
  1051. {
  1052. typename VectorType::FloatType testVector = VectorType::Sin(sourceVector1);
  1053. VectorType::StoreUnaligned(testStoreValues1, testVector);
  1054. switch (VectorType::ElementCount)
  1055. {
  1056. case 4:
  1057. EXPECT_NEAR(testStoreValues1[3], 0.0f, precision);
  1058. case 3:
  1059. EXPECT_NEAR(testStoreValues1[2], 1.0f, precision);
  1060. case 2:
  1061. EXPECT_NEAR(testStoreValues1[1], 0.5f, precision);
  1062. case 1:
  1063. EXPECT_NEAR(testStoreValues1[0], 0.0f, precision);
  1064. }
  1065. }
  1066. {
  1067. typename VectorType::FloatType testVector = VectorType::Sin(sourceVector2);
  1068. VectorType::StoreUnaligned(testStoreValues2, testVector);
  1069. switch (VectorType::ElementCount)
  1070. {
  1071. case 4:
  1072. EXPECT_NEAR(testStoreValues2[3], 0.0f, precision);
  1073. case 3:
  1074. EXPECT_NEAR(testStoreValues2[2], -1.0f, precision);
  1075. case 2:
  1076. EXPECT_NEAR(testStoreValues2[1], -0.8660254f, precision);
  1077. case 1:
  1078. EXPECT_NEAR(testStoreValues2[0], 0.0f, precision);
  1079. }
  1080. }
  1081. }
  1082. template <typename VectorType>
  1083. void TestCos()
  1084. {
  1085. float testLoadValues1[4] = { 0.0f, 0.523598775598f, 1.5707963267949f, 3.141594f };
  1086. float testLoadValues2[4] = { 21.991148575f, 4.18879020479f, -1.5707963267949f, -3.1415926f };
  1087. float testStoreValues1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1088. float testStoreValues2[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1089. float precision = 0.000002f;
  1090. typename VectorType::FloatType sourceVector1 = VectorType::LoadUnaligned(testLoadValues1);
  1091. typename VectorType::FloatType sourceVector2 = VectorType::LoadUnaligned(testLoadValues2);
  1092. {
  1093. typename VectorType::FloatType testVector = VectorType::Cos(sourceVector1);
  1094. VectorType::StoreUnaligned(testStoreValues1, testVector);
  1095. switch (VectorType::ElementCount)
  1096. {
  1097. case 4:
  1098. EXPECT_NEAR(testStoreValues1[3], -1.0f, precision);
  1099. case 3:
  1100. EXPECT_NEAR(testStoreValues1[2], 0.0f, precision);
  1101. case 2:
  1102. EXPECT_NEAR(testStoreValues1[1], 0.8660254f, precision);
  1103. case 1:
  1104. EXPECT_NEAR(testStoreValues1[0], 1.0f, precision);
  1105. }
  1106. }
  1107. {
  1108. typename VectorType::FloatType testVector = VectorType::Cos(sourceVector2);
  1109. VectorType::StoreUnaligned(testStoreValues2, testVector);
  1110. switch (VectorType::ElementCount)
  1111. {
  1112. case 4:
  1113. EXPECT_NEAR(testStoreValues2[3], -1.0f, precision);
  1114. case 3:
  1115. EXPECT_NEAR(testStoreValues2[2], 0.0f, precision);
  1116. case 2:
  1117. EXPECT_NEAR(testStoreValues2[1], -0.5f, precision);
  1118. case 1:
  1119. EXPECT_NEAR(testStoreValues2[0], -1.0f, precision);
  1120. }
  1121. }
  1122. }
  1123. template <typename VectorType>
  1124. void TestAcos()
  1125. {
  1126. float testLoadValues1[4] = { -1.0f, -0.8660254f, -0.5, 0.0f };
  1127. float testLoadValues2[4] = { 0.70710678f, 1.0f, -1.5f, 2.0f };
  1128. float testStoreValues1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1129. float testStoreValues2[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1130. float precision = 0.000002f;
  1131. typename VectorType::FloatType sourceVector1 = VectorType::LoadUnaligned(testLoadValues1);
  1132. typename VectorType::FloatType sourceVector2 = VectorType::LoadUnaligned(testLoadValues2);
  1133. {
  1134. typename VectorType::FloatType testVector = VectorType::Acos(sourceVector1);
  1135. VectorType::StoreUnaligned(testStoreValues1, testVector);
  1136. switch (VectorType::ElementCount)
  1137. {
  1138. case 4:
  1139. EXPECT_NEAR(testStoreValues1[3], Constants::HalfPi, precision);
  1140. case 3:
  1141. EXPECT_NEAR(testStoreValues1[2], 2 * Constants::Pi / 3.0f, precision);
  1142. case 2:
  1143. EXPECT_NEAR(testStoreValues1[1], 5 * Constants::Pi / 6.0f, precision);
  1144. case 1:
  1145. EXPECT_NEAR(testStoreValues1[0], Constants::Pi, precision);
  1146. }
  1147. }
  1148. {
  1149. typename VectorType::FloatType testVector = VectorType::Acos(sourceVector2);
  1150. VectorType::StoreUnaligned(testStoreValues2, testVector);
  1151. switch (VectorType::ElementCount)
  1152. {
  1153. case 4:
  1154. EXPECT_TRUE(AZStd::isnan(testStoreValues2[3]));
  1155. case 3:
  1156. EXPECT_TRUE(AZStd::isnan(testStoreValues2[2]));
  1157. case 2:
  1158. EXPECT_NEAR(testStoreValues2[1], 0.0f, precision);
  1159. case 1:
  1160. EXPECT_NEAR(testStoreValues2[0], Constants::QuarterPi, precision);
  1161. }
  1162. }
  1163. }
  1164. template <typename VectorType>
  1165. void TestAtan()
  1166. {
  1167. float testLoadValues1[4] = { 0.0f, 0.5773503f, 1.0f, 1000.0f };
  1168. float testLoadValues2[4] = { 0.0f, -0.5773503f, -1.0f, -1000.0f };
  1169. float testStoreValues1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1170. float testStoreValues2[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1171. float precision = 0.000002f;
  1172. typename VectorType::FloatType sourceVector1 = VectorType::LoadUnaligned(testLoadValues1);
  1173. typename VectorType::FloatType sourceVector2 = VectorType::LoadUnaligned(testLoadValues2);
  1174. {
  1175. typename VectorType::FloatType testVector = VectorType::Atan(sourceVector1);
  1176. VectorType::StoreUnaligned(testStoreValues1, testVector);
  1177. switch (VectorType::ElementCount)
  1178. {
  1179. case 4:
  1180. EXPECT_NEAR(testStoreValues1[3], 1.569796f, precision);
  1181. case 3:
  1182. EXPECT_NEAR(testStoreValues1[2], Constants::Pi / 4.0f, precision);
  1183. case 2:
  1184. EXPECT_NEAR(testStoreValues1[1], Constants::Pi / 6.0f, precision);
  1185. case 1:
  1186. EXPECT_NEAR(testStoreValues1[0], 0.0f, precision);
  1187. }
  1188. }
  1189. {
  1190. typename VectorType::FloatType testVector = VectorType::Atan(sourceVector2);
  1191. VectorType::StoreUnaligned(testStoreValues2, testVector);
  1192. switch (VectorType::ElementCount)
  1193. {
  1194. case 4:
  1195. EXPECT_NEAR(testStoreValues2[3], -1.569796f, precision);
  1196. case 3:
  1197. EXPECT_NEAR(testStoreValues2[2], -Constants::Pi / 4.0f, precision);
  1198. case 2:
  1199. EXPECT_NEAR(testStoreValues2[1], -Constants::Pi / 6.0f, precision);
  1200. case 1:
  1201. EXPECT_NEAR(testStoreValues2[0], 0.0f, precision);
  1202. }
  1203. }
  1204. }
  1205. template <typename VectorType>
  1206. void TestAtan2()
  1207. {
  1208. float testLoadValuesY1[4] = { 0.0f, 1.0f, -1.0f, 2.0f };
  1209. float testLoadValuesX1[4] = { 0.0f, 0.0f, 0.0f, 2.0f };
  1210. float testStoreValues1[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1211. float testLoadValuesY2[4] = { 0.0f, 1.0f, -1.0f, 0.0f };
  1212. float testLoadValuesX2[4] = { -1.0f, -1.0f, -1.0f, 1.0f };
  1213. float testStoreValues2[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1214. float precision = 0.000002f;
  1215. typename VectorType::FloatType sourceVectorY1 = VectorType::LoadUnaligned(testLoadValuesY1);
  1216. typename VectorType::FloatType sourceVectorX1 = VectorType::LoadUnaligned(testLoadValuesX1);
  1217. typename VectorType::FloatType sourceVectorY2 = VectorType::LoadUnaligned(testLoadValuesY2);
  1218. typename VectorType::FloatType sourceVectorX2 = VectorType::LoadUnaligned(testLoadValuesX2);
  1219. {
  1220. typename VectorType::FloatType testVector = VectorType::Atan2(sourceVectorY1, sourceVectorX1);
  1221. VectorType::StoreUnaligned(testStoreValues1, testVector);
  1222. switch (VectorType::ElementCount)
  1223. {
  1224. case 4:
  1225. EXPECT_NEAR(testStoreValues1[3], Constants::Pi / 4.0f, precision);
  1226. case 3:
  1227. EXPECT_NEAR(testStoreValues1[2], -Constants::HalfPi, precision);
  1228. case 2:
  1229. EXPECT_NEAR(testStoreValues1[1], Constants::HalfPi, precision);
  1230. case 1:
  1231. EXPECT_NEAR(testStoreValues1[0], 0.0f, precision);
  1232. }
  1233. }
  1234. {
  1235. typename VectorType::FloatType testVector = VectorType::Atan2(sourceVectorY2, sourceVectorX2);
  1236. VectorType::StoreUnaligned(testStoreValues2, testVector);
  1237. switch (VectorType::ElementCount)
  1238. {
  1239. case 4:
  1240. EXPECT_NEAR(testStoreValues2[3], 0.0f, precision);
  1241. case 3:
  1242. EXPECT_NEAR(testStoreValues2[2], -3 * Constants::Pi / 4.0f, precision);
  1243. case 2:
  1244. EXPECT_NEAR(testStoreValues2[1], 3 * Constants::Pi / 4.0f, precision);
  1245. case 1:
  1246. EXPECT_NEAR(testStoreValues2[0], Constants::Pi, precision);
  1247. }
  1248. }
  1249. }
  1250. template <typename VectorType>
  1251. void TestExpEstimate()
  1252. {
  1253. float testLoadValuesX1[4] = { 0.0f, 1.0f, -1.0f, 2.0f };
  1254. float testLoadValuesX2[4] = { 0.5f, 0.9f, -1.1f, 9.0f };
  1255. float precision = 0.005f;
  1256. typename VectorType::FloatType sourceVectorX1 = VectorType::LoadUnaligned(testLoadValuesX1);
  1257. typename VectorType::FloatType sourceVectorX2 = VectorType::LoadUnaligned(testLoadValuesX2);
  1258. {
  1259. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1260. typename VectorType::FloatType testVector = VectorType::ExpEstimate(sourceVectorX1);
  1261. VectorType::StoreUnaligned(testStoreValues, testVector);
  1262. switch (VectorType::ElementCount)
  1263. {
  1264. case 4:
  1265. EXPECT_TRUE(AZ::IsCloseMag(testStoreValues[3], exp(2.0f), precision));
  1266. case 3:
  1267. EXPECT_TRUE(AZ::IsCloseMag(testStoreValues[2], exp(-1.0f), precision));
  1268. case 2:
  1269. EXPECT_TRUE(AZ::IsCloseMag(testStoreValues[1], exp(1.0f), precision));
  1270. case 1:
  1271. EXPECT_TRUE(AZ::IsCloseMag(testStoreValues[0], exp(0.0f), precision));
  1272. }
  1273. }
  1274. {
  1275. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1276. typename VectorType::FloatType testVector = VectorType::ExpEstimate(sourceVectorX2);
  1277. VectorType::StoreUnaligned(testStoreValues, testVector);
  1278. switch (VectorType::ElementCount)
  1279. {
  1280. case 4:
  1281. EXPECT_TRUE(AZ::IsCloseMag(testStoreValues[3], exp(9.0f), precision));
  1282. case 3:
  1283. EXPECT_TRUE(AZ::IsCloseMag(testStoreValues[2], exp(-1.1f), precision));
  1284. case 2:
  1285. EXPECT_TRUE(AZ::IsCloseMag(testStoreValues[1], exp(0.9f), precision));
  1286. case 1:
  1287. EXPECT_TRUE(AZ::IsCloseMag(testStoreValues[0], exp(0.5f), precision));
  1288. }
  1289. }
  1290. }
  1291. template <typename VectorType>
  1292. void TestConvertToInt()
  1293. {
  1294. // Positive values
  1295. float testLoadValues[4] = { 0.2f, 0.4f, 0.6f, 0.8f };
  1296. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  1297. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  1298. {
  1299. typename VectorType::Int32Type testVector = VectorType::ConvertToInt(sourceVector);
  1300. VectorType::StoreUnaligned(testStoreValues, testVector);
  1301. int32_t results[4] = { 0, 0, 0, 0 };
  1302. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1303. {
  1304. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  1305. }
  1306. }
  1307. // Negative values
  1308. float testNegativeLoadValues[4] = { -0.2f, -0.4f, -0.6f, -0.8f };
  1309. sourceVector = VectorType::LoadUnaligned(testNegativeLoadValues);
  1310. {
  1311. typename VectorType::Int32Type testVector = VectorType::ConvertToInt(sourceVector);
  1312. VectorType::StoreUnaligned(testStoreValues, testVector);
  1313. int32_t results[4] = { 0, 0, 0, 0 };
  1314. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1315. {
  1316. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  1317. }
  1318. }
  1319. // Equidistant values
  1320. float testEquidistantLoadValues[4] = { 0.5f, -0.5f, 1.5f, -1.5f };
  1321. sourceVector = VectorType::LoadUnaligned(testEquidistantLoadValues);
  1322. {
  1323. typename VectorType::Int32Type testVector = VectorType::ConvertToInt(sourceVector);
  1324. VectorType::StoreUnaligned(testStoreValues, testVector);
  1325. int32_t results[4] = { 0, 0, 1, -1 };
  1326. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1327. {
  1328. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  1329. }
  1330. }
  1331. // Whole values
  1332. float testWholeLoadValues[4] = { 0.0f, 1.0f, -1.0f, 2.0f };
  1333. sourceVector = VectorType::LoadUnaligned(testWholeLoadValues);
  1334. {
  1335. typename VectorType::Int32Type testVector = VectorType::ConvertToInt(sourceVector);
  1336. VectorType::StoreUnaligned(testStoreValues, testVector);
  1337. int32_t results[4] = { 0, 1, -1, 2 };
  1338. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1339. {
  1340. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  1341. }
  1342. }
  1343. }
  1344. template <typename VectorType>
  1345. void TestConvertToIntNearest()
  1346. {
  1347. // Positive values
  1348. float testLoadValues[4] = { 0.2f, 0.4f, 0.6f, 0.8f };
  1349. int32_t testStoreValues[4] = { 0, 0, 0, 0 };
  1350. typename VectorType::FloatType sourceVector = VectorType::LoadUnaligned(testLoadValues);
  1351. {
  1352. typename VectorType::Int32Type testVector = VectorType::ConvertToIntNearest(sourceVector);
  1353. VectorType::StoreUnaligned(testStoreValues, testVector);
  1354. int32_t results[4] = { 0, 0, 1, 1 };
  1355. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1356. {
  1357. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  1358. }
  1359. }
  1360. // Negative values
  1361. float testNegativeLoadValues[4] = { -0.2f, -0.4f, -0.6f, -0.8f };
  1362. sourceVector = VectorType::LoadUnaligned(testNegativeLoadValues);
  1363. {
  1364. typename VectorType::Int32Type testVector = VectorType::ConvertToIntNearest(sourceVector);
  1365. VectorType::StoreUnaligned(testStoreValues, testVector);
  1366. int32_t results[4] = { 0, 0, -1, -1 };
  1367. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1368. {
  1369. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  1370. }
  1371. }
  1372. // Equidistant values
  1373. float testEquidistantLoadValues[4] = { 0.5f, -0.5f, 1.5f, -1.5f };
  1374. sourceVector = VectorType::LoadUnaligned(testEquidistantLoadValues);
  1375. {
  1376. typename VectorType::Int32Type testVector = VectorType::ConvertToIntNearest(sourceVector);
  1377. VectorType::StoreUnaligned(testStoreValues, testVector);
  1378. // The expected behaviour is ties to even (banker's rounding)
  1379. int32_t results[4] = { 0, 0, 2, -2 };
  1380. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1381. {
  1382. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  1383. }
  1384. }
  1385. // Whole values
  1386. float testWholeLoadValues[4] = { 0.0f, 1.0f, -1.0f, 2.0f };
  1387. sourceVector = VectorType::LoadUnaligned(testWholeLoadValues);
  1388. {
  1389. typename VectorType::Int32Type testVector = VectorType::ConvertToIntNearest(sourceVector);
  1390. VectorType::StoreUnaligned(testStoreValues, testVector);
  1391. int32_t results[4] = { 0, 1, -1, 2 };
  1392. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1393. {
  1394. EXPECT_THAT(testStoreValues[i], ::testing::Eq(results[i]));
  1395. }
  1396. }
  1397. }
  1398. template <typename VectorType>
  1399. void TestConvertToFloat()
  1400. {
  1401. int32_t testLoadValues[4] = { -1, 0, 2, 4 };
  1402. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1403. typename VectorType::Int32Type sourceVector = VectorType::LoadUnaligned(testLoadValues);
  1404. {
  1405. typename VectorType::FloatType testVector = VectorType::ConvertToFloat(sourceVector);
  1406. VectorType::StoreUnaligned(testStoreValues, testVector);
  1407. switch (VectorType::ElementCount)
  1408. {
  1409. case 4:
  1410. EXPECT_NEAR(testStoreValues[3], 4.0f, 0.002f);
  1411. case 3:
  1412. EXPECT_NEAR(testStoreValues[2], 2.0f, 0.002f);
  1413. case 2:
  1414. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.002f);
  1415. case 1:
  1416. EXPECT_NEAR(testStoreValues[0], -1.0f, 0.002f);
  1417. break;
  1418. }
  1419. }
  1420. }
  1421. template <typename VectorType>
  1422. void TestCast()
  1423. {
  1424. int32_t testLoadValues[4] = { -1, 0, 2, 4 };
  1425. float testStoreFloatValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  1426. int32_t testStoreInt32Values[4] = { 0, 0, 0, 0 };
  1427. typename VectorType::Int32Type sourceVector = VectorType::LoadUnaligned(testLoadValues);
  1428. typename VectorType::FloatType testVector1 = VectorType::CastToFloat(sourceVector);
  1429. VectorType::StoreUnaligned(testStoreFloatValues, testVector1);
  1430. EXPECT_TRUE(AZStd::isnan(testStoreFloatValues[0]));
  1431. if constexpr (VectorType::ElementCount > 1)
  1432. {
  1433. EXPECT_NEAR(testStoreFloatValues[1], 0.0f, 0.002f);
  1434. }
  1435. typename VectorType::Int32Type testVector2 = VectorType::CastToInt(testVector1);
  1436. VectorType::StoreUnaligned(testStoreInt32Values, testVector2);
  1437. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1438. {
  1439. EXPECT_THAT(testStoreInt32Values[i], ::testing::Eq(testLoadValues[i]));
  1440. }
  1441. }
  1442. template <typename VectorType>
  1443. void TestZeroVectorFloat()
  1444. {
  1445. const typename Simd::Vec4::FloatType testVector = Simd::Vec4::ZeroFloat();
  1446. float testStoreValues[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
  1447. Simd::Vec4::StoreUnaligned(testStoreValues, testVector);
  1448. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1449. {
  1450. EXPECT_THAT(testStoreValues[i], ::testing::FloatNear(0.0f, AZ::Constants::Tolerance));
  1451. }
  1452. }
  1453. template <typename VectorType>
  1454. void TestZeroVectorInt()
  1455. {
  1456. const typename Simd::Vec4::Int32Type testVector = Simd::Vec4::ZeroInt();
  1457. int32_t testStoreValues[4] = { 1, 1, 1, 1 };
  1458. Simd::Vec4::StoreUnaligned(testStoreValues, testVector);
  1459. for (int32_t i = 0; i < VectorType::ElementCount; ++i)
  1460. {
  1461. EXPECT_THAT(testStoreValues[i], ::testing::Eq(0));
  1462. }
  1463. }
  1464. TEST(MATH_SimdMath, TestToVec1InVec2)
  1465. {
  1466. TestToVec1<Simd::Vec2>();
  1467. }
  1468. TEST(MATH_SimdMath, TestFromVec1InVec2)
  1469. {
  1470. TestFromVec1<Simd::Vec2>();
  1471. }
  1472. TEST(MATH_SimdMath, TestToVec1InVec3)
  1473. {
  1474. TestToVec1<Simd::Vec3>();
  1475. }
  1476. TEST(MATH_SimdMath, TestFromVec1InVec3)
  1477. {
  1478. TestFromVec1<Simd::Vec3>();
  1479. }
  1480. TEST(MATH_SimdMath, TestToVec2InVec3)
  1481. {
  1482. TestToVec2<Simd::Vec3>();
  1483. }
  1484. TEST(MATH_SimdMath, TestFromVec2InVec3)
  1485. {
  1486. TestFromVec2<Simd::Vec3>();
  1487. }
  1488. TEST(MATH_SimdMath, TestToVec1InVec4)
  1489. {
  1490. TestToVec1<Simd::Vec4>();
  1491. }
  1492. TEST(MATH_SimdMath, TestFromVec1InVec4)
  1493. {
  1494. TestFromVec1<Simd::Vec4>();
  1495. }
  1496. TEST(MATH_SimdMath, TestToVec2InVec4)
  1497. {
  1498. TestToVec2<Simd::Vec4>();
  1499. }
  1500. TEST(MATH_SimdMath, TestFromVec2InVec4)
  1501. {
  1502. TestFromVec2<Simd::Vec4>();
  1503. }
  1504. TEST(MATH_SimdMath, TestToVec3InVec4)
  1505. {
  1506. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  1507. float testStoreValues[4] = { -1.0f, -1.0f, -1.0f, -1.0f };
  1508. typename Simd::Vec4::FloatType testVector = Simd::Vec4::LoadUnaligned(testLoadValues);
  1509. Simd::Vec3::FloatType testVec3 = Simd::Vec4::ToVec3(testVector);
  1510. Simd::Vec3::StoreUnaligned(testStoreValues, testVec3);
  1511. for (int32_t i = 0; i < Simd::Vec3::ElementCount; ++i)
  1512. {
  1513. EXPECT_NEAR(testLoadValues[i], testStoreValues[i], AZ::Constants::Tolerance);
  1514. }
  1515. }
  1516. TEST(MATH_SimdMath, TestFromVec3InVec4)
  1517. {
  1518. float testLoadValues[4] = { 1.0f, 2.0f, 3.0f, 4.0f };
  1519. float testStoreValues[4] = { -1.0f, -1.0f, -1.0f, -1.0f };
  1520. Simd::Vec3::FloatType testVec3 = Simd::Vec3::LoadUnaligned(testLoadValues);
  1521. typename Simd::Vec4::FloatType testVector = Simd::Vec4::FromVec3(testVec3);
  1522. Simd::Vec4::StoreUnaligned(testStoreValues, testVector);
  1523. // The first 3 elements must be set to (Vec3.x, Vec3.y, Vec3.z)
  1524. for (int32_t i = 0; i < Simd::Vec3::ElementCount; ++i)
  1525. {
  1526. EXPECT_NEAR(testLoadValues[i], testStoreValues[i], AZ::Constants::Tolerance);
  1527. }
  1528. // The rest of elements must be set to zero
  1529. for (int32_t i = Simd::Vec3::ElementCount; i < Simd::Vec4::ElementCount; ++i)
  1530. {
  1531. EXPECT_NEAR(0.0f, testStoreValues[i], AZ::Constants::Tolerance);
  1532. }
  1533. }
  1534. TEST(MATH_SimdMath, TestLoadStoreFloatVec1)
  1535. {
  1536. TestLoadStoreFloat<Simd::Vec1>();
  1537. }
  1538. TEST(MATH_SimdMath, TestLoadStoreFloatVec2)
  1539. {
  1540. TestLoadStoreFloat<Simd::Vec2>();
  1541. }
  1542. TEST(MATH_SimdMath, TestLoadStoreFloatVec3)
  1543. {
  1544. TestLoadStoreFloat<Simd::Vec3>();
  1545. }
  1546. TEST(MATH_SimdMath, TestLoadStoreFloatVec4)
  1547. {
  1548. TestLoadStoreFloat<Simd::Vec4>();
  1549. }
  1550. TEST(MATH_SimdMath, TestLoadStoreIntVec1)
  1551. {
  1552. TestLoadStoreInt<Simd::Vec1>();
  1553. }
  1554. TEST(MATH_SimdMath, TestLoadStoreIntVec2)
  1555. {
  1556. TestLoadStoreInt<Simd::Vec2>();
  1557. }
  1558. TEST(MATH_SimdMath, TestLoadStoreIntVec3)
  1559. {
  1560. TestLoadStoreInt<Simd::Vec3>();
  1561. }
  1562. TEST(MATH_SimdMath, TestLoadStoreIntVec4)
  1563. {
  1564. TestLoadStoreInt<Simd::Vec4>();
  1565. }
  1566. TEST(MATH_SimdMath, TestSelectFirstVec1)
  1567. {
  1568. TestSelectFirst<Simd::Vec1>();
  1569. }
  1570. TEST(MATH_SimdMath, TestSelectFirstVec2)
  1571. {
  1572. TestSelectFirst<Simd::Vec2>();
  1573. }
  1574. TEST(MATH_SimdMath, TestSelectSecondVec2)
  1575. {
  1576. TestSelectSecond<Simd::Vec2>();
  1577. }
  1578. TEST(MATH_SimdMath, TestSelectFirstVec3)
  1579. {
  1580. TestSelectFirst<Simd::Vec3>();
  1581. }
  1582. TEST(MATH_SimdMath, TestSelectSecondVec3)
  1583. {
  1584. TestSelectSecond<Simd::Vec3>();
  1585. }
  1586. TEST(MATH_SimdMath, TestSelectThirdVec3)
  1587. {
  1588. TestSelectThird<Simd::Vec3>();
  1589. }
  1590. TEST(MATH_SimdMath, TestSelectFirstVec4)
  1591. {
  1592. TestSelectFirst<Simd::Vec4>();
  1593. }
  1594. TEST(MATH_SimdMath, TestSelectSecondVec4)
  1595. {
  1596. TestSelectSecond<Simd::Vec4>();
  1597. }
  1598. TEST(MATH_SimdMath, TestSelectThirdVec4)
  1599. {
  1600. TestSelectThird<Simd::Vec4>();
  1601. }
  1602. TEST(MATH_SimdMath, TestSelectFourthVec4)
  1603. {
  1604. TestSelectFourth<Simd::Vec4>();
  1605. }
  1606. TEST(MATH_SimdMath, TestSplatFloatVec1)
  1607. {
  1608. TestSplatFloat<Simd::Vec1>();
  1609. }
  1610. TEST(MATH_SimdMath, TestSplatFloatVec2)
  1611. {
  1612. TestSplatFloat<Simd::Vec2>();
  1613. }
  1614. TEST(MATH_SimdMath, TestSplatFloatVec3)
  1615. {
  1616. TestSplatFloat<Simd::Vec3>();
  1617. }
  1618. TEST(MATH_SimdMath, TestSplatFloatVec4)
  1619. {
  1620. TestSplatFloat<Simd::Vec4>();
  1621. }
  1622. TEST(MATH_SimdMath, TestSplatIntVec1)
  1623. {
  1624. TestSplatInt<Simd::Vec1>();
  1625. }
  1626. TEST(MATH_SimdMath, TestSplatIntVec2)
  1627. {
  1628. TestSplatInt<Simd::Vec2>();
  1629. }
  1630. TEST(MATH_SimdMath, TestSplatIntVec3)
  1631. {
  1632. TestSplatInt<Simd::Vec3>();
  1633. }
  1634. TEST(MATH_SimdMath, TestSplatIntVec4)
  1635. {
  1636. TestSplatInt<Simd::Vec4>();
  1637. }
  1638. TEST(MATH_SimdMath, TestSplatFirstVec2)
  1639. {
  1640. TestSplatFirst<Simd::Vec2>();
  1641. }
  1642. TEST(MATH_SimdMath, TestSplatSecondVec2)
  1643. {
  1644. TestSplatSecond<Simd::Vec2>();
  1645. }
  1646. TEST(MATH_SimdMath, TestSplatFirstVec3)
  1647. {
  1648. TestSplatFirst<Simd::Vec3>();
  1649. }
  1650. TEST(MATH_SimdMath, TestSplatSecondVec3)
  1651. {
  1652. TestSplatSecond<Simd::Vec3>();
  1653. }
  1654. TEST(MATH_SimdMath, TestSplatThirdVec3)
  1655. {
  1656. TestSplatThird<Simd::Vec3>();
  1657. }
  1658. TEST(MATH_SimdMath, TestSplatFirstVec4)
  1659. {
  1660. TestSplatFirst<Simd::Vec4>();
  1661. }
  1662. TEST(MATH_SimdMath, TestSplatSecondVec4)
  1663. {
  1664. TestSplatSecond<Simd::Vec4>();
  1665. }
  1666. TEST(MATH_SimdMath, TestSplatThirdVec4)
  1667. {
  1668. TestSplatThird<Simd::Vec4>();
  1669. }
  1670. TEST(MATH_SimdMath, TestSplatFourthVec4)
  1671. {
  1672. TestSplatFourth<Simd::Vec4>();
  1673. }
  1674. TEST(MATH_SimdMath, TestReplaceFirstVec2)
  1675. {
  1676. TestReplaceFirst<Simd::Vec2>();
  1677. }
  1678. TEST(MATH_SimdMath, TestReplaceSecondVec2)
  1679. {
  1680. TestReplaceSecond<Simd::Vec2>();
  1681. }
  1682. TEST(MATH_SimdMath, TestReplaceFirstVec3)
  1683. {
  1684. TestReplaceFirst<Simd::Vec3>();
  1685. }
  1686. TEST(MATH_SimdMath, TestReplaceSecondVec3)
  1687. {
  1688. TestReplaceSecond<Simd::Vec3>();
  1689. }
  1690. TEST(MATH_SimdMath, TestReplaceThirdVec3)
  1691. {
  1692. TestReplaceThird<Simd::Vec3>();
  1693. }
  1694. TEST(MATH_SimdMath, TestReplaceFirstVec4)
  1695. {
  1696. TestReplaceFirst<Simd::Vec4>();
  1697. }
  1698. TEST(MATH_SimdMath, TestReplaceSecondVec4)
  1699. {
  1700. TestReplaceSecond<Simd::Vec4>();
  1701. }
  1702. TEST(MATH_SimdMath, TestReplaceThirdVec4)
  1703. {
  1704. TestReplaceThird<Simd::Vec4>();
  1705. }
  1706. TEST(MATH_SimdMath, TestReplaceFourthVec4)
  1707. {
  1708. TestReplaceFourth<Simd::Vec4>();
  1709. }
  1710. TEST(MATH_SimdMath, TestLoadImmediateFloatVec1)
  1711. {
  1712. TestLoadImmediateFloat<Simd::Vec1>();
  1713. }
  1714. TEST(MATH_SimdMath, TestLoadImmediateFloatVec2)
  1715. {
  1716. TestLoadImmediateFloat<Simd::Vec2>();
  1717. }
  1718. TEST(MATH_SimdMath, TestLoadImmediateFloatVec3)
  1719. {
  1720. TestLoadImmediateFloat<Simd::Vec3>();
  1721. }
  1722. TEST(MATH_SimdMath, TestLoadImmediateFloatVec4)
  1723. {
  1724. TestLoadImmediateFloat<Simd::Vec4>();
  1725. }
  1726. TEST(MATH_SimdMath, TestLoadImmediateIntVec1)
  1727. {
  1728. TestLoadImmediateInt<Simd::Vec1>();
  1729. }
  1730. TEST(MATH_SimdMath, TestLoadImmediateIntVec2)
  1731. {
  1732. TestLoadImmediateInt<Simd::Vec2>();
  1733. }
  1734. TEST(MATH_SimdMath, TestLoadImmediateIntVec3)
  1735. {
  1736. TestLoadImmediateInt<Simd::Vec3>();
  1737. }
  1738. TEST(MATH_SimdMath, TestLoadImmediateIntVec4)
  1739. {
  1740. TestLoadImmediateInt<Simd::Vec4>();
  1741. }
  1742. TEST(MATH_SimdMath, TestAddSubMulDivFloatVec1)
  1743. {
  1744. TestAddSubMulDivFloat<Simd::Vec1>();
  1745. }
  1746. TEST(MATH_SimdMath, TestAddSubMulDivFloatVec2)
  1747. {
  1748. TestAddSubMulDivFloat<Simd::Vec2>();
  1749. }
  1750. TEST(MATH_SimdMath, TestAddSubMulDivFloatVec3)
  1751. {
  1752. TestAddSubMulDivFloat<Simd::Vec3>();
  1753. }
  1754. TEST(MATH_SimdMath, TestAddSubMulDivFloatVec4)
  1755. {
  1756. TestAddSubMulDivFloat<Simd::Vec4>();
  1757. }
  1758. TEST(MATH_SimdMath, TestAddSubMulIntVec1)
  1759. {
  1760. TestAddSubMulInt<Simd::Vec1>();
  1761. }
  1762. TEST(MATH_SimdMath, TestAddSubMulIntVec2)
  1763. {
  1764. TestAddSubMulInt<Simd::Vec2>();
  1765. }
  1766. TEST(MATH_SimdMath, TestAddSubMulIntVec3)
  1767. {
  1768. TestAddSubMulInt<Simd::Vec3>();
  1769. }
  1770. TEST(MATH_SimdMath, TestAddSubMulIntVec4)
  1771. {
  1772. TestAddSubMulInt<Simd::Vec4>();
  1773. }
  1774. TEST(MATH_SimdMath, TestNotFloatVec1)
  1775. {
  1776. TestNotFloat<Simd::Vec1>();
  1777. }
  1778. TEST(MATH_SimdMath, TestNotFloatVec2)
  1779. {
  1780. TestNotFloat<Simd::Vec2>();
  1781. }
  1782. TEST(MATH_SimdMath, TestNotFloatVec3)
  1783. {
  1784. TestNotFloat<Simd::Vec3>();
  1785. }
  1786. TEST(MATH_SimdMath, TestNotFloatVec4)
  1787. {
  1788. TestNotFloat<Simd::Vec4>();
  1789. }
  1790. TEST(MATH_SimdMath, TestAndAndnotOrFloatVec1)
  1791. {
  1792. TestAndAndnotOrFloat<Simd::Vec1>();
  1793. }
  1794. TEST(MATH_SimdMath, TestAndAndnotOrFloatVec2)
  1795. {
  1796. TestAndAndnotOrFloat<Simd::Vec2>();
  1797. }
  1798. TEST(MATH_SimdMath, TestAndAndnotOrFloatVec3)
  1799. {
  1800. TestAndAndnotOrFloat<Simd::Vec3>();
  1801. }
  1802. TEST(MATH_SimdMath, TestAndAndnotOrFloatVec4)
  1803. {
  1804. TestAndAndnotOrFloat<Simd::Vec4>();
  1805. }
  1806. TEST(MATH_SimdMath, TestXorFloatVec1)
  1807. {
  1808. TestXorFloat<Simd::Vec1>();
  1809. }
  1810. TEST(MATH_SimdMath, TestXorFloatVec2)
  1811. {
  1812. TestXorFloat<Simd::Vec2>();
  1813. }
  1814. TEST(MATH_SimdMath, TestXorFloatVec3)
  1815. {
  1816. TestXorFloat<Simd::Vec3>();
  1817. }
  1818. TEST(MATH_SimdMath, TestXorFloatVec4)
  1819. {
  1820. TestXorFloat<Simd::Vec4>();
  1821. }
  1822. TEST(MATH_SimdMath, TestNotIntVec1)
  1823. {
  1824. TestNotInt<Simd::Vec1>();
  1825. }
  1826. TEST(MATH_SimdMath, TestNotIntVec2)
  1827. {
  1828. TestNotInt<Simd::Vec2>();
  1829. }
  1830. TEST(MATH_SimdMath, TestNotIntVec3)
  1831. {
  1832. TestNotInt<Simd::Vec3>();
  1833. }
  1834. TEST(MATH_SimdMath, TestNotIntVec4)
  1835. {
  1836. TestNotInt<Simd::Vec4>();
  1837. }
  1838. TEST(MATH_SimdMath, TestAndAndnotOrIntVec1)
  1839. {
  1840. TestAndAndnotOrInt<Simd::Vec1>();
  1841. }
  1842. TEST(MATH_SimdMath, TestAndAndnotOrIntVec2)
  1843. {
  1844. TestAndAndnotOrInt<Simd::Vec2>();
  1845. }
  1846. TEST(MATH_SimdMath, TestAndAndnotOrIntVec3)
  1847. {
  1848. TestAndAndnotOrInt<Simd::Vec3>();
  1849. }
  1850. TEST(MATH_SimdMath, TestAndAndnotOrIntVec4)
  1851. {
  1852. TestAndAndnotOrInt<Simd::Vec4>();
  1853. }
  1854. TEST(MATH_SimdMath, TestXorIntVec1)
  1855. {
  1856. TestXorInt<Simd::Vec1>();
  1857. }
  1858. TEST(MATH_SimdMath, TestXorIntVec2)
  1859. {
  1860. TestXorInt<Simd::Vec2>();
  1861. }
  1862. TEST(MATH_SimdMath, TestXorIntVec3)
  1863. {
  1864. TestXorInt<Simd::Vec3>();
  1865. }
  1866. TEST(MATH_SimdMath, TestXorIntVec4)
  1867. {
  1868. TestXorInt<Simd::Vec4>();
  1869. }
  1870. TEST(MATH_SimdMath, TestMinMaxIntVec1)
  1871. {
  1872. TestMinMaxInt<Simd::Vec1>();
  1873. }
  1874. TEST(MATH_SimdMath, TestMinMaxIntVec2)
  1875. {
  1876. TestMinMaxInt<Simd::Vec2>();
  1877. }
  1878. TEST(MATH_SimdMath, TestMinMaxIntVec3)
  1879. {
  1880. TestMinMaxInt<Simd::Vec3>();
  1881. }
  1882. TEST(MATH_SimdMath, TestMinMaxIntVec4)
  1883. {
  1884. TestMinMaxInt<Simd::Vec4>();
  1885. }
  1886. TEST(MATH_SimdMath, TestClampIntVec1)
  1887. {
  1888. TestClampInt<Simd::Vec1>();
  1889. }
  1890. TEST(MATH_SimdMath, TestClampIntVec2)
  1891. {
  1892. TestClampInt<Simd::Vec2>();
  1893. }
  1894. TEST(MATH_SimdMath, TestClampIntVec3)
  1895. {
  1896. TestClampInt<Simd::Vec3>();
  1897. }
  1898. TEST(MATH_SimdMath, TestClampIntVec4)
  1899. {
  1900. TestClampInt<Simd::Vec4>();
  1901. }
  1902. TEST(MATH_SimdMath, TestFloorFloatVec1)
  1903. {
  1904. TestFloorFloat<Simd::Vec1>();
  1905. }
  1906. TEST(MATH_SimdMath, TestFloorFloatVec2)
  1907. {
  1908. TestFloorFloat<Simd::Vec2>();
  1909. }
  1910. TEST(MATH_SimdMath, TestFloorFloatVec3)
  1911. {
  1912. TestFloorFloat<Simd::Vec3>();
  1913. }
  1914. TEST(MATH_SimdMath, TestFloorFloatVec4)
  1915. {
  1916. TestFloorFloat<Simd::Vec4>();
  1917. }
  1918. TEST(MATH_SimdMath, TestCeilFloatVec1)
  1919. {
  1920. TestCeilFloat<Simd::Vec1>();
  1921. }
  1922. TEST(MATH_SimdMath, TestCeilFloatVec2)
  1923. {
  1924. TestCeilFloat<Simd::Vec2>();
  1925. }
  1926. TEST(MATH_SimdMath, TestCeilFloatVec3)
  1927. {
  1928. TestCeilFloat<Simd::Vec3>();
  1929. }
  1930. TEST(MATH_SimdMath, TestCeilFloatVec4)
  1931. {
  1932. TestCeilFloat<Simd::Vec4>();
  1933. }
  1934. TEST(MATH_SimdMath, TestRoundFloatVec1)
  1935. {
  1936. TestRoundFloat<Simd::Vec1>();
  1937. }
  1938. TEST(MATH_SimdMath, TestRoundFloatVec2)
  1939. {
  1940. TestRoundFloat<Simd::Vec2>();
  1941. }
  1942. TEST(MATH_SimdMath, TestRoundFloatVec3)
  1943. {
  1944. TestRoundFloat<Simd::Vec3>();
  1945. }
  1946. TEST(MATH_SimdMath, TestRoundFloatVec4)
  1947. {
  1948. TestRoundFloat<Simd::Vec4>();
  1949. }
  1950. TEST(MATH_SimdMath, TestTruncateFloatVec1)
  1951. {
  1952. TestTruncateFloat<Simd::Vec1>();
  1953. }
  1954. TEST(MATH_SimdMath, TestTruncateFloatVec2)
  1955. {
  1956. TestTruncateFloat<Simd::Vec2>();
  1957. }
  1958. TEST(MATH_SimdMath, TestTruncateFloatVec3)
  1959. {
  1960. TestTruncateFloat<Simd::Vec3>();
  1961. }
  1962. TEST(MATH_SimdMath, TestTruncateFloatVec4)
  1963. {
  1964. TestTruncateFloat<Simd::Vec4>();
  1965. }
  1966. TEST(MATH_SimdMath, TestMinMaxFloatVec1)
  1967. {
  1968. TestMinMaxFloat<Simd::Vec1>();
  1969. }
  1970. TEST(MATH_SimdMath, TestMinMaxFloatVec2)
  1971. {
  1972. TestMinMaxFloat<Simd::Vec2>();
  1973. }
  1974. TEST(MATH_SimdMath, TestMinMaxFloatVec3)
  1975. {
  1976. TestMinMaxFloat<Simd::Vec3>();
  1977. }
  1978. TEST(MATH_SimdMath, TestMinMaxFloatVec4)
  1979. {
  1980. TestMinMaxFloat<Simd::Vec4>();
  1981. }
  1982. TEST(MATH_SimdMath, TestClampFloatVec1)
  1983. {
  1984. TestClampFloat<Simd::Vec1>();
  1985. }
  1986. TEST(MATH_SimdMath, TestClampFloatVec2)
  1987. {
  1988. TestClampFloat<Simd::Vec2>();
  1989. }
  1990. TEST(MATH_SimdMath, TestClampFloatVec3)
  1991. {
  1992. TestClampFloat<Simd::Vec3>();
  1993. }
  1994. TEST(MATH_SimdMath, TestClampFloatVec4)
  1995. {
  1996. TestClampFloat<Simd::Vec4>();
  1997. }
  1998. TEST(MATH_SimdMath, TestCompareFloatVec1)
  1999. {
  2000. TestCompareFloat<Simd::Vec1>();
  2001. }
  2002. TEST(MATH_SimdMath, TestCompareFloatVec2)
  2003. {
  2004. TestCompareFloat<Simd::Vec2>();
  2005. }
  2006. TEST(MATH_SimdMath, TestCompareFloatVec3)
  2007. {
  2008. TestCompareFloat<Simd::Vec3>();
  2009. }
  2010. TEST(MATH_SimdMath, TestCompareFloatVec4)
  2011. {
  2012. TestCompareFloat<Simd::Vec4>();
  2013. }
  2014. TEST(MATH_SimdMath, TestCompareAllFloatVec1)
  2015. {
  2016. TestCompareAllFloat<Simd::Vec1>();
  2017. }
  2018. TEST(MATH_SimdMath, TestCompareAllFloatVec2)
  2019. {
  2020. TestCompareAllFloat<Simd::Vec2>();
  2021. }
  2022. TEST(MATH_SimdMath, TestCompareAllFloatVec3)
  2023. {
  2024. TestCompareAllFloat<Simd::Vec3>();
  2025. }
  2026. TEST(MATH_SimdMath, TestCompareAllFloatVec4)
  2027. {
  2028. TestCompareAllFloat<Simd::Vec4>();
  2029. }
  2030. TEST(MATH_SimdMath, TestCompareIntVec1)
  2031. {
  2032. TestCompareInt<Simd::Vec1>();
  2033. }
  2034. TEST(MATH_SimdMath, TestCompareIntVec2)
  2035. {
  2036. TestCompareInt<Simd::Vec2>();
  2037. }
  2038. TEST(MATH_SimdMath, TestCompareIntVec3)
  2039. {
  2040. TestCompareInt<Simd::Vec3>();
  2041. }
  2042. TEST(MATH_SimdMath, TestCompareIntVec4)
  2043. {
  2044. TestCompareInt<Simd::Vec4>();
  2045. }
  2046. TEST(MATH_SimdMath, TestCompareAllIntVec1)
  2047. {
  2048. TestCompareAllInt<Simd::Vec1>();
  2049. }
  2050. TEST(MATH_SimdMath, TestCompareAllIntVec2)
  2051. {
  2052. TestCompareAllInt<Simd::Vec2>();
  2053. }
  2054. TEST(MATH_SimdMath, TestCompareAllIntVec3)
  2055. {
  2056. TestCompareAllInt<Simd::Vec3>();
  2057. }
  2058. TEST(MATH_SimdMath, TestCompareAllIntVec4)
  2059. {
  2060. TestCompareAllInt<Simd::Vec4>();
  2061. }
  2062. TEST(MATH_SimdMath, TestReciprocalFloatVec1)
  2063. {
  2064. TestReciprocalFloat<Simd::Vec1>();
  2065. }
  2066. TEST(MATH_SimdMath, TestReciprocalFloatVec2)
  2067. {
  2068. TestReciprocalFloat<Simd::Vec2>();
  2069. }
  2070. TEST(MATH_SimdMath, TestReciprocalFloatVec3)
  2071. {
  2072. TestReciprocalFloat<Simd::Vec3>();
  2073. }
  2074. TEST(MATH_SimdMath, TestReciprocalFloatVec4)
  2075. {
  2076. TestReciprocalFloat<Simd::Vec4>();
  2077. }
  2078. TEST(MATH_SimdMath, TestSqrtInvSqrtFloatVec1)
  2079. {
  2080. TestSqrtInvSqrtFloat<Simd::Vec1>();
  2081. }
  2082. TEST(MATH_SimdMath, TestSqrtInvSqrtFloatVec2)
  2083. {
  2084. TestSqrtInvSqrtFloat<Simd::Vec2>();
  2085. }
  2086. TEST(MATH_SimdMath, TestSqrtInvSqrtFloatVec3)
  2087. {
  2088. TestSqrtInvSqrtFloat<Simd::Vec3>();
  2089. }
  2090. TEST(MATH_SimdMath, TestSqrtInvSqrtFloatVec4)
  2091. {
  2092. TestSqrtInvSqrtFloat<Simd::Vec4>();
  2093. }
  2094. TEST(MATH_SimdMath, TestSinVec1)
  2095. {
  2096. TestSin<Simd::Vec1>();
  2097. }
  2098. TEST(MATH_SimdMath, TestSinVec2)
  2099. {
  2100. TestSin<Simd::Vec2>();
  2101. }
  2102. TEST(MATH_SimdMath, TestSinVec3)
  2103. {
  2104. TestSin<Simd::Vec3>();
  2105. }
  2106. TEST(MATH_SimdMath, TestSinVec4)
  2107. {
  2108. TestSin<Simd::Vec4>();
  2109. }
  2110. TEST(MATH_SimdMath, TestCosVec1)
  2111. {
  2112. TestCos<Simd::Vec1>();
  2113. }
  2114. TEST(MATH_SimdMath, TestCosVec2)
  2115. {
  2116. TestCos<Simd::Vec2>();
  2117. }
  2118. TEST(MATH_SimdMath, TestCosVec3)
  2119. {
  2120. TestCos<Simd::Vec3>();
  2121. }
  2122. TEST(MATH_SimdMath, TestCosVec4)
  2123. {
  2124. TestCos<Simd::Vec4>();
  2125. }
  2126. TEST(MATH_SimdMath, TestAcosVec1)
  2127. {
  2128. TestAcos<Simd::Vec1>();
  2129. }
  2130. TEST(MATH_SimdMath, TestAcosVec2)
  2131. {
  2132. TestAcos<Simd::Vec2>();
  2133. }
  2134. TEST(MATH_SimdMath, TestAcosVec3)
  2135. {
  2136. TestAcos<Simd::Vec3>();
  2137. }
  2138. TEST(MATH_SimdMath, TestAcosVec4)
  2139. {
  2140. TestAcos<Simd::Vec4>();
  2141. }
  2142. TEST(MATH_SimdMath, TestAtanVec1)
  2143. {
  2144. TestAtan<Simd::Vec1>();
  2145. }
  2146. TEST(MATH_SimdMath, TestAtanVec2)
  2147. {
  2148. TestAtan<Simd::Vec2>();
  2149. }
  2150. TEST(MATH_SimdMath, TestAtanVec3)
  2151. {
  2152. TestAtan<Simd::Vec3>();
  2153. }
  2154. TEST(MATH_SimdMath, TestAtanVec4)
  2155. {
  2156. TestAtan<Simd::Vec4>();
  2157. }
  2158. TEST(MATH_SimdMath, TestAtan2Vec1)
  2159. {
  2160. TestAtan2<Simd::Vec1>();
  2161. }
  2162. TEST(MATH_SimdMath, TestAtan2Vec2)
  2163. {
  2164. TestAtan2<Simd::Vec2>();
  2165. }
  2166. TEST(MATH_SimdMath, TestAtan2Vec3)
  2167. {
  2168. TestAtan2<Simd::Vec3>();
  2169. }
  2170. TEST(MATH_SimdMath, TestAtan2Vec4)
  2171. {
  2172. TestAtan2<Simd::Vec4>();
  2173. }
  2174. TEST(MATH_SimdMath, TestExpEstimateVec1)
  2175. {
  2176. TestExpEstimate<Simd::Vec1>();
  2177. }
  2178. TEST(MATH_SimdMath, TestExpEstimateVec2)
  2179. {
  2180. TestExpEstimate<Simd::Vec2>();
  2181. }
  2182. TEST(MATH_SimdMath, TestExpEstimateVec3)
  2183. {
  2184. TestExpEstimate<Simd::Vec3>();
  2185. }
  2186. TEST(MATH_SimdMath, TestExpEstimateVec4)
  2187. {
  2188. TestExpEstimate<Simd::Vec4>();
  2189. }
  2190. TEST(MATH_SimdMath, TestDotFloatVec2)
  2191. {
  2192. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2193. Simd::Vec2::FloatType sourceVector1 = Simd::Vec2::LoadImmediate(-1.0f, 16.0f);
  2194. Simd::Vec2::FloatType sourceVector2 = Simd::Vec2::LoadImmediate(-1.0f, 16.0f);
  2195. Simd::Vec1::FloatType testDot = Simd::Vec2::Dot(sourceVector1, sourceVector2);
  2196. Simd::Vec1::StoreUnaligned(testStoreValues, testDot);
  2197. EXPECT_NEAR(testStoreValues[0], 257.0f, 0.002f);
  2198. }
  2199. TEST(MATH_SimdMath, TestDotFloatVec3)
  2200. {
  2201. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2202. Simd::Vec3::FloatType sourceVector1 = Simd::Vec3::LoadImmediate(-1.0f, 16.0f, 1.0f);
  2203. Simd::Vec3::FloatType sourceVector2 = Simd::Vec3::LoadImmediate(-1.0f, 16.0f, 1.0f);
  2204. Simd::Vec1::FloatType testDot = Simd::Vec3::Dot(sourceVector1, sourceVector2);
  2205. Simd::Vec1::StoreUnaligned(testStoreValues, testDot);
  2206. EXPECT_NEAR(testStoreValues[0], 258.0f, 0.002f);
  2207. }
  2208. TEST(MATH_SimdMath, TestDotFloatVec4)
  2209. {
  2210. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2211. Simd::Vec4::FloatType sourceVector1 = Simd::Vec4::LoadImmediate(-1.0f, 16.0f, 1.0f, 1.0f);
  2212. Simd::Vec4::FloatType sourceVector2 = Simd::Vec4::LoadImmediate(-1.0f, 16.0f, 1.0f, -1.0f);
  2213. Simd::Vec1::FloatType testDot = Simd::Vec4::Dot(sourceVector1, sourceVector2);
  2214. Simd::Vec1::StoreUnaligned(testStoreValues, testDot);
  2215. EXPECT_NEAR(testStoreValues[0], 257.0f, 0.002f);
  2216. }
  2217. TEST(MATH_SimdMath, TestCrossFloatVec3)
  2218. {
  2219. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2220. Simd::Vec3::FloatType sourceVector1 = Simd::Vec3::LoadImmediate(1.0f, 0.0f, 0.0f);
  2221. Simd::Vec3::FloatType sourceVector2 = Simd::Vec3::LoadImmediate(0.0f, 1.0f, 0.0f);
  2222. Simd::Vec3::FloatType sourceVector3 = Simd::Vec3::LoadImmediate(0.0f, 0.0f, 1.0f);
  2223. {
  2224. Simd::Vec3::FloatType testVector = Simd::Vec3::Cross(sourceVector1, sourceVector2);
  2225. Simd::Vec3::StoreUnaligned(testStoreValues, testVector);
  2226. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2227. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.002f);
  2228. EXPECT_NEAR(testStoreValues[2], 1.0f, 0.002f);
  2229. // The 4th element value cannot be guaranteed, it generally sets garbage.
  2230. }
  2231. {
  2232. Simd::Vec3::FloatType testVector = Simd::Vec3::Cross(sourceVector2, sourceVector3);
  2233. Simd::Vec3::StoreUnaligned(testStoreValues, testVector);
  2234. EXPECT_NEAR(testStoreValues[0], 1.0f, 0.002f);
  2235. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.002f);
  2236. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.002f);
  2237. // The 4th element value cannot be guaranteed, it generally sets garbage.
  2238. }
  2239. {
  2240. Simd::Vec3::FloatType testVector = Simd::Vec3::Cross(sourceVector3, sourceVector1);
  2241. Simd::Vec3::StoreUnaligned(testStoreValues, testVector);
  2242. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2243. EXPECT_NEAR(testStoreValues[1], 1.0f, 0.002f);
  2244. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.002f);
  2245. // The 4th element value cannot be guaranteed, it generally sets garbage.
  2246. }
  2247. }
  2248. TEST(MATH_SimdMath, TestMat3x3Inverse)
  2249. {
  2250. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2251. Simd::Vec3::FloatType rows[3];
  2252. rows[0] = Simd::Vec3::LoadImmediate(2.0f, 0.0f, 0.0f);
  2253. rows[1] = Simd::Vec3::LoadImmediate(0.0f, 2.0f, 0.0f);
  2254. rows[2] = Simd::Vec3::LoadImmediate(0.0f, 0.0f, 2.0f);
  2255. Simd::Vec3::Mat3x3Inverse(rows, rows);
  2256. Simd::Vec3::StoreUnaligned(testStoreValues, rows[0]);
  2257. EXPECT_NEAR(testStoreValues[0], 0.5f, 0.002f);
  2258. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.002f);
  2259. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.002f);
  2260. Simd::Vec3::StoreUnaligned(testStoreValues, rows[1]);
  2261. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2262. EXPECT_NEAR(testStoreValues[1], 0.5f, 0.002f);
  2263. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.002f);
  2264. Simd::Vec3::StoreUnaligned(testStoreValues, rows[2]);
  2265. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2266. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.002f);
  2267. EXPECT_NEAR(testStoreValues[2], 0.5f, 0.002f);
  2268. }
  2269. TEST(MATH_SimdMath, TestMat3x3Adjugate)
  2270. {
  2271. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2272. Simd::Vec3::FloatType rows[3];
  2273. rows[0] = Simd::Vec3::LoadImmediate( 1.0f, 2.0f, 3.0f);
  2274. rows[1] = Simd::Vec3::LoadImmediate( 2.0f, 0.0f, 1.0f);
  2275. rows[2] = Simd::Vec3::LoadImmediate(-1.0f, 1.0f, 2.0f);
  2276. Simd::Vec3::Mat3x3Adjugate(rows, rows);
  2277. Simd::Vec3::StoreUnaligned(testStoreValues, rows[0]);
  2278. EXPECT_NEAR(testStoreValues[0], -1.0f, 0.002f);
  2279. EXPECT_NEAR(testStoreValues[1], -1.0f, 0.002f);
  2280. EXPECT_NEAR(testStoreValues[2], 2.0f, 0.002f);
  2281. Simd::Vec3::StoreUnaligned(testStoreValues, rows[1]);
  2282. EXPECT_NEAR(testStoreValues[0], -5.0f, 0.002f);
  2283. EXPECT_NEAR(testStoreValues[1], 5.0f, 0.002f);
  2284. EXPECT_NEAR(testStoreValues[2], 5.0f, 0.002f);
  2285. Simd::Vec3::StoreUnaligned(testStoreValues, rows[2]);
  2286. EXPECT_NEAR(testStoreValues[0], 2.0f, 0.002f);
  2287. EXPECT_NEAR(testStoreValues[1], -3.0f, 0.002f);
  2288. EXPECT_NEAR(testStoreValues[2], -4.0f, 0.002f);
  2289. }
  2290. TEST(MATH_SimdMath, TestMat3x3Transpose)
  2291. {
  2292. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2293. Simd::Vec3::FloatType rows[3];
  2294. rows[0] = Simd::Vec3::LoadImmediate(1.0f, 2.0f, 3.0f);
  2295. rows[1] = Simd::Vec3::LoadImmediate(4.0f, 5.0f, 6.0f);
  2296. rows[2] = Simd::Vec3::LoadImmediate(7.0f, 8.0f, 9.0f);
  2297. Simd::Vec3::Mat3x3Transpose(rows, rows);
  2298. Simd::Vec3::StoreUnaligned(testStoreValues, rows[0]);
  2299. EXPECT_NEAR(testStoreValues[0], 1.0f, 0.002f);
  2300. EXPECT_NEAR(testStoreValues[1], 4.0f, 0.002f);
  2301. EXPECT_NEAR(testStoreValues[2], 7.0f, 0.002f);
  2302. Simd::Vec3::StoreUnaligned(testStoreValues, rows[1]);
  2303. EXPECT_NEAR(testStoreValues[0], 2.0f, 0.002f);
  2304. EXPECT_NEAR(testStoreValues[1], 5.0f, 0.002f);
  2305. EXPECT_NEAR(testStoreValues[2], 8.0f, 0.002f);
  2306. Simd::Vec3::StoreUnaligned(testStoreValues, rows[2]);
  2307. EXPECT_NEAR(testStoreValues[0], 3.0f, 0.002f);
  2308. EXPECT_NEAR(testStoreValues[1], 6.0f, 0.002f);
  2309. EXPECT_NEAR(testStoreValues[2], 9.0f, 0.002f);
  2310. }
  2311. TEST(MATH_SimdMath, TestMat3x3Multiply)
  2312. {
  2313. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2314. Simd::Vec3::FloatType rowsA[3];
  2315. rowsA[0] = Simd::Vec3::LoadImmediate(2.0f, 0.0f, 0.0f);
  2316. rowsA[1] = Simd::Vec3::LoadImmediate(0.0f, 2.0f, 0.0f);
  2317. rowsA[2] = Simd::Vec3::LoadImmediate(0.0f, 0.0f, 2.0f);
  2318. Simd::Vec3::FloatType rowsB[3];
  2319. rowsB[0] = Simd::Vec3::LoadImmediate(0.5f, 0.0f, 0.0f);
  2320. rowsB[1] = Simd::Vec3::LoadImmediate(0.0f, 0.5f, 0.0f);
  2321. rowsB[2] = Simd::Vec3::LoadImmediate(0.0f, 0.0f, 0.5f);
  2322. Simd::Vec3::FloatType out[3];
  2323. Simd::Vec3::Mat3x3Multiply(rowsA, rowsB, out);
  2324. Simd::Vec3::StoreUnaligned(testStoreValues, out[0]);
  2325. EXPECT_NEAR(testStoreValues[0], 1.0f, 0.002f);
  2326. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.002f);
  2327. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.002f);
  2328. Simd::Vec3::StoreUnaligned(testStoreValues, out[1]);
  2329. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2330. EXPECT_NEAR(testStoreValues[1], 1.0f, 0.002f);
  2331. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.002f);
  2332. Simd::Vec3::StoreUnaligned(testStoreValues, out[2]);
  2333. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2334. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.002f);
  2335. EXPECT_NEAR(testStoreValues[2], 1.0f, 0.002f);
  2336. }
  2337. TEST(MATH_SimdMath, TestMat3x3TransposeMultiply)
  2338. {
  2339. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2340. Simd::Vec3::FloatType rowsA[3];
  2341. rowsA[0] = Simd::Vec3::LoadImmediate(2.0f, 0.0f, 0.0f);
  2342. rowsA[1] = Simd::Vec3::LoadImmediate(0.0f, 2.0f, 0.0f);
  2343. rowsA[2] = Simd::Vec3::LoadImmediate(0.0f, 0.0f, 2.0f);
  2344. Simd::Vec3::FloatType rowsB[3];
  2345. rowsB[0] = Simd::Vec3::LoadImmediate(0.5f, 0.0f, 0.0f);
  2346. rowsB[1] = Simd::Vec3::LoadImmediate(0.0f, 0.5f, 0.0f);
  2347. rowsB[2] = Simd::Vec3::LoadImmediate(0.0f, 0.0f, 0.5f);
  2348. Simd::Vec3::FloatType out[3];
  2349. Simd::Vec3::Mat3x3TransposeMultiply(rowsA, rowsB, out);
  2350. Simd::Vec3::StoreUnaligned(testStoreValues, out[0]);
  2351. EXPECT_NEAR(testStoreValues[0], 1.0f, 0.002f);
  2352. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.002f);
  2353. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.002f);
  2354. Simd::Vec3::StoreUnaligned(testStoreValues, out[1]);
  2355. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2356. EXPECT_NEAR(testStoreValues[1], 1.0f, 0.002f);
  2357. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.002f);
  2358. Simd::Vec3::StoreUnaligned(testStoreValues, out[2]);
  2359. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2360. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.002f);
  2361. EXPECT_NEAR(testStoreValues[2], 1.0f, 0.002f);
  2362. }
  2363. TEST(MATH_SimdMath, TestQuaternion)
  2364. {
  2365. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2366. AZ::Quaternion quat1 = AZ::Quaternion::CreateRotationZ(DegToRad(90.0f));
  2367. Simd::Vec4::FloatType quatVec1 = Simd::Vec4::LoadImmediate(quat1.GetX(), quat1.GetY(), quat1.GetZ(), quat1.GetW());
  2368. AZ::Quaternion quat2 = AZ::Quaternion::CreateRotationX(DegToRad(90.0f));
  2369. Simd::Vec4::FloatType quatVec2 = Simd::Vec4::LoadImmediate(quat2.GetX(), quat2.GetY(), quat2.GetZ(), quat2.GetW());
  2370. Simd::Vec3::FloatType yAxisVec = Simd::Vec3::LoadImmediate(0.0f, 1.0f, 0.0f);
  2371. {
  2372. Simd::Vec4::FloatType testVector = Simd::Vec4::QuaternionMultiply(quatVec1, quatVec2);
  2373. Simd::Vec4::StoreUnaligned(testStoreValues, testVector);
  2374. EXPECT_NEAR(testStoreValues[0], 0.5f, 0.003f); // TODO: Get new trig, improve precision
  2375. EXPECT_NEAR(testStoreValues[1], 0.5f, 0.003f); // TODO: Get new trig, improve precision
  2376. EXPECT_NEAR(testStoreValues[2], 0.5f, 0.003f); // TODO: Get new trig, improve precision
  2377. EXPECT_NEAR(testStoreValues[3], 0.5f, 0.003f); // TODO: Get new trig, improve precision
  2378. }
  2379. {
  2380. Simd::Vec3::FloatType testVector = Simd::Vec4::QuaternionTransform(quatVec1, yAxisVec);
  2381. Simd::Vec3::StoreUnaligned(testStoreValues, testVector);
  2382. EXPECT_NEAR(testStoreValues[0], -1.0f, 0.003f); // TODO: Get new trig, improve precision
  2383. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.003f); // TODO: Get new trig, improve precision
  2384. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.003f); // TODO: Get new trig, improve precision
  2385. }
  2386. {
  2387. Simd::Vec3::FloatType testVector = Simd::Vec4::QuaternionTransform(quatVec2, yAxisVec);
  2388. Simd::Vec3::StoreUnaligned(testStoreValues, testVector);
  2389. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.003f); // TODO: Get new trig, improve precision
  2390. EXPECT_NEAR(testStoreValues[1], 0.0f, 0.003f); // TODO: Get new trig, improve precision
  2391. EXPECT_NEAR(testStoreValues[2], 1.0f, 0.003f); // TODO: Get new trig, improve precision
  2392. }
  2393. }
  2394. TEST(MATH_SimdMath, TestPlane)
  2395. {
  2396. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2397. // Point offset orthogonal to the plane normal, offset should be discarded
  2398. {
  2399. Simd::Vec3::FloatType normalVec = Simd::Vec3::LoadImmediate(0.0f, 1.0f, 0.0f);
  2400. Simd::Vec3::FloatType pointVec = Simd::Vec3::LoadImmediate(1.0f, 0.0f, 0.0f);
  2401. Simd::Vec4::FloatType planeVec = Simd::Vec4::ConstructPlane(normalVec, pointVec);
  2402. Simd::Vec4::StoreUnaligned(testStoreValues, planeVec);
  2403. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2404. EXPECT_NEAR(testStoreValues[1], 1.0f, 0.002f);
  2405. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.002f);
  2406. EXPECT_NEAR(testStoreValues[3], 0.0f, 0.002f);
  2407. Simd::Vec3::FloatType testPoint = Simd::Vec3::LoadImmediate(0.0f, 10.0f, 0.0f);
  2408. Simd::Vec1::FloatType testDist = Simd::Vec4::PlaneDistance(planeVec, testPoint);
  2409. Simd::Vec1::StoreUnaligned(testStoreValues, testDist);
  2410. EXPECT_NEAR(testStoreValues[0], 10.0f, 0.002f);
  2411. }
  2412. // Point offset along the plane normal, offset should be preserved in distance calculations
  2413. {
  2414. Simd::Vec3::FloatType normalVec = Simd::Vec3::LoadImmediate(0.0f, 1.0f, 0.0f);
  2415. Simd::Vec3::FloatType pointVec = Simd::Vec3::LoadImmediate(0.0f, 10.0f, 0.0f);
  2416. Simd::Vec4::FloatType planeVec = Simd::Vec4::ConstructPlane(normalVec, pointVec);
  2417. Simd::Vec4::StoreUnaligned(testStoreValues, planeVec);
  2418. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2419. EXPECT_NEAR(testStoreValues[1], 1.0f, 0.002f);
  2420. EXPECT_NEAR(testStoreValues[2], 0.0f, 0.002f);
  2421. EXPECT_NEAR(testStoreValues[3], -10.0f, 0.002f);
  2422. Simd::Vec3::FloatType testPoint = Simd::Vec3::LoadImmediate(0.0f, -5.0f, 0.0f);
  2423. Simd::Vec1::FloatType testDist = Simd::Vec4::PlaneDistance(planeVec, testPoint);
  2424. Simd::Vec1::StoreUnaligned(testStoreValues, testDist);
  2425. EXPECT_NEAR(testStoreValues[0], -15.0f, 0.002f);
  2426. }
  2427. }
  2428. TEST(MATH_SimdMath, TestMat3x4Transpose)
  2429. {
  2430. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2431. Simd::Vec4::FloatType rows[4];
  2432. rows[0] = Simd::Vec4::LoadImmediate(0.0f, 1.0f, 2.0f, 3.0f);
  2433. rows[1] = Simd::Vec4::LoadImmediate(4.0f, 5.0f, 6.0f, 7.0f);
  2434. rows[2] = Simd::Vec4::LoadImmediate(8.0f, 9.0f, -1.0f, -2.0f);
  2435. Simd::Vec4::Mat3x4Transpose(rows, rows);
  2436. Simd::Vec4::StoreUnaligned(testStoreValues, rows[0]);
  2437. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2438. EXPECT_NEAR(testStoreValues[1], 4.0f, 0.002f);
  2439. EXPECT_NEAR(testStoreValues[2], 8.0f, 0.002f);
  2440. EXPECT_NEAR(testStoreValues[3], 0.0f, 0.002f);
  2441. Simd::Vec4::StoreUnaligned(testStoreValues, rows[1]);
  2442. EXPECT_NEAR(testStoreValues[0], 1.0f, 0.002f);
  2443. EXPECT_NEAR(testStoreValues[1], 5.0f, 0.002f);
  2444. EXPECT_NEAR(testStoreValues[2], 9.0f, 0.002f);
  2445. EXPECT_NEAR(testStoreValues[3], 0.0f, 0.002f);
  2446. Simd::Vec4::StoreUnaligned(testStoreValues, rows[2]);
  2447. EXPECT_NEAR(testStoreValues[0], 2.0f, 0.002f);
  2448. EXPECT_NEAR(testStoreValues[1], 6.0f, 0.002f);
  2449. EXPECT_NEAR(testStoreValues[2], -1.0f, 0.002f);
  2450. EXPECT_NEAR(testStoreValues[3], 0.0f, 0.002f);
  2451. }
  2452. TEST(MATH_SimdMath, TestMat4x4Transpose)
  2453. {
  2454. float testStoreValues[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
  2455. Simd::Vec4::FloatType rows[4];
  2456. rows[0] = Simd::Vec4::LoadImmediate(0.0f, 1.0f, 2.0f, 3.0f);
  2457. rows[1] = Simd::Vec4::LoadImmediate(4.0f, 5.0f, 6.0f, 7.0f);
  2458. rows[2] = Simd::Vec4::LoadImmediate(8.0f, 9.0f, 9.1f, 9.9f);
  2459. rows[3] = Simd::Vec4::LoadImmediate(-1.0f, -2.0f, -3.0f, -4.0f);
  2460. Simd::Vec4::Mat4x4Transpose(rows, rows);
  2461. Simd::Vec4::StoreUnaligned(testStoreValues, rows[0]);
  2462. EXPECT_NEAR(testStoreValues[0], 0.0f, 0.002f);
  2463. EXPECT_NEAR(testStoreValues[1], 4.0f, 0.002f);
  2464. EXPECT_NEAR(testStoreValues[2], 8.0f, 0.002f);
  2465. EXPECT_NEAR(testStoreValues[3], -1.0f, 0.002f);
  2466. Simd::Vec4::StoreUnaligned(testStoreValues, rows[1]);
  2467. EXPECT_NEAR(testStoreValues[0], 1.0f, 0.002f);
  2468. EXPECT_NEAR(testStoreValues[1], 5.0f, 0.002f);
  2469. EXPECT_NEAR(testStoreValues[2], 9.0f, 0.002f);
  2470. EXPECT_NEAR(testStoreValues[3], -2.0f, 0.002f);
  2471. Simd::Vec4::StoreUnaligned(testStoreValues, rows[2]);
  2472. EXPECT_NEAR(testStoreValues[0], 2.0f, 0.002f);
  2473. EXPECT_NEAR(testStoreValues[1], 6.0f, 0.002f);
  2474. EXPECT_NEAR(testStoreValues[2], 9.1f, 0.002f);
  2475. EXPECT_NEAR(testStoreValues[3], -3.0f, 0.002f);
  2476. Simd::Vec4::StoreUnaligned(testStoreValues, rows[3]);
  2477. EXPECT_NEAR(testStoreValues[0], 3.0f, 0.002f);
  2478. EXPECT_NEAR(testStoreValues[1], 7.0f, 0.002f);
  2479. EXPECT_NEAR(testStoreValues[2], 9.9f, 0.002f);
  2480. EXPECT_NEAR(testStoreValues[3], -4.0f, 0.002f);
  2481. }
  2482. TEST(MATH_SimdMath, TestConvertToIntVec1)
  2483. {
  2484. TestConvertToInt<Simd::Vec1>();
  2485. }
  2486. TEST(MATH_SimdMath, TestConvertToIntVec2)
  2487. {
  2488. TestConvertToInt<Simd::Vec2>();
  2489. }
  2490. TEST(MATH_SimdMath, TestConvertToIntVec3)
  2491. {
  2492. TestConvertToInt<Simd::Vec3>();
  2493. }
  2494. TEST(MATH_SimdMath, TestConvertToIntVec4)
  2495. {
  2496. TestConvertToInt<Simd::Vec4>();
  2497. }
  2498. TEST(MATH_SimdMath, TestConvertToIntNearestVec1)
  2499. {
  2500. TestConvertToIntNearest<Simd::Vec1>();
  2501. }
  2502. TEST(MATH_SimdMath, TestConvertToIntNearestVec2)
  2503. {
  2504. TestConvertToIntNearest<Simd::Vec2>();
  2505. }
  2506. TEST(MATH_SimdMath, TestConvertToIntNearestVec3)
  2507. {
  2508. TestConvertToIntNearest<Simd::Vec3>();
  2509. }
  2510. TEST(MATH_SimdMath, TestConvertToIntNearestVec4)
  2511. {
  2512. TestConvertToIntNearest<Simd::Vec4>();
  2513. }
  2514. TEST(MATH_SimdMath, TestConvertToFloatVec1)
  2515. {
  2516. TestConvertToFloat<Simd::Vec1>();
  2517. }
  2518. TEST(MATH_SimdMath, TestConvertToFloatVec2)
  2519. {
  2520. TestConvertToFloat<Simd::Vec2>();
  2521. }
  2522. TEST(MATH_SimdMath, TestConvertToFloatVec3)
  2523. {
  2524. TestConvertToFloat<Simd::Vec3>();
  2525. }
  2526. TEST(MATH_SimdMath, TestConvertToFloatVec4)
  2527. {
  2528. TestConvertToFloat<Simd::Vec4>();
  2529. }
  2530. TEST(MATH_SimdMath, TestCastVec1)
  2531. {
  2532. TestCast<Simd::Vec1>();
  2533. }
  2534. TEST(MATH_SimdMath, TestCastVec2)
  2535. {
  2536. TestCast<Simd::Vec2>();
  2537. }
  2538. TEST(MATH_SimdMath, TestCastVec3)
  2539. {
  2540. TestCast<Simd::Vec3>();
  2541. }
  2542. TEST(MATH_SimdMath, TestCastVec4)
  2543. {
  2544. TestCast<Simd::Vec4>();
  2545. }
  2546. TEST(MATH_SimdMath, TestZeroVectorFloatVec1)
  2547. {
  2548. TestZeroVectorFloat<Simd::Vec1>();
  2549. }
  2550. TEST(MATH_SimdMath, TestZeroVectorFloatVec2)
  2551. {
  2552. TestZeroVectorFloat<Simd::Vec2>();
  2553. }
  2554. TEST(MATH_SimdMath, TestZeroVectorFloatVec3)
  2555. {
  2556. TestZeroVectorFloat<Simd::Vec3>();
  2557. }
  2558. TEST(MATH_SimdMath, TestZeroVectorFloatVec4)
  2559. {
  2560. TestZeroVectorFloat<Simd::Vec4>();
  2561. }
  2562. TEST(MATH_SimdMath, TestZeroVectorIntVec1)
  2563. {
  2564. TestZeroVectorInt<Simd::Vec1>();
  2565. }
  2566. TEST(MATH_SimdMath, TestZeroVectorIntVec2)
  2567. {
  2568. TestZeroVectorInt<Simd::Vec2>();
  2569. }
  2570. TEST(MATH_SimdMath, TestZeroVectorIntVec3)
  2571. {
  2572. TestZeroVectorInt<Simd::Vec3>();
  2573. }
  2574. TEST(MATH_SimdMath, TestZeroVectorIntVec4)
  2575. {
  2576. TestZeroVectorInt<Simd::Vec4>();
  2577. }
  2578. }