testConstructor.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 testConstructor() {
  13. print("Constructor");
  14. equal(SIMD.Int8x16, undefined);
  15. equal(SIMD.Int8x16(1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4), undefined);
  16. var a = SIMD.Int8x16("2014/10/10", -0, 127, 126, "2014/10/10", -0, 127, 126, "2014/10/10", -0, 127, 126, "2014/10/10", -0, 127, 126);
  17. print("a.1: " + SIMD.Int8x16.extractLane(a, 0));
  18. print("a.2: " + SIMD.Int8x16.extractLane(a, 1));
  19. print("a.3: " + SIMD.Int8x16.extractLane(a, 2));
  20. print("a.4: " + SIMD.Int8x16.extractLane(a, 3));
  21. print("a.5: " + SIMD.Int8x16.extractLane(a, 4));
  22. print("a.6: " + SIMD.Int8x16.extractLane(a, 5));
  23. print("a.7: " + SIMD.Int8x16.extractLane(a, 6));
  24. print("a.8: " + SIMD.Int8x16.extractLane(a, 7));
  25. print("a.9: " + SIMD.Int8x16.extractLane(a, 8));
  26. print("a.10: " + SIMD.Int8x16.extractLane(a, 9));
  27. print("a.11: " + SIMD.Int8x16.extractLane(a, 10));
  28. print("a.12: " + SIMD.Int8x16.extractLane(a, 11));
  29. print("a.13: " + SIMD.Int8x16.extractLane(a, 12));
  30. print("a.14: " + SIMD.Int8x16.extractLane(a, 13));
  31. print("a.15: " + SIMD.Int8x16.extractLane(a, 14));
  32. print("a.16: " + SIMD.Int8x16.extractLane(a, 15));
  33. var b = SIMD.Int8x16(4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1);
  34. var c = SIMD.Int8x16.check(b);
  35. equal(c, b);
  36. equal(SIMD.Int8x16.extractLane(c, 0), SIMD.Int8x16.extractLane(b, 0));
  37. equal(SIMD.Int8x16.extractLane(c, 1), SIMD.Int8x16.extractLane(b, 1));
  38. equal(SIMD.Int8x16.extractLane(c, 2), SIMD.Int8x16.extractLane(b, 2));
  39. equal(SIMD.Int8x16.extractLane(c, 3), SIMD.Int8x16.extractLane(b, 3));
  40. equal(SIMD.Int8x16.extractLane(c, 4), SIMD.Int8x16.extractLane(b, 4));
  41. equal(SIMD.Int8x16.extractLane(c, 5), SIMD.Int8x16.extractLane(b, 5));
  42. equal(SIMD.Int8x16.extractLane(c, 6), SIMD.Int8x16.extractLane(b, 6));
  43. equal(SIMD.Int8x16.extractLane(c, 7), SIMD.Int8x16.extractLane(b, 7));
  44. equal(SIMD.Int8x16.extractLane(c, 8), SIMD.Int8x16.extractLane(b, 8));
  45. equal(SIMD.Int8x16.extractLane(c, 9), SIMD.Int8x16.extractLane(b, 9));
  46. equal(SIMD.Int8x16.extractLane(c, 10), SIMD.Int8x16.extractLane(b, 10));
  47. equal(SIMD.Int8x16.extractLane(c, 11), SIMD.Int8x16.extractLane(b, 11));
  48. equal(SIMD.Int8x16.extractLane(c, 12), SIMD.Int8x16.extractLane(b, 12));
  49. equal(SIMD.Int8x16.extractLane(c, 13), SIMD.Int8x16.extractLane(b, 13));
  50. equal(SIMD.Int8x16.extractLane(c, 14), SIMD.Int8x16.extractLane(b, 14));
  51. equal(SIMD.Int8x16.extractLane(c, 15), SIMD.Int8x16.extractLane(b, 15));
  52. try {
  53. var m = SIMD.Int8x16.check(1)
  54. }
  55. catch (e) {
  56. print("Type Error");
  57. }
  58. }
  59. function testFromFloat32x4Bits() {
  60. var m = SIMD.float32x4.fromInt8x16Bits(SIMD.Int8x16(0x3F800000, 0x40000000, 0x40400000, 0x40800000));
  61. var n = SIMD.Int8x16.fromFloat32x4Bits(m);
  62. print("FromFloat32x4Bits");
  63. equal(1, n.x);
  64. equal(2, n.y);
  65. equal(3, n.z);
  66. equal(4, n.w);
  67. var a = SIMD.float32x4(1.0, 2.0, 3.0, 4.0);
  68. var b = SIMD.Int8x16.fromFloat32x4Bits(a);
  69. equal(0x3F800000, b.x);
  70. equal(0x40000000, b.y);
  71. equal(0x40400000, b.z);
  72. equal(0x40800000, b.w);
  73. }
  74. testConstructor();
  75. testConstructor();
  76. testConstructor();
  77. testConstructor();
  78. testConstructor();
  79. testConstructor();