testSwizzle.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 i8swizzle = i8.swizzle;
  11. var i8add = i8.add;
  12. var i8mul = i8.mul;
  13. var globImporti8 = i8check(imports.g1);
  14. var i8g1 = i8(1, 2, 3, 4, 5, 6, 7, 8);
  15. var loopCOUNT = 3;
  16. function testswizzleLocal() {
  17. var a = i8(1, 2, 3, 4, 5, 6, 7, 8);
  18. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  19. var loopIndex = 0;
  20. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  21. result = i8swizzle(a, 0, 1, 4, 5, 7, 4, 2, 3);
  22. loopIndex = (loopIndex + 1) | 0;
  23. }
  24. return i8check(result);
  25. }
  26. function testswizzleGlobal() {
  27. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  28. var loopIndex = 0;
  29. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  30. result = i8swizzle(i8g1, 0, 1, 4, 5, 7, 4, 2, 3);
  31. loopIndex = (loopIndex + 1) | 0;
  32. }
  33. return i8check(result);
  34. }
  35. function testswizzleGlobalImport() {
  36. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  37. var loopIndex = 0;
  38. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  39. result = i8swizzle(globImporti8, 0, 1, 4, 5, 7, 4, 2, 3);
  40. loopIndex = (loopIndex + 1) | 0;
  41. }
  42. return i8check(result);
  43. }
  44. function testswizzleFunc() {
  45. var a = i8(1, 2, 3, 4, 5, 6, 7, 8);
  46. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  47. var loopIndex = 0;
  48. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  49. result = i8swizzle(i8add(a, i8g1), 0, 1, 4, 5, 7, 4, 2, 3);
  50. loopIndex = (loopIndex + 1) | 0;
  51. }
  52. return i8check(result);
  53. }
  54. return { testswizzleLocal: testswizzleLocal, testswizzleGlobal: testswizzleGlobal, testswizzleGlobalImport: testswizzleGlobalImport, testswizzleFunc: testswizzleFunc };
  55. }
  56. var m = asmModule(this, { g1: SIMD.Int16x8(-50, 1000, 3092, -3393, Infinity, -39283838, NaN, -838) });
  57. equalSimd([1, 2, 5, 6, 8, 5, 3, 4], m.testswizzleLocal(), SIMD.Int16x8, "");
  58. equalSimd([1, 2, 5, 6, 8, 5, 3, 4], m.testswizzleGlobal(), SIMD.Int16x8, "");
  59. equalSimd([-50, 1000, 0, -27774, -838, 0, 3092, -3393], m.testswizzleGlobalImport(), SIMD.Int16x8, "");
  60. equalSimd([2, 4, 10, 12, 16, 10, 6, 8], m.testswizzleFunc(), SIMD.Int16x8, "");
  61. print("PASS");