testShuffle.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. this.WScript.LoadScriptFile("..\\UnitTestFramework\\SimdJsHelpers.js");
  6. function asmModule(stdlib, imports) {
  7. "use asm";
  8. var i8 = stdlib.SIMD.Int16x8;
  9. var i8check = i8.check;
  10. var i8shuffle = i8.shuffle;
  11. var i8add = i8.add;
  12. var i8mul = i8.mul;
  13. var globImporti8 = i8check(imports.g1);
  14. var i8g1 = i8(10, -1073, -107, 1082, 10402, 12332, 311, -650);
  15. var i8g2 = i8(353216, -492529, -1128, 1085, 3692, 3937, 9755, 2638);
  16. var loopCOUNT = 3;
  17. function testShuffleLocal() {
  18. var a = i8(5033, -3401, 665, -3234, -948, 2834, 7748, -25);
  19. var b = i8(-3483, 2144, -5697, 65, 1000000, -984, 3434, -9876);
  20. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  21. var loopIndex = 0;
  22. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  23. result = i8shuffle(a, b, 0, 1, 4, 5, 8, 3, 2, 6);
  24. loopIndex = (loopIndex + 1) | 0;
  25. }
  26. return i8check(result);
  27. }
  28. function testShuffleGlobal() {
  29. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  30. var loopIndex = 0;
  31. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  32. result = i8shuffle(i8g1, i8g2, 0, 1, 4, 5, 8, 3, 2, 6);
  33. loopIndex = (loopIndex + 1) | 0;
  34. }
  35. return i8check(result);
  36. }
  37. function testShuffleGlobalImport() {
  38. var a = i8(5033, -3401, 665, -3234, -948, 2834, 7748, -25);
  39. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  40. var loopIndex = 0;
  41. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  42. result = i8shuffle(a, globImporti8, 0, 1, 4, 5, 8, 3, 2, 6);
  43. loopIndex = (loopIndex + 1) | 0;
  44. }
  45. return i8check(result);
  46. }
  47. function testShuffleFunc() {
  48. var a = i8(5033, -3401, 665, -3234, -948, 2834, 7748, -25);
  49. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  50. var loopIndex = 0;
  51. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  52. result = i8shuffle(i8add(a, i8g1), i8mul(a, i8g1), 0, 1, 4, 5, 8, 3, 2, 6);
  53. loopIndex = (loopIndex + 1) | 0;
  54. }
  55. return i8check(result);
  56. }
  57. return { testShuffleLocal: testShuffleLocal, testShuffleGlobal: testShuffleGlobal, testShuffleGlobalImport: testShuffleGlobalImport, testShuffleFunc: testShuffleFunc };
  58. }
  59. var m = asmModule(this, { g1: SIMD.Int16x8(-50, 1000, 3092, -3393, Infinity, -39283838, NaN, -838) });
  60. equalSimd([5033, -3401, -948, 2834, -3483, -3234, 665, 7748], m.testShuffleLocal(), SIMD.Int16x8, "");
  61. equalSimd([10, -1073, 10402, 12332, 25536, 1082, -107, 311], m.testShuffleGlobal(), SIMD.Int16x8, "");
  62. equalSimd([5033, -3401, -948, 2834, -50, -3234, 665, 7748], m.testShuffleGlobalImport(), SIMD.Int16x8, "");
  63. equalSimd([5043, -4474, 9454, 15166, -15206, -2152, 558, 8059], m.testShuffleFunc(), SIMD.Int16x8, "");
  64. print("PASS");