aboutsummaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/test-macro-assembler-x64.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/cctest/test-macro-assembler-x64.cc')
-rw-r--r--deps/v8/test/cctest/test-macro-assembler-x64.cc282
1 files changed, 253 insertions, 29 deletions
diff --git a/deps/v8/test/cctest/test-macro-assembler-x64.cc b/deps/v8/test/cctest/test-macro-assembler-x64.cc
index a2070a5ea8..61914b58c3 100644
--- a/deps/v8/test/cctest/test-macro-assembler-x64.cc
+++ b/deps/v8/test/cctest/test-macro-assembler-x64.cc
@@ -47,6 +47,7 @@ using v8::internal::MacroAssembler;
using v8::internal::OS;
using v8::internal::Operand;
using v8::internal::RelocInfo;
+using v8::internal::Representation;
using v8::internal::Smi;
using v8::internal::SmiIndex;
using v8::internal::byte;
@@ -141,8 +142,8 @@ TEST(Smi) {
static void TestMoveSmi(MacroAssembler* masm, Label* exit, int id, Smi* value) {
__ movl(rax, Immediate(id));
- __ Move(rcx, Smi::FromInt(0));
- __ Set(rdx, reinterpret_cast<intptr_t>(Smi::FromInt(0)));
+ __ Move(rcx, value);
+ __ Set(rdx, reinterpret_cast<intptr_t>(value));
__ cmpq(rcx, rdx);
__ j(not_equal, exit);
}
@@ -157,7 +158,7 @@ TEST(SmiMove) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
MacroAssembler* masm = &assembler; // Create a pointer for the __ macro.
@@ -246,7 +247,7 @@ TEST(SmiCompare) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -297,7 +298,7 @@ TEST(Integer32ToSmi) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -426,7 +427,7 @@ TEST(Integer64PlusConstantToSmi) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -471,7 +472,7 @@ TEST(SmiCheck) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -720,7 +721,7 @@ TEST(SmiNeg) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -751,8 +752,6 @@ TEST(SmiNeg) {
}
-
-
static void SmiAddTest(MacroAssembler* masm,
Label* exit,
int id,
@@ -802,15 +801,122 @@ static void SmiAddTest(MacroAssembler* masm,
}
+static void SmiAddOverflowTest(MacroAssembler* masm,
+ Label* exit,
+ int id,
+ int x) {
+ // Adds a Smi to x so that the addition overflows.
+ ASSERT(x != 0); // Can't overflow by adding a Smi.
+ int y_max = (x > 0) ? (Smi::kMaxValue + 0) : (Smi::kMinValue - x - 1);
+ int y_min = (x > 0) ? (Smi::kMaxValue - x + 1) : (Smi::kMinValue + 0);
+
+ __ movl(rax, Immediate(id));
+ __ Move(rcx, Smi::FromInt(x));
+ __ movq(r11, rcx); // Store original Smi value of x in r11.
+ __ Move(rdx, Smi::FromInt(y_min));
+ {
+ Label overflow_ok;
+ __ SmiAdd(r9, rcx, rdx, &overflow_ok);
+ __ jmp(exit);
+ __ bind(&overflow_ok);
+ __ incq(rax);
+ __ cmpq(rcx, r11);
+ __ j(not_equal, exit);
+ }
+
+ {
+ Label overflow_ok;
+ __ incq(rax);
+ __ SmiAdd(rcx, rcx, rdx, &overflow_ok);
+ __ jmp(exit);
+ __ bind(&overflow_ok);
+ __ incq(rax);
+ __ cmpq(rcx, r11);
+ __ j(not_equal, exit);
+ }
+
+ __ movq(rcx, r11);
+ {
+ Label overflow_ok;
+ __ incq(rax);
+ __ SmiAddConstant(r9, rcx, Smi::FromInt(y_min), &overflow_ok);
+ __ jmp(exit);
+ __ bind(&overflow_ok);
+ __ incq(rax);
+ __ cmpq(rcx, r11);
+ __ j(not_equal, exit);
+ }
+
+ {
+ Label overflow_ok;
+ __ incq(rax);
+ __ SmiAddConstant(rcx, rcx, Smi::FromInt(y_min), &overflow_ok);
+ __ jmp(exit);
+ __ bind(&overflow_ok);
+ __ incq(rax);
+ __ cmpq(rcx, r11);
+ __ j(not_equal, exit);
+ }
+
+ __ Move(rdx, Smi::FromInt(y_max));
+
+ {
+ Label overflow_ok;
+ __ incq(rax);
+ __ SmiAdd(r9, rcx, rdx, &overflow_ok);
+ __ jmp(exit);
+ __ bind(&overflow_ok);
+ __ incq(rax);
+ __ cmpq(rcx, r11);
+ __ j(not_equal, exit);
+ }
+
+ {
+ Label overflow_ok;
+ __ incq(rax);
+ __ SmiAdd(rcx, rcx, rdx, &overflow_ok);
+ __ jmp(exit);
+ __ bind(&overflow_ok);
+ __ incq(rax);
+ __ cmpq(rcx, r11);
+ __ j(not_equal, exit);
+ }
+
+ __ movq(rcx, r11);
+ {
+ Label overflow_ok;
+ __ incq(rax);
+ __ SmiAddConstant(r9, rcx, Smi::FromInt(y_max), &overflow_ok);
+ __ jmp(exit);
+ __ bind(&overflow_ok);
+ __ incq(rax);
+ __ cmpq(rcx, r11);
+ __ j(not_equal, exit);
+ }
+
+ {
+ Label overflow_ok;
+ __ incq(rax);
+ __ SmiAddConstant(rcx, rcx, Smi::FromInt(y_max), &overflow_ok);
+ __ jmp(exit);
+ __ bind(&overflow_ok);
+ __ incq(rax);
+ __ cmpq(rcx, r11);
+ __ j(not_equal, exit);
+ }
+}
+
+
TEST(SmiAdd) {
v8::internal::V8::Initialize(NULL);
// Allocate an executable page of memory.
size_t actual_size;
- byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
- &actual_size,
- true));
+ byte* buffer =
+ static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize * 2,
+ &actual_size,
+ true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -829,6 +935,14 @@ TEST(SmiAdd) {
SmiAddTest(masm, &exit, 0x70, Smi::kMaxValue, -5);
SmiAddTest(masm, &exit, 0x80, Smi::kMaxValue, Smi::kMinValue);
+ SmiAddOverflowTest(masm, &exit, 0x90, -1);
+ SmiAddOverflowTest(masm, &exit, 0xA0, 1);
+ SmiAddOverflowTest(masm, &exit, 0xB0, 1024);
+ SmiAddOverflowTest(masm, &exit, 0xC0, Smi::kMaxValue);
+ SmiAddOverflowTest(masm, &exit, 0xD0, -2);
+ SmiAddOverflowTest(masm, &exit, 0xE0, -42000);
+ SmiAddOverflowTest(masm, &exit, 0xF0, Smi::kMinValue);
+
__ xor_(rax, rax); // Success.
__ bind(&exit);
ExitCode(masm);
@@ -886,6 +1000,7 @@ static void SmiSubTest(MacroAssembler* masm,
__ j(not_equal, exit);
}
+
static void SmiSubOverflowTest(MacroAssembler* masm,
Label* exit,
int id,
@@ -1001,7 +1116,7 @@ TEST(SmiSub) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1092,7 +1207,7 @@ TEST(SmiMul) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1199,7 +1314,7 @@ TEST(SmiDiv) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1310,7 +1425,7 @@ TEST(SmiMod) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1408,7 +1523,7 @@ TEST(SmiIndex) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1478,7 +1593,7 @@ TEST(SmiSelectNonSmi) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1558,7 +1673,7 @@ TEST(SmiAnd) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1640,7 +1755,7 @@ TEST(SmiOr) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1724,7 +1839,7 @@ TEST(SmiXor) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1792,7 +1907,7 @@ TEST(SmiNot) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1889,7 +2004,7 @@ TEST(SmiShiftLeft) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -1996,7 +2111,7 @@ TEST(SmiShiftLogicalRight) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -2066,7 +2181,7 @@ TEST(SmiShiftArithmeticRight) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -2131,7 +2246,7 @@ TEST(PositiveSmiTimesPowerOfTwoToInteger64) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -2175,7 +2290,7 @@ TEST(OperandOffset) {
&actual_size,
true));
CHECK(buffer);
- Isolate* isolate = Isolate::Current();
+ Isolate* isolate = CcTest::i_isolate();
HandleScope handles(isolate);
MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
@@ -2520,5 +2635,114 @@ TEST(OperandOffset) {
}
+TEST(LoadAndStoreWithRepresentation) {
+ v8::internal::V8::Initialize(NULL);
+
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Isolate* isolate = CcTest::i_isolate();
+ HandleScope handles(isolate);
+ MacroAssembler assembler(isolate, buffer, static_cast<int>(actual_size));
+ MacroAssembler* masm = &assembler; // Create a pointer for the __ macro.
+ masm->set_allow_stub_calls(false);
+ EntryCode(masm);
+ __ subq(rsp, Immediate(1 * kPointerSize));
+ Label exit;
+
+ // Test 1.
+ __ movq(rax, Immediate(1)); // Test number.
+ __ movq(Operand(rsp, 0 * kPointerSize), Immediate(0));
+ __ movq(rcx, Immediate(-1));
+ __ Store(Operand(rsp, 0 * kPointerSize), rcx, Representation::Byte());
+ __ movq(rcx, Operand(rsp, 0 * kPointerSize));
+ __ movl(rdx, Immediate(255));
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+ __ Load(rdx, Operand(rsp, 0 * kPointerSize), Representation::Byte());
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+
+ // Test 2.
+ __ movq(rax, Immediate(2)); // Test number.
+ __ movq(Operand(rsp, 0 * kPointerSize), Immediate(0));
+ __ Set(rcx, V8_2PART_UINT64_C(0xdeadbeaf, 12345678));
+ __ Store(Operand(rsp, 0 * kPointerSize), rcx, Representation::Smi());
+ __ movq(rcx, Operand(rsp, 0 * kPointerSize));
+ __ Set(rdx, V8_2PART_UINT64_C(0xdeadbeaf, 12345678));
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+ __ Load(rdx, Operand(rsp, 0 * kPointerSize), Representation::Smi());
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+
+ // Test 3.
+ __ movq(rax, Immediate(3)); // Test number.
+ __ movq(Operand(rsp, 0 * kPointerSize), Immediate(0));
+ __ movq(rcx, Immediate(-1));
+ __ Store(Operand(rsp, 0 * kPointerSize), rcx, Representation::Integer32());
+ __ movq(rcx, Operand(rsp, 0 * kPointerSize));
+ __ movl(rdx, Immediate(-1));
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+ __ Load(rdx, Operand(rsp, 0 * kPointerSize), Representation::Integer32());
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+
+ // Test 4.
+ __ movq(rax, Immediate(4)); // Test number.
+ __ movq(Operand(rsp, 0 * kPointerSize), Immediate(0));
+ __ movl(rcx, Immediate(0x44332211));
+ __ Store(Operand(rsp, 0 * kPointerSize), rcx, Representation::HeapObject());
+ __ movq(rcx, Operand(rsp, 0 * kPointerSize));
+ __ movl(rdx, Immediate(0x44332211));
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+ __ Load(rdx, Operand(rsp, 0 * kPointerSize), Representation::HeapObject());
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+
+ // Test 5.
+ __ movq(rax, Immediate(5)); // Test number.
+ __ movq(Operand(rsp, 0 * kPointerSize), Immediate(0));
+ __ Set(rcx, V8_2PART_UINT64_C(0x12345678, deadbeaf));
+ __ Store(Operand(rsp, 0 * kPointerSize), rcx, Representation::Tagged());
+ __ movq(rcx, Operand(rsp, 0 * kPointerSize));
+ __ Set(rdx, V8_2PART_UINT64_C(0x12345678, deadbeaf));
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+ __ Load(rdx, Operand(rsp, 0 * kPointerSize), Representation::Tagged());
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+
+ // Test 6.
+ __ movq(rax, Immediate(6)); // Test number.
+ __ movq(Operand(rsp, 0 * kPointerSize), Immediate(0));
+ __ Set(rcx, V8_2PART_UINT64_C(0x11223344, 55667788));
+ __ Store(Operand(rsp, 0 * kPointerSize), rcx, Representation::External());
+ __ movq(rcx, Operand(rsp, 0 * kPointerSize));
+ __ Set(rdx, V8_2PART_UINT64_C(0x11223344, 55667788));
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+ __ Load(rdx, Operand(rsp, 0 * kPointerSize), Representation::External());
+ __ cmpq(rcx, rdx);
+ __ j(not_equal, &exit);
+
+ __ xor_(rax, rax); // Success.
+ __ bind(&exit);
+ __ addq(rsp, Immediate(1 * kPointerSize));
+ ExitCode(masm);
+ __ ret(0);
+
+ CodeDesc desc;
+ masm->GetCode(&desc);
+ // Call the function from C++.
+ int result = FUNCTION_CAST<F0>(buffer)();
+ CHECK_EQ(0, result);
+}
+
#undef __