Skip to content

Commit ff26244

Browse files
committed
Use ExactMath.truncateToUnsignedInt/Long and unsignedToFloat/Double.
1 parent 1a85a7d commit ff26244

File tree

1 file changed

+10
-34
lines changed

1 file changed

+10
-34
lines changed

wasm/src/org.graalvm.wasm/src/org/graalvm/wasm/nodes/WasmFunctionNode.java

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4117,7 +4117,7 @@ private void i32_trunc_f32_u(VirtualFrame frame, int stackPointer) {
41174117
enterErrorBranch();
41184118
throw WasmException.create(Failure.INT_OVERFLOW);
41194119
}
4120-
final int result = (int) WasmMath.truncFloatToUnsignedLong(x);
4120+
final int result = ExactMath.truncateToUnsignedInt(x);
41214121
pushInt(frame, stackPointer - 1, result);
41224122
}
41234123

@@ -4143,7 +4143,7 @@ private void i32_trunc_f64_u(VirtualFrame frame, int stackPointer) {
41434143
enterErrorBranch();
41444144
throw WasmException.create(Failure.INT_OVERFLOW);
41454145
}
4146-
final int result = (int) WasmMath.truncDoubleToUnsignedLong(x);
4146+
final int result = ExactMath.truncateToUnsignedInt(x);
41474147
pushInt(frame, stackPointer - 1, result);
41484148
}
41494149

@@ -4155,14 +4155,7 @@ private static void i32_trunc_sat_f32_s(VirtualFrame frame, int stackPointer) {
41554155

41564156
private static void i32_trunc_sat_f32_u(VirtualFrame frame, int stackPointer) {
41574157
final float x = popFloat(frame, stackPointer - 1);
4158-
final int result;
4159-
if (Float.isNaN(x) || x < MIN_FLOAT_TRUNCATABLE_TO_U_INT) {
4160-
result = 0;
4161-
} else if (x > MAX_FLOAT_TRUNCATABLE_TO_U_INT) {
4162-
result = 0xffff_ffff;
4163-
} else {
4164-
result = (int) WasmMath.truncFloatToUnsignedLong(x);
4165-
}
4158+
final int result = ExactMath.truncateToUnsignedInt(x);
41664159
pushInt(frame, stackPointer - 1, result);
41674160
}
41684161

@@ -4174,14 +4167,7 @@ private static void i32_trunc_sat_f64_s(VirtualFrame frame, int stackPointer) {
41744167

41754168
private static void i32_trunc_sat_f64_u(VirtualFrame frame, int stackPointer) {
41764169
final double x = popDouble(frame, stackPointer - 1);
4177-
final int result;
4178-
if (Double.isNaN(x) || x < MIN_DOUBLE_TRUNCATABLE_TO_U_INT) {
4179-
result = 0;
4180-
} else if (x > MAX_DOUBLE_TRUNCATABLE_TO_U_INT) {
4181-
result = 0xffff_ffff;
4182-
} else {
4183-
result = (int) WasmMath.truncDoubleToUnsignedLong(x);
4184-
}
4170+
final int result = ExactMath.truncateToUnsignedInt(x);
41854171
pushInt(frame, stackPointer - 1, result);
41864172
}
41874173

@@ -4218,7 +4204,7 @@ private void i64_trunc_f32_u(VirtualFrame frame, int stackPointer) {
42184204
enterErrorBranch();
42194205
throw WasmException.create(Failure.INT_OVERFLOW);
42204206
}
4221-
final long result = WasmMath.truncFloatToUnsignedLong(x);
4207+
final long result = ExactMath.truncateToUnsignedLong(x);
42224208
pushLong(frame, stackPointer - 1, result);
42234209
}
42244210

@@ -4244,7 +4230,7 @@ private void i64_trunc_f64_u(VirtualFrame frame, int stackPointer) {
42444230
enterErrorBranch();
42454231
throw WasmException.create(Failure.INT_OVERFLOW);
42464232
}
4247-
final long result = WasmMath.truncDoubleToUnsignedLong(x);
4233+
final long result = ExactMath.truncateToUnsignedLong(x);
42484234
pushLong(frame, stackPointer - 1, result);
42494235
}
42504236

@@ -4256,12 +4242,7 @@ private static void i64_trunc_sat_f32_s(VirtualFrame frame, int stackPointer) {
42564242

42574243
private static void i64_trunc_sat_f32_u(VirtualFrame frame, int stackPointer) {
42584244
final float x = popFloat(frame, stackPointer - 1);
4259-
final long result;
4260-
if (Float.isNaN(x) || x < MIN_FLOAT_TRUNCATABLE_TO_U_LONG) {
4261-
result = 0;
4262-
} else {
4263-
result = WasmMath.truncFloatToUnsignedLong(x);
4264-
}
4245+
final long result = ExactMath.truncateToUnsignedLong(x);
42654246
pushLong(frame, stackPointer - 1, result);
42664247
}
42674248

@@ -4273,12 +4254,7 @@ private static void i64_trunc_sat_f64_s(VirtualFrame frame, int stackPointer) {
42734254

42744255
private static void i64_trunc_sat_f64_u(VirtualFrame frame, int stackPointer) {
42754256
final double x = popDouble(frame, stackPointer - 1);
4276-
final long result;
4277-
if (Double.isNaN(x) || x < MIN_DOUBLE_TRUNCATABLE_TO_U_LONG) {
4278-
result = 0;
4279-
} else {
4280-
result = WasmMath.truncDoubleToUnsignedLong(x);
4281-
}
4257+
final long result = ExactMath.truncateToUnsignedLong(x);
42824258
pushLong(frame, stackPointer - 1, result);
42834259
}
42844260

@@ -4300,7 +4276,7 @@ private static void f32_convert_i64_s(VirtualFrame frame, int stackPointer) {
43004276

43014277
private static void f32_convert_i64_u(VirtualFrame frame, int stackPointer) {
43024278
long x = popLong(frame, stackPointer - 1);
4303-
float result = WasmMath.unsignedLongToFloat(x);
4279+
float result = ExactMath.unsignedToFloat(x);
43044280
pushFloat(frame, stackPointer - 1, result);
43054281
}
43064282

@@ -4327,7 +4303,7 @@ private static void f64_convert_i64_s(VirtualFrame frame, int stackPointer) {
43274303

43284304
private static void f64_convert_i64_u(VirtualFrame frame, int stackPointer) {
43294305
long x = popLong(frame, stackPointer - 1);
4330-
double result = WasmMath.unsignedLongToDouble(x);
4306+
double result = ExactMath.unsignedToDouble(x);
43314307
pushDouble(frame, stackPointer - 1, result);
43324308
}
43334309

0 commit comments

Comments
 (0)