testConstructor.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 testConstructor() {
  16. print("Constructor");
  17. print(SIMD.Float32x4 !== undefined);
  18. equal('function', typeof SIMD.Float32x4);
  19. print(SIMD.Float32x4(1.0, 2.0, 3.0, 4.0) !== undefined);
  20. var a = SIMD.Float32x4(1.0, 2.0, 3.0, 4.0);
  21. var b = SIMD.Float32x4.check(a);
  22. equal(a, b);
  23. try {
  24. var a = SIMD.Float32x4.check(1)
  25. }
  26. catch (e) {
  27. print("Type Error");
  28. }
  29. }
  30. function testFromInt32x4() {
  31. var m = SIMD.Int32x4(1, 2, 3, 4);
  32. var n = SIMD.Float32x4.fromInt32x4(m);
  33. print("FromInt32x4");
  34. equal(1.0, SIMD.Float32x4.extractLane(n, 0));
  35. equal(2.0, SIMD.Float32x4.extractLane(n, 1));
  36. equal(3.0, SIMD.Float32x4.extractLane(n, 2));
  37. equal(4.0, SIMD.Float32x4.extractLane(n, 3));
  38. }
  39. function testFromInt32x4Bits() {
  40. var m = SIMD.Int32x4(0x3F800000, 0x40000000, 0x40400000, 0x40800000);
  41. var n = SIMD.Float32x4.fromInt32x4Bits(m);
  42. print("FromInt32x4Bits");
  43. equal(1.0, SIMD.Float32x4.extractLane(n, 0));
  44. equal(2.0, SIMD.Float32x4.extractLane(n, 1));
  45. equal(3.0, SIMD.Float32x4.extractLane(n, 2));
  46. equal(4.0, SIMD.Float32x4.extractLane(n, 3));
  47. }
  48. testConstructor();
  49. testConstructor();
  50. testConstructor();
  51. testConstructor();
  52. testConstructor();
  53. testConstructor();
  54. testConstructor();
  55. testConstructor();
  56. testFromInt32x4();
  57. testFromInt32x4();
  58. testFromInt32x4();
  59. testFromInt32x4();
  60. testFromInt32x4();
  61. testFromInt32x4();
  62. testFromInt32x4();
  63. testFromInt32x4();
  64. testFromInt32x4Bits();
  65. testFromInt32x4Bits();
  66. testFromInt32x4Bits();
  67. testFromInt32x4Bits();
  68. testFromInt32x4Bits();
  69. testFromInt32x4Bits();
  70. testFromInt32x4Bits();