testMinMax.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 testMin() {
  16. print("Float32x4 Min");
  17. var a = SIMD.Float32x4(-20.0, 10.0, 30.0, 0.5);
  18. var lower = SIMD.Float32x4(2.0, 1.0, 50.0, 0.0);
  19. var c = SIMD.Float32x4.min(a, lower);
  20. equal(-20.0, SIMD.Float32x4.extractLane(c, 0));
  21. equal(1.0, SIMD.Float32x4.extractLane(c, 1));
  22. equal(30.0, SIMD.Float32x4.extractLane(c, 2));
  23. equal(0.0, SIMD.Float32x4.extractLane(c, 3));
  24. }
  25. function testMax() {
  26. print("Float32x4 Max");
  27. var a = SIMD.Float32x4(-20.0, 10.0, 30.0, 0.5);
  28. var upper = SIMD.Float32x4(2.5, 5.0, 55.0, 1.0);
  29. var c = SIMD.Float32x4.max(a, upper);
  30. equal(2.5, SIMD.Float32x4.extractLane(c, 0));
  31. equal(10.0, SIMD.Float32x4.extractLane(c, 1));
  32. equal(55.0, SIMD.Float32x4.extractLane(c, 2));
  33. equal(1.0, SIMD.Float32x4.extractLane(c, 3));
  34. }
  35. testMin();
  36. testMin();
  37. testMin();
  38. testMin();
  39. testMin();
  40. testMin();
  41. testMin();
  42. testMax();
  43. testMax();
  44. testMax();
  45. testMax();
  46. testMax();
  47. testMax();
  48. testMax();
  49. testMax();