| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756 |
- //-------------------------------------------------------------------------------------------------------
- // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
- // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
- //-------------------------------------------------------------------------------------------------------
- let passed = true;
- const OPS = Object.freeze({
- EQ : 0,
- NE : 1,
- LT : 2,
- LE : 3,
- GT : 4,
- GE : 5
- });
- function assertEquals(expected, actual) {
- if (expected != actual) {
- passed = false;
- throw `Expected ${expected}, received ${actual}`;
- }
- }
- const INITIAL_SIZE = 1;
- const memObj = new WebAssembly.Memory({initial:INITIAL_SIZE});
- const module = new WebAssembly.Module(readbuffer('comp.wasm'));
- const instance = new WebAssembly.Instance(module, { "dummy" : { "memory" : memObj } }).exports;
- const arrays = {
- "i32x4" : new Int32Array (memObj.buffer),
- "i16x8" : new Int16Array (memObj.buffer),
- "i8x16" : new Int8Array (memObj.buffer),
- "f32x4" : new Float32Array (memObj.buffer),
- "f64x2" : new Float64Array (memObj.buffer)
- };
- function moveArgsIntoArray(args, offset, arr) {
- for (let i = 0; i < args.length; i++) {
- arr[offset + i] = args[i];
- }
- }
- let testCompOps = function (funcname, args1, args2, op, resultArr) {
- const len = args1.length;
- const arr = arrays[funcname.split('_')[1]];
- moveArgsIntoArray(args1, 0, arr);
- moveArgsIntoArray(args2, len, arr);
- instance[funcname](op);
- for (let i = 0; i < len; i++) {
- assertEquals(resultArr[i], Number.isNaN(arr[i]) || !!arr[i]);
- }
- }
- testCompOps("func_i32x4_compare_s",
- [2147483647,0,-100,-2147483648],
- [2147483647,45,202,-2147483648],
- OPS.EQ,
- [1,0,0,1]
- );
- testCompOps("func_i32x4_compare_s",
- [277,2147483647,-100,2147483647],
- [431,2147483647,555,2147483647],
- OPS.EQ,
- [0,1,0,1]
- );
- testCompOps("func_i32x4_compare_s",
- [2147483647,0,-100,-2147483648],
- [2147483647,45,202,-2147483648],
- OPS.NE,
- [0,1,1,0]
- );
- testCompOps("func_i32x4_compare_s",
- [277,2147483647,-100,2147483647],
- [431,2147483647,555,2147483647],
- OPS.NE,
- [1,0,1,0]
- );
- testCompOps("func_i32x4_compare_s",
- [-1,1440,2100,-2147483648],
- [2147483647,45,202,4],
- OPS.LT,
- [1,0,0,1]
- );
- testCompOps("func_i32x4_compare_s",
- [431,-2147483646,555,21474836],
- [277,2147483647,-100,2147483647],
- OPS.LT,
- [0,1,0,1]
- );
- testCompOps("func_i32x4_compare_s",
- [2147483647,1440,2100,4],
- [2147483647,45,202,4],
- OPS.LE,
- [1,0,0,1]
- );
- testCompOps("func_i32x4_compare_s",
- [431,-2147483646,555,21474835],
- [277,-2147483646,-100,21474836],
- OPS.LE,
- [0,1,0,1]
- );
- testCompOps("func_i32x4_compare_s",
- [-1,1440,2100,-2147483648],
- [2147483647,45,202,4],
- OPS.GT,
- [0,1,1,0]
- );
- testCompOps("func_i32x4_compare_s",
- [431,-2147483646,555,21474836],
- [277,2147483647,-100,2147483647],
- OPS.GT,
- [1,0,1,0]
- );
- testCompOps("func_i32x4_compare_s",
- [-1,1440,2100,-2147483648],
- [2147483647,1440,202,4],
- OPS.GE,
- [0,1,1,0]
- );
- testCompOps("func_i32x4_compare_s",
- [431,-2147483646,-100,21474836],
- [277,2147483647,-100,2147483647],
- OPS.GE,
- [1,0,1,0]
- );
- testCompOps("func_i32x4_compare_u",
- [2147483647,0,-100,-2147483648],
- [2147483647,45,202,-2147483648],
- OPS.EQ,
- [1,0,0,1]
- );
- testCompOps("func_i32x4_compare_u",
- [277,2147483647,-100,2147483647],
- [431,2147483647,555,2147483647],
- OPS.EQ,
- [0,1,0,1]
- );
- testCompOps("func_i32x4_compare_u",
- [2147483647,0,-100,-2147483648],
- [2147483647,45,202,-2147483648],
- OPS.NE,
- [0,1,1,0]
- );
- testCompOps("func_i32x4_compare_u",
- [277,2147483647,-100,2147483647],
- [431,2147483647,555,2147483647],
- OPS.NE,
- [1,0,1,0]
- );
- testCompOps("func_i32x4_compare_u",
- [-100,1440,2100,-2147483648],
- [-1,45,202,-2147483647],
- OPS.LT,
- [1,0,0,1]
- );
- testCompOps("func_i32x4_compare_u",
- [431,2147483646,555,21474836],
- [277,-2147483647,100,2147483647],
- OPS.LT,
- [0,1,0,1]
- );
- testCompOps("func_i32x4_compare_u",
- [2147483647,1440,2100,4],
- [2147483647,45,202,4],
- OPS.LE,
- [1,0,0,1]
- );
- testCompOps("func_i32x4_compare_u",
- [431,-2147483646,-555,21474835],
- [277,-2147483646,100,21474836],
- OPS.LE,
- [0,1,0,1]
- );
- testCompOps("func_i32x4_compare_u",
- [2147483647,1440,2100,2147483647],
- [-1,45,202,-4],
- OPS.GT,
- [0,1,1,0]
- );
- testCompOps("func_i32x4_compare_u",
- [431,2147483646,555,21474836],
- [277,-2147483647,100,2147483647],
- OPS.GT,
- [1,0,1,0]
- );
- testCompOps("func_i32x4_compare_u",
- [1,1440,2100,2147483648],
- [-2147483647,1440,202,-4],
- OPS.GE,
- [0,1,1,0]
- );
- testCompOps("func_i32x4_compare_u",
- [431,2147483646,-100,21474836],
- [277,-2147483647,-100,2147483647],
- OPS.GE,
- [1,0,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [65535,0,-100,-777,4,2,207,-65536],
- [65535,0,-123,-777,3,1,202,-65536],
- OPS.EQ,
- [1,1,0,1,0,0,0,1]
- );
- testCompOps("func_i16x8_compare_s",
- [11,2147483647,-200,2147483647,431,2147483647,555,2147483647],
- [277,2147483647,-100,2147483647,432,2147483647,755,2147483647],
- OPS.EQ,
- [0,1,0,1,0,1,0,1]
- );
- testCompOps("func_i16x8_compare_s",
- [65535,0,-100,-777,4,2,207,-65536],
- [65535,0,-123,-777,3,1,202,-65536],
- OPS.NE,
- [0,0,1,0,1,1,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [11,2147483647,-200,2147483647,431,2147483647,555,2147483647],
- [277,2147483647,-100,2147483647,432,2147483647,755,2147483647],
- OPS.NE,
- [1,0,1,0,1,0,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [32766,-1,-100,-778,4,2,207,-32768],
- [32767,0,-123,-777,3,1,202,-32767],
- OPS.LT,
- [1,1,0,1,0,0,0,1]
- );
- testCompOps("func_i16x8_compare_s",
- [1111,32766,-99,32765,1001,1,855,-32768],
- [277,32767,-100,32766,432,2,755,-32767],
- OPS.LT,
- [0,1,0,1,0,1,0,1]
- );
- testCompOps("func_i16x8_compare_s",
- [32767,-1,-100,-778,4,2,207,-32768],
- [32767,-1,-123,-777,3,1,202,-32767],
- OPS.LE,
- [1,1,0,1,0,0,0,1]
- );
- testCompOps("func_i16x8_compare_s",
- [1111,32766,-99,32765,1001,1,855,-32768],
- [277,32767,-100,32766,432,2,855,-32767],
- OPS.LE,
- [0,1,0,1,0,1,1,1]
- );
- testCompOps("func_i16x8_compare_s",
- [32766,-1,-100,-778,4,2,207,-32768],
- [32767,0,-123,-777,3,1,202,-32767],
- OPS.GT,
- [0,0,1,0,1,1,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [1111,32766,-99,32765,1001,1,855,-32768],
- [277,32767,-100,32766,432,2,755,-32767],
- OPS.GT,
- [1,0,1,0,1,0,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [32767,-1,-100,-778,4,2,207,-32768],
- [32767,-1,-123,-777,3,1,202,-32767],
- OPS.GE,
- [1,1,1,0,1,1,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [1111,32766,-99,32765,1001,1,855,-32768],
- [277,32767,-100,32766,432,2,855,-32767],
- OPS.GE,
- [1,0,1,0,1,0,1,0]
- );
- testCompOps("func_i16x8_compare_u",
- [65534,32766,129,0,4,2,207,65530],
- [65535,32767,123,1,3,1,202,65531],
- OPS.LT,
- [1,1,0,1,0,0,0,1]
- );
- testCompOps("func_i16x8_compare_u",
- [1111,32766,65535,32765,1001,1,855,32767],
- [277,32767,65531,32766,432,2,755,32768],
- OPS.LT,
- [0,1,0,1,0,1,0,1]
- );
- testCompOps("func_i16x8_compare_u",
- [65535,32766,129,0,4,2,207,65530],
- [65535,32767,123,1,3,1,202,65531],
- OPS.LE,
- [1,1,0,1,0,0,0,1]
- );
- testCompOps("func_i16x8_compare_u",
- [1111,32766,65535,32765,1001,1,855,32767],
- [277,32767,65531,32766,432,2,855,32768],
- OPS.LE,
- [0,1,0,1,0,1,1,1]
- );
- testCompOps("func_i16x8_compare_u",
- [65534,32766,129,0,4,2,207,65530],
- [65535,32767,123,1,3,1,202,65531],
- OPS.GT,
- [0,0,1,0,1,1,1,0]
- );
- testCompOps("func_i16x8_compare_u",
- [1111,32766,65535,32765,1001,1,855,32767],
- [277,32767,65531,32766,432,2,755,32768],
- OPS.GT,
- [1,0,1,0,1,0,1,0]
- );
- testCompOps("func_i16x8_compare_u",
- [65535,32767,129,0,4,2,207,65530],
- [65535,32766,123,1,3,1,202,65531],
- OPS.GE,
- [1,1,1,0,1,1,1,0]
- );
- testCompOps("func_i16x8_compare_u",
- [1111,32766,65535,32765,1001,1,855,32767],
- [277,32767,65531,32766,432,2,855,32768],
- OPS.GE,
- [1,0,1,0,1,0,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [255,0,-100,-77,4,2,207,-1],
- [255,0,-123,-77,3,1,202,-1],
- OPS.EQ,
- [1,1,0,1,0,0,0,1]
- );
- testCompOps("func_i16x8_compare_s",
- [11,127,-111,127,43,127,55,127],
- [12,127,-100,127,42,127,75,127],
- OPS.EQ,
- [0,1,0,1,0,1,0,1]
- );
- testCompOps("func_i16x8_compare_s",
- [255,0,-100,-77,4,2,207,-1],
- [255,0,-123,-77,3,1,202,-1],
- OPS.NE,
- [0,0,1,0,1,1,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [11,127,-111,127,431,127,555,127],
- [12,127,-100,127,432,127,755,127],
- OPS.NE,
- [1,0,1,0,1,0,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [126,-1,-100,-78,4,2,27,-128],
- [127,0,-123,-77,3,1,22,-127],
- OPS.LT,
- [1,1,0,1,0,0,0,1]
- );
- testCompOps("func_i16x8_compare_s",
- [111,126,-99,64,101,1,85,-128],
- [12,127,-100,126,43,2,75,-127],
- OPS.LT,
- [0,1,0,1,0,1,0,1]
- );
- testCompOps("func_i16x8_compare_s",
- [127,-1,-100,-78,4,2,27,-128],
- [127,-1,-123,-77,3,1,22,-127],
- OPS.LE,
- [1,1,0,1,0,0,0,1]
- );
- testCompOps("func_i16x8_compare_s",
- [111,126,-99,64,101,1,85,-128],
- [12,127,-100,126,43,2,85,-127],
- OPS.LE,
- [0,1,0,1,0,1,1,1]
- );
- testCompOps("func_i16x8_compare_s",
- [126,-1,-100,-78,4,2,27,-128],
- [127,0,-123,-77,3,1,22,-127],
- OPS.GT,
- [0,0,1,0,1,1,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [111,126,-99,64,101,1,85,-128],
- [12,127,-100,126,43,2,75,-127],
- OPS.GT,
- [1,0,1,0,1,0,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [127,-1,-100,-78,4,2,27,-128],
- [127,-1,-123,-77,3,1,22,-127],
- OPS.GE,
- [1,1,1,0,1,1,1,0]
- );
- testCompOps("func_i16x8_compare_s",
- [111,126,-99,64,101,1,85,-128],
- [12,127,-100,126,42,2,85,-127],
- OPS.GE,
- [1,0,1,0,1,0,1,0]
- );
- testCompOps("func_i16x8_compare_u",
- [253,126,129,0,4,2,207,63],
- [255,127,123,1,3,1,202,65],
- OPS.LT,
- [1,1,0,1,0,0,0,1]
- );
- testCompOps("func_i16x8_compare_u",
- [111,126,255,64,101,1,85,127],
- [12,127,65,126,43,2,75,128],
- OPS.LT,
- [0,1,0,1,0,1,0,1]
- );
- testCompOps("func_i16x8_compare_u",
- [255,126,129,0,4,2,207,63],
- [255,127,123,1,3,1,202,65],
- OPS.LE,
- [1,1,0,1,0,0,0,1]
- );
- testCompOps("func_i16x8_compare_u",
- [111,126,255,64,101,1,85,127],
- [12,127,65,126,43,2,85,128],
- OPS.LE,
- [0,1,0,1,0,1,1,1]
- );
- testCompOps("func_i16x8_compare_u",
- [253,126,129,0,4,2,207,63],
- [255,127,123,1,3,1,202,65],
- OPS.GT,
- [0,0,1,0,1,1,1,0]
- );
- testCompOps("func_i16x8_compare_u",
- [111,126,255,64,101,1,85,127],
- [12,127,200,126,43,2,75,128],
- OPS.GT,
- [1,0,1,0,1,0,1,0]
- );
- testCompOps("func_i16x8_compare_u",
- [255,127,129,0,4,2,207,63],
- [255,126,123,1,3,1,202,65],
- OPS.GE,
- [1,1,1,0,1,1,1,0]
- );
- testCompOps("func_i16x8_compare_u",
- [111,126,255,64,101,1,85,127],
- [12,127,200,126,43,2,85,128],
- OPS.GE,
- [1,0,1,0,1,0,1,0]
- );
- testCompOps("func_f32x4_compare",
- [1234.5,0,NaN,-567.25],
- [1234.5,45,202,-567.25],
- OPS.EQ,
- [1,0,0,1]
- );
- testCompOps("func_f32x4_compare",
- [277,1234.5,-100,1234.5],
- [431,1234.5,NaN,1234.5],
- OPS.EQ,
- [0,1,0,1]
- );
- testCompOps("func_f32x4_compare",
- [1234.5,0,-100,-567.25],
- [1234.5,45,NaN,-567.25],
- OPS.NE,
- [0,1,1,0]
- );
- testCompOps("func_f32x4_compare",
- [277,1234.5,-100,1234.5],
- [431,1234.5,NaN,1234.5],
- OPS.NE,
- [1,0,1,0]
- );
- testCompOps("func_f32x4_compare",
- [-1,1440,2100,-567.25],
- [1234.5,45,202,4],
- OPS.LT,
- [1,0,0,1]
- );
- testCompOps("func_f32x4_compare",
- [431,-2147483646,555,1234.1],
- [277,1234.5,-100,1234.5],
- OPS.LT,
- [0,1,0,1]
- );
- testCompOps("func_f32x4_compare",
- [1234.5,1440,2100,4],
- [1234.5,45,202,4],
- OPS.LE,
- [1,0,0,1]
- );
- testCompOps("func_f32x4_compare",
- [431,-2147483646,555,21474835],
- [277,-2147483646,-100,21474836],
- OPS.LE,
- [0,1,0,1]
- );
- testCompOps("func_f32x4_compare",
- [-1,1440,2100,-567.25],
- [1234.5,45,202,4],
- OPS.GT,
- [0,1,1,0]
- );
- testCompOps("func_f32x4_compare",
- [431,-2147483646,555,1234.4],
- [277,1234.5,-100,1234.5],
- OPS.GT,
- [1,0,1,0]
- );
- testCompOps("func_f32x4_compare",
- [-1,1440,2100,-567.25],
- [1234.5,1440,202,4],
- OPS.GE,
- [0,1,1,0]
- );
- testCompOps("func_f32x4_compare",
- [431,-2147483646,-100,1234.4],
- [277,1234.5,-100,1234.5],
- OPS.GE,
- [1,0,1,0]
- );
- testCompOps("func_f64x2_compare",
- [1234.5,0],
- [1234.5,45],
- OPS.EQ,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [NaN,-567.25],
- [202,-567.25],
- OPS.EQ,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [277,1234.5],
- [431,1234.5],
- OPS.EQ,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [-100,1234.5],
- [NaN,1234.5],
- OPS.EQ,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [1234.5,0],
- [1234.5,45],
- OPS.NE,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [-100,-567.25],
- [NaN,-567.25],
- OPS.NE,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [277,1234.5],
- [431,1234.5],
- OPS.NE,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [-100,1234.5],
- [NaN,1234.5],
- OPS.NE,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [-1,1440],
- [1234.5,45],
- OPS.LT,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [2100,-567.25],
- [202,4],
- OPS.LT,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [431,-2147483646],
- [277,1234.5],
- OPS.LT,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [555,1234.1],
- [-100,1234.5],
- OPS.LT,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [1234.5,1440],
- [1234.5,45],
- OPS.LE,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [2100,4],
- [202,4],
- OPS.LE,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [431,-2147483646],
- [277,-2147483646],
- OPS.LE,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [555,21474835],
- [-100,21474836],
- OPS.LE,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [-1,1440],
- [1234.5,45],
- OPS.GT,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [2100,-567.25],
- [202,4],
- OPS.GT,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [431,-2147483646],
- [277,1234.5],
- OPS.GT,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [555,1234.4],
- [-100,1234.5],
- OPS.GT,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [-1,1440],
- [1234.5,1440],
- OPS.GE,
- [0,1]
- );
- testCompOps("func_f64x2_compare",
- [2100,-567.25],
- [202,4],
- OPS.GE,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [-100,1234.4],
- [-100,1234.5],
- OPS.GE,
- [1,0]
- );
- testCompOps("func_f64x2_compare",
- [431,-2147483646],
- [277,1234.5],
- OPS.GE,
- [1,0]
- );
- if (passed) {
- print("Passed");
- }
|