testAddSub.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. {
  8. print("Correct");
  9. }
  10. else
  11. {
  12. print(">> Fail!");
  13. }
  14. }
  15. function testAdd() {
  16. print("Float32x4 add");
  17. var a = SIMD.Float32x4(4.0, 3.0, 2.0, 1.0);
  18. var b = SIMD.Float32x4(10.0, 20.0, 30.0, 40.0);
  19. var c = SIMD.Float32x4.add(a, b);
  20. equal(14.0, SIMD.Float32x4.extractLane(c, 0));
  21. equal(23.0, SIMD.Float32x4.extractLane(c, 1));
  22. equal(32.0, SIMD.Float32x4.extractLane(c, 2));
  23. equal(41.0, SIMD.Float32x4.extractLane(c, 3));
  24. }
  25. function testSub() {
  26. print("Float32x4 sub");
  27. var a = SIMD.Float32x4(4.0, 3.0, 2.0, 1.0);
  28. var b = SIMD.Float32x4(10.0, 20.0, 30.0, 40.0);
  29. var c = SIMD.Float32x4.sub(a, b);
  30. equal(-6.0, SIMD.Float32x4.extractLane(c, 0));
  31. equal(-17.0, SIMD.Float32x4.extractLane(c, 1));
  32. equal(-28.0, SIMD.Float32x4.extractLane(c, 2));
  33. equal(-39.0, SIMD.Float32x4.extractLane(c, 3));
  34. }
  35. testAdd();
  36. testAdd();
  37. testAdd();
  38. testAdd();
  39. testAdd();
  40. testAdd();
  41. testAdd();
  42. testSub();
  43. testSub();
  44. testSub();
  45. testSub();
  46. testSub();
  47. testSub();
  48. testSub();