testShuffle.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. function asmModule(stdlib, imports) {
  6. "use asm";
  7. var i4 = stdlib.SIMD.Int32x4;
  8. var i4check = i4.check;
  9. var i4fromFloat64x2 = i4.fromFloat64x2;
  10. var i4fromFloat64x2Bits = i4.fromFloat64x2Bits;
  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 f4fromFloat64x2 = f4.fromFloat64x2;
  34. var f4fromFloat64x2Bits = f4.fromFloat64x2Bits;
  35. var f4fromInt32x4 = f4.fromInt32x4;
  36. var f4fromInt32x4Bits = f4.fromInt32x4Bits;
  37. var f4abs = f4.abs;
  38. var f4neg = f4.neg;
  39. var f4add = f4.add;
  40. var f4sub = f4.sub;
  41. var f4mul = f4.mul;
  42. var f4div = f4.div;
  43. var f4clamp = f4.clamp;
  44. var f4min = f4.min;
  45. var f4max = f4.max;
  46. var f4reciprocal = f4.reciprocal;
  47. var f4reciprocalSqrt = f4.reciprocalSqrt;
  48. var f4sqrt = f4.sqrt;
  49. var f4swizzle = f4.swizzle;
  50. var f4shuffle = f4.shuffle;
  51. var f4lessThan = f4.lessThan;
  52. var f4lessThanOrEqual = f4.lessThanOrEqual;
  53. var f4equal = f4.equal;
  54. var f4notEqual = f4.notEqual;
  55. var f4greaterThan = f4.greaterThan;
  56. var f4greaterThanOrEqual = f4.greaterThanOrEqual;
  57. var f4extractLane = f4.extractLane;
  58. var f4select = f4.select;
  59. var f4and = f4.and;
  60. var f4or = f4.or;
  61. var f4xor = f4.xor;
  62. var f4not = f4.not;
  63. var d2 = stdlib.SIMD.Float64x2;
  64. var d2check = d2.check;
  65. var d2fromFloat32x4 = d2.fromFloat32x4;
  66. var d2fromFloat32x4Bits = d2.fromFloat32x4Bits;
  67. var d2fromInt32x4 = d2.fromInt32x4;
  68. var d2fromInt32x4Bits = d2.fromInt32x4Bits;
  69. var d2abs = d2.abs;
  70. var d2neg = d2.neg;
  71. var d2add = d2.add;
  72. var d2sub = d2.sub;
  73. var d2mul = d2.mul;
  74. var d2div = d2.div;
  75. var d2clamp = d2.clamp;
  76. var d2min = d2.min;
  77. var d2max = d2.max;
  78. var d2reciprocal = d2.reciprocal;
  79. var d2reciprocalSqrt = d2.reciprocalSqrt;
  80. var d2sqrt = d2.sqrt;
  81. var d2swizzle = d2.swizzle;
  82. var d2shuffle = d2.shuffle;
  83. var d2lessThan = d2.lessThan;
  84. var d2lessThanOrEqual = d2.lessThanOrEqual;
  85. var d2equal = d2.equal;
  86. var d2notEqual = d2.notEqual;
  87. var d2greaterThan = d2.greaterThan;
  88. var d2greaterThanOrEqual = d2.greaterThanOrEqual;
  89. var d2select = d2.select;
  90. var fround = stdlib.Math.fround;
  91. var globImportF4 = f4check(imports.g1); // global var import
  92. var globImportI4 = i4check(imports.g2); // global var import
  93. var g1 = f4(1.0, 2.0, 3.0, -0.0); // global var initialized
  94. var g2 = f4(-5.3, -0.0, 7.332, 8.0); // global var initialized
  95. var g3 = i4(1, 2, 3, 4); // global var initialized
  96. var g4 = i4(5, 6, 7, 8); // global var initialized
  97. var g5 = d2(1.0, 2.0); // global var initialized
  98. var g6 = d2(3.0, 4.0); // global var initialized
  99. var gval = 1234;
  100. var gval2 = 1234.0;
  101. var f4splat = f4.splat;
  102. var sqrt = stdlib.Math.sqrt;
  103. var pow = stdlib.Math.pow;
  104. var loopCOUNT = 3;
  105. function shuffle1() {
  106. var xyxy = f4(0.0, 0.0, 0.0, 0.0);
  107. var zwzw = f4(0.0, 0.0, 0.0, 0.0);
  108. var xxxx = f4(0.0, 0.0, 0.0, 0.0);
  109. var xxyy = f4(0.0, 0.0, 0.0, 0.0);
  110. var x = 0.0, y = 0.0, z = 0.0, w = 0.0;
  111. var loopIndex = 0;
  112. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  113. xyxy = f4shuffle(g1, g2, 0, 1, 4, 5);
  114. zwzw = f4shuffle(g1, g2, 2, 3, 6, 7);
  115. xxxx = f4shuffle(g1, g2, 0, 0, 4, 4);
  116. xxyy = f4shuffle(g1, g2, 0, 0, 5, 5);
  117. loopIndex = (loopIndex + 1) | 0;
  118. }
  119. x = +sqrt((+fround(f4extractLane(xyxy, 0)) * +fround(f4extractLane(xyxy, 0)))
  120. + (+fround(f4extractLane(xyxy, 1)) * +fround(f4extractLane(xyxy, 1)))
  121. + (+fround(f4extractLane(xyxy, 2)) * +fround(f4extractLane(xyxy, 2)))
  122. + (+fround(f4extractLane(xyxy, 3)) * +fround(f4extractLane(xyxy, 3))));
  123. y = +sqrt((+fround(f4extractLane(zwzw, 0)) * +fround(f4extractLane(zwzw, 0)))
  124. + (+fround(f4extractLane(zwzw, 1)) * +fround(f4extractLane(zwzw, 1)))
  125. + (+fround(f4extractLane(zwzw, 2)) * +fround(f4extractLane(zwzw, 2)))
  126. + (+fround(f4extractLane(zwzw, 3)) * +fround(f4extractLane(zwzw, 3))));
  127. z = +sqrt((+fround(f4extractLane(xxxx, 0)) * +fround(f4extractLane(xxxx, 0)))
  128. + (+fround(f4extractLane(xxxx, 1)) * +fround(f4extractLane(xxxx, 1)))
  129. + (+fround(f4extractLane(xxxx, 2)) * +fround(f4extractLane(xxxx, 2)))
  130. + (+fround(f4extractLane(xxxx, 3)) * +fround(f4extractLane(xxxx, 3))));
  131. w = +sqrt((+fround(f4extractLane(xxyy, 0)) * +fround(f4extractLane(xxyy, 0)))
  132. + (+fround(f4extractLane(xxyy, 1)) * +fround(f4extractLane(xxyy, 1)))
  133. + (+fround(f4extractLane(xxyy, 2)) * +fround(f4extractLane(xxyy, 2)))
  134. + (+fround(f4extractLane(xxyy, 3)) * +fround(f4extractLane(xxyy, 3))));
  135. return f4check(f4(fround(x), fround(y), fround(z), fround(w)));
  136. }
  137. function shuffle2() {
  138. var xyxy = f4(0.0, 0.0, 0.0, 0.0);
  139. var zwzw = f4(0.0, 0.0, 0.0, 0.0);
  140. var xxxx = f4(0.0, 0.0, 0.0, 0.0);
  141. var xxyy = f4(0.0, 0.0, 0.0, 0.0);
  142. var v1 = f4(122.0, -0.0, 334.0, -9500.231);
  143. var v2 = f4(102.0, -33.13, -1.0, 233.000001);
  144. var x = 0.0, y = 0.0, z = 0.0, w = 0.0;
  145. var loopIndex = 0;
  146. for (loopIndex = 0; (loopIndex | 0) < (loopCOUNT | 0) ; loopIndex = (loopIndex + 1) | 0) {
  147. xyxy = f4shuffle(v1, v2, 0, 1, 4, 5);
  148. zwzw = f4shuffle(v1, v2, 2, 3, 6, 7);
  149. xxxx = f4shuffle(v1, v2, 0, 0, 4, 4);
  150. xxyy = f4shuffle(v1, v2, 0, 0, 5, 5);
  151. }
  152. x = +sqrt((+fround(f4extractLane(xyxy, 0)) * +fround(f4extractLane(xyxy, 0)))
  153. + (+fround(f4extractLane(xyxy, 1)) * +fround(f4extractLane(xyxy, 1)))
  154. + (+fround(f4extractLane(xyxy, 2)) * +fround(f4extractLane(xyxy, 2)))
  155. + (+fround(f4extractLane(xyxy, 3)) * +fround(f4extractLane(xyxy, 3))));
  156. y = +sqrt((+fround(f4extractLane(zwzw, 0)) * +fround(f4extractLane(zwzw, 0)))
  157. + (+fround(f4extractLane(zwzw, 1)) * +fround(f4extractLane(zwzw, 1)))
  158. + (+fround(f4extractLane(zwzw, 2)) * +fround(f4extractLane(zwzw, 2)))
  159. + (+fround(f4extractLane(zwzw, 3)) * +fround(f4extractLane(zwzw, 3))));
  160. z = +sqrt((+fround(f4extractLane(xxxx, 0)) * +fround(f4extractLane(xxxx, 0)))
  161. + (+fround(f4extractLane(xxxx, 1)) * +fround(f4extractLane(xxxx, 1)))
  162. + (+fround(f4extractLane(xxxx, 2)) * +fround(f4extractLane(xxxx, 2)))
  163. + (+fround(f4extractLane(xxxx, 3)) * +fround(f4extractLane(xxxx, 3))));
  164. w = +sqrt((+fround(f4extractLane(xxyy, 0)) * +fround(f4extractLane(xxyy, 0)))
  165. + (+fround(f4extractLane(xxyy, 1)) * +fround(f4extractLane(xxyy, 1)))
  166. + (+fround(f4extractLane(xxyy, 2)) * +fround(f4extractLane(xxyy, 2)))
  167. + (+fround(f4extractLane(xxyy, 3)) * +fround(f4extractLane(xxyy, 3))));
  168. return f4check(f4(fround(x), fround(y), fround(z), fround(w)));
  169. }
  170. function shuffle3() {
  171. var xyxy = f4(0.0, 0.0, 0.0, 0.0);
  172. var zwzw = f4(0.0, 0.0, 0.0, 0.0);
  173. var xxxx = f4(0.0, 0.0, 0.0, 0.0);
  174. var xxyy = f4(0.0, 0.0, 0.0, 0.0);
  175. var x = 0.0, y = 0.0, z = 0.0, w = 0.0;
  176. var v1 = f4(122.0, -0.0, 334.0, -9500.231);
  177. var loopIndex = 0;
  178. loopIndex = loopCOUNT | 0;
  179. do {
  180. xyxy = f4shuffle(f4add(v1, g2), v1, 0, 1, 4, 5);
  181. zwzw = f4shuffle(f4mul(v1, g2), g1, 2, 3, 6, 7);
  182. xxxx = f4shuffle(f4sub(v1, g2), v1, 0, 0, 4, 4);
  183. xxyy = f4shuffle(g2, v1, 0, 0, 5, 5);
  184. loopIndex = (loopIndex - 1) | 0;
  185. }
  186. while ((loopIndex | 0) > 0);
  187. x = +sqrt((+fround(f4extractLane(xyxy, 0)) * +fround(f4extractLane(xyxy, 0)))
  188. + (+fround(f4extractLane(xyxy, 1)) * +fround(f4extractLane(xyxy, 1)))
  189. + (+fround(f4extractLane(xyxy, 2)) * +fround(f4extractLane(xyxy, 2)))
  190. + (+fround(f4extractLane(xyxy, 3)) * +fround(f4extractLane(xyxy, 3))));
  191. y = +sqrt((+fround(f4extractLane(zwzw, 0)) * +fround(f4extractLane(zwzw, 0)))
  192. + (+fround(f4extractLane(zwzw, 1)) * +fround(f4extractLane(zwzw, 1)))
  193. + (+fround(f4extractLane(zwzw, 2)) * +fround(f4extractLane(zwzw, 2)))
  194. + (+fround(f4extractLane(zwzw, 3)) * +fround(f4extractLane(zwzw, 3))));
  195. z = +sqrt((+fround(f4extractLane(xxxx, 0)) * +fround(f4extractLane(xxxx, 0)))
  196. + (+fround(f4extractLane(xxxx, 1)) * +fround(f4extractLane(xxxx, 1)))
  197. + (+fround(f4extractLane(xxxx, 2)) * +fround(f4extractLane(xxxx, 2)))
  198. + (+fround(f4extractLane(xxxx, 3)) * +fround(f4extractLane(xxxx, 3))));
  199. w = +sqrt((+fround(f4extractLane(xxyy, 0)) * +fround(f4extractLane(xxyy, 0)))
  200. + (+fround(f4extractLane(xxyy, 1)) * +fround(f4extractLane(xxyy, 1)))
  201. + (+fround(f4extractLane(xxyy, 2)) * +fround(f4extractLane(xxyy, 2)))
  202. + (+fround(f4extractLane(xxyy, 3)) * +fround(f4extractLane(xxyy, 3))));
  203. return f4check(f4(fround(x), fround(y), fround(z), fround(w)));
  204. }
  205. return { func1: shuffle1, func2: shuffle2, func3: shuffle3 };
  206. }
  207. var m = asmModule(this, { g1: SIMD.Float32x4(9, 9, 9, 9), g2: SIMD.Int32x4(1, 2, 3, 4) });
  208. var ret1 = m.func1();
  209. var ret2 = m.func2();
  210. var ret3 = m.func3();
  211. print(typeof (ret1));
  212. print(ret1.toString());
  213. print(typeof (ret2));
  214. print(ret2.toString());
  215. print(typeof (ret3));
  216. print(ret3.toString());