2
0

testShuffle.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 testSwizzle() {
  16. print("Int32x4 Shuffle");
  17. var a = SIMD.Int32x4(1, 2, 3, 4);
  18. var k = true;
  19. var xyxy = SIMD.Int32x4.swizzle(a, 0, ["1"], false, true);
  20. var zwzw = SIMD.Int32x4.swizzle(a, 2, "3", 2, [3]);
  21. var xxxx = SIMD.Int32x4.swizzle(a, 0, 0, 0, 0);
  22. equal(1, SIMD.Int32x4.extractLane(xyxy, 0));
  23. equal(2, SIMD.Int32x4.extractLane(xyxy, 1));
  24. equal(1, SIMD.Int32x4.extractLane(xyxy, 2));
  25. equal(2, SIMD.Int32x4.extractLane(xyxy, 3));
  26. equal(3, SIMD.Int32x4.extractLane(zwzw, 0));
  27. equal(4, SIMD.Int32x4.extractLane(zwzw, 1));
  28. equal(3, SIMD.Int32x4.extractLane(zwzw, 2));
  29. equal(4, SIMD.Int32x4.extractLane(zwzw, 3));
  30. equal(1, SIMD.Int32x4.extractLane(xxxx, 0));
  31. equal(1, SIMD.Int32x4.extractLane(xxxx, 1));
  32. equal(1, SIMD.Int32x4.extractLane(xxxx, 2));
  33. equal(1, SIMD.Int32x4.extractLane(xxxx, 3));
  34. }
  35. function testShuffle() {
  36. print("Int32x4 ShuffleMix");
  37. var a = SIMD.Int32x4(1, 2, 3, 4);
  38. var b = SIMD.Int32x4(5, 6, 7, 8);
  39. var xyxy = SIMD.Int32x4.shuffle(a, b, false, true, "4", [5]);
  40. var zwzw = SIMD.Int32x4.shuffle(a, b, 2, 3, 6, 7);
  41. var xxxx = SIMD.Int32x4.shuffle(a, b, 0, 0, 4, 4);
  42. equal(1, SIMD.Int32x4.extractLane(xyxy, 0));
  43. equal(2, SIMD.Int32x4.extractLane(xyxy, 1));
  44. equal(5, SIMD.Int32x4.extractLane(xyxy, 2));
  45. equal(6, SIMD.Int32x4.extractLane(xyxy, 3));
  46. equal(3, SIMD.Int32x4.extractLane(zwzw, 0));
  47. equal(4, SIMD.Int32x4.extractLane(zwzw, 1));
  48. equal(7, SIMD.Int32x4.extractLane(zwzw, 2));
  49. equal(8, SIMD.Int32x4.extractLane(zwzw, 3));
  50. equal(1, SIMD.Int32x4.extractLane(xxxx, 0));
  51. equal(1, SIMD.Int32x4.extractLane(xxxx, 1));
  52. equal(5, SIMD.Int32x4.extractLane(xxxx, 2));
  53. equal(5, SIMD.Int32x4.extractLane(xxxx, 3));
  54. }
  55. testSwizzle();
  56. testSwizzle();
  57. testSwizzle();
  58. testSwizzle();
  59. testSwizzle();
  60. testSwizzle();
  61. testSwizzle();
  62. testSwizzle();
  63. testShuffle();
  64. testShuffle();
  65. testShuffle();
  66. testShuffle();
  67. testShuffle();
  68. testShuffle();
  69. testShuffle();
  70. testShuffle();