memset_simd.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. 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("memset_tester.js");
  6. const simdRegex = /^\w+(\d+)?x(\d+)$/;
  7. const allSimdTypes = Object.getOwnPropertyNames(SIMD)
  8. // just to make sure
  9. .filter(simdType => simdRegex.test(simdType))
  10. .map(simdType => {
  11. const result = simdRegex.exec(simdType);
  12. const nLanes = parseInt(result[2]);
  13. const simdInfo = {
  14. makeSimd() {
  15. const args = new Array(nLanes);
  16. for(let i = 0; i < nLanes; ++i) {
  17. args[i] = Math.random() * (1 << 62);
  18. }
  19. if (simdType != 'Float64x2') //Type is not part of spec. Will be removed as part of cleanup.
  20. {
  21. return SIMD[simdType](...args);
  22. }
  23. },
  24. makeStringValue() {
  25. const args = new Array(nLanes);
  26. for(let i = 0; i < nLanes; ++i) {
  27. args[i] = Math.random() * (1 << 62);
  28. }
  29. if (simdType != 'Float64x2') //Type is not part of spec. Will be removed as part of cleanup.
  30. {
  31. return `SIMD.${simdType}(${args.join(",")})`;
  32. }
  33. },
  34. nLanes,
  35. simdType
  36. };
  37. return simdInfo;
  38. });
  39. const allTypes = [0, 1.5, undefined, null, 9223372036854775807, "string", {a: null, b: "b"}];
  40. const tests = allSimdTypes.map(simdInfo => {
  41. return {
  42. name: `memset${simdInfo.simdType}`,
  43. stringValue: simdInfo.makeStringValue(),
  44. v2: simdInfo.makeSimd()
  45. };
  46. });
  47. const types = "Array".split(" ");
  48. let passed = RunMemsetTest(tests, types, allTypes);
  49. print(passed ? "PASSED" : "FAILED");