Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(693)

Unified Diff: test/cctest/test-assembler-x64.cc

Issue 113832: Add implementation of control flow and label binding to x64 assembler. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« src/x64/assembler-x64.cc ('K') | « src/x64/assembler-x64-inl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-assembler-x64.cc
===================================================================
--- test/cctest/test-assembler-x64.cc (revision 2056)
+++ test/cctest/test-assembler-x64.cc (working copy)
@@ -38,8 +38,13 @@
using v8::internal::byte;
using v8::internal::OS;
using v8::internal::Assembler;
+using v8::internal::Operand;
+using v8::internal::Label;
using v8::internal::rax;
using v8::internal::rsi;
+using v8::internal::rdi;
+using v8::internal::rbp;
+using v8::internal::rsp;
using v8::internal::FUNCTION_CAST;
using v8::internal::CodeDesc;
@@ -60,7 +65,7 @@
#define __ assm.
-TEST(AssemblerX640) {
+TEST(AssemblerX64ReturnOperation) {
// Allocate an executable page of memory.
size_t actual_size;
byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
@@ -81,4 +86,114 @@
CHECK_EQ(2, result);
}
+TEST(AssemblerX64StackOperations) {
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Assembler assm(buffer, actual_size);
+
+ // Assemble a simple function that copies argument 2 and returns it.
+ // We compile without stack frame pointers, so the gdb debugger shows
+ // incorrect stack frames when debugging this function (which has them).
+ __ push(rbp);
+ __ mov(rbp, rsp);
+ __ push(rsi); // Value at (rbp - 8)
+ __ push(rsi); // Value at (rbp - 16)
+ __ push(rdi); // Value at (rbp - 24)
+ __ pop(rax);
+ __ pop(rax);
+ __ pop(rax);
+ __ pop(rbp);
+ __ nop();
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ // Call the function from C++.
+ int result = FUNCTION_CAST<F2>(buffer)(3, 2);
+ CHECK_EQ(2, result);
+}
+
+TEST(AssemblerX64ArithmeticOperations) {
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Assembler assm(buffer, actual_size);
+
+ // Assemble a simple function that copies argument 2 and returns it.
+ __ mov(rax, rsi);
+ __ add(rax, rdi);
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ // Call the function from C++.
+ int result = FUNCTION_CAST<F2>(buffer)(3, 2);
+ CHECK_EQ(5, result);
+}
+
+TEST(AssemblerX64MemoryOperands) {
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Assembler assm(buffer, actual_size);
+
+ // Assemble a simple function that copies argument 2 and returns it.
+ __ push(rbp);
+ __ mov(rbp, rsp);
+ __ push(rsi); // Value at (rbp - 8)
+ __ push(rsi); // Value at (rbp - 16)
+ __ push(rdi); // Value at (rbp - 24)
+ // const int kStackElementSize = 8;
+ // __ mov(rax, Operand(rbp,-3 * kStackElementSize));
+ __ pop(rax);
+ __ pop(rax);
+ __ pop(rax);
+ __ pop(rbp);
+ __ nop();
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ // Call the function from C++.
+ int result = FUNCTION_CAST<F2>(buffer)(3, 2);
+ CHECK_EQ(2, result);
+}
+
+TEST(AssemblerX64ControlFlow) {
+ // Allocate an executable page of memory.
+ size_t actual_size;
+ byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
+ &actual_size,
+ true));
+ CHECK(buffer);
+ Assembler assm(buffer, actual_size);
+
+ // Assemble a simple function that copies argument 2 and returns it.
+ __ push(rbp);
+ __ mov(rbp, rsp);
+ __ mov(rax, rdi);
+ Label target;
+ __ jmp(&target);
+ __ mov(rax, rsi);
+ __ bind(&target);
+ __ pop(rbp);
+ __ ret(0);
+
+ CodeDesc desc;
+ assm.GetCode(&desc);
+ // Call the function from C++.
+ int result = FUNCTION_CAST<F2>(buffer)(3, 2);
+ CHECK_EQ(3, result);
+}
+
#undef __
« src/x64/assembler-x64.cc ('K') | « src/x64/assembler-x64-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698