testAddSub.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 i8add = i8.add;
  11. var i8sub = i8.sub;
  12. var globImporti8 = i8check(imports.g1);
  13. var i8g1 = i8(10, -1073, -107, 1082, 10402, 12332, 311, -650);
  14. var i8g2 = i8(353216, -492529, -1128, 1085, 3692, 3937, 9755, 2638);
  15. var loopCOUNT = 3;
  16. function testAddLocal()
  17. {
  18. var a = i8(5033,-3401, 665,-3234, -948, 2834, 7748, -25);
  19. var b = i8(-3483, 2144, -5697, 65, 1000000, -984, 3434, -9876);
  20. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  21. var loopIndex = 0;
  22. while ( (loopIndex|0) < (loopCOUNT|0)) {
  23. result = i8add(a, b);
  24. loopIndex = (loopIndex + 1) | 0;
  25. }
  26. return i8check(result);
  27. }
  28. function testSubLocal()
  29. {
  30. var a = i8(5033, -3401, 665, -3234, -948, 2834, 7748, -25);
  31. var b = i8(-3483, 2144, -5697, 65, 1000000, -984, 3434, -9876);
  32. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  33. var loopIndex = 0;
  34. while ( (loopIndex|0) < (loopCOUNT|0)) {
  35. result = i8sub(a, b);
  36. loopIndex = (loopIndex + 1) | 0;
  37. }
  38. return i8check(result);
  39. }
  40. function testAddGlobal()
  41. {
  42. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  43. var loopIndex = 0;
  44. while ( (loopIndex|0) < (loopCOUNT|0)) {
  45. result = i8add(i8g1, i8g2);
  46. loopIndex = (loopIndex + 1) | 0;
  47. }
  48. return i8check(result);
  49. }
  50. function testSubGlobal()
  51. {
  52. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  53. var loopIndex = 0;
  54. while ( (loopIndex|0) < (loopCOUNT|0)) {
  55. result = i8sub(i8g1, i8g2);
  56. loopIndex = (loopIndex + 1) | 0;
  57. }
  58. return i8check(result);
  59. }
  60. function testAddGlobalImport()
  61. {
  62. var a = i8(5033, -3401, 665, -3234, -948, 2834, 7748, -25);
  63. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  64. var loopIndex = 0;
  65. while ((loopIndex | 0) < (loopCOUNT | 0)) {
  66. result = i8add(globImporti8, a);
  67. loopIndex = (loopIndex + 1) | 0;
  68. }
  69. return i8check(result);
  70. }
  71. function testSubGlobalImport()
  72. {
  73. var a = i8(5033, -3401, 665, -3234, -948, 2834, 7748, -25);
  74. var result = i8(0, 0, 0, 0, 0, 0, 0, 0);
  75. var loopIndex = 0;
  76. while ( (loopIndex|0) < (loopCOUNT|0)) {
  77. result = i8sub(globImporti8, a);
  78. loopIndex = (loopIndex + 1) | 0;
  79. }
  80. return i8check(result);
  81. }
  82. return { testAddLocal: testAddLocal, testSubLocal: testSubLocal, testAddGlobal: testAddGlobal, testSubGlobal: testSubGlobal, testAddGlobalImport: testAddGlobalImport, testSubGlobalImport: testSubGlobalImport };
  83. }
  84. var m = asmModule(this, {g1:SIMD.Int16x8(100, -1073741824, -1028, -102, 3883, -38, -92929, 1442)});
  85. equalSimd([1550, -1257, -5032, -3169, 16012, 1850, 11182, -9901], m.testAddLocal(), SIMD.Int16x8, "Func1");
  86. equalSimd([8516, -5545, 6362, -3299, -17908, 3818, 4314, 9851], m.testSubLocal(), SIMD.Int16x8, "Func2");
  87. equalSimd([25546, 30686, -1235, 2167, 14094, 16269, 10066, 1988], m.testAddGlobal(), SIMD.Int16x8, "Func3");
  88. equalSimd([-25526, 32704, 1021, -3, 6710, 8395, -9444, -3288], m.testSubGlobal(), SIMD.Int16x8, "Func4");
  89. equalSimd([5133, -3401, -363, -3336, 2935, 2796, -19645, 1417], m.testAddGlobalImport(), SIMD.Int16x8, "Func5");
  90. equalSimd([-4933, 3401, -1693, 3132, 4831, -2872, 30395, 1467], m.testSubGlobalImport(), SIMD.Int16x8, "Func6");
  91. print("PASS");