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

Side by Side Diff: test/cctest/test-assembler-x64.cc

Issue 6794050: Revert "[Arguments] Merge (7442,7496] from bleeding_edge." (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/arguments
Patch Set: Created 9 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-assembler-ia32.cc ('k') | test/cctest/test-disasm-arm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2009 the V8 project authors. All rights reserved. 1 // Copyright 2009 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 17 matching lines...) Expand all
28 #include <stdlib.h> 28 #include <stdlib.h>
29 29
30 #include "v8.h" 30 #include "v8.h"
31 31
32 #include "macro-assembler.h" 32 #include "macro-assembler.h"
33 #include "factory.h" 33 #include "factory.h"
34 #include "platform.h" 34 #include "platform.h"
35 #include "serialize.h" 35 #include "serialize.h"
36 #include "cctest.h" 36 #include "cctest.h"
37 37
38 using v8::internal::byte;
39 using v8::internal::OS;
38 using v8::internal::Assembler; 40 using v8::internal::Assembler;
41 using v8::internal::Operand;
42 using v8::internal::Immediate;
43 using v8::internal::Label;
44 using v8::internal::rax;
45 using v8::internal::rsi;
46 using v8::internal::rdi;
47 using v8::internal::rcx;
48 using v8::internal::rdx;
49 using v8::internal::rbp;
50 using v8::internal::rsp;
51 using v8::internal::r8;
52 using v8::internal::r9;
53 using v8::internal::r13;
54 using v8::internal::r15;
55 using v8::internal::times_1;
56
57 using v8::internal::FUNCTION_CAST;
39 using v8::internal::CodeDesc; 58 using v8::internal::CodeDesc;
40 using v8::internal::FUNCTION_CAST;
41 using v8::internal::Immediate;
42 using v8::internal::Isolate;
43 using v8::internal::Label;
44 using v8::internal::OS;
45 using v8::internal::Operand;
46 using v8::internal::byte;
47 using v8::internal::greater;
48 using v8::internal::less_equal; 59 using v8::internal::less_equal;
49 using v8::internal::not_equal; 60 using v8::internal::not_equal;
50 using v8::internal::r13; 61 using v8::internal::greater;
51 using v8::internal::r15;
52 using v8::internal::r8;
53 using v8::internal::r9;
54 using v8::internal::rax;
55 using v8::internal::rbp;
56 using v8::internal::rcx;
57 using v8::internal::rdi;
58 using v8::internal::rdx;
59 using v8::internal::rsi;
60 using v8::internal::rsp;
61 using v8::internal::times_1;
62 62
63 // Test the x64 assembler by compiling some simple functions into 63 // Test the x64 assembler by compiling some simple functions into
64 // a buffer and executing them. These tests do not initialize the 64 // a buffer and executing them. These tests do not initialize the
65 // V8 library, create a context, or use any V8 objects. 65 // V8 library, create a context, or use any V8 objects.
66 // The AMD64 calling convention is used, with the first six arguments 66 // The AMD64 calling convention is used, with the first six arguments
67 // in RDI, RSI, RDX, RCX, R8, and R9, and floating point arguments in 67 // in RDI, RSI, RDX, RCX, R8, and R9, and floating point arguments in
68 // the XMM registers. The return value is in RAX. 68 // the XMM registers. The return value is in RAX.
69 // This calling convention is used on Linux, with GCC, and on Mac OS, 69 // This calling convention is used on Linux, with GCC, and on Mac OS,
70 // with GCC. A different convention is used on 64-bit windows, 70 // with GCC. A different convention is used on 64-bit windows,
71 // where the first four integer arguments are passed in RCX, RDX, R8 and R9. 71 // where the first four integer arguments are passed in RCX, RDX, R8 and R9.
(...skipping 14 matching lines...) Expand all
86 86
87 87
88 TEST(AssemblerX64ReturnOperation) { 88 TEST(AssemblerX64ReturnOperation) {
89 OS::Setup(); 89 OS::Setup();
90 // Allocate an executable page of memory. 90 // Allocate an executable page of memory.
91 size_t actual_size; 91 size_t actual_size;
92 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 92 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
93 &actual_size, 93 &actual_size,
94 true)); 94 true));
95 CHECK(buffer); 95 CHECK(buffer);
96 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); 96 Assembler assm(buffer, static_cast<int>(actual_size));
97 97
98 // Assemble a simple function that copies argument 2 and returns it. 98 // Assemble a simple function that copies argument 2 and returns it.
99 __ movq(rax, arg2); 99 __ movq(rax, arg2);
100 __ nop(); 100 __ nop();
101 __ ret(0); 101 __ ret(0);
102 102
103 CodeDesc desc; 103 CodeDesc desc;
104 assm.GetCode(&desc); 104 assm.GetCode(&desc);
105 // Call the function from C++. 105 // Call the function from C++.
106 int result = FUNCTION_CAST<F2>(buffer)(3, 2); 106 int result = FUNCTION_CAST<F2>(buffer)(3, 2);
107 CHECK_EQ(2, result); 107 CHECK_EQ(2, result);
108 } 108 }
109 109
110 TEST(AssemblerX64StackOperations) { 110 TEST(AssemblerX64StackOperations) {
111 OS::Setup(); 111 OS::Setup();
112 // Allocate an executable page of memory. 112 // Allocate an executable page of memory.
113 size_t actual_size; 113 size_t actual_size;
114 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 114 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
115 &actual_size, 115 &actual_size,
116 true)); 116 true));
117 CHECK(buffer); 117 CHECK(buffer);
118 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); 118 Assembler assm(buffer, static_cast<int>(actual_size));
119 119
120 // Assemble a simple function that copies argument 2 and returns it. 120 // Assemble a simple function that copies argument 2 and returns it.
121 // We compile without stack frame pointers, so the gdb debugger shows 121 // We compile without stack frame pointers, so the gdb debugger shows
122 // incorrect stack frames when debugging this function (which has them). 122 // incorrect stack frames when debugging this function (which has them).
123 __ push(rbp); 123 __ push(rbp);
124 __ movq(rbp, rsp); 124 __ movq(rbp, rsp);
125 __ push(arg2); // Value at (rbp - 8) 125 __ push(arg2); // Value at (rbp - 8)
126 __ push(arg2); // Value at (rbp - 16) 126 __ push(arg2); // Value at (rbp - 16)
127 __ push(arg1); // Value at (rbp - 24) 127 __ push(arg1); // Value at (rbp - 24)
128 __ pop(rax); 128 __ pop(rax);
(...skipping 11 matching lines...) Expand all
140 } 140 }
141 141
142 TEST(AssemblerX64ArithmeticOperations) { 142 TEST(AssemblerX64ArithmeticOperations) {
143 OS::Setup(); 143 OS::Setup();
144 // Allocate an executable page of memory. 144 // Allocate an executable page of memory.
145 size_t actual_size; 145 size_t actual_size;
146 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 146 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
147 &actual_size, 147 &actual_size,
148 true)); 148 true));
149 CHECK(buffer); 149 CHECK(buffer);
150 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); 150 Assembler assm(buffer, static_cast<int>(actual_size));
151 151
152 // Assemble a simple function that adds arguments returning the sum. 152 // Assemble a simple function that adds arguments returning the sum.
153 __ movq(rax, arg2); 153 __ movq(rax, arg2);
154 __ addq(rax, arg1); 154 __ addq(rax, arg1);
155 __ ret(0); 155 __ ret(0);
156 156
157 CodeDesc desc; 157 CodeDesc desc;
158 assm.GetCode(&desc); 158 assm.GetCode(&desc);
159 // Call the function from C++. 159 // Call the function from C++.
160 int result = FUNCTION_CAST<F2>(buffer)(3, 2); 160 int result = FUNCTION_CAST<F2>(buffer)(3, 2);
161 CHECK_EQ(5, result); 161 CHECK_EQ(5, result);
162 } 162 }
163 163
164 TEST(AssemblerX64ImulOperation) { 164 TEST(AssemblerX64ImulOperation) {
165 OS::Setup(); 165 OS::Setup();
166 // Allocate an executable page of memory. 166 // Allocate an executable page of memory.
167 size_t actual_size; 167 size_t actual_size;
168 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 168 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
169 &actual_size, 169 &actual_size,
170 true)); 170 true));
171 CHECK(buffer); 171 CHECK(buffer);
172 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); 172 Assembler assm(buffer, static_cast<int>(actual_size));
173 173
174 // Assemble a simple function that multiplies arguments returning the high 174 // Assemble a simple function that multiplies arguments returning the high
175 // word. 175 // word.
176 __ movq(rax, arg2); 176 __ movq(rax, arg2);
177 __ imul(arg1); 177 __ imul(arg1);
178 __ movq(rax, rdx); 178 __ movq(rax, rdx);
179 __ ret(0); 179 __ ret(0);
180 180
181 CodeDesc desc; 181 CodeDesc desc;
182 assm.GetCode(&desc); 182 assm.GetCode(&desc);
183 // Call the function from C++. 183 // Call the function from C++.
184 int result = FUNCTION_CAST<F2>(buffer)(3, 2); 184 int result = FUNCTION_CAST<F2>(buffer)(3, 2);
185 CHECK_EQ(0, result); 185 CHECK_EQ(0, result);
186 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); 186 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l);
187 CHECK_EQ(1, result); 187 CHECK_EQ(1, result);
188 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); 188 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l);
189 CHECK_EQ(-1, result); 189 CHECK_EQ(-1, result);
190 } 190 }
191 191
192 TEST(AssemblerX64MemoryOperands) { 192 TEST(AssemblerX64MemoryOperands) {
193 OS::Setup(); 193 OS::Setup();
194 // Allocate an executable page of memory. 194 // Allocate an executable page of memory.
195 size_t actual_size; 195 size_t actual_size;
196 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 196 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
197 &actual_size, 197 &actual_size,
198 true)); 198 true));
199 CHECK(buffer); 199 CHECK(buffer);
200 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); 200 Assembler assm(buffer, static_cast<int>(actual_size));
201 201
202 // Assemble a simple function that copies argument 2 and returns it. 202 // Assemble a simple function that copies argument 2 and returns it.
203 __ push(rbp); 203 __ push(rbp);
204 __ movq(rbp, rsp); 204 __ movq(rbp, rsp);
205 205
206 __ push(arg2); // Value at (rbp - 8) 206 __ push(arg2); // Value at (rbp - 8)
207 __ push(arg2); // Value at (rbp - 16) 207 __ push(arg2); // Value at (rbp - 16)
208 __ push(arg1); // Value at (rbp - 24) 208 __ push(arg1); // Value at (rbp - 24)
209 209
210 const int kStackElementSize = 8; 210 const int kStackElementSize = 8;
(...skipping 13 matching lines...) Expand all
224 } 224 }
225 225
226 TEST(AssemblerX64ControlFlow) { 226 TEST(AssemblerX64ControlFlow) {
227 OS::Setup(); 227 OS::Setup();
228 // Allocate an executable page of memory. 228 // Allocate an executable page of memory.
229 size_t actual_size; 229 size_t actual_size;
230 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 230 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
231 &actual_size, 231 &actual_size,
232 true)); 232 true));
233 CHECK(buffer); 233 CHECK(buffer);
234 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); 234 Assembler assm(buffer, static_cast<int>(actual_size));
235 235
236 // Assemble a simple function that copies argument 1 and returns it. 236 // Assemble a simple function that copies argument 1 and returns it.
237 __ push(rbp); 237 __ push(rbp);
238 238
239 __ movq(rbp, rsp); 239 __ movq(rbp, rsp);
240 __ movq(rax, arg1); 240 __ movq(rax, arg1);
241 Label target; 241 Label target;
242 __ jmp(&target); 242 __ jmp(&target);
243 __ movq(rax, arg2); 243 __ movq(rax, arg2);
244 __ bind(&target); 244 __ bind(&target);
245 __ pop(rbp); 245 __ pop(rbp);
246 __ ret(0); 246 __ ret(0);
247 247
248 CodeDesc desc; 248 CodeDesc desc;
249 assm.GetCode(&desc); 249 assm.GetCode(&desc);
250 // Call the function from C++. 250 // Call the function from C++.
251 int result = FUNCTION_CAST<F2>(buffer)(3, 2); 251 int result = FUNCTION_CAST<F2>(buffer)(3, 2);
252 CHECK_EQ(3, result); 252 CHECK_EQ(3, result);
253 } 253 }
254 254
255 TEST(AssemblerX64LoopImmediates) { 255 TEST(AssemblerX64LoopImmediates) {
256 OS::Setup(); 256 OS::Setup();
257 // Allocate an executable page of memory. 257 // Allocate an executable page of memory.
258 size_t actual_size; 258 size_t actual_size;
259 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, 259 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize,
260 &actual_size, 260 &actual_size,
261 true)); 261 true));
262 CHECK(buffer); 262 CHECK(buffer);
263 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); 263 Assembler assm(buffer, static_cast<int>(actual_size));
264 // Assemble two loops using rax as counter, and verify the ending counts. 264 // Assemble two loops using rax as counter, and verify the ending counts.
265 Label Fail; 265 Label Fail;
266 __ movq(rax, Immediate(-3)); 266 __ movq(rax, Immediate(-3));
267 Label Loop1_test; 267 Label Loop1_test;
268 Label Loop1_body; 268 Label Loop1_body;
269 __ jmp(&Loop1_test); 269 __ jmp(&Loop1_test);
270 __ bind(&Loop1_body); 270 __ bind(&Loop1_body);
271 __ addq(rax, Immediate(7)); 271 __ addq(rax, Immediate(7));
272 __ bind(&Loop1_test); 272 __ bind(&Loop1_test);
273 __ cmpq(rax, Immediate(20)); 273 __ cmpq(rax, Immediate(20));
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 339
340 CHECK(Operand(rsp, rbp, times_1, offset).AddressUsesRegister(rsp)); 340 CHECK(Operand(rsp, rbp, times_1, offset).AddressUsesRegister(rsp));
341 CHECK(Operand(rsp, rbp, times_1, offset).AddressUsesRegister(rbp)); 341 CHECK(Operand(rsp, rbp, times_1, offset).AddressUsesRegister(rbp));
342 CHECK(!Operand(rsp, rbp, times_1, offset).AddressUsesRegister(rax)); 342 CHECK(!Operand(rsp, rbp, times_1, offset).AddressUsesRegister(rax));
343 CHECK(!Operand(rsp, rbp, times_1, offset).AddressUsesRegister(r15)); 343 CHECK(!Operand(rsp, rbp, times_1, offset).AddressUsesRegister(r15));
344 CHECK(!Operand(rsp, rbp, times_1, offset).AddressUsesRegister(r13)); 344 CHECK(!Operand(rsp, rbp, times_1, offset).AddressUsesRegister(r13));
345 } 345 }
346 } 346 }
347 347
348 #undef __ 348 #undef __
OLDNEW
« no previous file with comments | « test/cctest/test-assembler-ia32.cc ('k') | test/cctest/test-disasm-arm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698