Commit b1e34590 authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] Int64Lowering of FXXXConvertI64 instructions.

On 32-bit systems FXXXConvertI64 instructions are compiled to calls to
C functions. The TF node for the function call is already generated in
the wasm compiler, the lowering of the I64 parameter is done in the
Int64Lowering.

R=titzer@chromium.org, yangguo@chromium.org

Review URL: https://codereview.chromium.org/1738623003

Cr-Commit-Position: refs/heads/master@{#34487}
parent 64350d7f
......@@ -1361,6 +1361,7 @@ source_set("v8_base") {
"src/wasm/encoder.h",
"src/wasm/module-decoder.cc",
"src/wasm/module-decoder.h",
"src/wasm/wasm-external-refs.h",
"src/wasm/wasm-js.cc",
"src/wasm/wasm-js.h",
"src/wasm/wasm-macro-gen.h",
......
......@@ -61,6 +61,7 @@
#include "src/runtime/runtime.h"
#include "src/simulator.h" // For flushing instruction cache.
#include "src/snapshot/serializer-common.h"
#include "src/wasm/wasm-external-refs.h"
#if V8_TARGET_ARCH_IA32
#include "src/ia32/assembler-ia32-inl.h" // NOLINT
......@@ -1147,66 +1148,61 @@ ExternalReference ExternalReference::compute_output_frames_function(
Redirect(isolate, FUNCTION_ADDR(Deoptimizer::ComputeOutputFrames)));
}
static void f32_trunc_wrapper(float* param) { *param = truncf(*param); }
ExternalReference ExternalReference::f32_trunc_wrapper_function(
Isolate* isolate) {
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f32_trunc_wrapper)));
ExternalReference ExternalReference::wasm_f32_trunc(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(wasm::f32_trunc_wrapper)));
}
static void f32_floor_wrapper(float* param) { *param = floorf(*param); }
ExternalReference ExternalReference::f32_floor_wrapper_function(
Isolate* isolate) {
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f32_floor_wrapper)));
ExternalReference ExternalReference::wasm_f32_floor(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(wasm::f32_floor_wrapper)));
}
static void f32_ceil_wrapper(float* param) { *param = ceilf(*param); }
ExternalReference ExternalReference::f32_ceil_wrapper_function(
Isolate* isolate) {
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f32_ceil_wrapper)));
ExternalReference ExternalReference::wasm_f32_ceil(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(wasm::f32_ceil_wrapper)));
}
static void f32_nearest_int_wrapper(float* param) {
*param = nearbyintf(*param);
ExternalReference ExternalReference::wasm_f32_nearest_int(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(wasm::f32_nearest_int_wrapper)));
}
ExternalReference ExternalReference::f32_nearest_int_wrapper_function(
Isolate* isolate) {
ExternalReference ExternalReference::wasm_f64_trunc(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(f32_nearest_int_wrapper)));
Redirect(isolate, FUNCTION_ADDR(wasm::f64_trunc_wrapper)));
}
static void f64_trunc_wrapper(double* param) { *param = trunc(*param); }
ExternalReference ExternalReference::f64_trunc_wrapper_function(
Isolate* isolate) {
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_trunc_wrapper)));
ExternalReference ExternalReference::wasm_f64_floor(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(wasm::f64_floor_wrapper)));
}
static void f64_floor_wrapper(double* param) { *param = floor(*param); }
ExternalReference ExternalReference::wasm_f64_ceil(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(wasm::f64_ceil_wrapper)));
}
ExternalReference ExternalReference::f64_floor_wrapper_function(
Isolate* isolate) {
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_floor_wrapper)));
ExternalReference ExternalReference::wasm_f64_nearest_int(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(wasm::f64_nearest_int_wrapper)));
}
static void f64_ceil_wrapper(double* param) { *param = ceil(*param); }
ExternalReference ExternalReference::wasm_int64_to_float32(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(wasm::int64_to_float32_wrapper)));
}
ExternalReference ExternalReference::f64_ceil_wrapper_function(
Isolate* isolate) {
return ExternalReference(Redirect(isolate, FUNCTION_ADDR(f64_ceil_wrapper)));
ExternalReference ExternalReference::wasm_uint64_to_float32(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(wasm::uint64_to_float32_wrapper)));
}
static void f64_nearest_int_wrapper(double* param) {
*param = nearbyint(*param);
ExternalReference ExternalReference::wasm_int64_to_float64(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(wasm::int64_to_float64_wrapper)));
}
ExternalReference ExternalReference::f64_nearest_int_wrapper_function(
Isolate* isolate) {
ExternalReference ExternalReference::wasm_uint64_to_float64(Isolate* isolate) {
return ExternalReference(
Redirect(isolate, FUNCTION_ADDR(f64_nearest_int_wrapper)));
Redirect(isolate, FUNCTION_ADDR(wasm::uint64_to_float64_wrapper)));
}
static void f64_acos_wrapper(double* param) { *param = std::acos(*param); }
......
......@@ -914,14 +914,18 @@ class ExternalReference BASE_EMBEDDED {
static ExternalReference new_deoptimizer_function(Isolate* isolate);
static ExternalReference compute_output_frames_function(Isolate* isolate);
static ExternalReference f32_trunc_wrapper_function(Isolate* isolate);
static ExternalReference f32_floor_wrapper_function(Isolate* isolate);
static ExternalReference f32_ceil_wrapper_function(Isolate* isolate);
static ExternalReference f32_nearest_int_wrapper_function(Isolate* isolate);
static ExternalReference f64_trunc_wrapper_function(Isolate* isolate);
static ExternalReference f64_floor_wrapper_function(Isolate* isolate);
static ExternalReference f64_ceil_wrapper_function(Isolate* isolate);
static ExternalReference f64_nearest_int_wrapper_function(Isolate* isolate);
static ExternalReference wasm_f32_trunc(Isolate* isolate);
static ExternalReference wasm_f32_floor(Isolate* isolate);
static ExternalReference wasm_f32_ceil(Isolate* isolate);
static ExternalReference wasm_f32_nearest_int(Isolate* isolate);
static ExternalReference wasm_f64_trunc(Isolate* isolate);
static ExternalReference wasm_f64_floor(Isolate* isolate);
static ExternalReference wasm_f64_ceil(Isolate* isolate);
static ExternalReference wasm_f64_nearest_int(Isolate* isolate);
static ExternalReference wasm_int64_to_float32(Isolate* isolate);
static ExternalReference wasm_uint64_to_float32(Isolate* isolate);
static ExternalReference wasm_int64_to_float64(Isolate* isolate);
static ExternalReference wasm_uint64_to_float64(Isolate* isolate);
static ExternalReference f64_acos_wrapper_function(Isolate* isolate);
static ExternalReference f64_asin_wrapper_function(Isolate* isolate);
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_COMPILER_INT64_REDUCER_H_
#define V8_COMPILER_INT64_REDUCER_H_
#ifndef V8_COMPILER_INT64_LOWERING_H_
#define V8_COMPILER_INT64_LOWERING_H_
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
......@@ -62,4 +62,4 @@ class Int64Lowering {
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_INT64_REDUCER_H_
#endif // V8_COMPILER_INT64_LOWERING_H_
......@@ -548,25 +548,6 @@ Node* WasmGraphBuilder::Binop(wasm::WasmOpcode opcode, Node* left,
std::swap(left, right);
break;
// kExprI32ConvertI64:
// kExprI64SConvertI32:
// kExprI64UConvertI32:
// kExprF64ReinterpretI64:
// kExprI64ReinterpretF64:
// kExprI64Clz:
// kExprI64Ctz:
// kExprI64Popcnt:
// kExprF32SConvertI64:
// kExprF32UConvertI64:
// kExprF64SConvertI64:
// kExprF64UConvertI64:
// kExprI64SConvertF32:
// kExprI64SConvertF64:
// kExprI64UConvertF32:
// kExprI64UConvertF64:
#if WASM_64
// Opcodes only supported on 64-bit platforms.
// TODO(titzer): query the machine operator builder here instead of #ifdef.
......@@ -870,27 +851,56 @@ Node* WasmGraphBuilder::Unop(wasm::WasmOpcode opcode, Node* input) {
case wasm::kExprI32ConvertI64:
op = m->TruncateInt64ToInt32();
break;
#if WASM_64
// Opcodes only supported on 64-bit platforms.
// TODO(titzer): query the machine operator builder here instead of #ifdef.
case wasm::kExprI64SConvertI32:
op = m->ChangeInt32ToInt64();
break;
case wasm::kExprI64UConvertI32:
op = m->ChangeUint32ToUint64();
break;
// kExprI32ConvertI64:
// kExprI64SConvertI32:
// kExprI64UConvertI32:
// kExprF64ReinterpretI64:
// kExprI64ReinterpretF64:
// kExprI64Clz:
// kExprI64Ctz:
// kExprI64Popcnt:
// kExprF32SConvertI64:
case wasm::kExprF32SConvertI64:
if (kPointerSize == 4) {
return BuildF32SConvertI64(input);
}
op = m->RoundInt64ToFloat32();
break;
// kExprF32UConvertI64:
case wasm::kExprF32UConvertI64:
if (kPointerSize == 4) {
return BuildF32UConvertI64(input);
}
op = m->RoundUint64ToFloat32();
break;
// kExprF64SConvertI64:
case wasm::kExprF64SConvertI64:
if (kPointerSize == 4) {
return BuildF64SConvertI64(input);
}
op = m->RoundInt64ToFloat64();
break;
// kExprF64UConvertI64:
case wasm::kExprF64UConvertI64:
if (kPointerSize == 4) {
return BuildF64UConvertI64(input);
}
op = m->RoundUint64ToFloat64();
break;
// kExprI64SConvertF32:
// kExprI64SConvertF64:
// kExprI64UConvertF32:
// kExprI64UConvertF64:
#if WASM_64
// Opcodes only supported on 64-bit platforms.
// TODO(titzer): query the machine operator builder here instead of #ifdef.
case wasm::kExprI64SConvertI32:
op = m->ChangeInt32ToInt64();
break;
case wasm::kExprI64UConvertI32:
op = m->ChangeUint32ToUint64();
break;
case wasm::kExprI64SConvertF32: {
Node* trunc = graph()->NewNode(m->TryTruncateFloat32ToInt64(), input);
Node* result =
......@@ -1460,56 +1470,57 @@ Node* WasmGraphBuilder::BuildI64Popcnt(Node* input) {
Node* WasmGraphBuilder::BuildF32Trunc(Node* input) {
MachineType type = MachineType::Float32();
ExternalReference ref =
ExternalReference::f32_trunc_wrapper_function(jsgraph()->isolate());
ExternalReference::wasm_f32_trunc(jsgraph()->isolate());
return BuildCFuncInstruction(ref, type, input);
}
Node* WasmGraphBuilder::BuildF32Floor(Node* input) {
MachineType type = MachineType::Float32();
ExternalReference ref =
ExternalReference::f32_floor_wrapper_function(jsgraph()->isolate());
ExternalReference::wasm_f32_floor(jsgraph()->isolate());
return BuildCFuncInstruction(ref, type, input);
}
Node* WasmGraphBuilder::BuildF32Ceil(Node* input) {
MachineType type = MachineType::Float32();
ExternalReference ref =
ExternalReference::f32_ceil_wrapper_function(jsgraph()->isolate());
ExternalReference::wasm_f32_ceil(jsgraph()->isolate());
return BuildCFuncInstruction(ref, type, input);
}
Node* WasmGraphBuilder::BuildF32NearestInt(Node* input) {
MachineType type = MachineType::Float32();
ExternalReference ref =
ExternalReference::f32_nearest_int_wrapper_function(jsgraph()->isolate());
ExternalReference::wasm_f32_nearest_int(jsgraph()->isolate());
return BuildCFuncInstruction(ref, type, input);
}
Node* WasmGraphBuilder::BuildF64Trunc(Node* input) {
MachineType type = MachineType::Float64();
ExternalReference ref =
ExternalReference::f64_trunc_wrapper_function(jsgraph()->isolate());
ExternalReference::wasm_f64_trunc(jsgraph()->isolate());
return BuildCFuncInstruction(ref, type, input);
}
Node* WasmGraphBuilder::BuildF64Floor(Node* input) {
MachineType type = MachineType::Float64();
ExternalReference ref =
ExternalReference::f64_floor_wrapper_function(jsgraph()->isolate());
ExternalReference::wasm_f64_floor(jsgraph()->isolate());
return BuildCFuncInstruction(ref, type, input);
}
Node* WasmGraphBuilder::BuildF64Ceil(Node* input) {
MachineType type = MachineType::Float64();
ExternalReference ref =
ExternalReference::f64_ceil_wrapper_function(jsgraph()->isolate());
ExternalReference::wasm_f64_ceil(jsgraph()->isolate());
return BuildCFuncInstruction(ref, type, input);
}
Node* WasmGraphBuilder::BuildF64NearestInt(Node* input) {
MachineType type = MachineType::Float64();
ExternalReference ref =
ExternalReference::f64_nearest_int_wrapper_function(jsgraph()->isolate());
ExternalReference::wasm_f64_nearest_int(jsgraph()->isolate());
return BuildCFuncInstruction(ref, type, input);
}
......@@ -1645,6 +1656,53 @@ Node* WasmGraphBuilder::BuildCFuncInstruction(ExternalReference ref,
return load;
}
Node* WasmGraphBuilder::BuildF32SConvertI64(Node* input) {
return BuildConversionInstruction(
input, ExternalReference::wasm_int64_to_float32(jsgraph()->isolate()),
MachineRepresentation::kWord64, MachineType::Float32());
}
Node* WasmGraphBuilder::BuildF32UConvertI64(Node* input) {
return BuildConversionInstruction(
input, ExternalReference::wasm_uint64_to_float32(jsgraph()->isolate()),
MachineRepresentation::kWord64, MachineType::Float32());
}
Node* WasmGraphBuilder::BuildF64SConvertI64(Node* input) {
return BuildConversionInstruction(
input, ExternalReference::wasm_int64_to_float64(jsgraph()->isolate()),
MachineRepresentation::kWord64, MachineType::Float64());
}
Node* WasmGraphBuilder::BuildF64UConvertI64(Node* input) {
return BuildConversionInstruction(
input, ExternalReference::wasm_uint64_to_float64(jsgraph()->isolate()),
MachineRepresentation::kWord64, MachineType::Float64());
}
Node* WasmGraphBuilder::BuildConversionInstruction(
Node* input, ExternalReference ref,
MachineRepresentation parameter_representation,
const MachineType result_type) {
Node* stack_slot_param = graph()->NewNode(
jsgraph()->machine()->StackSlot(parameter_representation));
Node* stack_slot_result = graph()->NewNode(
jsgraph()->machine()->StackSlot(result_type.representation()));
const Operator* store_op = jsgraph()->machine()->Store(
StoreRepresentation(parameter_representation, kNoWriteBarrier));
*effect_ =
graph()->NewNode(store_op, stack_slot_param, jsgraph()->Int32Constant(0),
input, *effect_, *control_);
MachineSignature::Builder sig_builder(jsgraph()->zone(), 0, 2);
sig_builder.AddParam(MachineType::Pointer());
sig_builder.AddParam(MachineType::Pointer());
Node* function = graph()->NewNode(jsgraph()->common()->ExternalConstant(ref));
Node* args[] = {function, stack_slot_param, stack_slot_result};
BuildCCall(sig_builder.Build(), args);
const Operator* load_op = jsgraph()->machine()->Load(result_type);
Node* load =
graph()->NewNode(load_op, stack_slot_result, jsgraph()->Int32Constant(0),
*effect_, *control_);
*effect_ = load;
return load;
}
Node* WasmGraphBuilder::BuildCCall(MachineSignature* sig, Node** args) {
const size_t params = sig->parameter_count();
const size_t extra = 2; // effect and control inputs.
......
......@@ -205,6 +205,15 @@ class WasmGraphBuilder {
Node* BuildF64Atan2(Node* left, Node* right);
Node* BuildF64Mod(Node* left, Node* right);
Node* BuildConversionInstruction(
Node* input, ExternalReference ref,
MachineRepresentation parameter_representation,
const MachineType result_type);
Node* BuildF32SConvertI64(Node* input);
Node* BuildF32UConvertI64(Node* input);
Node* BuildF64SConvertI64(Node* input);
Node* BuildF64UConvertI64(Node* input);
Node** Realloc(Node** buffer, size_t count) {
Node** buf = Buffer(count);
if (buf != buffer) memcpy(buf, buffer, count * sizeof(Node*));
......
......@@ -99,23 +99,30 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
"InvokeFunctionCallback");
Add(ExternalReference::invoke_accessor_getter_callback(isolate).address(),
"InvokeAccessorGetterCallback");
Add(ExternalReference::f32_trunc_wrapper_function(isolate).address(),
"f32_trunc_wrapper");
Add(ExternalReference::f32_floor_wrapper_function(isolate).address(),
"f32_floor_wrapper");
Add(ExternalReference::f32_ceil_wrapper_function(isolate).address(),
"f32_ceil_wrapper");
Add(ExternalReference::f32_nearest_int_wrapper_function(isolate).address(),
"f32_nearest_int_wrapper");
Add(ExternalReference::f64_trunc_wrapper_function(isolate).address(),
"f64_trunc_wrapper");
Add(ExternalReference::f64_floor_wrapper_function(isolate).address(),
"f64_floor_wrapper");
Add(ExternalReference::f64_ceil_wrapper_function(isolate).address(),
"f64_ceil_wrapper");
Add(ExternalReference::f64_nearest_int_wrapper_function(isolate).address(),
"f64_nearest_int_wrapper");
Add(ExternalReference::wasm_f32_trunc(isolate).address(),
"wasm::f32_trunc_wrapper");
Add(ExternalReference::wasm_f32_floor(isolate).address(),
"wasm::f32_floor_wrapper");
Add(ExternalReference::wasm_f32_ceil(isolate).address(),
"wasm::f32_ceil_wrapper");
Add(ExternalReference::wasm_f32_nearest_int(isolate).address(),
"wasm::f32_nearest_int_wrapper");
Add(ExternalReference::wasm_f64_trunc(isolate).address(),
"wasm::f64_trunc_wrapper");
Add(ExternalReference::wasm_f64_floor(isolate).address(),
"wasm::f64_floor_wrapper");
Add(ExternalReference::wasm_f64_ceil(isolate).address(),
"wasm::f64_ceil_wrapper");
Add(ExternalReference::wasm_f64_nearest_int(isolate).address(),
"wasm::f64_nearest_int_wrapper");
Add(ExternalReference::wasm_int64_to_float32(isolate).address(),
"wasm::int64_to_float32_wrapper");
Add(ExternalReference::wasm_uint64_to_float32(isolate).address(),
"wasm::uint64_to_float32_wrapper");
Add(ExternalReference::wasm_int64_to_float64(isolate).address(),
"wasm::int64_to_float64_wrapper");
Add(ExternalReference::wasm_uint64_to_float64(isolate).address(),
"wasm::uint64_to_float64_wrapper");
Add(ExternalReference::f64_acos_wrapper_function(isolate).address(),
"f64_acos_wrapper");
Add(ExternalReference::f64_asin_wrapper_function(isolate).address(),
......@@ -138,7 +145,6 @@ ExternalReferenceTable::ExternalReferenceTable(Isolate* isolate) {
"f64_atan2_wrapper");
Add(ExternalReference::f64_mod_wrapper_function(isolate).address(),
"f64_mod_wrapper");
Add(ExternalReference::log_enter_external_function(isolate).address(),
"Logger::EnterExternal");
Add(ExternalReference::log_leave_external_function(isolate).address(),
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef WASM_EXTERNAL_REFS_H
#define WASM_EXTERNAL_REFS_H
namespace v8 {
namespace internal {
namespace wasm {
static void f32_trunc_wrapper(float* param) { *param = truncf(*param); }
static void f32_floor_wrapper(float* param) { *param = floorf(*param); }
static void f32_ceil_wrapper(float* param) { *param = ceilf(*param); }
static void f32_nearest_int_wrapper(float* param) {
*param = nearbyintf(*param);
}
static void f64_trunc_wrapper(double* param) { *param = trunc(*param); }
static void f64_floor_wrapper(double* param) { *param = floor(*param); }
static void f64_ceil_wrapper(double* param) { *param = ceil(*param); }
static void f64_nearest_int_wrapper(double* param) {
*param = nearbyint(*param);
}
static void int64_to_float32_wrapper(int64_t* input, float* output) {
*output = static_cast<float>(*input);
}
static void uint64_to_float32_wrapper(uint64_t* input, float* output) {
#if V8_CC_MSVC
// With MSVC we use static_cast<float>(uint32_t) instead of
// static_cast<float>(uint64_t) to achieve round-to-nearest-ties-even
// semantics. The idea is to calculate
// static_cast<float>(high_word) * 2^32 + static_cast<float>(low_word). To
// achieve proper rounding in all cases we have to adjust the high_word
// with a "rounding bit" sometimes. The rounding bit is stored in the LSB of
// the high_word if the low_word may affect the rounding of the high_word.
uint32_t low_word = static_cast<uint32_t>(*input & 0xffffffff);
uint32_t high_word = static_cast<uint32_t>(*input >> 32);
float shift = static_cast<float>(1ull << 32);
// If the MSB of the high_word is set, then we make space for a rounding bit.
if (high_word < 0x80000000) {
high_word <<= 1;
shift = static_cast<float>(1ull << 31);
}
if ((high_word & 0xfe000000) && low_word) {
// Set the rounding bit.
high_word |= 1;
}
float result = static_cast<float>(high_word);
result *= shift;
result += static_cast<float>(low_word);
*output = result;
#else
*output = static_cast<float>(*input);
#endif
}
static void int64_to_float64_wrapper(int64_t* input, double* output) {
*output = static_cast<double>(*input);
}
static void uint64_to_float64_wrapper(uint64_t* input, double* output) {
#if V8_CC_MSVC
// With MSVC we use static_cast<double>(uint32_t) instead of
// static_cast<double>(uint64_t) to achieve round-to-nearest-ties-even
// semantics. The idea is to calculate
// static_cast<double>(high_word) * 2^32 + static_cast<double>(low_word).
uint32_t low_word = static_cast<uint32_t>(*input & 0xffffffff);
uint32_t high_word = static_cast<uint32_t>(*input >> 32);
double shift = static_cast<double>(1ull << 32);
double result = static_cast<double>(high_word);
result *= shift;
result += static_cast<double>(low_word);
*output = result;
#else
*output = static_cast<double>(*input);
#endif
}
} // namespace wasm
} // namespace internal
} // namespace v8
#endif
......@@ -71,6 +71,7 @@
'compiler/test-pipeline.cc',
'compiler/test-representation-change.cc',
'compiler/test-run-bytecode-graph-builder.cc',
'compiler/test-run-calls-to-external-references.cc',
'compiler/test-run-deopt.cc',
'compiler/test-run-inlining.cc',
'compiler/test-run-intrinsics.cc',
......
This diff is collapsed.
......@@ -5653,79 +5653,6 @@ TEST(RunCallCFunction8) {
}
#endif // USE_SIMULATOR
template <typename T>
void TestExternalReferenceFunction(
BufferedRawMachineAssemblerTester<int32_t>* m, ExternalReference ref,
T (*comparison)(T)) {
T parameter;
Node* function = m->ExternalConstant(ref);
m->CallCFunction1(MachineType::Pointer(), MachineType::Pointer(), function,
m->PointerConstant(&parameter));
m->Return(m->Int32Constant(4356));
FOR_FLOAT64_INPUTS(i) {
parameter = *i;
m->Call();
CheckDoubleEq(comparison(*i), parameter);
}
}
TEST(RunCallExternalReferenceF32Trunc) {
BufferedRawMachineAssemblerTester<int32_t> m;
ExternalReference ref =
ExternalReference::f32_trunc_wrapper_function(m.isolate());
TestExternalReferenceFunction<float>(&m, ref, truncf);
}
TEST(RunCallExternalReferenceF32Floor) {
BufferedRawMachineAssemblerTester<int32_t> m;
ExternalReference ref =
ExternalReference::f32_floor_wrapper_function(m.isolate());
TestExternalReferenceFunction<float>(&m, ref, floorf);
}
TEST(RunCallExternalReferenceF32Ceil) {
BufferedRawMachineAssemblerTester<int32_t> m;
ExternalReference ref =
ExternalReference::f32_ceil_wrapper_function(m.isolate());
TestExternalReferenceFunction<float>(&m, ref, ceilf);
}
TEST(RunCallExternalReferenceF32RoundTiesEven) {
BufferedRawMachineAssemblerTester<int32_t> m;
ExternalReference ref =
ExternalReference::f32_nearest_int_wrapper_function(m.isolate());
TestExternalReferenceFunction<float>(&m, ref, nearbyintf);
}
TEST(RunCallExternalReferenceF64Trunc) {
BufferedRawMachineAssemblerTester<int32_t> m;
ExternalReference ref =
ExternalReference::f64_trunc_wrapper_function(m.isolate());
TestExternalReferenceFunction<double>(&m, ref, trunc);
}
TEST(RunCallExternalReferenceF64Floor) {
BufferedRawMachineAssemblerTester<int32_t> m;
ExternalReference ref =
ExternalReference::f64_floor_wrapper_function(m.isolate());
TestExternalReferenceFunction<double>(&m, ref, floor);
}
TEST(RunCallExternalReferenceF64Ceil) {
BufferedRawMachineAssemblerTester<int32_t> m;
ExternalReference ref =
ExternalReference::f64_ceil_wrapper_function(m.isolate());
TestExternalReferenceFunction<double>(&m, ref, ceil);
}
TEST(RunCallExternalReferenceF64RoundTiesEven) {
BufferedRawMachineAssemblerTester<int32_t> m;
ExternalReference ref =
ExternalReference::f64_nearest_int_wrapper_function(m.isolate());
TestExternalReferenceFunction<double>(&m, ref, nearbyint);
}
#if V8_TARGET_ARCH_64_BIT
// TODO(titzer): run int64 tests on all platforms when supported.
TEST(RunCheckedLoadInt64) {
......
......@@ -147,9 +147,194 @@ TEST(Run_WasmI32ConvertI64) {
// kExprI64Popcnt:
// kExprF32SConvertI64:
TEST(Run_Wasm_F32SConvertI64) {
WasmRunner<float> r(MachineType::Int64());
BUILD(r, WASM_F32_SCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_EQ(static_cast<float>(*i), r.Call(*i)); }
}
// kExprF32UConvertI64:
TEST(Run_Wasm_F32UConvertI64) {
struct {
uint64_t input;
uint32_t expected;
} values[] = {{0x0, 0x0},
{0x1, 0x3f800000},
{0xffffffff, 0x4f800000},
{0x1b09788b, 0x4dd84bc4},
{0x4c5fce8, 0x4c98bf9d},
{0xcc0de5bf, 0x4f4c0de6},
{0x2, 0x40000000},
{0x3, 0x40400000},
{0x4, 0x40800000},
{0x5, 0x40a00000},
{0x8, 0x41000000},
{0x9, 0x41100000},
{0xffffffffffffffff, 0x5f800000},
{0xfffffffffffffffe, 0x5f800000},
{0xfffffffffffffffd, 0x5f800000},
{0x0, 0x0},
{0x100000000, 0x4f800000},
{0xffffffff00000000, 0x5f800000},
{0x1b09788b00000000, 0x5dd84bc4},
{0x4c5fce800000000, 0x5c98bf9d},
{0xcc0de5bf00000000, 0x5f4c0de6},
{0x200000000, 0x50000000},
{0x300000000, 0x50400000},
{0x400000000, 0x50800000},
{0x500000000, 0x50a00000},
{0x800000000, 0x51000000},
{0x900000000, 0x51100000},
{0x273a798e187937a3, 0x5e1ce9e6},
{0xece3af835495a16b, 0x5f6ce3b0},
{0xb668ecc11223344, 0x5d3668ed},
{0x9e, 0x431e0000},
{0x43, 0x42860000},
{0xaf73, 0x472f7300},
{0x116b, 0x458b5800},
{0x658ecc, 0x4acb1d98},
{0x2b3b4c, 0x4a2ced30},
{0x88776655, 0x4f087766},
{0x70000000, 0x4ee00000},
{0x7200000, 0x4ce40000},
{0x7fffffff, 0x4f000000},
{0x56123761, 0x4eac246f},
{0x7fffff00, 0x4efffffe},
{0x761c4761eeeeeeee, 0x5eec388f},
{0x80000000eeeeeeee, 0x5f000000},
{0x88888888dddddddd, 0x5f088889},
{0xa0000000dddddddd, 0x5f200000},
{0xddddddddaaaaaaaa, 0x5f5dddde},
{0xe0000000aaaaaaaa, 0x5f600000},
{0xeeeeeeeeeeeeeeee, 0x5f6eeeef},
{0xfffffffdeeeeeeee, 0x5f800000},
{0xf0000000dddddddd, 0x5f700000},
{0x7fffffdddddddd, 0x5b000000},
{0x3fffffaaaaaaaa, 0x5a7fffff},
{0x1fffffaaaaaaaa, 0x59fffffd},
{0xfffff, 0x497ffff0},
{0x7ffff, 0x48ffffe0},
{0x3ffff, 0x487fffc0},
{0x1ffff, 0x47ffff80},
{0xffff, 0x477fff00},
{0x7fff, 0x46fffe00},
{0x3fff, 0x467ffc00},
{0x1fff, 0x45fff800},
{0xfff, 0x457ff000},
{0x7ff, 0x44ffe000},
{0x3ff, 0x447fc000},
{0x1ff, 0x43ff8000},
{0x3fffffffffff, 0x56800000},
{0x1fffffffffff, 0x56000000},
{0xfffffffffff, 0x55800000},
{0x7ffffffffff, 0x55000000},
{0x3ffffffffff, 0x54800000},
{0x1ffffffffff, 0x54000000},
{0x8000008000000000, 0x5f000000},
{0x8000008000000001, 0x5f000001},
{0x8000000000000400, 0x5f000000},
{0x8000000000000401, 0x5f000000}};
WasmRunner<float> r(MachineType::Uint64());
BUILD(r, WASM_F32_UCONVERT_I64(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(bit_cast<float>(values[i].expected), r.Call(values[i].input));
}
}
// kExprF64SConvertI64:
TEST(Run_WasmF64SConvertI64) {
WasmRunner<double> r(MachineType::Int64());
BUILD(r, WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_EQ(static_cast<double>(*i), r.Call(*i)); }
}
// kExprF64UConvertI64:
TEST(Run_Wasm_F64UConvertI64) {
struct {
uint64_t input;
uint64_t expected;
} values[] = {{0x0, 0x0},
{0x1, 0x3ff0000000000000},
{0xffffffff, 0x41efffffffe00000},
{0x1b09788b, 0x41bb09788b000000},
{0x4c5fce8, 0x419317f3a0000000},
{0xcc0de5bf, 0x41e981bcb7e00000},
{0x2, 0x4000000000000000},
{0x3, 0x4008000000000000},
{0x4, 0x4010000000000000},
{0x5, 0x4014000000000000},
{0x8, 0x4020000000000000},
{0x9, 0x4022000000000000},
{0xffffffffffffffff, 0x43f0000000000000},
{0xfffffffffffffffe, 0x43f0000000000000},
{0xfffffffffffffffd, 0x43f0000000000000},
{0x100000000, 0x41f0000000000000},
{0xffffffff00000000, 0x43efffffffe00000},
{0x1b09788b00000000, 0x43bb09788b000000},
{0x4c5fce800000000, 0x439317f3a0000000},
{0xcc0de5bf00000000, 0x43e981bcb7e00000},
{0x200000000, 0x4200000000000000},
{0x300000000, 0x4208000000000000},
{0x400000000, 0x4210000000000000},
{0x500000000, 0x4214000000000000},
{0x800000000, 0x4220000000000000},
{0x900000000, 0x4222000000000000},
{0x273a798e187937a3, 0x43c39d3cc70c3c9c},
{0xece3af835495a16b, 0x43ed9c75f06a92b4},
{0xb668ecc11223344, 0x43a6cd1d98224467},
{0x9e, 0x4063c00000000000},
{0x43, 0x4050c00000000000},
{0xaf73, 0x40e5ee6000000000},
{0x116b, 0x40b16b0000000000},
{0x658ecc, 0x415963b300000000},
{0x2b3b4c, 0x41459da600000000},
{0x88776655, 0x41e10eeccaa00000},
{0x70000000, 0x41dc000000000000},
{0x7200000, 0x419c800000000000},
{0x7fffffff, 0x41dfffffffc00000},
{0x56123761, 0x41d5848dd8400000},
{0x7fffff00, 0x41dfffffc0000000},
{0x761c4761eeeeeeee, 0x43dd8711d87bbbbc},
{0x80000000eeeeeeee, 0x43e00000001dddde},
{0x88888888dddddddd, 0x43e11111111bbbbc},
{0xa0000000dddddddd, 0x43e40000001bbbbc},
{0xddddddddaaaaaaaa, 0x43ebbbbbbbb55555},
{0xe0000000aaaaaaaa, 0x43ec000000155555},
{0xeeeeeeeeeeeeeeee, 0x43edddddddddddde},
{0xfffffffdeeeeeeee, 0x43efffffffbdddde},
{0xf0000000dddddddd, 0x43ee0000001bbbbc},
{0x7fffffdddddddd, 0x435ffffff7777777},
{0x3fffffaaaaaaaa, 0x434fffffd5555555},
{0x1fffffaaaaaaaa, 0x433fffffaaaaaaaa},
{0xfffff, 0x412ffffe00000000},
{0x7ffff, 0x411ffffc00000000},
{0x3ffff, 0x410ffff800000000},
{0x1ffff, 0x40fffff000000000},
{0xffff, 0x40efffe000000000},
{0x7fff, 0x40dfffc000000000},
{0x3fff, 0x40cfff8000000000},
{0x1fff, 0x40bfff0000000000},
{0xfff, 0x40affe0000000000},
{0x7ff, 0x409ffc0000000000},
{0x3ff, 0x408ff80000000000},
{0x1ff, 0x407ff00000000000},
{0x3fffffffffff, 0x42cfffffffffff80},
{0x1fffffffffff, 0x42bfffffffffff00},
{0xfffffffffff, 0x42affffffffffe00},
{0x7ffffffffff, 0x429ffffffffffc00},
{0x3ffffffffff, 0x428ffffffffff800},
{0x1ffffffffff, 0x427ffffffffff000},
{0x8000008000000000, 0x43e0000010000000},
{0x8000008000000001, 0x43e0000010000000},
{0x8000000000000400, 0x43e0000000000000},
{0x8000000000000401, 0x43e0000000000001}};
WasmRunner<double> r(MachineType::Uint64());
BUILD(r, WASM_F64_UCONVERT_I64(WASM_GET_LOCAL(0)));
for (size_t i = 0; i < arraysize(values); i++) {
CHECK_EQ(bit_cast<double>(values[i].expected), r.Call(values[i].input));
}
}
// kExprI64SConvertF32:
// kExprI64SConvertF64:
// kExprI64UConvertF32:
......
......@@ -3176,40 +3176,6 @@ TEST(Run_Wasm_F64Max_Snan) {
#endif
#if WASM_64
TEST(Run_Wasm_F32SConvertI64) {
WasmRunner<float> r(MachineType::Int64());
BUILD(r, WASM_F32_SCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_EQ(static_cast<float>(*i), r.Call(*i)); }
}
#if !defined(_WIN64)
// TODO(ahaas): Fix this failure.
TEST(Run_Wasm_F32UConvertI64) {
WasmRunner<float> r(MachineType::Uint64());
BUILD(r, WASM_F32_UCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(static_cast<float>(*i), r.Call(*i)); }
}
#endif
TEST(Run_Wasm_F64SConvertI64) {
WasmRunner<double> r(MachineType::Int64());
BUILD(r, WASM_F64_SCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_INT64_INPUTS(i) { CHECK_EQ(static_cast<double>(*i), r.Call(*i)); }
}
#if !defined(_WIN64)
// TODO(ahaas): Fix this failure.
TEST(Run_Wasm_F64UConvertI64) {
WasmRunner<double> r(MachineType::Uint64());
BUILD(r, WASM_F64_UCONVERT_I64(WASM_GET_LOCAL(0)));
FOR_UINT64_INPUTS(i) { CHECK_EQ(static_cast<double>(*i), r.Call(*i)); }
}
#endif
TEST(Run_Wasm_I64SConvertF32) {
WasmRunner<int64_t> r(MachineType::Float32());
BUILD(r, WASM_I64_SCONVERT_F32(WASM_GET_LOCAL(0)));
......
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