testBitwise.js 3.3 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 b16 = stdlib.SIMD.Bool8x16;
  9. var b16check = b16.check;
  10. var b16and = b16.and;
  11. var b16or = b16.or;
  12. var b16not = b16.not;
  13. var b16xor = b16.xor;
  14. var globImportb16 = b16check(imports.g1);
  15. var b16g1 = b16(1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0);
  16. var loopCOUNT = 5;
  17. function testBitwiseAND()
  18. {
  19. var a = b16(1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1);
  20. var result = b16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  21. var loopIndex = 0;
  22. while ((loopIndex | 0) < (loopCOUNT | 0))
  23. {
  24. result = b16and(a, b16g1);
  25. result = b16and(result, globImportb16);
  26. b16check(result);
  27. loopIndex = (loopIndex + 1) | 0;
  28. }
  29. return b16check(result);
  30. }
  31. function testBitwiseOR() {
  32. var a = b16(1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1);
  33. var result = b16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  34. var loopIndex = 0;
  35. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  36. result = b16or(a, b16g1);
  37. result = b16or(result, globImportb16);
  38. b16check(result);
  39. loopIndex = (loopIndex + 1) | 0;
  40. }
  41. return b16check(result);
  42. }
  43. function testBitwiseXOR() {
  44. var a = b16(1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1);
  45. var result = b16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  46. var loopIndex = 0;
  47. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  48. result = b16xor(a, b16g1);
  49. result = b16xor(result, globImportb16);
  50. b16check(result);
  51. loopIndex = (loopIndex + 1) | 0;
  52. }
  53. return b16check(result);
  54. }
  55. function testBitwiseNOT() {
  56. var a = b16(1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1);
  57. var result = b16(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
  58. var loopIndex = 0;
  59. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  60. result = b16and(a, b16g1);
  61. result = b16and(result, globImportb16);
  62. b16check(result);
  63. loopIndex = (loopIndex + 1) | 0;
  64. }
  65. return b16check(result);
  66. }
  67. return {testBitwiseAND:testBitwiseAND, testBitwiseOR,testBitwiseOR, testBitwiseXOR:testBitwiseXOR, testBitwiseNOT:testBitwiseNOT};
  68. }
  69. var m = asmModule(this, { g1: SIMD.Bool8x16(0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1) });
  70. equalSimd([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], m.testBitwiseAND(), SIMD.Bool8x16, "Func1");
  71. equalSimd([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], m.testBitwiseOR(), SIMD.Bool8x16, "Func2");
  72. equalSimd([0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0], m.testBitwiseXOR(), SIMD.Bool8x16, "Func3");
  73. equalSimd([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], m.testBitwiseNOT(), SIMD.Bool8x16, "Func4");
  74. print("PASS");