2014-07-30 13:54:45 +00:00
|
|
|
// Copyright 2014 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 V8_CCTEST_COMPILER_CODEGEN_TESTER_H_
|
|
|
|
#define V8_CCTEST_COMPILER_CODEGEN_TESTER_H_
|
|
|
|
|
Add floor, ceil, round (truncate) instructions for ia32, x64 (if SSE4.1) and
add floor, ceil, round (truncate and away from zero) for arm64.
R=bmeurer@chromium.org, dcarney@chromium.org, mstarzinger@chromium.org, rodolph.perfetta@arm.com
TEST=test/mjsunit/asm/math-floor.js,test/mjsunit/asm/math-ceil.js,test/unittest/compiler/js-builtin-reducer-unittest.cc
Review URL: https://codereview.chromium.org/677433002
Cr-Commit-Position: refs/heads/master@{#25018}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25018 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2014-10-30 14:15:20 +00:00
|
|
|
#include "src/compiler/instruction-selector.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler/pipeline.h"
|
2015-07-07 15:02:39 +00:00
|
|
|
#include "src/compiler/raw-machine-assembler.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/simulator.h"
|
|
|
|
#include "test/cctest/compiler/call-tester.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2015-05-29 14:05:39 +00:00
|
|
|
template <typename ReturnType>
|
|
|
|
class RawMachineAssemblerTester : public HandleAndZoneScope,
|
|
|
|
public CallHelper<ReturnType>,
|
|
|
|
public RawMachineAssembler {
|
2014-07-30 13:54:45 +00:00
|
|
|
public:
|
2015-12-10 09:03:30 +00:00
|
|
|
RawMachineAssemblerTester(MachineType p0 = MachineType::None(),
|
|
|
|
MachineType p1 = MachineType::None(),
|
|
|
|
MachineType p2 = MachineType::None(),
|
|
|
|
MachineType p3 = MachineType::None(),
|
|
|
|
MachineType p4 = MachineType::None())
|
2014-07-30 13:54:45 +00:00
|
|
|
: HandleAndZoneScope(),
|
2015-05-29 14:05:39 +00:00
|
|
|
CallHelper<ReturnType>(
|
2014-09-03 10:13:21 +00:00
|
|
|
main_isolate(),
|
2015-06-02 15:00:55 +00:00
|
|
|
CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0, p1,
|
|
|
|
p2, p3, p4)),
|
2015-05-29 14:05:39 +00:00
|
|
|
RawMachineAssembler(
|
2015-01-23 15:19:34 +00:00
|
|
|
main_isolate(), new (main_zone()) Graph(main_zone()),
|
2015-07-21 15:54:16 +00:00
|
|
|
Linkage::GetSimplifiedCDescriptor(
|
|
|
|
main_zone(),
|
|
|
|
CSignature::New(main_zone(), MachineTypeForC<ReturnType>(), p0,
|
2016-02-01 09:16:59 +00:00
|
|
|
p1, p2, p3, p4),
|
|
|
|
true),
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType::PointerRepresentation(),
|
|
|
|
InstructionSelector::SupportedMachineOperatorFlags()) {}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2016-02-02 12:26:38 +00:00
|
|
|
virtual ~RawMachineAssemblerTester() {}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
void CheckNumber(double expected, Object* number) {
|
|
|
|
CHECK(this->isolate()->factory()->NewNumber(expected)->SameValue(number));
|
|
|
|
}
|
|
|
|
|
|
|
|
void CheckString(const char* expected, Object* string) {
|
|
|
|
CHECK(
|
|
|
|
this->isolate()->factory()->InternalizeUtf8String(expected)->SameValue(
|
|
|
|
string));
|
|
|
|
}
|
|
|
|
|
|
|
|
void GenerateCode() { Generate(); }
|
|
|
|
|
2015-10-01 17:11:34 +00:00
|
|
|
Handle<Code> GetCode() {
|
|
|
|
Generate();
|
|
|
|
return code_.ToHandleChecked();
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
protected:
|
|
|
|
virtual byte* Generate() {
|
|
|
|
if (code_.is_null()) {
|
|
|
|
Schedule* schedule = this->Export();
|
|
|
|
CallDescriptor* call_descriptor = this->call_descriptor();
|
|
|
|
Graph* graph = this->graph();
|
2015-08-28 09:02:09 +00:00
|
|
|
CompilationInfo info("testing", main_isolate(), main_zone());
|
|
|
|
code_ = Pipeline::GenerateCodeForTesting(&info, call_descriptor, graph,
|
|
|
|
schedule);
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
return this->code_.ToHandleChecked()->entry();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
MaybeHandle<Code> code_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-10-30 21:32:35 +00:00
|
|
|
template <typename ReturnType>
|
|
|
|
class BufferedRawMachineAssemblerTester
|
|
|
|
: public RawMachineAssemblerTester<int32_t> {
|
|
|
|
public:
|
2015-12-10 09:03:30 +00:00
|
|
|
BufferedRawMachineAssemblerTester(MachineType p0 = MachineType::None(),
|
|
|
|
MachineType p1 = MachineType::None(),
|
|
|
|
MachineType p2 = MachineType::None(),
|
|
|
|
MachineType p3 = MachineType::None())
|
2015-11-06 07:22:27 +00:00
|
|
|
: BufferedRawMachineAssemblerTester(ComputeParameterCount(p0, p1, p2, p3),
|
|
|
|
p0, p1, p2, p3) {}
|
2015-10-30 21:32:35 +00:00
|
|
|
|
2016-02-02 12:26:38 +00:00
|
|
|
virtual byte* Generate() { return RawMachineAssemblerTester::Generate(); }
|
2015-10-30 21:32:35 +00:00
|
|
|
|
|
|
|
// The BufferedRawMachineAssemblerTester does not pass parameters directly
|
|
|
|
// to the constructed IR graph. Instead it passes a pointer to the parameter
|
|
|
|
// to the IR graph, and adds Load nodes to the IR graph to load the
|
|
|
|
// parameters from memory. Thereby it is possible to pass 64 bit parameters
|
|
|
|
// to the IR graph.
|
|
|
|
Node* Parameter(size_t index) {
|
[turbofan] Add the TruncateFloat32ToInt32 operator to turbofan.
The new operator converts a float32 input to int32 through truncation.
I provide implementations of the new operator for x64, ia32, arm,
arm64, mips, mips64, and x87. @v8-ppc-ports, can you please take care
of the ppc implementation?
R=titzer@chromium.org, v8-arm-ports@googlegroups.com, v8-mips-ports@googlegroups.com, weiliang.lin@intel.com
Review URL: https://codereview.chromium.org/1583323004
Cr-Commit-Position: refs/heads/master@{#33346}
2016-01-16 11:40:47 +00:00
|
|
|
CHECK(index < 4);
|
2015-10-30 21:32:35 +00:00
|
|
|
return parameter_nodes_[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
// The BufferedRawMachineAssemblerTester adds a Store node to the IR graph
|
|
|
|
// to store the graph's return value in memory. The memory address for the
|
|
|
|
// Store node is provided as a parameter. By storing the return value in
|
|
|
|
// memory it is possible to return 64 bit values.
|
|
|
|
void Return(Node* input) {
|
2015-12-11 15:34:00 +00:00
|
|
|
Store(MachineTypeForC<ReturnType>().representation(),
|
2015-10-30 21:32:35 +00:00
|
|
|
RawMachineAssembler::Parameter(return_parameter_index_), input,
|
|
|
|
kNoWriteBarrier);
|
|
|
|
RawMachineAssembler::Return(Int32Constant(1234));
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnType Call() {
|
|
|
|
ReturnType return_value;
|
2016-02-18 09:55:25 +00:00
|
|
|
CSignature::VerifyParams(test_graph_signature_);
|
2015-10-30 21:32:35 +00:00
|
|
|
CallHelper<int32_t>::Call(reinterpret_cast<void*>(&return_value));
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename P0>
|
|
|
|
ReturnType Call(P0 p0) {
|
|
|
|
ReturnType return_value;
|
2016-02-18 09:55:25 +00:00
|
|
|
CSignature::VerifyParams<P0>(test_graph_signature_);
|
2015-10-30 21:32:35 +00:00
|
|
|
CallHelper<int32_t>::Call(reinterpret_cast<void*>(&p0),
|
|
|
|
reinterpret_cast<void*>(&return_value));
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename P0, typename P1>
|
|
|
|
ReturnType Call(P0 p0, P1 p1) {
|
|
|
|
ReturnType return_value;
|
2016-02-18 09:55:25 +00:00
|
|
|
CSignature::VerifyParams<P0, P1>(test_graph_signature_);
|
2015-10-30 21:32:35 +00:00
|
|
|
CallHelper<int32_t>::Call(reinterpret_cast<void*>(&p0),
|
|
|
|
reinterpret_cast<void*>(&p1),
|
|
|
|
reinterpret_cast<void*>(&return_value));
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename P0, typename P1, typename P2>
|
|
|
|
ReturnType Call(P0 p0, P1 p1, P2 p2) {
|
|
|
|
ReturnType return_value;
|
2016-02-18 09:55:25 +00:00
|
|
|
CSignature::VerifyParams<P0, P1, P2>(test_graph_signature_);
|
2015-10-30 21:32:35 +00:00
|
|
|
CallHelper<int32_t>::Call(
|
|
|
|
reinterpret_cast<void*>(&p0), reinterpret_cast<void*>(&p1),
|
|
|
|
reinterpret_cast<void*>(&p2), reinterpret_cast<void*>(&return_value));
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename P0, typename P1, typename P2, typename P3>
|
|
|
|
ReturnType Call(P0 p0, P1 p1, P2 p2, P3 p3) {
|
|
|
|
ReturnType return_value;
|
2016-02-18 09:55:25 +00:00
|
|
|
CSignature::VerifyParams<P0, P1, P2, P3>(test_graph_signature_);
|
2015-10-30 21:32:35 +00:00
|
|
|
CallHelper<int32_t>::Call(
|
|
|
|
reinterpret_cast<void*>(&p0), reinterpret_cast<void*>(&p1),
|
|
|
|
reinterpret_cast<void*>(&p2), reinterpret_cast<void*>(&p3),
|
|
|
|
reinterpret_cast<void*>(&return_value));
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
BufferedRawMachineAssemblerTester(uint32_t return_parameter_index,
|
|
|
|
MachineType p0, MachineType p1,
|
|
|
|
MachineType p2, MachineType p3)
|
|
|
|
: RawMachineAssemblerTester<int32_t>(
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType::Pointer(),
|
|
|
|
p0 == MachineType::None() ? MachineType::None()
|
|
|
|
: MachineType::Pointer(),
|
|
|
|
p1 == MachineType::None() ? MachineType::None()
|
|
|
|
: MachineType::Pointer(),
|
|
|
|
p2 == MachineType::None() ? MachineType::None()
|
|
|
|
: MachineType::Pointer(),
|
|
|
|
p3 == MachineType::None() ? MachineType::None()
|
|
|
|
: MachineType::Pointer()),
|
2015-10-30 21:32:35 +00:00
|
|
|
test_graph_signature_(
|
2015-12-10 09:03:30 +00:00
|
|
|
CSignature::New(main_zone(), MachineType::Int32(), p0, p1, p2, p3)),
|
2015-10-30 21:32:35 +00:00
|
|
|
return_parameter_index_(return_parameter_index) {
|
2015-12-10 09:03:30 +00:00
|
|
|
parameter_nodes_[0] = p0 == MachineType::None()
|
|
|
|
? nullptr
|
|
|
|
: Load(p0, RawMachineAssembler::Parameter(0));
|
|
|
|
parameter_nodes_[1] = p1 == MachineType::None()
|
|
|
|
? nullptr
|
|
|
|
: Load(p1, RawMachineAssembler::Parameter(1));
|
|
|
|
parameter_nodes_[2] = p2 == MachineType::None()
|
|
|
|
? nullptr
|
|
|
|
: Load(p2, RawMachineAssembler::Parameter(2));
|
|
|
|
parameter_nodes_[3] = p3 == MachineType::None()
|
|
|
|
? nullptr
|
|
|
|
: Load(p3, RawMachineAssembler::Parameter(3));
|
2015-10-30 21:32:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-06 07:22:27 +00:00
|
|
|
static uint32_t ComputeParameterCount(MachineType p0, MachineType p1,
|
|
|
|
MachineType p2, MachineType p3) {
|
2015-12-10 09:03:30 +00:00
|
|
|
if (p0 == MachineType::None()) {
|
2015-11-06 07:22:27 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-12-10 09:03:30 +00:00
|
|
|
if (p1 == MachineType::None()) {
|
2015-11-06 07:22:27 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2015-12-10 09:03:30 +00:00
|
|
|
if (p2 == MachineType::None()) {
|
2015-11-06 07:22:27 +00:00
|
|
|
return 2;
|
|
|
|
}
|
2015-12-10 09:03:30 +00:00
|
|
|
if (p3 == MachineType::None()) {
|
2015-11-06 07:22:27 +00:00
|
|
|
return 3;
|
|
|
|
}
|
|
|
|
return 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-30 21:32:35 +00:00
|
|
|
CSignature* test_graph_signature_;
|
|
|
|
Node* parameter_nodes_[4];
|
|
|
|
uint32_t return_parameter_index_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <>
|
|
|
|
class BufferedRawMachineAssemblerTester<void>
|
|
|
|
: public RawMachineAssemblerTester<void> {
|
|
|
|
public:
|
2015-12-10 09:03:30 +00:00
|
|
|
BufferedRawMachineAssemblerTester(MachineType p0 = MachineType::None(),
|
|
|
|
MachineType p1 = MachineType::None(),
|
|
|
|
MachineType p2 = MachineType::None(),
|
|
|
|
MachineType p3 = MachineType::None())
|
|
|
|
: RawMachineAssemblerTester<void>(
|
|
|
|
p0 == MachineType::None() ? MachineType::None()
|
|
|
|
: MachineType::Pointer(),
|
|
|
|
p1 == MachineType::None() ? MachineType::None()
|
|
|
|
: MachineType::Pointer(),
|
|
|
|
p2 == MachineType::None() ? MachineType::None()
|
|
|
|
: MachineType::Pointer(),
|
|
|
|
p3 == MachineType::None() ? MachineType::None()
|
|
|
|
: MachineType::Pointer()),
|
2015-10-30 21:32:35 +00:00
|
|
|
test_graph_signature_(
|
|
|
|
CSignature::New(RawMachineAssemblerTester<void>::main_zone(),
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType::None(), p0, p1, p2, p3)) {
|
|
|
|
parameter_nodes_[0] = p0 == MachineType::None()
|
|
|
|
? nullptr
|
|
|
|
: Load(p0, RawMachineAssembler::Parameter(0));
|
|
|
|
parameter_nodes_[1] = p1 == MachineType::None()
|
|
|
|
? nullptr
|
|
|
|
: Load(p1, RawMachineAssembler::Parameter(1));
|
|
|
|
parameter_nodes_[2] = p2 == MachineType::None()
|
|
|
|
? nullptr
|
|
|
|
: Load(p2, RawMachineAssembler::Parameter(2));
|
|
|
|
parameter_nodes_[3] = p3 == MachineType::None()
|
|
|
|
? nullptr
|
|
|
|
: Load(p3, RawMachineAssembler::Parameter(3));
|
2015-10-30 21:32:35 +00:00
|
|
|
}
|
|
|
|
|
2016-02-02 12:26:38 +00:00
|
|
|
virtual byte* Generate() { return RawMachineAssemblerTester::Generate(); }
|
|
|
|
|
2015-10-30 21:32:35 +00:00
|
|
|
// The BufferedRawMachineAssemblerTester does not pass parameters directly
|
|
|
|
// to the constructed IR graph. Instead it passes a pointer to the parameter
|
|
|
|
// to the IR graph, and adds Load nodes to the IR graph to load the
|
|
|
|
// parameters from memory. Thereby it is possible to pass 64 bit parameters
|
|
|
|
// to the IR graph.
|
|
|
|
Node* Parameter(size_t index) {
|
|
|
|
CHECK(index >= 0 && index < 4);
|
|
|
|
return parameter_nodes_[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Call() {
|
2016-02-18 09:55:25 +00:00
|
|
|
CSignature::VerifyParams(test_graph_signature_);
|
2015-10-30 21:32:35 +00:00
|
|
|
CallHelper<void>::Call();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename P0>
|
|
|
|
void Call(P0 p0) {
|
2016-02-18 09:55:25 +00:00
|
|
|
CSignature::VerifyParams<P0>(test_graph_signature_);
|
2015-10-30 21:32:35 +00:00
|
|
|
CallHelper<void>::Call(reinterpret_cast<void*>(&p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename P0, typename P1>
|
|
|
|
void Call(P0 p0, P1 p1) {
|
2016-02-18 09:55:25 +00:00
|
|
|
CSignature::VerifyParams<P0, P1>(test_graph_signature_);
|
2015-10-30 21:32:35 +00:00
|
|
|
CallHelper<void>::Call(reinterpret_cast<void*>(&p0),
|
|
|
|
reinterpret_cast<void*>(&p1));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename P0, typename P1, typename P2>
|
|
|
|
void Call(P0 p0, P1 p1, P2 p2) {
|
2016-02-18 09:55:25 +00:00
|
|
|
CSignature::VerifyParams<P0, P1, P2>(test_graph_signature_);
|
2015-10-30 21:32:35 +00:00
|
|
|
CallHelper<void>::Call(reinterpret_cast<void*>(&p0),
|
|
|
|
reinterpret_cast<void*>(&p1),
|
|
|
|
reinterpret_cast<void*>(&p2));
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename P0, typename P1, typename P2, typename P3>
|
|
|
|
void Call(P0 p0, P1 p1, P2 p2, P3 p3) {
|
2016-02-18 09:55:25 +00:00
|
|
|
CSignature::VerifyParams<P0, P1, P2, P3>(test_graph_signature_);
|
2015-10-30 21:32:35 +00:00
|
|
|
CallHelper<void>::Call(
|
|
|
|
reinterpret_cast<void*>(&p0), reinterpret_cast<void*>(&p1),
|
|
|
|
reinterpret_cast<void*>(&p2), reinterpret_cast<void*>(&p3));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
CSignature* test_graph_signature_;
|
|
|
|
Node* parameter_nodes_[4];
|
|
|
|
};
|
2014-07-30 13:54:45 +00:00
|
|
|
static const bool USE_RESULT_BUFFER = true;
|
|
|
|
static const bool USE_RETURN_REGISTER = false;
|
2014-07-31 09:30:16 +00:00
|
|
|
static const int32_t CHECK_VALUE = 0x99BEEDCE;
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
// TODO(titzer): use the C-style calling convention, or any register-based
|
|
|
|
// calling convention for binop tests.
|
2015-12-10 09:03:30 +00:00
|
|
|
template <typename CType, bool use_result_buffer>
|
2014-07-30 13:54:45 +00:00
|
|
|
class BinopTester {
|
|
|
|
public:
|
2015-12-10 09:03:30 +00:00
|
|
|
explicit BinopTester(RawMachineAssemblerTester<int32_t>* tester,
|
|
|
|
MachineType rep)
|
2014-07-30 13:54:45 +00:00
|
|
|
: T(tester),
|
|
|
|
param0(T->LoadFromPointer(&p0, rep)),
|
|
|
|
param1(T->LoadFromPointer(&p1, rep)),
|
2015-12-10 09:03:30 +00:00
|
|
|
rep(rep),
|
2014-07-30 13:54:45 +00:00
|
|
|
p0(static_cast<CType>(0)),
|
|
|
|
p1(static_cast<CType>(0)),
|
|
|
|
result(static_cast<CType>(0)) {}
|
|
|
|
|
|
|
|
RawMachineAssemblerTester<int32_t>* T;
|
|
|
|
Node* param0;
|
|
|
|
Node* param1;
|
|
|
|
|
|
|
|
CType call(CType a0, CType a1) {
|
|
|
|
p0 = a0;
|
|
|
|
p1 = a1;
|
|
|
|
if (use_result_buffer) {
|
|
|
|
CHECK_EQ(CHECK_VALUE, T->Call());
|
|
|
|
return result;
|
|
|
|
} else {
|
2015-03-30 07:33:46 +00:00
|
|
|
return static_cast<CType>(T->Call());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddReturn(Node* val) {
|
|
|
|
if (use_result_buffer) {
|
2015-12-11 15:34:00 +00:00
|
|
|
T->Store(rep.representation(), T->PointerConstant(&result),
|
|
|
|
T->Int32Constant(0), val, kNoWriteBarrier);
|
2014-07-30 13:54:45 +00:00
|
|
|
T->Return(T->Int32Constant(CHECK_VALUE));
|
|
|
|
} else {
|
|
|
|
T->Return(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-31 07:44:29 +00:00
|
|
|
template <typename Ci, typename Cj, typename Fn>
|
|
|
|
void Run(const Ci& ci, const Cj& cj, const Fn& fn) {
|
|
|
|
typename Ci::const_iterator i;
|
|
|
|
typename Cj::const_iterator j;
|
|
|
|
for (i = ci.begin(); i != ci.end(); ++i) {
|
|
|
|
for (j = cj.begin(); j != cj.end(); ++j) {
|
|
|
|
CHECK_EQ(fn(*i, *j), this->call(*i, *j));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
protected:
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType rep;
|
2014-07-30 13:54:45 +00:00
|
|
|
CType p0;
|
|
|
|
CType p1;
|
|
|
|
CType result;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A helper class for testing code sequences that take two int parameters and
|
|
|
|
// return an int value.
|
2015-12-10 09:03:30 +00:00
|
|
|
class Int32BinopTester : public BinopTester<int32_t, USE_RETURN_REGISTER> {
|
2014-07-30 13:54:45 +00:00
|
|
|
public:
|
|
|
|
explicit Int32BinopTester(RawMachineAssemblerTester<int32_t>* tester)
|
2015-12-10 09:03:30 +00:00
|
|
|
: BinopTester<int32_t, USE_RETURN_REGISTER>(tester,
|
|
|
|
MachineType::Int32()) {}
|
2014-08-14 09:19:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-12-24 18:50:37 +00:00
|
|
|
// A helper class for testing code sequences that take two int parameters and
|
|
|
|
// return an int value.
|
|
|
|
class Int64BinopTester : public BinopTester<int64_t, USE_RETURN_REGISTER> {
|
|
|
|
public:
|
|
|
|
explicit Int64BinopTester(RawMachineAssemblerTester<int32_t>* tester)
|
|
|
|
: BinopTester<int64_t, USE_RETURN_REGISTER>(tester,
|
|
|
|
MachineType::Int64()) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-08-14 09:19:54 +00:00
|
|
|
// A helper class for testing code sequences that take two uint parameters and
|
|
|
|
// return an uint value.
|
2015-12-10 09:03:30 +00:00
|
|
|
class Uint32BinopTester : public BinopTester<uint32_t, USE_RETURN_REGISTER> {
|
2014-08-14 09:19:54 +00:00
|
|
|
public:
|
|
|
|
explicit Uint32BinopTester(RawMachineAssemblerTester<int32_t>* tester)
|
2015-12-10 09:03:30 +00:00
|
|
|
: BinopTester<uint32_t, USE_RETURN_REGISTER>(tester,
|
|
|
|
MachineType::Uint32()) {}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-08-14 09:19:54 +00:00
|
|
|
uint32_t call(uint32_t a0, uint32_t a1) {
|
|
|
|
p0 = a0;
|
|
|
|
p1 = a1;
|
|
|
|
return static_cast<uint32_t>(T->Call());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-03-30 07:33:46 +00:00
|
|
|
// A helper class for testing code sequences that take two float parameters and
|
|
|
|
// return a float value.
|
2015-12-10 09:03:30 +00:00
|
|
|
class Float32BinopTester : public BinopTester<float, USE_RESULT_BUFFER> {
|
2015-03-30 07:33:46 +00:00
|
|
|
public:
|
|
|
|
explicit Float32BinopTester(RawMachineAssemblerTester<int32_t>* tester)
|
2015-12-10 09:03:30 +00:00
|
|
|
: BinopTester<float, USE_RESULT_BUFFER>(tester, MachineType::Float32()) {}
|
2015-03-30 07:33:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// A helper class for testing code sequences that take two double parameters and
|
|
|
|
// return a double value.
|
2015-12-10 09:03:30 +00:00
|
|
|
class Float64BinopTester : public BinopTester<double, USE_RESULT_BUFFER> {
|
2014-07-30 13:54:45 +00:00
|
|
|
public:
|
|
|
|
explicit Float64BinopTester(RawMachineAssemblerTester<int32_t>* tester)
|
2015-12-10 09:03:30 +00:00
|
|
|
: BinopTester<double, USE_RESULT_BUFFER>(tester, MachineType::Float64()) {
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A helper class for testing code sequences that take two pointer parameters
|
|
|
|
// and return a pointer value.
|
|
|
|
// TODO(titzer): pick word size of pointers based on V8_TARGET.
|
|
|
|
template <typename Type>
|
2015-12-10 09:03:30 +00:00
|
|
|
class PointerBinopTester : public BinopTester<Type*, USE_RETURN_REGISTER> {
|
2014-07-30 13:54:45 +00:00
|
|
|
public:
|
|
|
|
explicit PointerBinopTester(RawMachineAssemblerTester<int32_t>* tester)
|
2015-12-10 09:03:30 +00:00
|
|
|
: BinopTester<Type*, USE_RETURN_REGISTER>(tester,
|
|
|
|
MachineType::Pointer()) {}
|
2014-07-30 13:54:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A helper class for testing code sequences that take two tagged parameters and
|
|
|
|
// return a tagged value.
|
|
|
|
template <typename Type>
|
2015-12-10 09:03:30 +00:00
|
|
|
class TaggedBinopTester : public BinopTester<Type*, USE_RETURN_REGISTER> {
|
2014-07-30 13:54:45 +00:00
|
|
|
public:
|
|
|
|
explicit TaggedBinopTester(RawMachineAssemblerTester<int32_t>* tester)
|
2015-12-10 09:03:30 +00:00
|
|
|
: BinopTester<Type*, USE_RETURN_REGISTER>(tester,
|
|
|
|
MachineType::AnyTagged()) {}
|
2014-07-30 13:54:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// A helper class for testing compares. Wraps a machine opcode and provides
|
|
|
|
// evaluation routines and the operators.
|
|
|
|
class CompareWrapper {
|
|
|
|
public:
|
|
|
|
explicit CompareWrapper(IrOpcode::Value op) : opcode(op) {}
|
|
|
|
|
|
|
|
Node* MakeNode(RawMachineAssemblerTester<int32_t>* m, Node* a, Node* b) {
|
2015-09-23 09:08:15 +00:00
|
|
|
return m->AddNode(op(m->machine()), a, b);
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
2014-09-10 12:23:45 +00:00
|
|
|
const Operator* op(MachineOperatorBuilder* machine) {
|
2014-07-30 13:54:45 +00:00
|
|
|
switch (opcode) {
|
|
|
|
case IrOpcode::kWord32Equal:
|
|
|
|
return machine->Word32Equal();
|
|
|
|
case IrOpcode::kInt32LessThan:
|
|
|
|
return machine->Int32LessThan();
|
|
|
|
case IrOpcode::kInt32LessThanOrEqual:
|
|
|
|
return machine->Int32LessThanOrEqual();
|
|
|
|
case IrOpcode::kUint32LessThan:
|
|
|
|
return machine->Uint32LessThan();
|
|
|
|
case IrOpcode::kUint32LessThanOrEqual:
|
|
|
|
return machine->Uint32LessThanOrEqual();
|
|
|
|
case IrOpcode::kFloat64Equal:
|
|
|
|
return machine->Float64Equal();
|
|
|
|
case IrOpcode::kFloat64LessThan:
|
|
|
|
return machine->Float64LessThan();
|
|
|
|
case IrOpcode::kFloat64LessThanOrEqual:
|
|
|
|
return machine->Float64LessThanOrEqual();
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Int32Compare(int32_t a, int32_t b) {
|
|
|
|
switch (opcode) {
|
|
|
|
case IrOpcode::kWord32Equal:
|
|
|
|
return a == b;
|
|
|
|
case IrOpcode::kInt32LessThan:
|
|
|
|
return a < b;
|
|
|
|
case IrOpcode::kInt32LessThanOrEqual:
|
|
|
|
return a <= b;
|
|
|
|
case IrOpcode::kUint32LessThan:
|
|
|
|
return static_cast<uint32_t>(a) < static_cast<uint32_t>(b);
|
|
|
|
case IrOpcode::kUint32LessThanOrEqual:
|
|
|
|
return static_cast<uint32_t>(a) <= static_cast<uint32_t>(b);
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Float64Compare(double a, double b) {
|
|
|
|
switch (opcode) {
|
|
|
|
case IrOpcode::kFloat64Equal:
|
|
|
|
return a == b;
|
|
|
|
case IrOpcode::kFloat64LessThan:
|
|
|
|
return a < b;
|
|
|
|
case IrOpcode::kFloat64LessThanOrEqual:
|
|
|
|
return a <= b;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
IrOpcode::Value opcode;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A small closure class to generate code for a function of two inputs that
|
|
|
|
// produces a single output so that it can be used in many different contexts.
|
|
|
|
// The {expected()} method should compute the expected output for a given
|
|
|
|
// pair of inputs.
|
|
|
|
template <typename T>
|
|
|
|
class BinopGen {
|
|
|
|
public:
|
|
|
|
virtual void gen(RawMachineAssemblerTester<int32_t>* m, Node* a, Node* b) = 0;
|
|
|
|
virtual T expected(T a, T b) = 0;
|
|
|
|
virtual ~BinopGen() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
// A helper class to generate various combination of input shape combinations
|
|
|
|
// and run the generated code to ensure it produces the correct results.
|
|
|
|
class Int32BinopInputShapeTester {
|
|
|
|
public:
|
2016-02-02 12:26:38 +00:00
|
|
|
explicit Int32BinopInputShapeTester(BinopGen<int32_t>* g)
|
|
|
|
: gen(g), input_a(0), input_b(0) {}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
void TestAllInputShapes();
|
|
|
|
|
|
|
|
private:
|
|
|
|
BinopGen<int32_t>* gen;
|
|
|
|
int32_t input_a;
|
|
|
|
int32_t input_b;
|
|
|
|
|
|
|
|
void Run(RawMachineAssemblerTester<int32_t>* m);
|
|
|
|
void RunLeft(RawMachineAssemblerTester<int32_t>* m);
|
|
|
|
void RunRight(RawMachineAssemblerTester<int32_t>* m);
|
|
|
|
};
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
|
|
|
|
|
|
|
#endif // V8_CCTEST_COMPILER_CODEGEN_TESTER_H_
|