testBitwise.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. this.WScript.LoadScriptFile("..\\UnitTestFramework\\SimdJsHelpers.js");
  6. function asmModule(stdlib, imports) {
  7. "use asm";
  8. var b4 = stdlib.SIMD.Bool32x4;
  9. var b4check = b4.check;
  10. var b4and = b4.and;
  11. var b4or = b4.or;
  12. var b4not = b4.not;
  13. var b4xor = b4.xor;
  14. var globImportb4 = b4check(imports.g1);
  15. var b4g1 = b4(1,1,1,1);
  16. var loopCOUNT = 5;
  17. function testBitwiseAND()
  18. {
  19. var a = b4(1, 0, 1, 1);
  20. var result = b4(0, 0, 0, 0);
  21. var loopIndex = 0;
  22. while ((loopIndex | 0) < (loopCOUNT | 0))
  23. {
  24. result = b4and(b4g1, b4g1);
  25. result = b4and(result, globImportb4);
  26. b4check(result);
  27. loopIndex = (loopIndex + 1) | 0;
  28. }
  29. return b4check(b4g1);
  30. }
  31. function testBitwiseOR() {
  32. var a = b4(1, 0, 1, 1);
  33. var result = b4(0, 0, 0, 0);
  34. var loopIndex = 0;
  35. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  36. result = b4or(a, b4g1);
  37. result = b4or(result, globImportb4);
  38. b4check(result);
  39. loopIndex = (loopIndex + 1) | 0;
  40. }
  41. return b4check(result);
  42. }
  43. function testBitwiseXOR() {
  44. var a = b4(1, 0, 1, 1);
  45. var result = b4(0, 0, 0, 0);
  46. var loopIndex = 0;
  47. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  48. result = b4xor(a, b4g1);
  49. result = b4xor(result, globImportb4);
  50. b4check(result);
  51. loopIndex = (loopIndex + 1) | 0;
  52. }
  53. return b4check(result);
  54. }
  55. function testBitwiseNOT() {
  56. var a = b4(1, 0, 1, 1);
  57. var result = b4(0, 0, 0, 0);
  58. var loopIndex = 0;
  59. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  60. result = b4and(a, b4g1);
  61. result = b4and(result, globImportb4);
  62. b4check(result);
  63. loopIndex = (loopIndex + 1) | 0;
  64. }
  65. return b4check(result);
  66. }
  67. return {testBitwiseAND:testBitwiseAND, testBitwiseOR,testBitwiseOR, testBitwiseXOR:testBitwiseXOR, testBitwiseNOT:testBitwiseNOT};
  68. }
  69. var m = asmModule(this, {g1:SIMD.Bool32x4(1, 0, 1, 0)});
  70. equalSimd([1, 1, 1, 1], m.testBitwiseAND(), SIMD.Bool32x4, "Func1");
  71. equalSimd([1, 1, 1, 1], m.testBitwiseOR(), SIMD.Bool32x4, "Func2");
  72. equalSimd([1, 1, 1, 0], m.testBitwiseXOR(), SIMD.Bool32x4, "Func3");
  73. equalSimd([1, 0, 1, 0], m.testBitwiseNOT(), SIMD.Bool32x4, "Func4");
  74. print("PASS");