2
0

testShift.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 equal(a, b) {
  6. if (a == b)
  7. print("Correct");
  8. else
  9. print(">> Fail!");
  10. }
  11. function testShiftleftByScalar() {
  12. print("Int32x4 shiftLeftByScalar");
  13. var a = SIMD.Int32x4(0x80000000, 0x7000000, 0xFFFFFFFF, 0x0);
  14. var b = SIMD.Int32x4.shiftLeftByScalar(a, 1)
  15. equal(0x0, SIMD.Int32x4.extractLane(b, 0));
  16. equal(0xE000000, SIMD.Int32x4.extractLane(b, 1));
  17. equal(-2, SIMD.Int32x4.extractLane(b, 2));
  18. equal(0x0, SIMD.Int32x4.extractLane(b, 3));
  19. var c = SIMD.Int32x4(1, 2, 3, 4);
  20. var d = SIMD.Int32x4.shiftLeftByScalar(c, 1)
  21. equal(2, SIMD.Int32x4.extractLane(d, 0));
  22. equal(4, SIMD.Int32x4.extractLane(d, 1));
  23. equal(6, SIMD.Int32x4.extractLane(d, 2));
  24. equal(8, SIMD.Int32x4.extractLane(d, 3));
  25. }
  26. function testShiftRightByScalar() {
  27. print("Int32x4 shiftRightByScalar");
  28. var a = SIMD.Int32x4(0x80000000, 0x7000000, 0xFFFFFFFF, 0x0);
  29. var b = SIMD.Int32x4.shiftRightByScalar(a, 1)
  30. equal(-1073741824, SIMD.Int32x4.extractLane(b, 0));
  31. equal(0x03800000, SIMD.Int32x4.extractLane(b, 1));
  32. equal(-1, SIMD.Int32x4.extractLane(b, 2));
  33. equal(0x0, SIMD.Int32x4.extractLane(b, 3));
  34. var c = SIMD.Int32x4(1, 2, 3, 4);
  35. var d = SIMD.Int32x4.shiftRightByScalar(c, 1)
  36. equal(0, SIMD.Int32x4.extractLane(d, 0));
  37. equal(1, SIMD.Int32x4.extractLane(d, 1));
  38. equal(1, SIMD.Int32x4.extractLane(d, 2));
  39. equal(2, SIMD.Int32x4.extractLane(d, 3));
  40. var c = SIMD.Int32x4(-1, -2, -3, -4);
  41. var d = SIMD.Int32x4.shiftRightByScalar(c, 1)
  42. equal(-1, SIMD.Int32x4.extractLane(d, 0));
  43. equal(-1, SIMD.Int32x4.extractLane(d, 1));
  44. equal(-2, SIMD.Int32x4.extractLane(d, 2));
  45. equal(-2, SIMD.Int32x4.extractLane(d, 3));
  46. }
  47. testShiftleftByScalar();
  48. testShiftleftByScalar();
  49. testShiftleftByScalar();
  50. testShiftleftByScalar();
  51. testShiftRightByScalar();
  52. testShiftRightByScalar();
  53. testShiftRightByScalar();
  54. testShiftRightByScalar();