Commit b8f9829a authored by Ng Zhi An's avatar Ng Zhi An Committed by Commit Bot

[wasm] Convert float to int without using external calls

Follow-up from https://crrev.com/c/2649147/. There are still 2 usages of
_wrapper functions in the interpreter, these are slightly more annoying
to get rid of since the definitions have a ifdef for MSCV/OS_WIN.

Bug: v8:11384
Change-Id: Ic5ca860678f406e1c832c99398b235707da058f9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2713166Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Commit-Queue: Zhi An Ng <zhin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72969}
parent 02cf7349
......@@ -459,13 +459,14 @@ dst_type CallExternalIntToFloatFunction(src_type input) {
return ReadUnalignedValue<dst_type>(data_addr);
}
template <typename dst_type, typename src_type, int32_t (*fn)(Address)>
dst_type CallExternalFloatToIntFunction(src_type input, TrapReason* trap) {
uint8_t data[std::max(sizeof(dst_type), sizeof(src_type))];
Address data_addr = reinterpret_cast<Address>(data);
WriteUnalignedValue<src_type>(data_addr, input);
if (!fn(data_addr)) *trap = kTrapFloatUnrepresentable;
return ReadUnalignedValue<dst_type>(data_addr);
template <typename dst_type, typename src_type>
dst_type ConvertFloatToIntOrTrap(src_type input, TrapReason* trap) {
if (base::IsValueInRangeForNumericType<dst_type>(input)) {
return static_cast<dst_type>(input);
} else {
*trap = kTrapFloatUnrepresentable;
return 0;
}
}
uint32_t ExecuteI32ConvertI64(int64_t a, TrapReason* trap) {
......@@ -473,23 +474,19 @@ uint32_t ExecuteI32ConvertI64(int64_t a, TrapReason* trap) {
}
int64_t ExecuteI64SConvertF32(float a, TrapReason* trap) {
return CallExternalFloatToIntFunction<int64_t, float,
float32_to_int64_wrapper>(a, trap);
return ConvertFloatToIntOrTrap<int64_t, float>(a, trap);
}
int64_t ExecuteI64SConvertF64(double a, TrapReason* trap) {
return CallExternalFloatToIntFunction<int64_t, double,
float64_to_int64_wrapper>(a, trap);
return ConvertFloatToIntOrTrap<int64_t, double>(a, trap);
}
uint64_t ExecuteI64UConvertF32(float a, TrapReason* trap) {
return CallExternalFloatToIntFunction<uint64_t, float,
float32_to_uint64_wrapper>(a, trap);
return ConvertFloatToIntOrTrap<uint64_t, float>(a, trap);
}
uint64_t ExecuteI64UConvertF64(double a, TrapReason* trap) {
return CallExternalFloatToIntFunction<uint64_t, double,
float64_to_uint64_wrapper>(a, trap);
return ConvertFloatToIntOrTrap<uint64_t, double>(a, trap);
}
int64_t ExecuteI64SConvertI32(int32_t a, TrapReason* trap) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment