Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 49c0d8a

Browse files
author
Lars T Hansen
committed
Bug 1669964 - Fix code generation for pmin/pmax on x86. r=jseward
pmin and pmax handled NaN incorrectly because the wonky semantics of MINPS and MAXPS require arguments to be reversed to properly handle NaN for these wasm SIMD instructions. We fix this the expedient way: we keep the same masm abstraction and introduce moves to rearrange the arguments. This should be optimized eventually and a bug will be filed for that now. Differential Revision: https://phabricator.services.mozilla.com/D92927
1 parent dec2b41 commit 49c0d8a

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ function V128StoreExpr(addr, v) {
6767
}
6868

6969
// Pseudo-min/max, https://github.com/WebAssembly/simd/pull/122
70-
var fxs = [5, 1, -4, 2];
70+
var fxs = [5, 1, -4, NaN];
7171
var fys = [6, 0, -7, 3];
72-
var dxs = [5, 1];
72+
var dxs = [5, NaN];
7373
var dys = [6, 0];
7474

7575
for ( let [opcode, xs, ys, operator] of [[F32x4PMinCode, fxs, fys, pmin],

js/src/jit/x86-shared/MacroAssembler-x86-shared-inl.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,24 +1981,36 @@ void MacroAssembler::maxFloat64x2(FloatRegister rhs, FloatRegister lhsDest,
19811981

19821982
void MacroAssembler::pseudoMinFloat32x4(FloatRegister rhs,
19831983
FloatRegister lhsDest) {
1984-
vminps(Operand(rhs), lhsDest, lhsDest);
1984+
ScratchSimd128Scope scratch(*this);
1985+
vmovaps(rhs, scratch);
1986+
vminps(Operand(lhsDest), scratch, scratch);
1987+
vmovaps(scratch, lhsDest);
19851988
}
19861989

19871990
void MacroAssembler::pseudoMinFloat64x2(FloatRegister rhs,
19881991
FloatRegister lhsDest) {
1989-
vminpd(Operand(rhs), lhsDest, lhsDest);
1992+
ScratchSimd128Scope scratch(*this);
1993+
vmovapd(rhs, scratch);
1994+
vminpd(Operand(lhsDest), scratch, scratch);
1995+
vmovapd(scratch, lhsDest);
19901996
}
19911997

19921998
// Compare-based maximum
19931999

19942000
void MacroAssembler::pseudoMaxFloat32x4(FloatRegister rhs,
19952001
FloatRegister lhsDest) {
1996-
vmaxps(Operand(rhs), lhsDest, lhsDest);
2002+
ScratchSimd128Scope scratch(*this);
2003+
vmovaps(rhs, scratch);
2004+
vmaxps(Operand(lhsDest), scratch, scratch);
2005+
vmovaps(scratch, lhsDest);
19972006
}
19982007

19992008
void MacroAssembler::pseudoMaxFloat64x2(FloatRegister rhs,
20002009
FloatRegister lhsDest) {
2001-
vmaxpd(Operand(rhs), lhsDest, lhsDest);
2010+
ScratchSimd128Scope scratch(*this);
2011+
vmovapd(rhs, scratch);
2012+
vmaxpd(Operand(lhsDest), scratch, scratch);
2013+
vmovapd(scratch, lhsDest);
20022014
}
20032015

20042016
void MacroAssembler::widenDotInt16x8(FloatRegister rhs, FloatRegister lhsDest) {

0 commit comments

Comments
 (0)