testMulDiv.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. }
  12. function testMul() {
  13. print("Float32x4 mul");
  14. var a = SIMD.Float32x4(4.0, 3.0, 2.0, 1.0);
  15. var b = SIMD.Float32x4(10.0, 20.0, 30.0, 40.0);
  16. var c = SIMD.Float32x4.mul(a, b);
  17. equal(40.0, SIMD.Float32x4.extractLane(c, 0));
  18. equal(60.0, SIMD.Float32x4.extractLane(c, 1));
  19. equal(60.0, SIMD.Float32x4.extractLane(c, 2));
  20. equal(40.0, SIMD.Float32x4.extractLane(c, 3));
  21. }
  22. function testDiv() {
  23. print("Float32x4 div");
  24. var a = SIMD.Float32x4(4.0, 9.0, 8.0, 1.0);
  25. var b = SIMD.Float32x4(2.0, 3.0, 1.0, 0.5);
  26. var c = SIMD.Float32x4.div(a, b);
  27. equal(2.0, SIMD.Float32x4.extractLane(c, 0));
  28. equal(3.0, SIMD.Float32x4.extractLane(c, 1));
  29. equal(8.0, SIMD.Float32x4.extractLane(c, 2));
  30. equal(2.0, SIMD.Float32x4.extractLane(c, 3));
  31. }
  32. testMul();
  33. testMul();
  34. testMul();
  35. testMul();
  36. testMul();
  37. testMul();
  38. testMul();
  39. testMul();
  40. testDiv();
  41. testDiv();
  42. testDiv();
  43. testDiv();
  44. testDiv();
  45. testDiv();
  46. testDiv();
  47. testDiv();