testShift.js 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. this.WScript.LoadScriptFile("..\\UnitTestFramework\\SimdJsHelpers.js");
  6. function testShiftleftByScalar() {
  7. var a = SIMD.Int32x4(0x80000000, 0x7000000, 0xFFFFFFFF, 0x0);
  8. var b = SIMD.Int32x4.shiftLeftByScalar(a, 1)
  9. equal(0x0, SIMD.Int32x4.extractLane(b, 0));
  10. equal(0xE000000, SIMD.Int32x4.extractLane(b, 1));
  11. equal(-2, SIMD.Int32x4.extractLane(b, 2));
  12. equal(0x0, SIMD.Int32x4.extractLane(b, 3));
  13. var b = SIMD.Int32x4.shiftLeftByScalar(a, 33)
  14. equal(0x0, SIMD.Int32x4.extractLane(b, 0));
  15. equal(0xE000000, SIMD.Int32x4.extractLane(b, 1));
  16. equal(-2, SIMD.Int32x4.extractLane(b, 2));
  17. equal(0x0, SIMD.Int32x4.extractLane(b, 3));
  18. var b = SIMD.Int32x4.shiftLeftByScalar(a, 1)
  19. equal(0x0, SIMD.Int32x4.extractLane(b, 0));
  20. equal(0xE000000, SIMD.Int32x4.extractLane(b, 1));
  21. equal(-2, SIMD.Int32x4.extractLane(b, 2));
  22. equal(0x0, SIMD.Int32x4.extractLane(b, 3));
  23. var c = SIMD.Int32x4(1, 2, 3, 4);
  24. var d = SIMD.Int32x4.shiftLeftByScalar(c, 1)
  25. equal(2, SIMD.Int32x4.extractLane(d, 0));
  26. equal(4, SIMD.Int32x4.extractLane(d, 1));
  27. equal(6, SIMD.Int32x4.extractLane(d, 2));
  28. equal(8, SIMD.Int32x4.extractLane(d, 3));
  29. var c = SIMD.Int32x4(1, 2, 3, 4);
  30. var d = SIMD.Int32x4.shiftLeftByScalar(c, 33)
  31. equal(2, SIMD.Int32x4.extractLane(d, 0));
  32. equal(4, SIMD.Int32x4.extractLane(d, 1));
  33. equal(6, SIMD.Int32x4.extractLane(d, 2));
  34. equal(8, SIMD.Int32x4.extractLane(d, 3));
  35. }
  36. function testShiftRightByScalar() {
  37. var a = SIMD.Int32x4(0x80000000, 0x7000000, 0xFFFFFFFF, 0x0);
  38. var b = SIMD.Int32x4.shiftRightByScalar(a, 1)
  39. equal(-1073741824, SIMD.Int32x4.extractLane(b, 0));
  40. equal(0x03800000, SIMD.Int32x4.extractLane(b, 1));
  41. equal(-1, SIMD.Int32x4.extractLane(b, 2));
  42. equal(0x0, SIMD.Int32x4.extractLane(b, 3));
  43. var b = SIMD.Int32x4.shiftRightByScalar(a, 33)
  44. equal(-1073741824, SIMD.Int32x4.extractLane(b, 0));
  45. equal(0x03800000, SIMD.Int32x4.extractLane(b, 1));
  46. equal(-1, SIMD.Int32x4.extractLane(b, 2));
  47. equal(0x0, SIMD.Int32x4.extractLane(b, 3));
  48. var c = SIMD.Int32x4(1, 2, 3, 4);
  49. var d = SIMD.Int32x4.shiftRightByScalar(c, 1)
  50. equal(0, SIMD.Int32x4.extractLane(d, 0));
  51. equal(1, SIMD.Int32x4.extractLane(d, 1));
  52. equal(1, SIMD.Int32x4.extractLane(d, 2));
  53. equal(2, SIMD.Int32x4.extractLane(d, 3));
  54. var d = SIMD.Int32x4.shiftRightByScalar(c, 33)
  55. equal(0, SIMD.Int32x4.extractLane(d, 0));
  56. equal(1, SIMD.Int32x4.extractLane(d, 1));
  57. equal(1, SIMD.Int32x4.extractLane(d, 2));
  58. equal(2, SIMD.Int32x4.extractLane(d, 3));
  59. var c = SIMD.Int32x4(-1, -2, -3, -4);
  60. var d = SIMD.Int32x4.shiftRightByScalar(c, 1)
  61. equal(-1, SIMD.Int32x4.extractLane(d, 0));
  62. equal(-1, SIMD.Int32x4.extractLane(d, 1));
  63. equal(-2, SIMD.Int32x4.extractLane(d, 2));
  64. equal(-2, SIMD.Int32x4.extractLane(d, 3));
  65. var c = SIMD.Int32x4(-1, -2, -3, -4);
  66. var d = SIMD.Int32x4.shiftRightByScalar(c, 65)
  67. equal(-1, SIMD.Int32x4.extractLane(d, 0));
  68. equal(-1, SIMD.Int32x4.extractLane(d, 1));
  69. equal(-2, SIMD.Int32x4.extractLane(d, 2));
  70. equal(-2, SIMD.Int32x4.extractLane(d, 3));
  71. }
  72. testShiftleftByScalar();
  73. testShiftleftByScalar();
  74. testShiftleftByScalar();
  75. testShiftleftByScalar();
  76. testShiftRightByScalar();
  77. testShiftRightByScalar();
  78. testShiftRightByScalar();
  79. testShiftRightByScalar();
  80. WScript.Echo("PASS");