Skip to content

Commit dec2b41

Browse files
author
Lars T Hansen
committed
Bug 1669938 - Promote fp rounding wasm SIMD instructions to accepted status. r=jseward
Background: WebAssembly/simd#232 For all the rounding SIMD instructions: - remove the internal 'Experimental' opcode suffix in the C++ code - remove the guard on experimental Wasm instructions in all the C++ decoders - move the test cases from simd/experimental.js to simd/ad-hack.js I have checked that current V8 and wasm-tools use the same opcode mappings. V8 in turn guarantees the correct mapping for LLVM and binaryen. Drive-by bug fix: the test predicate for f64 square root was wrong, it would round its argument to float. This did not matter for the test inputs we had but started to matter when I added more difficult inputs for testing rounding. Differential Revision: https://phabricator.services.mozilla.com/D92926
1 parent e015128 commit dec2b41

File tree

9 files changed

+68
-109
lines changed

9 files changed

+68
-109
lines changed

js/src/jit-test/tests/wasm/simd/ad-hack.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ BigInt64Array.rectify = (x) => BigInt(x);
271271

272272
Float32Array.inputs = [[1, -1, 1e10, -1e10],
273273
[-1, -2, -1e10, 1e10],
274+
[5.1, -1.1, -4.3, -0],
274275
...permute([1, -10, NaN, Infinity])];
275276
Float32Array.rectify = (x) => Math.fround(x);
276277

@@ -812,8 +813,16 @@ function iabs(bits) { return (a) => zero_extend(a < 0 ? -a : a, bits) }
812813
function fneg(a) { return -a }
813814
function fabs(a) { return Math.abs(a) }
814815
function fsqrt(a) { return Math.fround(Math.sqrt(Math.fround(a))) }
815-
function sqrt(a) { return Math.sqrt(Math.fround(a)) }
816+
function dsqrt(a) { return Math.sqrt(a) }
816817
function bitnot(a) { return (~a) & 255 }
818+
function ffloor(x) { return Math.fround(Math.floor(x)) }
819+
function fceil(x) { return Math.fround(Math.ceil(x)) }
820+
function ftrunc(x) { return Math.fround(Math.sign(x)*Math.floor(Math.abs(x))) }
821+
function fnearest(x) { return Math.fround(Math.round(x)) }
822+
function dfloor(x) { return Math.floor(x) }
823+
function dceil(x) { return Math.ceil(x) }
824+
function dtrunc(x) { return Math.sign(x)*Math.floor(Math.abs(x)) }
825+
function dnearest(x) { return Math.round(x) }
817826

818827
for ( let [op, memtype, rop, resultmemtype] of
819828
[['i8x16.neg', Int8Array, ineg(8)],
@@ -828,7 +837,15 @@ for ( let [op, memtype, rop, resultmemtype] of
828837
['f32x4.abs', Float32Array, fabs],
829838
['f64x2.abs', Float64Array, fabs],
830839
['f32x4.sqrt', Float32Array, fsqrt],
831-
['f64x2.sqrt', Float64Array, sqrt],
840+
['f64x2.sqrt', Float64Array, dsqrt],
841+
['f32x4.ceil', Float32Array, fceil],
842+
['f32x4.floor', Float32Array, ffloor],
843+
['f32x4.trunc', Float32Array, ftrunc],
844+
['f32x4.nearest', Float32Array, fnearest],
845+
['f64x2.ceil', Float64Array, dceil],
846+
['f64x2.floor', Float64Array, dfloor],
847+
['f64x2.trunc', Float64Array, dtrunc],
848+
['f64x2.nearest', Float64Array, dnearest],
832849
['v128.not', Uint8Array, bitnot],
833850
])
834851
{

js/src/jit-test/tests/wasm/simd/experimental.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ function iota(len) {
5353
function pmin(x, y) { return y < x ? y : x }
5454
function pmax(x, y) { return x < y ? y : x }
5555

56-
function ffloor(x) { return Math.fround(Math.floor(x)) }
57-
function fceil(x) { return Math.fround(Math.ceil(x)) }
58-
function ftrunc(x) { return Math.fround(Math.sign(x)*Math.floor(Math.abs(x))) }
59-
function fnearest(x) { return Math.fround(Math.round(x)) }
60-
61-
function dfloor(x) { return Math.floor(x) }
62-
function dceil(x) { return Math.ceil(x) }
63-
function dtrunc(x) { return Math.sign(x)*Math.floor(Math.abs(x)) }
64-
function dnearest(x) { return Math.round(x) }
65-
6656
const v2vSig = {args:[], ret:VoidCode};
6757

6858
function V128Load(addr) {
@@ -138,40 +128,6 @@ ins.exports.run();
138128
var result = get(mem32, 0, 4);
139129
assertSame(result, ans);
140130

141-
// Rounding, https://github.com/WebAssembly/simd/pull/232
142-
143-
var fxs = [5.1, -1.1, -4.3, 0];
144-
var dxs = [5.1, -1.1];
145-
146-
for ( let [opcode, xs, operator] of [[F32x4CeilCode, fxs, fceil],
147-
[F32x4FloorCode, fxs, ffloor],
148-
[F32x4TruncCode, fxs, ftrunc],
149-
[F32x4NearestCode, fxs, fnearest],
150-
[F64x2CeilCode, dxs, dceil],
151-
[F64x2FloorCode, dxs, dfloor],
152-
[F64x2TruncCode, dxs, dtrunc],
153-
[F64x2NearestCode, dxs, dnearest]] ) {
154-
var k = xs.length;
155-
var ans = xs.map(operator);
156-
157-
var ins = wasmEval(moduleWithSections([
158-
sigSection([v2vSig]),
159-
declSection([0]),
160-
memorySection(1),
161-
exportSection([{funcIndex: 0, name: "run"},
162-
{memIndex: 0, name: "mem"}]),
163-
bodySection([
164-
funcBody({locals:[],
165-
body: [...V128StoreExpr(0, [...V128Load(16),
166-
SimdPrefix, varU32(opcode)])]})])]));
167-
168-
var mem = new (k == 4 ? Float32Array : Float64Array)(ins.exports.mem.buffer);
169-
set(mem, k, xs);
170-
ins.exports.run();
171-
var result = get(mem, 0, k);
172-
assertSame(result, ans);
173-
}
174-
175131
// Zero-extending SIMD load, https://github.com/WebAssembly/simd/pull/237
176132

177133
for ( let [opcode, k, log2align, cons, cast] of [[V128Load32ZeroCode, 4, 2, Int32Array, Number],

js/src/jit/MacroAssembler.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,8 +2674,7 @@ class MacroAssembler : public MacroAssemblerSpecific {
26742674
inline void widenDotInt16x8(FloatRegister rhs, FloatRegister lhsDest)
26752675
DEFINED_ON(x86_shared, arm64);
26762676

2677-
// Floating point rounding (experimental as of August, 2020)
2678-
// https://github.com/WebAssembly/simd/pull/232
2677+
// Floating point rounding
26792678

26802679
inline void ceilFloat32x4(FloatRegister src, FloatRegister dest)
26812680
DEFINED_ON(x86_shared, arm64);

js/src/jit/x86-shared/CodeGenerator-x86-shared.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,28 +3136,28 @@ void CodeGenerator::visitWasmUnarySimd128(LWasmUnarySimd128* ins) {
31363136
case wasm::SimdOp::I32x4Abs:
31373137
masm.absInt32x4(src, dest);
31383138
break;
3139-
case wasm::SimdOp::F32x4CeilExperimental:
3139+
case wasm::SimdOp::F32x4Ceil:
31403140
masm.ceilFloat32x4(src, dest);
31413141
break;
3142-
case wasm::SimdOp::F32x4FloorExperimental:
3142+
case wasm::SimdOp::F32x4Floor:
31433143
masm.floorFloat32x4(src, dest);
31443144
break;
3145-
case wasm::SimdOp::F32x4TruncExperimental:
3145+
case wasm::SimdOp::F32x4Trunc:
31463146
masm.truncFloat32x4(src, dest);
31473147
break;
3148-
case wasm::SimdOp::F32x4NearestExperimental:
3148+
case wasm::SimdOp::F32x4Nearest:
31493149
masm.nearestFloat32x4(src, dest);
31503150
break;
3151-
case wasm::SimdOp::F64x2CeilExperimental:
3151+
case wasm::SimdOp::F64x2Ceil:
31523152
masm.ceilFloat64x2(src, dest);
31533153
break;
3154-
case wasm::SimdOp::F64x2FloorExperimental:
3154+
case wasm::SimdOp::F64x2Floor:
31553155
masm.floorFloat64x2(src, dest);
31563156
break;
3157-
case wasm::SimdOp::F64x2TruncExperimental:
3157+
case wasm::SimdOp::F64x2Trunc:
31583158
masm.truncFloat64x2(src, dest);
31593159
break;
3160-
case wasm::SimdOp::F64x2NearestExperimental:
3160+
case wasm::SimdOp::F64x2Nearest:
31613161
masm.nearestFloat64x2(src, dest);
31623162
break;
31633163
default:

js/src/wasm/WasmBaselineCompile.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15037,29 +15037,21 @@ bool BaseCompiler::emitBody() {
1503715037
CHECK_NEXT(dispatchVectorUnary(AbsI16x8));
1503815038
case uint32_t(SimdOp::I32x4Abs):
1503915039
CHECK_NEXT(dispatchVectorUnary(AbsI32x4));
15040-
case uint32_t(SimdOp::F32x4CeilExperimental):
15041-
CHECK_SIMD_EXPERIMENTAL();
15040+
case uint32_t(SimdOp::F32x4Ceil):
1504215041
CHECK_NEXT(dispatchVectorUnary(CeilF32x4));
15043-
case uint32_t(SimdOp::F32x4FloorExperimental):
15044-
CHECK_SIMD_EXPERIMENTAL();
15042+
case uint32_t(SimdOp::F32x4Floor):
1504515043
CHECK_NEXT(dispatchVectorUnary(FloorF32x4));
15046-
case uint32_t(SimdOp::F32x4TruncExperimental):
15047-
CHECK_SIMD_EXPERIMENTAL();
15044+
case uint32_t(SimdOp::F32x4Trunc):
1504815045
CHECK_NEXT(dispatchVectorUnary(TruncF32x4));
15049-
case uint32_t(SimdOp::F32x4NearestExperimental):
15050-
CHECK_SIMD_EXPERIMENTAL();
15046+
case uint32_t(SimdOp::F32x4Nearest):
1505115047
CHECK_NEXT(dispatchVectorUnary(NearestF32x4));
15052-
case uint32_t(SimdOp::F64x2CeilExperimental):
15053-
CHECK_SIMD_EXPERIMENTAL();
15048+
case uint32_t(SimdOp::F64x2Ceil):
1505415049
CHECK_NEXT(dispatchVectorUnary(CeilF64x2));
15055-
case uint32_t(SimdOp::F64x2FloorExperimental):
15056-
CHECK_SIMD_EXPERIMENTAL();
15050+
case uint32_t(SimdOp::F64x2Floor):
1505715051
CHECK_NEXT(dispatchVectorUnary(FloorF64x2));
15058-
case uint32_t(SimdOp::F64x2TruncExperimental):
15059-
CHECK_SIMD_EXPERIMENTAL();
15052+
case uint32_t(SimdOp::F64x2Trunc):
1506015053
CHECK_NEXT(dispatchVectorUnary(TruncF64x2));
15061-
case uint32_t(SimdOp::F64x2NearestExperimental):
15062-
CHECK_SIMD_EXPERIMENTAL();
15054+
case uint32_t(SimdOp::F64x2Nearest):
1506315055
CHECK_NEXT(dispatchVectorUnary(NearestF64x2));
1506415056
case uint32_t(SimdOp::I8x16Shl):
1506515057
CHECK_NEXT(dispatchVectorVariableShift(ShiftLeftI8x16));

js/src/wasm/WasmConstants.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,14 +642,14 @@ enum class SimdOp {
642642
I64x2Mul = 0xd5,
643643
// MinS = 0xd6
644644
// MinU = 0xd7
645-
F32x4CeilExperimental = 0xd8,
646-
F32x4FloorExperimental = 0xd9,
647-
F32x4TruncExperimental = 0xda,
648-
F32x4NearestExperimental = 0xdb,
649-
F64x2CeilExperimental = 0xdc,
650-
F64x2FloorExperimental = 0xdd,
651-
F64x2TruncExperimental = 0xde,
652-
F64x2NearestExperimental = 0xdf,
645+
F32x4Ceil = 0xd8,
646+
F32x4Floor = 0xd9,
647+
F32x4Trunc = 0xda,
648+
F32x4Nearest = 0xdb,
649+
F64x2Ceil = 0xdc,
650+
F64x2Floor = 0xdd,
651+
F64x2Trunc = 0xde,
652+
F64x2Nearest = 0xdf,
653653
F32x4Abs = 0xe0,
654654
F32x4Neg = 0xe1,
655655
// Round = 0xe2

js/src/wasm/WasmIonCompile.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4950,16 +4950,14 @@ static bool EmitBodyExprs(FunctionCompiler& f) {
49504950
case uint32_t(SimdOp::I8x16Abs):
49514951
case uint32_t(SimdOp::I16x8Abs):
49524952
case uint32_t(SimdOp::I32x4Abs):
4953-
CHECK(EmitUnarySimd128(f, SimdOp(op.b1)));
4954-
case uint32_t(SimdOp::F32x4CeilExperimental):
4955-
case uint32_t(SimdOp::F32x4FloorExperimental):
4956-
case uint32_t(SimdOp::F32x4TruncExperimental):
4957-
case uint32_t(SimdOp::F32x4NearestExperimental):
4958-
case uint32_t(SimdOp::F64x2CeilExperimental):
4959-
case uint32_t(SimdOp::F64x2FloorExperimental):
4960-
case uint32_t(SimdOp::F64x2TruncExperimental):
4961-
case uint32_t(SimdOp::F64x2NearestExperimental):
4962-
CHECK_SIMD_EXPERIMENTAL();
4953+
case uint32_t(SimdOp::F32x4Ceil):
4954+
case uint32_t(SimdOp::F32x4Floor):
4955+
case uint32_t(SimdOp::F32x4Trunc):
4956+
case uint32_t(SimdOp::F32x4Nearest):
4957+
case uint32_t(SimdOp::F64x2Ceil):
4958+
case uint32_t(SimdOp::F64x2Floor):
4959+
case uint32_t(SimdOp::F64x2Trunc):
4960+
case uint32_t(SimdOp::F64x2Nearest):
49634961
CHECK(EmitUnarySimd128(f, SimdOp(op.b1)));
49644962
case uint32_t(SimdOp::I8x16AnyTrue):
49654963
case uint32_t(SimdOp::I16x8AnyTrue):

js/src/wasm/WasmOpIter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,14 +462,14 @@ OpKind wasm::Classify(OpBytes op) {
462462
case SimdOp::I8x16Abs:
463463
case SimdOp::I16x8Abs:
464464
case SimdOp::I32x4Abs:
465-
case SimdOp::F32x4CeilExperimental:
466-
case SimdOp::F32x4FloorExperimental:
467-
case SimdOp::F32x4TruncExperimental:
468-
case SimdOp::F32x4NearestExperimental:
469-
case SimdOp::F64x2CeilExperimental:
470-
case SimdOp::F64x2FloorExperimental:
471-
case SimdOp::F64x2TruncExperimental:
472-
case SimdOp::F64x2NearestExperimental:
465+
case SimdOp::F32x4Ceil:
466+
case SimdOp::F32x4Floor:
467+
case SimdOp::F32x4Trunc:
468+
case SimdOp::F32x4Nearest:
469+
case SimdOp::F64x2Ceil:
470+
case SimdOp::F64x2Floor:
471+
case SimdOp::F64x2Trunc:
472+
case SimdOp::F64x2Nearest:
473473
WASM_SIMD_OP(OpKind::Unary);
474474
case SimdOp::I8x16Shl:
475475
case SimdOp::I8x16ShrS:

js/src/wasm/WasmValidate.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,17 +1088,14 @@ static bool DecodeFunctionBodyExprs(const ModuleEnvironment& env,
10881088
case uint32_t(SimdOp::I8x16Abs):
10891089
case uint32_t(SimdOp::I16x8Abs):
10901090
case uint32_t(SimdOp::I32x4Abs):
1091-
CHECK(iter.readUnary(ValType::V128, &nothing));
1092-
1093-
case uint32_t(SimdOp::F32x4CeilExperimental):
1094-
case uint32_t(SimdOp::F32x4FloorExperimental):
1095-
case uint32_t(SimdOp::F32x4TruncExperimental):
1096-
case uint32_t(SimdOp::F32x4NearestExperimental):
1097-
case uint32_t(SimdOp::F64x2CeilExperimental):
1098-
case uint32_t(SimdOp::F64x2FloorExperimental):
1099-
case uint32_t(SimdOp::F64x2TruncExperimental):
1100-
case uint32_t(SimdOp::F64x2NearestExperimental):
1101-
CHECK_SIMD_EXPERIMENTAL();
1091+
case uint32_t(SimdOp::F32x4Ceil):
1092+
case uint32_t(SimdOp::F32x4Floor):
1093+
case uint32_t(SimdOp::F32x4Trunc):
1094+
case uint32_t(SimdOp::F32x4Nearest):
1095+
case uint32_t(SimdOp::F64x2Ceil):
1096+
case uint32_t(SimdOp::F64x2Floor):
1097+
case uint32_t(SimdOp::F64x2Trunc):
1098+
case uint32_t(SimdOp::F64x2Nearest):
11021099
CHECK(iter.readUnary(ValType::V128, &nothing));
11031100

11041101
case uint32_t(SimdOp::I8x16Shl):

0 commit comments

Comments
 (0)