testBitwise.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 equalNaN(a) {
  16. if (isNaN(a))
  17. {
  18. print("Correct");
  19. }
  20. else
  21. {
  22. print(">> Fail!");
  23. }
  24. }
  25. function testOr() {
  26. print("Float32x4 Or");
  27. var a = SIMD.Float32x4(4.0, 3.0, 2.0, 1.0);
  28. var b = SIMD.Float32x4(10.0, 20.0, 30.0, 40.0);
  29. var c = SIMD.Float32x4.or(a, b);
  30. equal(20, SIMD.Float32x4.extractLane(c, 0));
  31. equal(28, SIMD.Float32x4.extractLane(c, 1));
  32. equal(30, SIMD.Float32x4.extractLane(c, 2));
  33. equalNaN(SIMD.Float32x4.extractLane(c, 3));
  34. }
  35. function testNot() {
  36. print("Float32x4 Not");
  37. var a = SIMD.Float32x4(4.0, 3.0, 2.0, 1.0);
  38. var b = SIMD.Float32x4(10.0, 20.0, 30.0, 40.0);
  39. var c = SIMD.Float32x4.not(a, b);
  40. equal(-0.9999999403953552, SIMD.Float32x4.extractLane(c, 0));
  41. equal(-1.4999998807907104, SIMD.Float32x4.extractLane(c, 1));
  42. equal(-1.9999998807907104, SIMD.Float32x4.extractLane(c, 2));
  43. equal(-3.999999761581421, SIMD.Float32x4.extractLane(c, 3));
  44. }
  45. function testAnd() {
  46. print("Float32x4 And");
  47. var a = SIMD.Float32x4(4.0, 3.0, 2.0, 1.0);
  48. var b = SIMD.Float32x4(10.0, 20.0, 30.0, 40.0);
  49. var c = SIMD.Float32x4.and(a, b);
  50. equal(2, SIMD.Float32x4.extractLane(c, 0));
  51. equal(2, SIMD.Float32x4.extractLane(c, 1));
  52. equal(2, SIMD.Float32x4.extractLane(c, 2));
  53. equal(9.4039548065783e-38, SIMD.Float32x4.extractLane(c, 3));
  54. }
  55. function testXor() {
  56. print("Float32x4 Xor");
  57. var a = SIMD.Float32x4(4.0, 3.0, 2.0, 1.0);
  58. var b = SIMD.Float32x4(10.0, 20.0, 30.0, 40.0);
  59. var c = SIMD.Float32x4.xor(a, b);
  60. equal(5.877471754111438e-38, SIMD.Float32x4.extractLane(c, 0));
  61. equal(8.228460455756013e-38, SIMD.Float32x4.extractLane(c, 1));
  62. equal(8.816207631167156e-38, SIMD.Float32x4.extractLane(c, 2));
  63. equal(2.6584559915698317e+37, SIMD.Float32x4.extractLane(c, 3));
  64. }
  65. testOr();
  66. testOr();
  67. testOr();
  68. testOr();
  69. testOr();
  70. testOr();
  71. testOr();
  72. testOr();
  73. testXor();
  74. testXor();
  75. testXor();
  76. testXor();
  77. testXor();
  78. testXor();
  79. testXor();
  80. testXor();
  81. testAnd();
  82. testAnd();
  83. testAnd();
  84. testAnd();
  85. testAnd();
  86. testAnd();
  87. testAnd();
  88. testAnd();
  89. testNot();
  90. testNot();
  91. testNot();
  92. testNot();
  93. testNot();
  94. testNot();
  95. testNot();
  96. testNot();