testShuffle.js 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 i4 = stdlib.SIMD.Int32x4;
  9. var i4check = i4.check;
  10. var i4extractLane = i4.extractLane;
  11. var i4fromFloat32x4 = i4.fromFloat32x4;
  12. var i4fromFloat32x4Bits = i4.fromFloat32x4Bits;
  13. //var i4abs = i4.abs;
  14. var i4neg = i4.neg;
  15. var i4add = i4.add;
  16. var i4sub = i4.sub;
  17. var i4mul = i4.mul;
  18. var i4swizzle = i4.swizzle;
  19. var i4shuffle = i4.shuffle;
  20. var i4lessThan = i4.lessThan;
  21. var i4equal = i4.equal;
  22. var i4greaterThan = i4.greaterThan;
  23. var i4select = i4.select;
  24. var i4and = i4.and;
  25. var i4or = i4.or;
  26. var i4xor = i4.xor;
  27. var i4not = i4.not;
  28. //var i4shiftLeftByScalar = i4.shiftLeftByScalar;
  29. //var i4shiftRightByScalar = i4.shiftRightByScalar;
  30. //var i4shiftRightArithmeticByScalar = i4.shiftRightArithmeticByScalar;
  31. var f4 = stdlib.SIMD.Float32x4;
  32. var f4check = f4.check;
  33. var f4fromInt32x4 = f4.fromInt32x4;
  34. var f4fromInt32x4Bits = f4.fromInt32x4Bits;
  35. var f4abs = f4.abs;
  36. var f4neg = f4.neg;
  37. var f4add = f4.add;
  38. var f4sub = f4.sub;
  39. var f4mul = f4.mul;
  40. var f4div = f4.div;
  41. var f4min = f4.min;
  42. var f4max = f4.max;
  43. var f4sqrt = f4.sqrt;
  44. var f4swizzle = f4.swizzle;
  45. var f4shuffle = f4.shuffle;
  46. var f4lessThan = f4.lessThan;
  47. var f4lessThanOrEqual = f4.lessThanOrEqual;
  48. var f4equal = f4.equal;
  49. var f4notEqual = f4.notEqual;
  50. var f4greaterThan = f4.greaterThan;
  51. var f4greaterThanOrEqual = f4.greaterThanOrEqual;
  52. var f4select = f4.select;
  53. var fround = stdlib.Math.fround;
  54. var globImportF4 = f4check(imports.g1); // global var import
  55. var globImportI4 = i4check(imports.g2); // global var import
  56. var g1 = f4(1.0, 2.0, 3.0, -0.0); // global var initialized
  57. var g2 = f4(-5.3, -0.0, 7.332, 8.0); // global var initialized
  58. var g3 = i4(1, 2, 3, 4); // global var initialized
  59. var g4 = i4(5, 6, 7, 8); // global var initialized
  60. //var g5 = d2(1.0, 2.0); // global var initialized
  61. //var g6 = d2(3.0, 4.0); // global var initialized
  62. var gval = 1234;
  63. var gval2 = 1234.0;
  64. var f4splat = f4.splat;
  65. var sqrt = stdlib.Math.sqrt;
  66. var pow = stdlib.Math.pow;
  67. var loopCOUNT = 3;
  68. function shuffle1() {
  69. var xyxy = i4(0, 0, 0, 0);
  70. var zwzw = i4(0, 0, 0, 0);
  71. var xxxx = i4(0, 0, 0, 0);
  72. var xxyy = i4(0, 0, 0, 0);
  73. var x = 0, y = 0, z = 0, w = 0;
  74. var loopIndex = 0;
  75. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  76. xyxy = i4shuffle(g3, g4, 0, 1, 4, 5);
  77. zwzw = i4shuffle(g3, g4, 2, 3, 6, 7);
  78. xxxx = i4shuffle(g3, g4, 0, 0, 4, 4);
  79. xxyy = i4shuffle(g3, g4, 0, 0, 5, 5);
  80. loopIndex = (loopIndex + 1) | 0;
  81. }
  82. x = (((i4extractLane(xyxy, 0) + i4extractLane(xyxy, 0)) | 0) + ((i4extractLane(xyxy, 1) + i4extractLane(xyxy, 1)) | 0) + ((i4extractLane(xyxy, 2) + i4extractLane(xyxy, 2)) | 0) + ((i4extractLane(xyxy, 3) + i4extractLane(xyxy, 3)) | 0)) | 0;
  83. y = (((i4extractLane(zwzw, 0) + i4extractLane(zwzw, 0)) | 0) + ((i4extractLane(zwzw, 1) + i4extractLane(zwzw, 1)) | 0) + ((i4extractLane(zwzw, 2) + i4extractLane(zwzw, 2)) | 0) + ((i4extractLane(zwzw, 3) + i4extractLane(zwzw, 3)) | 0)) | 0;
  84. z = (((i4extractLane(xxxx, 0) + i4extractLane(xxxx, 0)) | 0) + ((i4extractLane(xxxx, 1) + i4extractLane(xxxx, 1)) | 0) + ((i4extractLane(xxxx, 2) + i4extractLane(xxxx, 2)) | 0) + ((i4extractLane(xxxx, 3) + i4extractLane(xxxx, 3)) | 0)) | 0;
  85. w = (((i4extractLane(xxyy, 0) + i4extractLane(xxyy, 0)) | 0) + ((i4extractLane(xxyy, 1) + i4extractLane(xxyy, 1)) | 0) + ((i4extractLane(xxyy, 2) + i4extractLane(xxyy, 2)) | 0) + ((i4extractLane(xxyy, 3) + i4extractLane(xxyy, 3)) | 0)) | 0;
  86. return i4check(i4(x, y, z, w));
  87. }
  88. function shuffle2() {
  89. var xyxy = i4(0, 0, 0, 0);
  90. var zwzw = i4(0, 0, 0, 0);
  91. var xxxx = i4(0, 0, 0, 0);
  92. var xxyy = i4(0, 0, 0, 0);
  93. var v1 = i4(122, 0, 334, -9500);
  94. var v2 = i4(102, 3313, 1, 233);
  95. var x = 0, y = 0, z = 0, w = 0;
  96. var loopIndex = 0;
  97. for (loopIndex = 0; (loopIndex | 0) < (loopCOUNT | 0) ; loopIndex = (loopIndex + 1) | 0) {
  98. xyxy = i4shuffle(v1, v2, 0, 1, 4, 5);
  99. zwzw = i4shuffle(v1, v2, 2, 3, 6, 7);
  100. xxxx = i4shuffle(v1, v2, 0, 0, 4, 4);
  101. xxyy = i4shuffle(v1, v2, 0, 0, 5, 5);
  102. }
  103. x = (((i4extractLane(xyxy, 0) + i4extractLane(xyxy, 0)) | 0) + ((i4extractLane(xyxy, 1) + i4extractLane(xyxy, 1)) | 0) + ((i4extractLane(xyxy, 2) + i4extractLane(xyxy, 2)) | 0) + ((i4extractLane(xyxy, 3) + i4extractLane(xyxy, 3)) | 0)) | 0;
  104. y = (((i4extractLane(zwzw, 0) + i4extractLane(zwzw, 0)) | 0) + ((i4extractLane(zwzw, 1) + i4extractLane(zwzw, 1)) | 0) + ((i4extractLane(zwzw, 2) + i4extractLane(zwzw, 2)) | 0) + ((i4extractLane(zwzw, 3) + i4extractLane(zwzw, 3)) | 0)) | 0;
  105. z = (((i4extractLane(xxxx, 0) + i4extractLane(xxxx, 0)) | 0) + ((i4extractLane(xxxx, 1) + i4extractLane(xxxx, 1)) | 0) + ((i4extractLane(xxxx, 2) + i4extractLane(xxxx, 2)) | 0) + ((i4extractLane(xxxx, 3) + i4extractLane(xxxx, 3)) | 0)) | 0;
  106. w = (((i4extractLane(xxyy, 0) + i4extractLane(xxyy, 0)) | 0) + ((i4extractLane(xxyy, 1) + i4extractLane(xxyy, 1)) | 0) + ((i4extractLane(xxyy, 2) + i4extractLane(xxyy, 2)) | 0) + ((i4extractLane(xxyy, 3) + i4extractLane(xxyy, 3)) | 0)) | 0;
  107. return i4check(i4(x, y, z, w));
  108. }
  109. function shuffle3() {
  110. var xyxy = i4(0, 0, 0, 0);
  111. var zwzw = i4(0, 0, 0, 0);
  112. var xxxx = i4(0, 0, 0, 0);
  113. var xxyy = i4(0, 0, 0, 0);
  114. var v1 = i4(122, 0, 334, -9500);
  115. var x = 0, y = 0, z = 0, w = 0;
  116. var loopIndex = 0;
  117. loopIndex = loopCOUNT | 0;
  118. do {
  119. xyxy = i4shuffle(i4add(v1, g3), v1, 0, 1, 4, 5);
  120. zwzw = i4shuffle(i4mul(v1, g3), g4, 2, 3, 6, 7);
  121. xxxx = i4shuffle(i4sub(v1, g3), v1, 0, 0, 4, 4);
  122. xxyy = i4shuffle(g3, v1, 0, 0, 5, 5);
  123. loopIndex = (loopIndex - 1) | 0;
  124. }
  125. while ((loopIndex | 0) > 0);
  126. x = (((i4extractLane(xyxy, 0) + i4extractLane(xyxy, 0)) | 0) + ((i4extractLane(xyxy, 1) + i4extractLane(xyxy, 1)) | 0) + ((i4extractLane(xyxy, 2) + i4extractLane(xyxy, 2)) | 0) + ((i4extractLane(xyxy, 3) + i4extractLane(xyxy, 3)) | 0)) | 0;
  127. y = (((i4extractLane(zwzw, 0) + i4extractLane(zwzw, 0)) | 0) + ((i4extractLane(zwzw, 1) + i4extractLane(zwzw, 1)) | 0) + ((i4extractLane(zwzw, 2) + i4extractLane(zwzw, 2)) | 0) + ((i4extractLane(zwzw, 3) + i4extractLane(zwzw, 3)) | 0)) | 0;
  128. z = (((i4extractLane(xxxx, 0) + i4extractLane(xxxx, 0)) | 0) + ((i4extractLane(xxxx, 1) + i4extractLane(xxxx, 1)) | 0) + ((i4extractLane(xxxx, 2) + i4extractLane(xxxx, 2)) | 0) + ((i4extractLane(xxxx, 3) + i4extractLane(xxxx, 3)) | 0)) | 0;
  129. w = (((i4extractLane(xxyy, 0) + i4extractLane(xxyy, 0)) | 0) + ((i4extractLane(xxyy, 1) + i4extractLane(xxyy, 1)) | 0) + ((i4extractLane(xxyy, 2) + i4extractLane(xxyy, 2)) | 0) + ((i4extractLane(xxyy, 3) + i4extractLane(xxyy, 3)) | 0)) | 0;
  130. return i4check(i4(x, y, z, w));
  131. }
  132. return { func1: shuffle1 , func2: shuffle2, func3: shuffle3 };
  133. }
  134. var m = asmModule(this, { g1: SIMD.Float32x4(9.0, 9.0, 9.0, 9.0), g2: SIMD.Int32x4(1, 2, 3, 4) });
  135. var ret1 = m.func1();
  136. var ret2 = m.func2();
  137. var ret3 = m.func3();
  138. equalSimd([28, 44, 24, 28], ret1, SIMD.Int32x4, "");
  139. equalSimd([7074, -17864, 896, 13740], ret2, SIMD.Int32x4, "");
  140. equalSimd([494, -73966, 972, 4], ret3, SIMD.Int32x4, "");
  141. print("PASS");