testSwizzle.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 i16 = stdlib.SIMD.Int8x16;
  9. var i16check = i16.check;
  10. var i16swizzle = i16.swizzle;
  11. var i16add = i16.add;
  12. var i16mul = i16.mul;
  13. var globImporti16 = i16check(imports.g1);
  14. var i16g1 = i16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
  15. var i16g2 = i16(128, 128, -128, -128, 0, 0, 1000, -1000, 5, 15, -3, -399, 299, 21, 12 ,12);
  16. var loopCOUNT = 3;
  17. function testswizzleLocal() {
  18. var a = i16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
  19. var result = i16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  20. var loopIndex = 0;
  21. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  22. result = i16swizzle(a, 0, 1, 4, 5, 8, 10, 11, 12, 4, 2, 1, 6, 2, 8, 14, 0);
  23. loopIndex = (loopIndex + 1) | 0;
  24. }
  25. return i16check(result);
  26. }
  27. function testswizzleGlobal() {
  28. var result = i16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  29. var loopIndex = 0;
  30. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  31. result = i16swizzle(i16g1, 0, 1, 4, 5, 8, 10, 11, 12, 4, 2, 1, 6, 2, 8, 14, 0);
  32. loopIndex = (loopIndex + 1) | 0;
  33. }
  34. return i16check(result);
  35. }
  36. function testswizzleGlobalImport() {
  37. var result = i16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  38. var loopIndex = 0;
  39. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  40. result = i16swizzle(globImporti16, 0, 1, 4, 5, 8, 10, 11, 12, 4, 2, 1, 6, 2, 8, 14, 0);
  41. loopIndex = (loopIndex + 1) | 0;
  42. }
  43. return i16check(result);
  44. }
  45. function testswizzleFunc() {
  46. var a = i16(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
  47. var result = i16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  48. var loopIndex = 0;
  49. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  50. result = i16swizzle(i16add(a, i16g1), 0, 1, 4, 5, 8, 10, 11, 12, 4, 2, 1, 6, 2, 8, 14, 0);
  51. loopIndex = (loopIndex + 1) | 0;
  52. }
  53. return i16check(result);
  54. }
  55. return { testswizzleLocal: testswizzleLocal, testswizzleGlobal: testswizzleGlobal, testswizzleGlobalImport: testswizzleGlobalImport, testswizzleFunc: testswizzleFunc };
  56. }
  57. var m = asmModule(this, { g1: SIMD.Int8x16(100, -10, -128, -102, 83, -38, -9, 12, 52, 127, -127, -129, 129, 0, 88, 100234) });
  58. equalSimd([1, 2, 5, 6, 9, 11, 12, 13, 5, 3, 2, 7, 3, 9, 15, 1], m.testswizzleLocal(), SIMD.Int8x16, "");
  59. equalSimd([1, 2, 5, 6, 9, 11, 12, 13, 5, 3, 2, 7, 3, 9, 15, 1], m.testswizzleGlobal(), SIMD.Int8x16, "");
  60. equalSimd([100, -10, 83, -38, 52, -127, 127, -127, 83, -128, -10, -9, -128, 52, 88, 100], m.testswizzleGlobalImport(), SIMD.Int8x16, "");
  61. equalSimd([2, 4, 10, 12, 18, 22, 24, 26, 10, 6, 4, 14, 6, 18, 30, 2], m.testswizzleFunc(), SIMD.Int8x16, "");
  62. print("PASS");