int64x2Tests.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. let passed = true;
  6. function assertEquals(expected, actual) {
  7. if (expected != actual) {
  8. passed = false;
  9. throw `Expected ${expected}, received ${actual}`;
  10. }
  11. }
  12. const INITIAL_SIZE = 1;
  13. const memObj = new WebAssembly.Memory({initial:INITIAL_SIZE});
  14. const array = new Int32Array (memObj.buffer);
  15. const int64Module = new WebAssembly.Module(readbuffer('int64x2.wasm'));
  16. const int64Instance = new WebAssembly.Instance(int64Module, { "dummy" : { "memory" : memObj } }).exports;
  17. function moveArgsIntoArray(args, offset, arr) {
  18. for (let i = 0; i < args.length; i++) {
  19. arr[offset + i] = args[i];
  20. }
  21. }
  22. let testInt64MathOps = function (funcname, inputArr, funcArgs, resultArr) {
  23. moveArgsIntoArray(inputArr, 0, array);
  24. int64Instance[funcname](...funcArgs);
  25. for (let i = 0; i < resultArr.length; i++) {
  26. assertEquals(array[i], resultArr[i]);
  27. }
  28. }
  29. testInt64MathOps("func_i64x2_splat", [0xF0F0F0F0, 0xAABBAABB], [], [0xF0F0F0F0|0, 0xAABBAABB|0, 0xF0F0F0F0|0, 0xAABBAABB|0]);
  30. testInt64MathOps("func_i64x2_splat", [0xBEEF0000, 0xCAFEFFFF], [], [0xBEEF0000|0, 0xCAFEFFFF|0, 0xBEEF0000|0, 0xCAFEFFFF|0]);
  31. testInt64MathOps("func_i64x2_extractlane_0", [0xDEADDEAD, 0xABBAABBA, 0x0, 0x0], [], [0xDEADDEAD|0, 0xABBAABBA|0, 0xDEADDEAD|0, 0xABBAABBA|0]);
  32. testInt64MathOps("func_i64x2_extractlane_1", [0x0, 0x0, 0xDEADDEAD, 0xABBAABBA], [], [0xDEADDEAD|0, 0xABBAABBA|0, 0xDEADDEAD|0, 0xABBAABBA|0]);
  33. testInt64MathOps("func_i64x2_replacelane_0", [0xDEADDEAD, 0xABBAABBA, 0xBEEF0000, 0xCAFEFFFF, 0xCCCCCCCC, 0xDDDDDDDD], [], [0xCCCCCCCC|0, 0xDDDDDDDD|0, 0xBEEF0000|0, 0xCAFEFFFF|0]);
  34. testInt64MathOps("func_i64x2_replacelane_1", [0xDEADDEAD, 0xABBAABBA, 0xBEEF0000, 0xCAFEFFFF, 0xCCCCCCCC, 0xDDDDDDDD], [], [0xDEADDEAD|0, 0xABBAABBA|0, 0xCCCCCCCC|0, 0xDDDDDDDD|0]);
  35. testInt64MathOps("func_i64x2_add", [0x00000001, 0x000FF000, 0xC, 0xA, 0xFFFFFFFF, 0xFF00000E, 0x3, 0x5], [], [0x0, 0xFF0FF00F|0, 0xF, 0xF]);
  36. testInt64MathOps("func_i64x2_sub", [00000003, 0xD0CFB000, 0xC, 0xA, 0xFFFFFFFF, 0xD0BA0000, 0x3, 0x5], [], [0x00000004, 0x0015afff, 0x9, 0x5]);
  37. testInt64MathOps("func_i64x2_neg", [0x0, 0x80000000, 0xFFFFFFFF, 0x7FFFFFFF], [], [0x0, 0x80000000|0, 0x00000001, 0x80000000|0]);
  38. testInt64MathOps("func_i64x2_shl", [0x00100001, 0x80000001, 0xFFFFFFFF, 0xFFFFFFFF], [3], [0x00800008|0, 0x00000008, 0xFFFFFFF8|0, 0xFFFFFFFF|0]);
  39. testInt64MathOps("func_i64x2_shl", [0x00100001, 0x80000001, 0xFFFFFFFF, 0xFFFFFFFF], [67], [0x00800008|0, 0x00000008, 0xFFFFFFF8|0, 0xFFFFFFFF|0]);
  40. testInt64MathOps("func_i64x2_shr_u", [0x00100001, 0x80000001, 0xFFFFFFFF, 0xFFFFFFFF], [3], [0x20020000|0, 0x10000000|0, 0xFFFFFFFF|0, 0x1FFFFFFF|0]);
  41. testInt64MathOps("func_i64x2_shr_u", [0x00100001, 0x80000001, 0xFFFFFFFF, 0xFFFFFFFF], [67], [0x20020000|0, 0x10000000|0, 0xFFFFFFFF|0, 0x1FFFFFFF|0]);
  42. testInt64MathOps("func_i64x2_shr_s", [0x00100001, 0x80000001, 0xFFFFFFFF, 0xFFFFFFFF], [3], [0x20020000|0, 0xf0000000|0, 0xFFFFFFFF|0, 0xFFFFFFFF|0]);
  43. testInt64MathOps("func_i64x2_shr_s", [0x00100001, 0x80000001, 0xFFFFFFFF, 0xFFFFFFFF], [67], [0x20020000|0, 0xf0000000|0, 0xFFFFFFFF|0, 0xFFFFFFFF|0]);
  44. if (passed) {
  45. print("Passed");
  46. }