testFields.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. var si = SIMD.Int32x4(10, -20, 30, 0);
  12. function testScalarGetters() {
  13. print('Int32x4 scalar getters');
  14. var a = SIMD.Int32x4(1, 2, 3, 4);
  15. equal(1, SIMD.Int32x4.extractLane(a, 0));
  16. equal(2, SIMD.Int32x4.extractLane(a, 1));
  17. equal(3, SIMD.Int32x4.extractLane(a, 2));
  18. equal(4, SIMD.Int32x4.extractLane(a, 3));
  19. }
  20. function testExtractLane1() {
  21. print("I4 ExtractLane");
  22. print(typeof si);
  23. print(si.toString());
  24. print(typeof SIMD.Int32x4.extractLane(si, 0));
  25. print(SIMD.Int32x4.extractLane(si, 0).toString());
  26. print(typeof SIMD.Int32x4.extractLane(si, 1))
  27. print(SIMD.Int32x4.extractLane(si, 1).toString());
  28. print(typeof SIMD.Int32x4.extractLane(si, 2));
  29. print(SIMD.Int32x4.extractLane(si, 2).toString());
  30. print(typeof SIMD.Int32x4.extractLane(si, 3));
  31. print(SIMD.Int32x4.extractLane(si, 3).toString());
  32. }
  33. function testReplaceLane1() {
  34. print("I4 ReplaceLane");
  35. var v = SIMD.Int32x4.replaceLane(si, 0, 10)
  36. print(v.toString());
  37. v = SIMD.Int32x4.replaceLane(si, 1, 12)
  38. print(v.toString());
  39. v = SIMD.Int32x4.replaceLane(si, 2, -30)
  40. print(v.toString());
  41. v = SIMD.Int32x4.replaceLane(si, 3, 0)
  42. print(v.toString());
  43. }
  44. testScalarGetters();
  45. testScalarGetters();
  46. testScalarGetters();
  47. testScalarGetters();
  48. testScalarGetters();
  49. testScalarGetters();
  50. testScalarGetters();
  51. testScalarGetters();
  52. testExtractLane1();
  53. print();
  54. testReplaceLane1();
  55. print();