testConstructor.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 b4 = stdlib.SIMD.Bool32x4;
  9. var i4 = stdlib.SIMD.Int32x4;
  10. var i4lessThan = i4.lessThan;
  11. var b4check = b4.check;
  12. var b4splat = b4.splat;
  13. var b4and = b4.and;
  14. var b4xor = b4.xor;
  15. var b4extractLane = b4.extractLane;
  16. var b4replaceLane = b4.replaceLane;
  17. var globImportb4 = b4check(imports.g1);
  18. var b4g1 = b4(0, 0, 0, 0);
  19. var loopCOUNT = 5;
  20. function testConstructor() {
  21. var a = b4(0, 0, 0, 0);
  22. var b = b4(0, 0, 0, 0);
  23. var i1 = i4(1, 0, 1, 8);
  24. var i2 = i4(12,13,0, 1);
  25. var loopIndex = 0;
  26. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  27. loopIndex = (loopIndex + 1) | 0;
  28. a = b4(10*10,0,-1,loopIndex);
  29. b = i4lessThan(i1,i2);
  30. a = b4and(a, b);
  31. }
  32. return b4check(a);
  33. }
  34. function testSplat() {
  35. var a = b4(0, 0, 0, 0);
  36. var b = b4(0, 0, 0, 0);
  37. var loopIndex = 0;
  38. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  39. loopIndex = (loopIndex + 1) | 0;
  40. a = b4splat(3);
  41. b = b4splat((3-3));
  42. a = b4xor(a, b);
  43. }
  44. return b4check(a);
  45. }
  46. function testLaneAccess() {
  47. var a = b4(5, 0, 1, 0);
  48. var result = b4(0, 0, 0, 0);
  49. var m = 0;
  50. var n = 0;
  51. var o = 0;
  52. var p = 0;
  53. var loopIndex = 0;
  54. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  55. loopIndex = (loopIndex + 1) | 0;
  56. m = b4extractLane(a, 0)|0;
  57. n = b4extractLane(a, 1)|0;
  58. o = b4extractLane(a, 2)|0;
  59. p = b4extractLane(a, 3)|0;
  60. result = b4replaceLane(a, 0, p);
  61. result = b4replaceLane(result, 1, o);
  62. result = b4replaceLane(result, 2, n);
  63. result = b4replaceLane(result, 3, m);
  64. }
  65. return b4check(result);
  66. }
  67. //Validation will fail with the bug
  68. function retValueCoercionBug()
  69. {
  70. var ret1 = 0;
  71. var a = b4(1,2,3,4);
  72. ret1 = (b4extractLane(a, 0))|0;
  73. }
  74. return {testConstructor:testConstructor,
  75. testSplat:testSplat,
  76. testLaneAccess: testLaneAccess};
  77. }
  78. var m = asmModule(this, {g1:SIMD.Bool32x4(1, 0, 1, 1)});
  79. equalSimd([true, false, false, false], m.testConstructor(), SIMD.Bool32x4, "testConstructor");
  80. equalSimd([true, true, true, true], m.testSplat(), SIMD.Bool32x4, "testSplat");
  81. equalSimd([false, true, false, true], m.testLaneAccess(), SIMD.Bool32x4, "testLaneAccess");
  82. // WScript.Echo((m.testConstructor().toString()));
  83. // WScript.Echo((m.testSplat().toString()));
  84. // WScript.Echo((m.testLaneAccess().toString()));
  85. print("PASS");