2015-07-23 14:21:26 +00:00
|
|
|
// Copyright 2015 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.
|
|
|
|
|
2016-02-10 16:38:49 +00:00
|
|
|
#include "test/unittests/interpreter/interpreter-assembler-unittest.h"
|
2015-07-23 14:21:26 +00:00
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
#include "src/code-factory.h"
|
2015-07-23 14:21:26 +00:00
|
|
|
#include "src/compiler/node.h"
|
2015-09-02 13:03:06 +00:00
|
|
|
#include "src/interface-descriptors.h"
|
2015-09-01 10:30:40 +00:00
|
|
|
#include "src/isolate.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/objects-inl.h"
|
2015-07-23 14:21:26 +00:00
|
|
|
#include "test/unittests/compiler/compiler-test-utils.h"
|
|
|
|
#include "test/unittests/compiler/node-test-utils.h"
|
|
|
|
|
2015-08-18 12:41:41 +00:00
|
|
|
using ::testing::_;
|
2017-09-04 10:47:27 +00:00
|
|
|
using v8::internal::compiler::Node;
|
|
|
|
|
|
|
|
namespace c = v8::internal::compiler;
|
2015-08-18 12:41:41 +00:00
|
|
|
|
2015-07-23 14:21:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2016-02-10 16:38:49 +00:00
|
|
|
namespace interpreter {
|
2017-10-18 17:01:45 +00:00
|
|
|
namespace interpreter_assembler_unittest {
|
2015-07-23 14:21:26 +00:00
|
|
|
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState::InterpreterAssemblerTestState(
|
|
|
|
InterpreterAssemblerTest* test, Bytecode bytecode)
|
|
|
|
: compiler::CodeAssemblerState(
|
|
|
|
test->isolate(), test->zone(),
|
|
|
|
InterpreterDispatchDescriptor(test->isolate()),
|
2017-09-29 14:59:24 +00:00
|
|
|
Code::BYTECODE_HANDLER, Bytecodes::ToString(bytecode),
|
|
|
|
Bytecodes::ReturnCount(bytecode)) {}
|
2016-11-16 11:48:07 +00:00
|
|
|
|
2015-07-23 14:21:26 +00:00
|
|
|
const interpreter::Bytecode kBytecodes[] = {
|
2015-07-30 13:56:47 +00:00
|
|
|
#define DEFINE_BYTECODE(Name, ...) interpreter::Bytecode::k##Name,
|
2015-07-23 14:21:26 +00:00
|
|
|
BYTECODE_LIST(DEFINE_BYTECODE)
|
|
|
|
#undef DEFINE_BYTECODE
|
|
|
|
};
|
|
|
|
|
2016-12-12 14:52:30 +00:00
|
|
|
|
2016-04-06 07:57:35 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::
|
|
|
|
~InterpreterAssemblerForTest() {
|
|
|
|
// Tests don't necessarily read and write accumulator but
|
|
|
|
// InterpreterAssembler checks accumulator uses.
|
|
|
|
if (Bytecodes::ReadsAccumulator(bytecode())) {
|
|
|
|
GetAccumulator();
|
|
|
|
}
|
|
|
|
if (Bytecodes::WritesAccumulator(bytecode())) {
|
|
|
|
SetAccumulator(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-23 14:21:26 +00:00
|
|
|
Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsLoad(
|
2017-09-04 10:47:27 +00:00
|
|
|
const Matcher<c::LoadRepresentation>& rep_matcher,
|
2015-07-23 14:21:26 +00:00
|
|
|
const Matcher<Node*>& base_matcher, const Matcher<Node*>& index_matcher) {
|
2015-12-10 17:07:15 +00:00
|
|
|
return ::i::compiler::IsLoad(rep_matcher, base_matcher, index_matcher, _, _);
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Matcher<Node*> InterpreterAssemblerTest::InterpreterAssemblerForTest::IsStore(
|
2017-09-04 10:47:27 +00:00
|
|
|
const Matcher<c::StoreRepresentation>& rep_matcher,
|
2015-07-23 14:21:26 +00:00
|
|
|
const Matcher<Node*>& base_matcher, const Matcher<Node*>& index_matcher,
|
|
|
|
const Matcher<Node*>& value_matcher) {
|
|
|
|
return ::i::compiler::IsStore(rep_matcher, base_matcher, index_matcher,
|
2015-12-10 17:07:15 +00:00
|
|
|
value_matcher, _, _);
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
2015-08-18 15:29:21 +00:00
|
|
|
Matcher<Node*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedByteOperand(
|
2015-10-01 17:22:58 +00:00
|
|
|
int offset) {
|
2017-09-11 13:44:42 +00:00
|
|
|
return IsLoad(
|
|
|
|
MachineType::Uint8(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
|
|
|
c::IsIntPtrAdd(
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
|
|
|
c::IsIntPtrConstant(offset)));
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedByteOperand(
|
|
|
|
int offset) {
|
2017-09-11 13:44:42 +00:00
|
|
|
return IsLoad(
|
|
|
|
MachineType::Int8(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
|
|
|
c::IsIntPtrAdd(
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
|
|
|
c::IsIntPtrConstant(offset)));
|
2015-07-30 11:36:26 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 17:22:58 +00:00
|
|
|
Matcher<Node*>
|
2016-03-21 17:08:21 +00:00
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedShortOperand(
|
2015-10-01 17:22:58 +00:00
|
|
|
int offset) {
|
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
|
|
|
return IsLoad(
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineType::Uint16(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offset)));
|
2015-10-01 17:22:58 +00:00
|
|
|
} else {
|
|
|
|
#if V8_TARGET_LITTLE_ENDIAN
|
2016-03-21 17:08:21 +00:00
|
|
|
const int kStep = -1;
|
|
|
|
const int kMsbOffset = 1;
|
2015-10-01 17:22:58 +00:00
|
|
|
#elif V8_TARGET_BIG_ENDIAN
|
2016-03-21 17:08:21 +00:00
|
|
|
const int kStep = 1;
|
|
|
|
const int kMsbOffset = 0;
|
2015-10-01 17:22:58 +00:00
|
|
|
#else
|
|
|
|
#error "Unknown Architecture"
|
|
|
|
#endif
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*> bytes[2];
|
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
MachineType::Uint8(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
2017-09-11 13:44:42 +00:00
|
|
|
return c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[0], c::IsInt32Constant(kBitsPerByte)), bytes[1]);
|
2015-10-01 17:22:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedShortOperand(
|
|
|
|
int offset) {
|
2016-01-04 17:38:17 +00:00
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
2016-12-12 14:52:30 +00:00
|
|
|
return IsLoad(
|
2016-01-04 17:38:17 +00:00
|
|
|
MachineType::Int16(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offset)));
|
2016-01-04 17:38:17 +00:00
|
|
|
} else {
|
|
|
|
#if V8_TARGET_LITTLE_ENDIAN
|
2016-03-21 17:08:21 +00:00
|
|
|
const int kStep = -1;
|
|
|
|
const int kMsbOffset = 1;
|
2016-01-04 17:38:17 +00:00
|
|
|
#elif V8_TARGET_BIG_ENDIAN
|
2016-03-21 17:08:21 +00:00
|
|
|
const int kStep = 1;
|
|
|
|
const int kMsbOffset = 0;
|
2016-01-04 17:38:17 +00:00
|
|
|
#else
|
|
|
|
#error "Unknown Architecture"
|
|
|
|
#endif
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*> bytes[2];
|
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
(i == 0) ? MachineType::Int8() : MachineType::Uint8(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
2017-09-11 13:44:42 +00:00
|
|
|
return c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[0], c::IsInt32Constant(kBitsPerByte)), bytes[1]);
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedQuadOperand(
|
|
|
|
int offset) {
|
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
|
|
|
return IsLoad(
|
|
|
|
MachineType::Uint32(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offset)));
|
2016-03-21 17:08:21 +00:00
|
|
|
} else {
|
|
|
|
#if V8_TARGET_LITTLE_ENDIAN
|
|
|
|
const int kStep = -1;
|
|
|
|
const int kMsbOffset = 3;
|
|
|
|
#elif V8_TARGET_BIG_ENDIAN
|
|
|
|
const int kStep = 1;
|
|
|
|
const int kMsbOffset = 0;
|
|
|
|
#else
|
|
|
|
#error "Unknown Architecture"
|
|
|
|
#endif
|
|
|
|
Matcher<Node*> bytes[4];
|
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
MachineType::Uint8(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
2017-09-11 13:44:42 +00:00
|
|
|
return c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[0], c::IsInt32Constant(3 * kBitsPerByte)),
|
|
|
|
c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[1], c::IsInt32Constant(2 * kBitsPerByte)),
|
|
|
|
c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[2], c::IsInt32Constant(1 * kBitsPerByte)),
|
|
|
|
bytes[3])));
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedQuadOperand(
|
|
|
|
int offset) {
|
|
|
|
if (TargetSupportsUnalignedAccess()) {
|
2016-12-12 14:52:30 +00:00
|
|
|
return IsLoad(
|
2016-03-21 17:08:21 +00:00
|
|
|
MachineType::Int32(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offset)));
|
2016-03-21 17:08:21 +00:00
|
|
|
} else {
|
|
|
|
#if V8_TARGET_LITTLE_ENDIAN
|
|
|
|
const int kStep = -1;
|
|
|
|
int kMsbOffset = 3;
|
|
|
|
#elif V8_TARGET_BIG_ENDIAN
|
|
|
|
const int kStep = 1;
|
|
|
|
int kMsbOffset = 0;
|
|
|
|
#else
|
|
|
|
#error "Unknown Architecture"
|
|
|
|
#endif
|
|
|
|
Matcher<Node*> bytes[4];
|
|
|
|
for (int i = 0; i < static_cast<int>(arraysize(bytes)); i++) {
|
|
|
|
bytes[i] = IsLoad(
|
|
|
|
(i == 0) ? MachineType::Int8() : MachineType::Uint8(),
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offset + kMsbOffset + kStep * i)));
|
2016-03-21 17:08:21 +00:00
|
|
|
}
|
2017-09-11 13:44:42 +00:00
|
|
|
return c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[0], c::IsInt32Constant(3 * kBitsPerByte)),
|
|
|
|
c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[1], c::IsInt32Constant(2 * kBitsPerByte)),
|
|
|
|
c::IsWord32Or(
|
|
|
|
c::IsWord32Shl(bytes[2], c::IsInt32Constant(1 * kBitsPerByte)),
|
|
|
|
bytes[3])));
|
2016-01-04 17:38:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-21 17:08:21 +00:00
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsSignedOperand(
|
|
|
|
int offset, OperandSize operand_size) {
|
|
|
|
switch (operand_size) {
|
|
|
|
case OperandSize::kByte:
|
|
|
|
return IsSignedByteOperand(offset);
|
|
|
|
case OperandSize::kShort:
|
|
|
|
return IsSignedShortOperand(offset);
|
|
|
|
case OperandSize::kQuad:
|
|
|
|
return IsSignedQuadOperand(offset);
|
|
|
|
case OperandSize::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Matcher<Node*>
|
|
|
|
InterpreterAssemblerTest::InterpreterAssemblerForTest::IsUnsignedOperand(
|
|
|
|
int offset, OperandSize operand_size) {
|
|
|
|
switch (operand_size) {
|
|
|
|
case OperandSize::kByte:
|
|
|
|
return IsUnsignedByteOperand(offset);
|
|
|
|
case OperandSize::kShort:
|
|
|
|
return IsUnsignedShortOperand(offset);
|
|
|
|
case OperandSize::kQuad:
|
|
|
|
return IsUnsignedQuadOperand(offset);
|
|
|
|
case OperandSize::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, Jump) {
|
2016-02-19 18:46:54 +00:00
|
|
|
// If debug code is enabled we emit extra code in Jump.
|
|
|
|
if (FLAG_debug_code) return;
|
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
int jump_offsets[] = {-9710, -77, 0, +3, +97109};
|
|
|
|
TRACED_FOREACH(int, jump_offset, jump_offsets) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-07-20 12:51:11 +00:00
|
|
|
if (!interpreter::Bytecodes::IsJump(bytecode)) return;
|
|
|
|
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2016-04-22 13:55:53 +00:00
|
|
|
Node* tail_call_node = m.Jump(m.IntPtrConstant(jump_offset));
|
2015-09-24 15:20:47 +00:00
|
|
|
|
2017-09-11 13:44:42 +00:00
|
|
|
Matcher<Node*> next_bytecode_offset_matcher = c::IsIntPtrAdd(
|
2017-09-04 10:47:27 +00:00
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeOffset),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(jump_offset));
|
2016-02-19 18:46:54 +00:00
|
|
|
Matcher<Node*> target_bytecode_matcher =
|
|
|
|
m.IsLoad(MachineType::Uint8(), _, next_bytecode_offset_matcher);
|
2017-09-11 13:44:42 +00:00
|
|
|
target_bytecode_matcher =
|
|
|
|
c::IsChangeUint32ToWord(target_bytecode_matcher);
|
2017-09-04 10:47:27 +00:00
|
|
|
Matcher<Node*> code_target_matcher = m.IsLoad(
|
|
|
|
MachineType::Pointer(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kDispatchTable),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsWordShl(target_bytecode_matcher,
|
|
|
|
c::IsIntPtrConstant(kPointerSizeLog2)));
|
2016-02-10 16:38:49 +00:00
|
|
|
|
2015-09-24 15:20:47 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
tail_call_node,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsTailCall(
|
2017-09-04 10:47:27 +00:00
|
|
|
_, code_target_matcher,
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kAccumulator),
|
|
|
|
next_bytecode_offset_matcher, _,
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kDispatchTable), _,
|
|
|
|
_));
|
2015-09-24 15:20:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-30 13:56:47 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
|
2016-03-21 17:08:21 +00:00
|
|
|
static const OperandScale kOperandScales[] = {
|
|
|
|
OperandScale::kSingle, OperandScale::kDouble, OperandScale::kQuadruple};
|
2015-07-23 14:21:26 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-03-21 17:08:21 +00:00
|
|
|
TRACED_FOREACH(interpreter::OperandScale, operand_scale, kOperandScales) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode, operand_scale);
|
2016-03-21 17:08:21 +00:00
|
|
|
int number_of_operands =
|
|
|
|
interpreter::Bytecodes::NumberOfOperands(bytecode);
|
|
|
|
for (int i = 0; i < number_of_operands; i++) {
|
|
|
|
int offset = interpreter::Bytecodes::GetOperandOffset(bytecode, i,
|
|
|
|
operand_scale);
|
|
|
|
OperandType operand_type =
|
|
|
|
interpreter::Bytecodes::GetOperandType(bytecode, i);
|
|
|
|
OperandSize operand_size =
|
|
|
|
Bytecodes::SizeOfOperand(operand_type, operand_scale);
|
|
|
|
switch (interpreter::Bytecodes::GetOperandType(bytecode, i)) {
|
|
|
|
case interpreter::OperandType::kRegCount:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandCount(i),
|
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kFlag8:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandFlag(i),
|
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kIdx:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandIdx(i),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsChangeUint32ToWord(
|
2016-12-12 14:52:30 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size)));
|
2016-03-21 17:08:21 +00:00
|
|
|
break;
|
2017-09-05 11:23:26 +00:00
|
|
|
case interpreter::OperandType::kNativeContextIndex:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandNativeContextIndex(i),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsChangeUint32ToWord(
|
2017-09-05 11:23:26 +00:00
|
|
|
m.IsUnsignedOperand(offset, operand_size)));
|
|
|
|
break;
|
2016-09-13 14:48:39 +00:00
|
|
|
case interpreter::OperandType::kUImm:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandUImm(i),
|
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
|
|
|
break;
|
2016-03-21 17:08:21 +00:00
|
|
|
case interpreter::OperandType::kImm: {
|
|
|
|
EXPECT_THAT(m.BytecodeOperandImm(i),
|
|
|
|
m.IsSignedOperand(offset, operand_size));
|
|
|
|
break;
|
|
|
|
}
|
2016-10-05 16:14:12 +00:00
|
|
|
case interpreter::OperandType::kRegList:
|
2016-03-21 17:08:21 +00:00
|
|
|
case interpreter::OperandType::kReg:
|
|
|
|
case interpreter::OperandType::kRegOut:
|
2017-06-02 11:55:48 +00:00
|
|
|
case interpreter::OperandType::kRegOutList:
|
2016-03-21 17:08:21 +00:00
|
|
|
case interpreter::OperandType::kRegOutPair:
|
|
|
|
case interpreter::OperandType::kRegOutTriple:
|
|
|
|
case interpreter::OperandType::kRegPair:
|
2017-09-11 13:44:42 +00:00
|
|
|
EXPECT_THAT(m.BytecodeOperandReg(i),
|
|
|
|
c::IsChangeInt32ToIntPtr(
|
|
|
|
m.IsSignedOperand(offset, operand_size)));
|
2016-03-21 17:08:21 +00:00
|
|
|
break;
|
|
|
|
case interpreter::OperandType::kRuntimeId:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandRuntimeId(i),
|
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
|
|
|
break;
|
2016-06-21 14:37:16 +00:00
|
|
|
case interpreter::OperandType::kIntrinsicId:
|
|
|
|
EXPECT_THAT(m.BytecodeOperandIntrinsicId(i),
|
|
|
|
m.IsUnsignedOperand(offset, operand_size));
|
|
|
|
break;
|
2016-03-21 17:08:21 +00:00
|
|
|
case interpreter::OperandType::kNone:
|
|
|
|
UNREACHABLE();
|
|
|
|
break;
|
|
|
|
}
|
2015-08-18 12:41:41 +00:00
|
|
|
}
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-15 09:33:21 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, GetContext) {
|
2016-01-23 00:07:21 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2016-04-15 09:33:21 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
m.GetContext(),
|
2017-09-04 10:47:27 +00:00
|
|
|
m.IsLoad(MachineType::AnyTagged(), c::IsLoadParentFramePointer(),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(Register::current_context().ToOperand()
|
|
|
|
<< kPointerSizeLog2)));
|
2016-01-23 00:07:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, RegisterLocation) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2017-09-11 13:44:42 +00:00
|
|
|
Node* reg_index_node = m.Parameter(0);
|
2015-09-14 10:05:18 +00:00
|
|
|
Node* reg_location_node = m.RegisterLocation(reg_index_node);
|
2017-09-11 13:44:42 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
reg_location_node,
|
|
|
|
c::IsIntPtrAdd(c::IsLoadParentFramePointer(),
|
|
|
|
c::IsWordShl(reg_index_node,
|
|
|
|
c::IsIntPtrConstant(kPointerSizeLog2))));
|
2015-09-14 10:05:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-18 12:41:41 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadRegister) {
|
2015-07-23 14:21:26 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2017-09-11 13:44:42 +00:00
|
|
|
Node* reg_index_node = m.Parameter(0);
|
2015-08-18 12:41:41 +00:00
|
|
|
Node* load_reg_node = m.LoadRegister(reg_index_node);
|
2017-09-04 10:47:27 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
load_reg_node,
|
2017-09-11 13:44:42 +00:00
|
|
|
m.IsLoad(MachineType::AnyTagged(), c::IsLoadParentFramePointer(),
|
|
|
|
c::IsWordShl(reg_index_node,
|
|
|
|
c::IsIntPtrConstant(kPointerSizeLog2))));
|
2015-07-23 14:21:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, StoreRegister) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2015-07-23 14:21:26 +00:00
|
|
|
Node* store_value = m.Int32Constant(0xdeadbeef);
|
2017-09-11 13:44:42 +00:00
|
|
|
Node* reg_index_node = m.Parameter(0);
|
2015-07-23 14:21:26 +00:00
|
|
|
Node* store_reg_node = m.StoreRegister(store_value, reg_index_node);
|
2017-09-11 13:44:42 +00:00
|
|
|
EXPECT_THAT(store_reg_node,
|
|
|
|
m.IsStore(c::StoreRepresentation(MachineRepresentation::kTagged,
|
|
|
|
kNoWriteBarrier),
|
|
|
|
c::IsLoadParentFramePointer(),
|
|
|
|
c::IsWordShl(reg_index_node,
|
|
|
|
c::IsIntPtrConstant(kPointerSizeLog2)),
|
|
|
|
store_value));
|
2015-09-14 10:05:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-28 15:40:52 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadConstantPoolEntry) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2016-12-12 14:52:30 +00:00
|
|
|
{
|
|
|
|
Node* index = m.IntPtrConstant(2);
|
|
|
|
Node* load_constant = m.LoadConstantPoolEntry(index);
|
2017-09-04 10:47:27 +00:00
|
|
|
Matcher<Node*> constant_pool_matcher = m.IsLoad(
|
|
|
|
MachineType::AnyTagged(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(BytecodeArray::kConstantPoolOffset -
|
|
|
|
kHeapObjectTag));
|
|
|
|
EXPECT_THAT(
|
|
|
|
load_constant,
|
|
|
|
m.IsLoad(MachineType::AnyTagged(), constant_pool_matcher,
|
|
|
|
c::IsIntPtrConstant(FixedArray::OffsetOfElementAt(2) -
|
|
|
|
kHeapObjectTag)));
|
2016-12-12 14:52:30 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
Node* index = m.Parameter(2);
|
|
|
|
Node* load_constant = m.LoadConstantPoolEntry(index);
|
2017-09-04 10:47:27 +00:00
|
|
|
Matcher<Node*> constant_pool_matcher = m.IsLoad(
|
|
|
|
MachineType::AnyTagged(),
|
|
|
|
c::IsParameter(InterpreterDispatchDescriptor::kBytecodeArray),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(BytecodeArray::kConstantPoolOffset -
|
|
|
|
kHeapObjectTag));
|
2016-12-12 14:52:30 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
load_constant,
|
|
|
|
m.IsLoad(
|
|
|
|
MachineType::AnyTagged(), constant_pool_matcher,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrAdd(
|
|
|
|
c::IsIntPtrConstant(FixedArray::kHeaderSize - kHeapObjectTag),
|
|
|
|
c::IsWordShl(index, c::IsIntPtrConstant(kPointerSizeLog2)))));
|
2016-12-12 14:52:30 +00:00
|
|
|
}
|
2015-10-29 12:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadObjectField) {
|
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2015-10-29 12:06:00 +00:00
|
|
|
Node* object = m.IntPtrConstant(0xdeadbeef);
|
|
|
|
int offset = 16;
|
|
|
|
Node* load_field = m.LoadObjectField(object, offset);
|
|
|
|
EXPECT_THAT(load_field,
|
2015-12-10 09:03:30 +00:00
|
|
|
m.IsLoad(MachineType::AnyTagged(), object,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offset - kHeapObjectTag)));
|
2015-10-29 12:06:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 18:13:41 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, CallRuntime2) {
|
2015-08-25 11:31:09 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2015-09-10 13:04:15 +00:00
|
|
|
Node* arg1 = m.Int32Constant(2);
|
|
|
|
Node* arg2 = m.Int32Constant(3);
|
2016-04-19 12:47:25 +00:00
|
|
|
Node* context = m.Int32Constant(4);
|
2016-02-10 16:38:49 +00:00
|
|
|
Node* call_runtime = m.CallRuntime(Runtime::kAdd, context, arg1, arg2);
|
2017-09-11 13:44:42 +00:00
|
|
|
EXPECT_THAT(call_runtime, c::IsCall(_, _, arg1, arg2, _,
|
|
|
|
c::IsInt32Constant(2), context, _, _));
|
2015-09-02 13:03:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-02 18:13:41 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, CallRuntime) {
|
2016-01-08 15:15:52 +00:00
|
|
|
const int kResultSizes[] = {1, 2};
|
2015-10-02 18:13:41 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-01-08 15:15:52 +00:00
|
|
|
TRACED_FOREACH(int, result_size, kResultSizes) {
|
2017-02-16 16:54:02 +00:00
|
|
|
if (Bytecodes::IsCallRuntime(bytecode)) {
|
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
|
|
|
Callable builtin =
|
|
|
|
CodeFactory::InterpreterCEntry(isolate(), result_size);
|
|
|
|
|
|
|
|
Node* function_id = m.Int32Constant(0);
|
|
|
|
Node* first_arg = m.IntPtrConstant(1);
|
|
|
|
Node* arg_count = m.Int32Constant(2);
|
|
|
|
Node* context = m.IntPtrConstant(4);
|
|
|
|
|
2017-09-04 10:47:27 +00:00
|
|
|
Matcher<Node*> function_table = c::IsExternalConstant(
|
2017-02-16 16:54:02 +00:00
|
|
|
ExternalReference::runtime_function_table_address(isolate()));
|
2017-09-11 13:44:42 +00:00
|
|
|
Matcher<Node*> function = c::IsIntPtrAdd(
|
2017-02-16 16:54:02 +00:00
|
|
|
function_table,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsChangeUint32ToWord(c::IsInt32Mul(
|
2017-09-04 10:47:27 +00:00
|
|
|
function_id, c::IsInt32Constant(sizeof(Runtime::Function)))));
|
2017-02-16 16:54:02 +00:00
|
|
|
Matcher<Node*> function_entry =
|
|
|
|
m.IsLoad(MachineType::Pointer(), function,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(offsetof(Runtime::Function, entry)));
|
2017-02-16 16:54:02 +00:00
|
|
|
|
|
|
|
Node* call_runtime = m.CallRuntimeN(function_id, context, first_arg,
|
|
|
|
arg_count, result_size);
|
|
|
|
EXPECT_THAT(call_runtime,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsCall(_, c::IsHeapConstant(builtin.code()), arg_count,
|
|
|
|
first_arg, function_entry, context, _, _));
|
2017-02-16 16:54:02 +00:00
|
|
|
}
|
2016-01-08 15:15:52 +00:00
|
|
|
}
|
2015-10-02 18:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-07 14:05:02 +00:00
|
|
|
TARGET_TEST_F(InterpreterAssemblerTest, LoadFeedbackVector) {
|
2015-09-02 13:03:06 +00:00
|
|
|
TRACED_FOREACH(interpreter::Bytecode, bytecode, kBytecodes) {
|
2016-11-16 11:48:07 +00:00
|
|
|
InterpreterAssemblerTestState state(this, bytecode);
|
|
|
|
InterpreterAssemblerForTest m(&state, bytecode);
|
2017-02-07 14:05:02 +00:00
|
|
|
Node* feedback_vector = m.LoadFeedbackVector();
|
2015-09-02 13:03:06 +00:00
|
|
|
|
2016-04-19 12:47:25 +00:00
|
|
|
Matcher<Node*> load_function_matcher =
|
2017-09-04 10:47:27 +00:00
|
|
|
m.IsLoad(MachineType::AnyTagged(), c::IsLoadParentFramePointer(),
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(Register::function_closure().ToOperand()
|
|
|
|
<< kPointerSizeLog2));
|
|
|
|
Matcher<Node*> load_vector_cell_matcher =
|
|
|
|
m.IsLoad(MachineType::AnyTagged(), load_function_matcher,
|
|
|
|
c::IsIntPtrConstant(JSFunction::kFeedbackVectorOffset -
|
|
|
|
kHeapObjectTag));
|
2017-02-06 10:18:05 +00:00
|
|
|
EXPECT_THAT(
|
|
|
|
feedback_vector,
|
|
|
|
m.IsLoad(MachineType::AnyTagged(), load_vector_cell_matcher,
|
2017-09-11 13:44:42 +00:00
|
|
|
c::IsIntPtrConstant(Cell::kValueOffset - kHeapObjectTag)));
|
2015-08-25 11:31:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-18 17:01:45 +00:00
|
|
|
} // namespace interpreter_assembler_unittest
|
2016-02-10 16:38:49 +00:00
|
|
|
} // namespace interpreter
|
2015-07-23 14:21:26 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|