testNeg.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 i8 = stdlib.SIMD.Int16x8;
  9. var i8check = i8.check;
  10. var i8neg = i8.neg;
  11. var globImporti8 = i8check(imports.g1);
  12. var i8g1 = i8(1, 2, 3, 4, -1, -2, -3, -4);
  13. var loopCOUNT = 3;
  14. function testNegLocal()
  15. {
  16. var a = i8(5, -10, 15, -20, 25, -30, 35, -40);
  17. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  18. var loopIndex = 0;
  19. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  20. result = i8neg(a)
  21. loopIndex = (loopIndex + 1) | 0;
  22. }
  23. return i8check(result);
  24. }
  25. function testNegGlobal()
  26. {
  27. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  28. var loopIndex = 0;
  29. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  30. result = i8neg(i8g1);
  31. loopIndex = (loopIndex + 1) | 0;
  32. }
  33. return i8check(result);
  34. }
  35. function testNegGlobalImport()
  36. {
  37. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  38. var loopIndex = 0;
  39. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  40. result = i8neg(globImporti8);
  41. loopIndex = (loopIndex + 1) | 0;
  42. }
  43. return i8check(result);
  44. }
  45. return {testNegLocal:testNegLocal, testNegGlobal:testNegGlobal, testNegGlobalImport:testNegGlobalImport};
  46. }
  47. var m = asmModule(this, { g1: SIMD.Int16x8(-10, 10, -20, 20, -30, 30, -40, 40) });
  48. equalSimd([-5, 10, -15, 20, -25, 30, -35, 40], m.testNegLocal(), SIMD.Int16x8, "Test Neg");
  49. equalSimd([-1, -2, -3, -4, 1, 2, 3, 4], m.testNegGlobal(), SIMD.Int16x8, "Test Neg");
  50. equalSimd([10, -10, 20, -20, 30, -30, 40, -40], m.testNegGlobalImport(), SIMD.Int16x8, "Test Neg");
  51. print("PASS");