| 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 89 #define __ assm. | 89 #define __ assm. |
| 90 | 90 |
| 91 | 91 |
| 92 TEST(AssemblerX64ReturnOperation) { | 92 TEST(AssemblerX64ReturnOperation) { |
| 93 // Allocate an executable page of memory. | 93 // Allocate an executable page of memory. |
| 94 size_t actual_size; | 94 size_t actual_size; |
| 95 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 95 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 96 &actual_size, | 96 &actual_size, |
| 97 true)); | 97 true)); |
| 98 CHECK(buffer); | 98 CHECK(buffer); |
| 99 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 99 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 100 | 100 |
| 101 // Assemble a simple function that copies argument 2 and returns it. | 101 // Assemble a simple function that copies argument 2 and returns it. |
| 102 __ movq(rax, arg2); | 102 __ movq(rax, arg2); |
| 103 __ nop(); | 103 __ nop(); |
| 104 __ ret(0); | 104 __ ret(0); |
| 105 | 105 |
| 106 CodeDesc desc; | 106 CodeDesc desc; |
| 107 assm.GetCode(&desc); | 107 assm.GetCode(&desc); |
| 108 // Call the function from C++. | 108 // Call the function from C++. |
| 109 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 109 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 110 CHECK_EQ(2, result); | 110 CHECK_EQ(2, result); |
| 111 } | 111 } |
| 112 | 112 |
| 113 | 113 |
| 114 TEST(AssemblerX64StackOperations) { | 114 TEST(AssemblerX64StackOperations) { |
| 115 // Allocate an executable page of memory. | 115 // Allocate an executable page of memory. |
| 116 size_t actual_size; | 116 size_t actual_size; |
| 117 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 117 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 118 &actual_size, | 118 &actual_size, |
| 119 true)); | 119 true)); |
| 120 CHECK(buffer); | 120 CHECK(buffer); |
| 121 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 121 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 122 | 122 |
| 123 // Assemble a simple function that copies argument 2 and returns it. | 123 // Assemble a simple function that copies argument 2 and returns it. |
| 124 // We compile without stack frame pointers, so the gdb debugger shows | 124 // We compile without stack frame pointers, so the gdb debugger shows |
| 125 // incorrect stack frames when debugging this function (which has them). | 125 // incorrect stack frames when debugging this function (which has them). |
| 126 __ push(rbp); | 126 __ push(rbp); |
| 127 __ movq(rbp, rsp); | 127 __ movq(rbp, rsp); |
| 128 __ push(arg2); // Value at (rbp - 8) | 128 __ push(arg2); // Value at (rbp - 8) |
| 129 __ push(arg2); // Value at (rbp - 16) | 129 __ push(arg2); // Value at (rbp - 16) |
| 130 __ push(arg1); // Value at (rbp - 24) | 130 __ push(arg1); // Value at (rbp - 24) |
| 131 __ pop(rax); | 131 __ pop(rax); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 143 } | 143 } |
| 144 | 144 |
| 145 | 145 |
| 146 TEST(AssemblerX64ArithmeticOperations) { | 146 TEST(AssemblerX64ArithmeticOperations) { |
| 147 // Allocate an executable page of memory. | 147 // Allocate an executable page of memory. |
| 148 size_t actual_size; | 148 size_t actual_size; |
| 149 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 149 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 150 &actual_size, | 150 &actual_size, |
| 151 true)); | 151 true)); |
| 152 CHECK(buffer); | 152 CHECK(buffer); |
| 153 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 153 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 154 | 154 |
| 155 // Assemble a simple function that adds arguments returning the sum. | 155 // Assemble a simple function that adds arguments returning the sum. |
| 156 __ movq(rax, arg2); | 156 __ movq(rax, arg2); |
| 157 __ addq(rax, arg1); | 157 __ addq(rax, arg1); |
| 158 __ ret(0); | 158 __ ret(0); |
| 159 | 159 |
| 160 CodeDesc desc; | 160 CodeDesc desc; |
| 161 assm.GetCode(&desc); | 161 assm.GetCode(&desc); |
| 162 // Call the function from C++. | 162 // Call the function from C++. |
| 163 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 163 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 164 CHECK_EQ(5, result); | 164 CHECK_EQ(5, result); |
| 165 } | 165 } |
| 166 | 166 |
| 167 | 167 |
| 168 TEST(AssemblerX64ImulOperation) { | 168 TEST(AssemblerX64ImulOperation) { |
| 169 // Allocate an executable page of memory. | 169 // Allocate an executable page of memory. |
| 170 size_t actual_size; | 170 size_t actual_size; |
| 171 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 171 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 172 &actual_size, | 172 &actual_size, |
| 173 true)); | 173 true)); |
| 174 CHECK(buffer); | 174 CHECK(buffer); |
| 175 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 175 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 176 | 176 |
| 177 // Assemble a simple function that multiplies arguments returning the high | 177 // Assemble a simple function that multiplies arguments returning the high |
| 178 // word. | 178 // word. |
| 179 __ movq(rax, arg2); | 179 __ movq(rax, arg2); |
| 180 __ imul(arg1); | 180 __ imul(arg1); |
| 181 __ movq(rax, rdx); | 181 __ movq(rax, rdx); |
| 182 __ ret(0); | 182 __ ret(0); |
| 183 | 183 |
| 184 CodeDesc desc; | 184 CodeDesc desc; |
| 185 assm.GetCode(&desc); | 185 assm.GetCode(&desc); |
| 186 // Call the function from C++. | 186 // Call the function from C++. |
| 187 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 187 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 188 CHECK_EQ(0, result); | 188 CHECK_EQ(0, result); |
| 189 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); | 189 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); |
| 190 CHECK_EQ(1, result); | 190 CHECK_EQ(1, result); |
| 191 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); | 191 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); |
| 192 CHECK_EQ(-1, result); | 192 CHECK_EQ(-1, result); |
| 193 } | 193 } |
| 194 | 194 |
| 195 | 195 |
| 196 TEST(AssemblerX64MemoryOperands) { | 196 TEST(AssemblerX64MemoryOperands) { |
| 197 // Allocate an executable page of memory. | 197 // Allocate an executable page of memory. |
| 198 size_t actual_size; | 198 size_t actual_size; |
| 199 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 199 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 200 &actual_size, | 200 &actual_size, |
| 201 true)); | 201 true)); |
| 202 CHECK(buffer); | 202 CHECK(buffer); |
| 203 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 203 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 204 | 204 |
| 205 // Assemble a simple function that copies argument 2 and returns it. | 205 // Assemble a simple function that copies argument 2 and returns it. |
| 206 __ push(rbp); | 206 __ push(rbp); |
| 207 __ movq(rbp, rsp); | 207 __ movq(rbp, rsp); |
| 208 | 208 |
| 209 __ push(arg2); // Value at (rbp - 8) | 209 __ push(arg2); // Value at (rbp - 8) |
| 210 __ push(arg2); // Value at (rbp - 16) | 210 __ push(arg2); // Value at (rbp - 16) |
| 211 __ push(arg1); // Value at (rbp - 24) | 211 __ push(arg1); // Value at (rbp - 24) |
| 212 | 212 |
| 213 const int kStackElementSize = 8; | 213 const int kStackElementSize = 8; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 227 } | 227 } |
| 228 | 228 |
| 229 | 229 |
| 230 TEST(AssemblerX64ControlFlow) { | 230 TEST(AssemblerX64ControlFlow) { |
| 231 // Allocate an executable page of memory. | 231 // Allocate an executable page of memory. |
| 232 size_t actual_size; | 232 size_t actual_size; |
| 233 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 233 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 234 &actual_size, | 234 &actual_size, |
| 235 true)); | 235 true)); |
| 236 CHECK(buffer); | 236 CHECK(buffer); |
| 237 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 237 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 238 | 238 |
| 239 // Assemble a simple function that copies argument 1 and returns it. | 239 // Assemble a simple function that copies argument 1 and returns it. |
| 240 __ push(rbp); | 240 __ push(rbp); |
| 241 | 241 |
| 242 __ movq(rbp, rsp); | 242 __ movq(rbp, rsp); |
| 243 __ movq(rax, arg1); | 243 __ movq(rax, arg1); |
| 244 Label target; | 244 Label target; |
| 245 __ jmp(&target); | 245 __ jmp(&target); |
| 246 __ movq(rax, arg2); | 246 __ movq(rax, arg2); |
| 247 __ bind(&target); | 247 __ bind(&target); |
| 248 __ pop(rbp); | 248 __ pop(rbp); |
| 249 __ ret(0); | 249 __ ret(0); |
| 250 | 250 |
| 251 CodeDesc desc; | 251 CodeDesc desc; |
| 252 assm.GetCode(&desc); | 252 assm.GetCode(&desc); |
| 253 // Call the function from C++. | 253 // Call the function from C++. |
| 254 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 254 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 255 CHECK_EQ(3, result); | 255 CHECK_EQ(3, result); |
| 256 } | 256 } |
| 257 | 257 |
| 258 | 258 |
| 259 TEST(AssemblerX64LoopImmediates) { | 259 TEST(AssemblerX64LoopImmediates) { |
| 260 // Allocate an executable page of memory. | 260 // Allocate an executable page of memory. |
| 261 size_t actual_size; | 261 size_t actual_size; |
| 262 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 262 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 263 &actual_size, | 263 &actual_size, |
| 264 true)); | 264 true)); |
| 265 CHECK(buffer); | 265 CHECK(buffer); |
| 266 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 266 Assembler assm(CcTest::i_isolate(), buffer, static_cast<int>(actual_size)); |
| 267 // Assemble two loops using rax as counter, and verify the ending counts. | 267 // Assemble two loops using rax as counter, and verify the ending counts. |
| 268 Label Fail; | 268 Label Fail; |
| 269 __ movq(rax, Immediate(-3)); | 269 __ movq(rax, Immediate(-3)); |
| 270 Label Loop1_test; | 270 Label Loop1_test; |
| 271 Label Loop1_body; | 271 Label Loop1_body; |
| 272 __ jmp(&Loop1_test); | 272 __ jmp(&Loop1_test); |
| 273 __ bind(&Loop1_body); | 273 __ bind(&Loop1_body); |
| 274 __ addq(rax, Immediate(7)); | 274 __ addq(rax, Immediate(7)); |
| 275 __ bind(&Loop1_test); | 275 __ bind(&Loop1_test); |
| 276 __ cmpq(rax, Immediate(20)); | 276 __ cmpq(rax, Immediate(20)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 CHECK(!Operand(rsp, rbp, times_1, offset).AddressUsesRegister(r15)); | 346 CHECK(!Operand(rsp, rbp, times_1, offset).AddressUsesRegister(r15)); |
| 347 CHECK(!Operand(rsp, rbp, times_1, offset).AddressUsesRegister(r13)); | 347 CHECK(!Operand(rsp, rbp, times_1, offset).AddressUsesRegister(r13)); |
| 348 } | 348 } |
| 349 } | 349 } |
| 350 | 350 |
| 351 | 351 |
| 352 TEST(AssemblerX64LabelChaining) { | 352 TEST(AssemblerX64LabelChaining) { |
| 353 // Test chaining of label usages within instructions (issue 1644). | 353 // Test chaining of label usages within instructions (issue 1644). |
| 354 CcTest::InitializeVM(); | 354 CcTest::InitializeVM(); |
| 355 v8::HandleScope scope(CcTest::isolate()); | 355 v8::HandleScope scope(CcTest::isolate()); |
| 356 Assembler assm(Isolate::Current(), NULL, 0); | 356 Assembler assm(CcTest::i_isolate(), NULL, 0); |
| 357 | 357 |
| 358 Label target; | 358 Label target; |
| 359 __ j(equal, &target); | 359 __ j(equal, &target); |
| 360 __ j(not_equal, &target); | 360 __ j(not_equal, &target); |
| 361 __ bind(&target); | 361 __ bind(&target); |
| 362 __ nop(); | 362 __ nop(); |
| 363 } | 363 } |
| 364 | 364 |
| 365 | 365 |
| 366 TEST(AssemblerMultiByteNop) { | 366 TEST(AssemblerMultiByteNop) { |
| 367 CcTest::InitializeVM(); | 367 CcTest::InitializeVM(); |
| 368 v8::HandleScope scope(CcTest::isolate()); | 368 v8::HandleScope scope(CcTest::isolate()); |
| 369 v8::internal::byte buffer[1024]; | 369 v8::internal::byte buffer[1024]; |
| 370 Isolate* isolate = Isolate::Current(); | 370 Isolate* isolate = CcTest::i_isolate(); |
| 371 Assembler assm(isolate, buffer, sizeof(buffer)); | 371 Assembler assm(isolate, buffer, sizeof(buffer)); |
| 372 __ push(rbx); | 372 __ push(rbx); |
| 373 __ push(rcx); | 373 __ push(rcx); |
| 374 __ push(rdx); | 374 __ push(rdx); |
| 375 __ push(rdi); | 375 __ push(rdi); |
| 376 __ push(rsi); | 376 __ push(rsi); |
| 377 __ movq(rax, Immediate(1)); | 377 __ movq(rax, Immediate(1)); |
| 378 __ movq(rbx, Immediate(2)); | 378 __ movq(rbx, Immediate(2)); |
| 379 __ movq(rcx, Immediate(3)); | 379 __ movq(rcx, Immediate(3)); |
| 380 __ movq(rdx, Immediate(4)); | 380 __ movq(rdx, Immediate(4)); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 434 |
| 435 void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) { | 435 void DoSSE2(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 436 CcTest::InitializeVM(); | 436 CcTest::InitializeVM(); |
| 437 v8::HandleScope scope(CcTest::isolate()); | 437 v8::HandleScope scope(CcTest::isolate()); |
| 438 v8::internal::byte buffer[1024]; | 438 v8::internal::byte buffer[1024]; |
| 439 | 439 |
| 440 CHECK(args[0]->IsArray()); | 440 CHECK(args[0]->IsArray()); |
| 441 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); | 441 v8::Local<v8::Array> vec = v8::Local<v8::Array>::Cast(args[0]); |
| 442 CHECK_EQ(ELEMENT_COUNT, vec->Length()); | 442 CHECK_EQ(ELEMENT_COUNT, vec->Length()); |
| 443 | 443 |
| 444 Isolate* isolate = Isolate::Current(); | 444 Isolate* isolate = CcTest::i_isolate(); |
| 445 Assembler assm(isolate, buffer, sizeof(buffer)); | 445 Assembler assm(isolate, buffer, sizeof(buffer)); |
| 446 | 446 |
| 447 // Remove return address from the stack for fix stack frame alignment. | 447 // Remove return address from the stack for fix stack frame alignment. |
| 448 __ pop(rcx); | 448 __ pop(rcx); |
| 449 | 449 |
| 450 // Store input vector on the stack. | 450 // Store input vector on the stack. |
| 451 for (int i = 0; i < ELEMENT_COUNT; i++) { | 451 for (int i = 0; i < ELEMENT_COUNT; i++) { |
| 452 __ movl(rax, Immediate(vec->Get(i)->Int32Value())); | 452 __ movl(rax, Immediate(vec->Get(i)->Int32Value())); |
| 453 __ shl(rax, Immediate(0x20)); | 453 __ shl(rax, Immediate(0x20)); |
| 454 __ or_(rax, Immediate(vec->Get(++i)->Int32Value())); | 454 __ or_(rax, Immediate(vec->Get(++i)->Int32Value())); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 | 511 |
| 512 // The mask should be 0b1000. | 512 // The mask should be 0b1000. |
| 513 CHECK_EQ(8, result->Int32Value()); | 513 CHECK_EQ(8, result->Int32Value()); |
| 514 } | 514 } |
| 515 | 515 |
| 516 #undef ELEMENT_COUNT | 516 #undef ELEMENT_COUNT |
| 517 #endif // __GNUC__ | 517 #endif // __GNUC__ |
| 518 | 518 |
| 519 | 519 |
| 520 #undef __ | 520 #undef __ |
| OLD | NEW |