OLD | NEW |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 // in RDI, RSI, RDX, RCX, R8, and R9, and floating point arguments in | 44 // in RDI, RSI, RDX, RCX, R8, and R9, and floating point arguments in |
45 // the XMM registers. The return value is in RAX. | 45 // the XMM registers. The return value is in RAX. |
46 // This calling convention is used on Linux, with GCC, and on Mac OS, | 46 // This calling convention is used on Linux, with GCC, and on Mac OS, |
47 // with GCC. A different convention is used on 64-bit windows, | 47 // with GCC. A different convention is used on 64-bit windows, |
48 // where the first four integer arguments are passed in RCX, RDX, R8 and R9. | 48 // where the first four integer arguments are passed in RCX, RDX, R8 and R9. |
49 | 49 |
50 typedef int (*F0)(); | 50 typedef int (*F0)(); |
51 typedef int (*F1)(int64_t x); | 51 typedef int (*F1)(int64_t x); |
52 typedef int (*F2)(int64_t x, int64_t y); | 52 typedef int (*F2)(int64_t x, int64_t y); |
53 typedef int (*F3)(double x); | 53 typedef int (*F3)(double x); |
| 54 typedef int64_t (*F4)(int64_t* x, int64_t* y); |
| 55 typedef int64_t (*F5)(int64_t x); |
54 | 56 |
55 #ifdef _WIN64 | 57 #ifdef _WIN64 |
56 static const Register arg1 = rcx; | 58 static const Register arg1 = rcx; |
57 static const Register arg2 = rdx; | 59 static const Register arg2 = rdx; |
58 #else | 60 #else |
59 static const Register arg1 = rdi; | 61 static const Register arg1 = rdi; |
60 static const Register arg2 = rsi; | 62 static const Register arg2 = rsi; |
61 #endif | 63 #endif |
62 | 64 |
63 #define __ assm. | 65 #define __ assm. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 // Call the function from C++. | 162 // Call the function from C++. |
161 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 163 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
162 CHECK_EQ(0, result); | 164 CHECK_EQ(0, result); |
163 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); | 165 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); |
164 CHECK_EQ(1, result); | 166 CHECK_EQ(1, result); |
165 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); | 167 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); |
166 CHECK_EQ(-1, result); | 168 CHECK_EQ(-1, result); |
167 } | 169 } |
168 | 170 |
169 | 171 |
| 172 TEST(AssemblerX64XchglOperations) { |
| 173 // Allocate an executable page of memory. |
| 174 size_t actual_size; |
| 175 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 176 &actual_size, |
| 177 true)); |
| 178 CHECK(buffer); |
| 179 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 180 |
| 181 __ movq(rax, Operand(arg1, 0)); |
| 182 __ movq(rbx, Operand(arg2, 0)); |
| 183 __ xchgl(rax, rbx); |
| 184 __ movq(Operand(arg1, 0), rax); |
| 185 __ movq(Operand(arg2, 0), rbx); |
| 186 __ ret(0); |
| 187 |
| 188 CodeDesc desc; |
| 189 assm.GetCode(&desc); |
| 190 // Call the function from C++. |
| 191 int64_t left = V8_2PART_UINT64_C(0x10000000, 20000000); |
| 192 int64_t right = V8_2PART_UINT64_C(0x30000000, 40000000); |
| 193 int64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right); |
| 194 CHECK_EQ(V8_2PART_UINT64_C(0x00000000, 40000000), left); |
| 195 CHECK_EQ(V8_2PART_UINT64_C(0x00000000, 20000000), right); |
| 196 USE(result); |
| 197 } |
| 198 |
| 199 |
| 200 TEST(AssemblerX64OrlOperations) { |
| 201 // Allocate an executable page of memory. |
| 202 size_t actual_size; |
| 203 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 204 &actual_size, |
| 205 true)); |
| 206 CHECK(buffer); |
| 207 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 208 |
| 209 __ movq(rax, Operand(arg2, 0)); |
| 210 __ orl(Operand(arg1, 0), rax); |
| 211 __ ret(0); |
| 212 |
| 213 CodeDesc desc; |
| 214 assm.GetCode(&desc); |
| 215 // Call the function from C++. |
| 216 int64_t left = V8_2PART_UINT64_C(0x10000000, 20000000); |
| 217 int64_t right = V8_2PART_UINT64_C(0x30000000, 40000000); |
| 218 int64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right); |
| 219 CHECK_EQ(V8_2PART_UINT64_C(0x10000000, 60000000), left); |
| 220 USE(result); |
| 221 } |
| 222 |
| 223 |
| 224 TEST(AssemblerX64RollOperations) { |
| 225 // Allocate an executable page of memory. |
| 226 size_t actual_size; |
| 227 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 228 &actual_size, |
| 229 true)); |
| 230 CHECK(buffer); |
| 231 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 232 |
| 233 __ movq(rax, arg1); |
| 234 __ roll(rax, Immediate(1)); |
| 235 __ ret(0); |
| 236 |
| 237 CodeDesc desc; |
| 238 assm.GetCode(&desc); |
| 239 // Call the function from C++. |
| 240 int64_t src = V8_2PART_UINT64_C(0x10000000, C0000000); |
| 241 int64_t result = FUNCTION_CAST<F5>(buffer)(src); |
| 242 CHECK_EQ(V8_2PART_UINT64_C(0x00000000, 80000001), result); |
| 243 } |
| 244 |
| 245 |
| 246 TEST(AssemblerX64SublOperations) { |
| 247 // Allocate an executable page of memory. |
| 248 size_t actual_size; |
| 249 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 250 &actual_size, |
| 251 true)); |
| 252 CHECK(buffer); |
| 253 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 254 |
| 255 __ movq(rax, Operand(arg2, 0)); |
| 256 __ subl(Operand(arg1, 0), rax); |
| 257 __ ret(0); |
| 258 |
| 259 CodeDesc desc; |
| 260 assm.GetCode(&desc); |
| 261 // Call the function from C++. |
| 262 int64_t left = V8_2PART_UINT64_C(0x10000000, 20000000); |
| 263 int64_t right = V8_2PART_UINT64_C(0x30000000, 40000000); |
| 264 int64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right); |
| 265 CHECK_EQ(V8_2PART_UINT64_C(0x10000000, e0000000), left); |
| 266 USE(result); |
| 267 } |
| 268 |
| 269 |
| 270 TEST(AssemblerX64TestlOperations) { |
| 271 // Allocate an executable page of memory. |
| 272 size_t actual_size; |
| 273 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 274 &actual_size, |
| 275 true)); |
| 276 CHECK(buffer); |
| 277 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 278 |
| 279 // Set rax with the ZF flag of the testl instruction. |
| 280 Label done; |
| 281 __ movq(rax, Immediate(1)); |
| 282 __ movq(rbx, Operand(arg2, 0)); |
| 283 __ testl(Operand(arg1, 0), rbx); |
| 284 __ j(zero, &done, Label::kNear); |
| 285 __ movq(rax, Immediate(0)); |
| 286 __ bind(&done); |
| 287 __ ret(0); |
| 288 |
| 289 CodeDesc desc; |
| 290 assm.GetCode(&desc); |
| 291 // Call the function from C++. |
| 292 int64_t left = V8_2PART_UINT64_C(0x10000000, 20000000); |
| 293 int64_t right = V8_2PART_UINT64_C(0x30000000, 00000000); |
| 294 int64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right); |
| 295 CHECK_EQ(static_cast<int64_t>(1), result); |
| 296 } |
| 297 |
| 298 |
| 299 TEST(AssemblerX64XorlOperations) { |
| 300 // Allocate an executable page of memory. |
| 301 size_t actual_size; |
| 302 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 303 &actual_size, |
| 304 true)); |
| 305 CHECK(buffer); |
| 306 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 307 |
| 308 __ movq(rax, Operand(arg2, 0)); |
| 309 __ xorl(Operand(arg1, 0), rax); |
| 310 __ ret(0); |
| 311 |
| 312 CodeDesc desc; |
| 313 assm.GetCode(&desc); |
| 314 // Call the function from C++. |
| 315 int64_t left = V8_2PART_UINT64_C(0x10000000, 20000000); |
| 316 int64_t right = V8_2PART_UINT64_C(0x30000000, 60000000); |
| 317 int64_t result = FUNCTION_CAST<F4>(buffer)(&left, &right); |
| 318 CHECK_EQ(V8_2PART_UINT64_C(0x10000000, 40000000), left); |
| 319 USE(result); |
| 320 } |
| 321 |
| 322 |
170 TEST(AssemblerX64MemoryOperands) { | 323 TEST(AssemblerX64MemoryOperands) { |
171 // Allocate an executable page of memory. | 324 // Allocate an executable page of memory. |
172 size_t actual_size; | 325 size_t actual_size; |
173 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 326 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
174 &actual_size, | 327 &actual_size, |
175 true)); | 328 true)); |
176 CHECK(buffer); | 329 CHECK(buffer); |
177 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); | 330 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
178 | 331 |
179 // Assemble a simple function that copies argument 2 and returns it. | 332 // Assemble a simple function that copies argument 2 and returns it. |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
517 | 670 |
518 F3 f = FUNCTION_CAST<F3>(Code::cast(code)->entry()); | 671 F3 f = FUNCTION_CAST<F3>(Code::cast(code)->entry()); |
519 uint64_t value1 = V8_2PART_UINT64_C(0x12345678, 87654321); | 672 uint64_t value1 = V8_2PART_UINT64_C(0x12345678, 87654321); |
520 CHECK_EQ(0x12345678, f(uint64_to_double(value1))); | 673 CHECK_EQ(0x12345678, f(uint64_to_double(value1))); |
521 uint64_t value2 = V8_2PART_UINT64_C(0x87654321, 12345678); | 674 uint64_t value2 = V8_2PART_UINT64_C(0x87654321, 12345678); |
522 CHECK_EQ(0x87654321, f(uint64_to_double(value2))); | 675 CHECK_EQ(0x87654321, f(uint64_to_double(value2))); |
523 } | 676 } |
524 | 677 |
525 | 678 |
526 #undef __ | 679 #undef __ |
OLD | NEW |