Skip to content

Commit 7ba4a7f

Browse files
committed
Wasm: codegen for trunc and nearest with more tests
1 parent 398fad1 commit 7ba4a7f

File tree

6 files changed

+56
-27
lines changed

6 files changed

+56
-27
lines changed

lib/Backend/LowerMDShared.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8918,6 +8918,10 @@ void LowererMD::GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMeth
89188918
case Js::OpCode::InlineMathFloor:
89198919
case Js::OpCode::InlineMathCeil:
89208920
case Js::OpCode::InlineMathRound:
8921+
#ifdef ENABLE_WASM
8922+
case Js::OpCode::Trunc_A:
8923+
case Js::OpCode::Nearest_A:
8924+
#endif //ENABLE_WASM
89218925
{
89228926
Assert(AutoSystemInfo::Data.SSE4_1Available());
89238927
Assert(instr->GetDst()->IsInt32() || instr->GetDst()->IsFloat());
@@ -9150,6 +9154,7 @@ void LowererMD::GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMeth
91509154

91519155
// ROUNDSD srcCopy, srcCopy, round_mode
91529156
IR::Opnd * roundMode;
9157+
#ifdef ENABLE_WASM
91539158
if (instr->m_opcode == Js::OpCode::Trunc_A)
91549159
{
91559160
roundMode = IR::IntConstOpnd::New(0x03, TyInt32, this->m_func);
@@ -9158,17 +9163,21 @@ void LowererMD::GenerateFastInlineBuiltInCall(IR::Instr* instr, IR::JnHelperMeth
91589163
{
91599164
roundMode = IR::IntConstOpnd::New(0x00, TyInt32, this->m_func);
91609165
}
9161-
else if(isNotCeil)
9162-
{
9163-
roundMode = IR::IntConstOpnd::New(0x01, TyInt32, this->m_func);
9164-
}
9165-
else if (instr->GetDst()->IsInt32() || instr->m_opcode != Js::OpCode::InlineMathFloor)
9166-
{
9167-
roundMode = IR::IntConstOpnd::New(0x02, TyInt32, this->m_func);
9168-
}
91699166
else
9167+
#endif //ENABLE_WASM
91709168
{
9171-
roundMode = IR::IntConstOpnd::New(0x03, TyInt32, this->m_func);
9169+
if (isNotCeil)
9170+
{
9171+
roundMode = IR::IntConstOpnd::New(0x01, TyInt32, this->m_func);
9172+
}
9173+
else if (instr->GetDst()->IsInt32() || instr->m_opcode != Js::OpCode::InlineMathFloor)
9174+
{
9175+
roundMode = IR::IntConstOpnd::New(0x02, TyInt32, this->m_func);
9176+
}
9177+
else
9178+
{
9179+
roundMode = IR::IntConstOpnd::New(0x03, TyInt32, this->m_func);
9180+
}
91729181
}
91739182
IR::Instr* roundInstr = IR::Instr::New(src->IsFloat64() ? Js::OpCode::ROUNDSD : Js::OpCode::ROUNDSS, roundedFloat, roundedFloat, roundMode, this->m_func);
91749183

lib/WasmReader/WasmBinaryOpCodes.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ WASM_UNARY__OPCODE(F32Neg, 0x7c, F_F , Neg_Flt , false)
191191
WASM_BINARY_OPCODE(F32CopySign, 0x7d, F_FF, Copysign_Flt , false)
192192
WASM_UNARY__OPCODE(F32Ceil, 0x7e, F_F , Ceil_Flt , false)
193193
WASM_UNARY__OPCODE(F32Floor, 0x7f, F_F , Floor_Flt , false)
194-
WASM_UNARY__OPCODE(F32Trunc, 0x80, F_F , Trunc_Flt , true)
195-
WASM_UNARY__OPCODE(F32NearestInt, 0x81, F_F , Nearest_Flt , true)
194+
WASM_UNARY__OPCODE(F32Trunc, 0x80, F_F , Trunc_Flt , false)
195+
WASM_UNARY__OPCODE(F32NearestInt, 0x81, F_F , Nearest_Flt , false)
196196
WASM_UNARY__OPCODE(F32Sqrt, 0x82, F_F , Sqrt_Flt , false)
197197
WASM_BINARY_OPCODE(F32Eq, 0x83, I_FF, CmEq_Flt , false)
198198
WASM_BINARY_OPCODE(F32Ne, 0x84, I_FF, CmNe_Flt , false)
@@ -211,8 +211,8 @@ WASM_UNARY__OPCODE(F64Neg, 0x90, D_D , Neg_Db , false)
211211
WASM_BINARY_OPCODE(F64CopySign, 0x91, D_DD, Copysign_Db , true)
212212
WASM_UNARY__OPCODE(F64Ceil, 0x92, D_D , Ceil_Db , false)
213213
WASM_UNARY__OPCODE(F64Floor, 0x93, D_D , Floor_Db , false)
214-
WASM_UNARY__OPCODE(F64Trunc, 0x94, D_D , Trunc_Db , true)
215-
WASM_UNARY__OPCODE(F64NearestInt, 0x95, D_D , Nearest_Db , true)
214+
WASM_UNARY__OPCODE(F64Trunc, 0x94, D_D , Trunc_Db , false)
215+
WASM_UNARY__OPCODE(F64NearestInt, 0x95, D_D , Nearest_Db , false)
216216
WASM_UNARY__OPCODE(F64Sqrt, 0x96, D_D , Sqrt_Db , false)
217217
WASM_BINARY_OPCODE(F64Eq, 0x97, I_DD, CmEq_Db , false)
218218
WASM_BINARY_OPCODE(F64Ne, 0x98, I_DD, CmNe_Db , false)
@@ -248,6 +248,7 @@ WASM_UNARY__OPCODE(I64ReinterpretF64, 0xb5, L_D , Nop , true)
248248
WASM_BINARY_OPCODE(I32Ror, 0xb6, I_II, Ror_Int , false)
249249
WASM_BINARY_OPCODE(I32Rol, 0xb7, I_II, Rol_Int , false)
250250

251+
251252
#undef WASM_OPCODE
252253
#undef WASM_SIGNATURE
253254
#undef WASM_CTRL_OPCODE

test/wasm/misc.baseline

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,18 @@
77
1
88
0
99
0
10+
0
11+
-1
12+
NaN
13+
NaN
14+
Infinity
15+
-Infinity
1016
1
1117
0
18+
0
19+
-1
20+
-2
21+
NaN
22+
NaN
23+
Infinity
24+
-Infinity

test/wasm/misc.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,19 @@ print(a.f32copysign(255.0,1.0)); // == 255.0
1515
print(a.eqz(0)); // == 1
1616
print(a.eqz(-1)); // == 0
1717
print(a.eqz(1)); // == 0
18-
//print(a.trunc(0.5)); // == 0
19-
//print(a.trunc(-1.5)); // == -1
20-
//print(a.trunc(Number.NaN)); // == NaN
21-
//print(a.trunc(-Number.NaN)); // == -NaN
18+
print(a.trunc(0.5)); // == 0
19+
print(a.trunc(-1.5)); // == -1
20+
print(a.trunc(NaN)); // == NaN
21+
print(a.trunc(-NaN)); // == NaN
22+
print(a.trunc(Infinity)); // == Infinity
23+
print(a.trunc(-Infinity)); // == -Infinity
2224
print(a.ifeqz(0)); // == 1
2325
print(a.ifeqz(-1)); // == 0
24-
//print(a.nearest(-0.1)); // == 0
25-
//print(a.nearest(-0.7)); // == -1
26-
//print(a.nearest(-1.5)); // == -2
26+
print(a.nearest(-0.1)); // == 0
27+
print(a.nearest(-0.7)); // == -1
28+
print(a.nearest(-1.5)); // == -2
29+
print(a.nearest(NaN)); // == NaN
30+
print(a.nearest(-NaN)); // == NaN
31+
print(a.nearest(Infinity)); // == Infinity
32+
print(a.nearest(-Infinity)); // == -Infinity
2733
//print(a.f64copysign(255.0,-1.0)); // == -255.0

test/wasm/misc.wasm

-29 Bytes
Binary file not shown.

test/wasm/misc.wast

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
(module
77
(func (param f32) (param f32) (result f32)
88
(return (f32.copysign (get_local 0) (get_local 1))))
9-
(func (param f64) (param f64) (result f64)
10-
(return (f64.copysign (get_local 0) (get_local 1))))
9+
;;(func (param f64) (param f64) (result f64)
10+
;; (return (f64.copysign (get_local 0) (get_local 1))))
1111
(func (param i32) (result i32)
1212
(return (i32.eqz (get_local 0))))
1313
(func (param f32) (result f32)
@@ -18,9 +18,9 @@
1818
(if (i32.eqz (get_local 0)) (return (i32.const 1)))
1919
(return (i32.const 0)))
2020
(export "f32copysign" 0)
21-
(export "f64copysign" 1)
22-
(export "eqz" 2)
23-
(export "trunc" 3)
24-
(export "nearest" 4)
25-
(export "ifeqz" 5)
21+
;;(export "f64copysign" 1)
22+
(export "eqz" 1)
23+
(export "trunc" 2)
24+
(export "nearest" 3)
25+
(export "ifeqz" 4)
2626
)

0 commit comments

Comments
 (0)