|
3 | 3 | // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information. |
4 | 4 | //------------------------------------------------------------------------------------------------------- |
5 | 5 |
|
6 | | -function* makeValueGen(a, b) { |
7 | | - // return a for profiling |
8 | | - yield a; |
9 | | - // return b to bailout |
10 | | - yield b; |
11 | | - // return b again to compare with non jit function |
12 | | - yield b; |
13 | | -} |
14 | | - |
15 | | -function* makeStartGen(a, b) { |
16 | | - yield 0; // for interpreter |
17 | | - yield 32; // for jitted version |
18 | | - yield 32; // for jitted version |
19 | | -} |
20 | | - |
21 | | -function makeTest(name, config) { |
22 | | - const f1 = `function ${name}(arr) { |
23 | | - for(var i = -5; i < 15; ++i) {arr[i] = ${config.v1};} |
24 | | - return arr; |
25 | | - }`; |
26 | | - const f2 = customName => `function ${customName}P(arr, v) { |
27 | | - for(var i = 1; i < 8; ++i) {arr[i] = v;} |
28 | | - return arr; |
29 | | - }`; |
30 | | - const f3 = `function ${name}V(arr) { |
31 | | - const v = ${config.v1}; |
32 | | - for(var i = -2; i < 17; ++i) {arr[i] = v;} |
33 | | - return arr; |
34 | | - }`; |
35 | | - const f4 = customName => `function ${customName}Z(arr, start) { |
36 | | - const v = ${config.v1}; |
37 | | - for(var i = start; i < 5; ++i) {arr[i] = v;} |
38 | | - return arr; |
39 | | - }`; |
40 | | - |
41 | | - const extraTests = (config.wrongTypes || []).map((wrongType, i) => { |
42 | | - const difValue = {f: f2(`${name}W${i}`), compare: f2(`${name}WC${i}`)}; |
43 | | - const genValue = makeValueGen(config.v1, wrongType); |
44 | | - Reflect.defineProperty(difValue, "v", { |
45 | | - get: () => genValue.next().value |
46 | | - }); |
47 | | - return difValue; |
48 | | - }); |
49 | | - |
50 | | - const negativeLengthTest = {f: f4(name), compare: f4(`${name}C`), newForCompare: true}; |
51 | | - const genIndex = makeStartGen(); |
52 | | - Reflect.defineProperty(negativeLengthTest, "v", { |
53 | | - get: () => genIndex.next().value |
54 | | - }); |
55 | | - |
56 | | - const tests = [ |
57 | | - {f: f1}, |
58 | | - {f: f2(name), v: config.v2 !== undefined ? config.v2 : config.v1}, |
59 | | - {f: f3}, |
60 | | - negativeLengthTest |
61 | | - ].concat(extraTests); |
62 | | - |
63 | | - const convertTest = function(fnText) { |
64 | | - var fn; |
65 | | - eval(`fn = ${fnText}`); |
66 | | - return fn; |
67 | | - }; |
68 | | - for(const t of tests) { |
69 | | - t.f = convertTest(t.f); |
70 | | - t.compare = t.compare && convertTest(t.compare); |
71 | | - } |
72 | | - return tests; |
73 | | -} |
| 6 | +this.WScript.LoadScriptFile(".\\memset_tester.js"); |
74 | 7 |
|
75 | 8 | const allTypes = [0, 1.5, undefined, null, 9223372036854775807, "string", {a: null, b: "b"}]; |
| 9 | + |
76 | 10 | const tests = [ |
77 | | - {name: "memsetUndefined", v1: undefined, wrongTypes: allTypes}, |
78 | | - {name: "memsetNull", v1: null, wrongTypes: allTypes}, |
79 | | - {name: "memsetFloat", v1: 3.14, v2: -87.684, wrongTypes: allTypes}, |
80 | | - {name: "memsetNumber", v1: 9223372036854775807, v2: -987654987654987, wrongTypes: allTypes}, |
81 | | - {name: "memsetBoolean", v1: true, v2: false, wrongTypes: allTypes}, |
82 | | - {name: "memsetString", v1: "\"thatString\"", v2: "`A template string`", wrongTypes: allTypes}, |
83 | | - {name: "memsetObject", v1: "{test: 1}", v2: [1, 2, 3], wrongTypes: allTypes}, |
| 11 | + {name: "memsetUndefined", stringValue: undefined}, |
| 12 | + {name: "memsetNull", stringValue: null}, |
| 13 | + {name: "memsetInt", stringValue: 0, v2: 1 << 30}, |
| 14 | + {name: "memsetFloat", stringValue: 3.14, v2: -87.684}, |
| 15 | + {name: "memsetNumber", stringValue: 9223372036854775807, v2: -987654987654987}, |
| 16 | + {name: "memsetBoolean", stringValue: true, v2: false}, |
| 17 | + {name: "memsetString", stringValue: "\"thatString\"", v2: "`A template string`"}, |
| 18 | + {name: "memsetObject", stringValue: "{test: 1}", v2: [1, 2, 3]}, |
84 | 19 | ]; |
85 | 20 |
|
86 | 21 | const types = "Int8Array Uint8Array Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Array".split(" "); |
87 | | -const global = this; |
88 | 22 |
|
89 | | -let passed = true; |
90 | | -for(const test of tests) { |
91 | | - for(const t of types) { |
92 | | - const fns = makeTest(`${test.name}${t}`, test); |
93 | | - for(const detail of fns) { |
94 | | - const fn = detail.f; |
95 | | - let a1 = fn(new global[t](10), detail.v); |
96 | | - const a2 = fn(new global[t](10), detail.v); |
97 | | - if(detail.compare) { |
98 | | - // the optimized version ran with a different value. Run again with a clean function to compare= |
99 | | - a1 = detail.compare(detail.newForCompare ? new global[t](10) : a1, detail.v); |
100 | | - } |
101 | | - if(a1.length !== a2.length) { |
102 | | - passed = false; |
103 | | - print(`${fn.name} (${t}) didn't return arrays with same length`); |
104 | | - continue; |
105 | | - } |
106 | | - for(let i = 0; i < a1.length; ++i) { |
107 | | - if(a1[i] !== a2[i] && !(isNaN(a1[i]) && isNaN(a2[i]))) { |
108 | | - passed = false; |
109 | | - print(`${fn.name} (${t}): a1[${i}](${a1[i]}) != a2[${i}](${a2[i]})`); |
110 | | - break; |
111 | | - } |
112 | | - } |
113 | | - } |
114 | | - } |
115 | | -} |
| 23 | +let passed = RunMemsetTest(tests, types, allTypes); |
116 | 24 |
|
117 | 25 | function memsetSymbol() {const s = Symbol(); const arr = new Array(10); for(let i = 0; i < 10; ++i) {arr[i] = s;} return arr;} |
118 | 26 | function memsetSymbolV(v) {const arr = new Array(10); for(let i = 0; i < 10; ++i) {arr[i] = v;} return arr;} |
|
0 commit comments