testAddSub.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 testAdd() {
  7. var a = SIMD.Int32x4(0xFFFFFFFF, 0xFFFFFFFF, 0x7fffffff, 0x0);
  8. var b = SIMD.Int32x4(0x1, 0xFFFFFFFF, 0x1, 0xFFFFFFFF);
  9. var c = SIMD.Int32x4.add(a, b);
  10. equal(0x0, SIMD.Int32x4.extractLane(c, 0));
  11. equal(-2, SIMD.Int32x4.extractLane(c, 1));
  12. equal(-0x80000000, SIMD.Int32x4.extractLane(c, 2));
  13. equal(-1, SIMD.Int32x4.extractLane(c, 3));
  14. var m = SIMD.Int32x4(4, 3, 2, 1);
  15. var n = SIMD.Int32x4(10, 20, 30, 40);
  16. var f = SIMD.Int32x4.add(m, n);
  17. equal(14, SIMD.Int32x4.extractLane(f, 0));
  18. equal(23, SIMD.Int32x4.extractLane(f, 1));
  19. equal(32, SIMD.Int32x4.extractLane(f, 2));
  20. equal(41, SIMD.Int32x4.extractLane(f, 3));
  21. }
  22. function testSub() {
  23. var a = SIMD.Int32x4(0xFFFFFFFF, 0xFFFFFFFF, 0x80000000, 0x0);
  24. var b = SIMD.Int32x4(0x1, 0xFFFFFFFF, 0x1, 0xFFFFFFFF);
  25. var c = SIMD.Int32x4.sub(a, b);
  26. equal(-2, SIMD.Int32x4.extractLane(c, 0));
  27. equal(0x0, SIMD.Int32x4.extractLane(c, 1));
  28. equal(0x7FFFFFFF, SIMD.Int32x4.extractLane(c, 2));
  29. equal(0x1, SIMD.Int32x4.extractLane(c, 3));
  30. var d = SIMD.Int32x4(4, 3, 2, 1);
  31. var e = SIMD.Int32x4(10, 20, 30, 40);
  32. var f = SIMD.Int32x4.sub(d, e);
  33. equal(-6, SIMD.Int32x4.extractLane(f, 0));
  34. equal(-17, SIMD.Int32x4.extractLane(f, 1));
  35. equal(-28, SIMD.Int32x4.extractLane(f, 2));
  36. equal(-39, SIMD.Int32x4.extractLane(f, 3));
  37. }
  38. testAdd();
  39. testAdd();
  40. testAdd();
  41. testAdd();
  42. testAdd();
  43. testAdd();
  44. testAdd();
  45. testSub();
  46. testSub();
  47. testSub();
  48. testSub();
  49. testSub();
  50. testSub();
  51. testSub();
  52. print("PASS");