testFields.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. var sf = SIMD.Float32x4(1.35, -2.0, 3.4, 0.0);
  7. function testExtractLane() {
  8. equal(1.35,SIMD.Float32x4.extractLane(sf, 0));
  9. equal(-2.0, SIMD.Float32x4.extractLane(sf, 1));
  10. equal(3.4, SIMD.Float32x4.extractLane(sf, 2));
  11. equal(0.0, SIMD.Float32x4.extractLane(sf, 3));
  12. }
  13. function testReplaceLane() {
  14. var v = SIMD.Float32x4.replaceLane(sf, 0, 10.2)
  15. equalSimd([10.199999809265136, -2, 3.4000000953674316, 0], v, SIMD.Float32x4, "Replace Lane");
  16. v = SIMD.Float32x4.replaceLane(sf, 1, 12.3)
  17. equalSimd([1.350000023841858, 12.300000190734863, 3.4000000953674316, 0], v, SIMD.Float32x4, "Replace Lane");
  18. v = SIMD.Float32x4.replaceLane(sf, 2, -30.2)
  19. equalSimd([1.350000023841858, -2, -30.200000762939453, 0], v, SIMD.Float32x4, "Replace Lane");
  20. v = SIMD.Float32x4.replaceLane(sf, 3, 0.0)
  21. equalSimd([1.350000023841858, -2, 3.4000000953674316, 0], v, SIMD.Float32x4, "Replace Lane");
  22. }
  23. function testScalarGetters() {
  24. var a = SIMD.Float32x4(1.0, 2.0, 3.0, 4.0);
  25. equal(1.0, SIMD.Float32x4.extractLane(a, 0));
  26. equal(2.0, SIMD.Float32x4.extractLane(a, 1));
  27. equal(3.0, SIMD.Float32x4.extractLane(a, 2));
  28. equal(4.0, SIMD.Float32x4.extractLane(a, 3));
  29. }
  30. testScalarGetters();
  31. testScalarGetters();
  32. testScalarGetters();
  33. testExtractLane();
  34. testReplaceLane();
  35. print("PASS");