testSplat.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 i8splat = i8.splat;
  11. var gval = 20;
  12. var loopCOUNT = 3;
  13. function splat1()
  14. {
  15. var a = i8(0, 0, 0, 0, 0, 0, 0, 0);
  16. var loopIndex = 0;
  17. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  18. a = i8splat(100);
  19. loopIndex = (loopIndex + 1) | 0;
  20. }
  21. return i8check(a);
  22. }
  23. function splat2()
  24. {
  25. var a = i8(0, 0, 0, 0, 0, 0, 0, 0);
  26. var loopIndex = 0;
  27. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  28. a = i8splat(value() | 0);
  29. loopIndex = (loopIndex + 1) | 0;
  30. }
  31. return i8check(a);
  32. }
  33. function splat3()
  34. {
  35. var a = i8(0, 0, 0, 0, 0, 0, 0, 0);
  36. var loopIndex = 0;
  37. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  38. a = i8splat(gval);
  39. loopIndex = (loopIndex + 1) | 0;
  40. }
  41. return i8check(a);
  42. }
  43. function value()
  44. {
  45. var ret = 1;
  46. var i = 0;
  47. for (i = 0; (i | 0) < 100; i = (i + 1) | 0)
  48. ret = (ret + i) | 0;
  49. return ret | 0;
  50. }
  51. return {func1:splat1, func2:splat2, func3:splat3};
  52. }
  53. var m = asmModule(this, {g1:SIMD.Int16x8(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)});
  54. var ret1 = m.func1(SIMD.Int16x8(1, 2, 3, 4, 5, 6, 7, 8), SIMD.Float32x4(1, 2, 3, 4)/*, SIMD.Float64x2(1, 2, 3, 4)*/);
  55. var ret2 = m.func2(SIMD.Int16x8(1, 2, 3, 4, 5, 6, 7, 8), SIMD.Float32x4(1, 2, 3, 4)/*, SIMD.Float64x2(1, 2, 3, 4)*/);
  56. var ret3 = m.func3(SIMD.Int16x8(1, 2, 3, 4, 5, 6, 7, 8), SIMD.Float32x4(1, 2, 3, 4)/*, SIMD.Float64x2(1, 2, 3, 4)*/);
  57. equalSimd([100, 100, 100, 100, 100, 100, 100, 100], ret1, SIMD.Int16x8, "");
  58. equalSimd([4951, 4951, 4951, 4951, 4951, 4951, 4951, 4951], ret2, SIMD.Int16x8, "");
  59. equalSimd([20, 20, 20, 20, 20, 20, 20, 20], ret3, SIMD.Int16x8, "");
  60. print("PASS");