| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 static const v8::internal::Register arg2 = rdx; | 83 static const v8::internal::Register arg2 = rdx; |
| 84 #else | 84 #else |
| 85 static const v8::internal::Register arg1 = rdi; | 85 static const v8::internal::Register arg1 = rdi; |
| 86 static const v8::internal::Register arg2 = rsi; | 86 static const v8::internal::Register arg2 = rsi; |
| 87 #endif | 87 #endif |
| 88 | 88 |
| 89 #define __ assm. | 89 #define __ assm. |
| 90 | 90 |
| 91 | 91 |
| 92 TEST(AssemblerX64ReturnOperation) { | 92 TEST(AssemblerX64ReturnOperation) { |
| 93 OS::SetUp(); | |
| 94 // Allocate an executable page of memory. | 93 // Allocate an executable page of memory. |
| 95 size_t actual_size; | 94 size_t actual_size; |
| 96 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 95 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 97 &actual_size, | 96 &actual_size, |
| 98 true)); | 97 true)); |
| 99 CHECK(buffer); | 98 CHECK(buffer); |
| 100 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 99 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
| 101 | 100 |
| 102 // Assemble a simple function that copies argument 2 and returns it. | 101 // Assemble a simple function that copies argument 2 and returns it. |
| 103 __ movq(rax, arg2); | 102 __ movq(rax, arg2); |
| 104 __ nop(); | 103 __ nop(); |
| 105 __ ret(0); | 104 __ ret(0); |
| 106 | 105 |
| 107 CodeDesc desc; | 106 CodeDesc desc; |
| 108 assm.GetCode(&desc); | 107 assm.GetCode(&desc); |
| 109 // Call the function from C++. | 108 // Call the function from C++. |
| 110 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 109 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 111 CHECK_EQ(2, result); | 110 CHECK_EQ(2, result); |
| 112 } | 111 } |
| 113 | 112 |
| 114 | 113 |
| 115 TEST(AssemblerX64StackOperations) { | 114 TEST(AssemblerX64StackOperations) { |
| 116 OS::SetUp(); | |
| 117 // Allocate an executable page of memory. | 115 // Allocate an executable page of memory. |
| 118 size_t actual_size; | 116 size_t actual_size; |
| 119 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 117 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 120 &actual_size, | 118 &actual_size, |
| 121 true)); | 119 true)); |
| 122 CHECK(buffer); | 120 CHECK(buffer); |
| 123 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 121 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
| 124 | 122 |
| 125 // Assemble a simple function that copies argument 2 and returns it. | 123 // Assemble a simple function that copies argument 2 and returns it. |
| 126 // We compile without stack frame pointers, so the gdb debugger shows | 124 // We compile without stack frame pointers, so the gdb debugger shows |
| (...skipping 12 matching lines...) Expand all Loading... |
| 139 | 137 |
| 140 CodeDesc desc; | 138 CodeDesc desc; |
| 141 assm.GetCode(&desc); | 139 assm.GetCode(&desc); |
| 142 // Call the function from C++. | 140 // Call the function from C++. |
| 143 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 141 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 144 CHECK_EQ(2, result); | 142 CHECK_EQ(2, result); |
| 145 } | 143 } |
| 146 | 144 |
| 147 | 145 |
| 148 TEST(AssemblerX64ArithmeticOperations) { | 146 TEST(AssemblerX64ArithmeticOperations) { |
| 149 OS::SetUp(); | |
| 150 // Allocate an executable page of memory. | 147 // Allocate an executable page of memory. |
| 151 size_t actual_size; | 148 size_t actual_size; |
| 152 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 149 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 153 &actual_size, | 150 &actual_size, |
| 154 true)); | 151 true)); |
| 155 CHECK(buffer); | 152 CHECK(buffer); |
| 156 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 153 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
| 157 | 154 |
| 158 // Assemble a simple function that adds arguments returning the sum. | 155 // Assemble a simple function that adds arguments returning the sum. |
| 159 __ movq(rax, arg2); | 156 __ movq(rax, arg2); |
| 160 __ addq(rax, arg1); | 157 __ addq(rax, arg1); |
| 161 __ ret(0); | 158 __ ret(0); |
| 162 | 159 |
| 163 CodeDesc desc; | 160 CodeDesc desc; |
| 164 assm.GetCode(&desc); | 161 assm.GetCode(&desc); |
| 165 // Call the function from C++. | 162 // Call the function from C++. |
| 166 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 163 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 167 CHECK_EQ(5, result); | 164 CHECK_EQ(5, result); |
| 168 } | 165 } |
| 169 | 166 |
| 170 | 167 |
| 171 TEST(AssemblerX64ImulOperation) { | 168 TEST(AssemblerX64ImulOperation) { |
| 172 OS::SetUp(); | |
| 173 // Allocate an executable page of memory. | 169 // Allocate an executable page of memory. |
| 174 size_t actual_size; | 170 size_t actual_size; |
| 175 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 171 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 176 &actual_size, | 172 &actual_size, |
| 177 true)); | 173 true)); |
| 178 CHECK(buffer); | 174 CHECK(buffer); |
| 179 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 175 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
| 180 | 176 |
| 181 // Assemble a simple function that multiplies arguments returning the high | 177 // Assemble a simple function that multiplies arguments returning the high |
| 182 // word. | 178 // word. |
| 183 __ movq(rax, arg2); | 179 __ movq(rax, arg2); |
| 184 __ imul(arg1); | 180 __ imul(arg1); |
| 185 __ movq(rax, rdx); | 181 __ movq(rax, rdx); |
| 186 __ ret(0); | 182 __ ret(0); |
| 187 | 183 |
| 188 CodeDesc desc; | 184 CodeDesc desc; |
| 189 assm.GetCode(&desc); | 185 assm.GetCode(&desc); |
| 190 // Call the function from C++. | 186 // Call the function from C++. |
| 191 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 187 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 192 CHECK_EQ(0, result); | 188 CHECK_EQ(0, result); |
| 193 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); | 189 result = FUNCTION_CAST<F2>(buffer)(0x100000000l, 0x100000000l); |
| 194 CHECK_EQ(1, result); | 190 CHECK_EQ(1, result); |
| 195 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); | 191 result = FUNCTION_CAST<F2>(buffer)(-0x100000000l, 0x100000000l); |
| 196 CHECK_EQ(-1, result); | 192 CHECK_EQ(-1, result); |
| 197 } | 193 } |
| 198 | 194 |
| 199 | 195 |
| 200 TEST(AssemblerX64MemoryOperands) { | 196 TEST(AssemblerX64MemoryOperands) { |
| 201 OS::SetUp(); | |
| 202 // Allocate an executable page of memory. | 197 // Allocate an executable page of memory. |
| 203 size_t actual_size; | 198 size_t actual_size; |
| 204 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 199 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 205 &actual_size, | 200 &actual_size, |
| 206 true)); | 201 true)); |
| 207 CHECK(buffer); | 202 CHECK(buffer); |
| 208 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 203 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
| 209 | 204 |
| 210 // Assemble a simple function that copies argument 2 and returns it. | 205 // Assemble a simple function that copies argument 2 and returns it. |
| 211 __ push(rbp); | 206 __ push(rbp); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 226 | 221 |
| 227 CodeDesc desc; | 222 CodeDesc desc; |
| 228 assm.GetCode(&desc); | 223 assm.GetCode(&desc); |
| 229 // Call the function from C++. | 224 // Call the function from C++. |
| 230 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 225 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 231 CHECK_EQ(3, result); | 226 CHECK_EQ(3, result); |
| 232 } | 227 } |
| 233 | 228 |
| 234 | 229 |
| 235 TEST(AssemblerX64ControlFlow) { | 230 TEST(AssemblerX64ControlFlow) { |
| 236 OS::SetUp(); | |
| 237 // Allocate an executable page of memory. | 231 // Allocate an executable page of memory. |
| 238 size_t actual_size; | 232 size_t actual_size; |
| 239 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 233 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 240 &actual_size, | 234 &actual_size, |
| 241 true)); | 235 true)); |
| 242 CHECK(buffer); | 236 CHECK(buffer); |
| 243 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 237 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
| 244 | 238 |
| 245 // Assemble a simple function that copies argument 1 and returns it. | 239 // Assemble a simple function that copies argument 1 and returns it. |
| 246 __ push(rbp); | 240 __ push(rbp); |
| 247 | 241 |
| 248 __ movq(rbp, rsp); | 242 __ movq(rbp, rsp); |
| 249 __ movq(rax, arg1); | 243 __ movq(rax, arg1); |
| 250 Label target; | 244 Label target; |
| 251 __ jmp(&target); | 245 __ jmp(&target); |
| 252 __ movq(rax, arg2); | 246 __ movq(rax, arg2); |
| 253 __ bind(&target); | 247 __ bind(&target); |
| 254 __ pop(rbp); | 248 __ pop(rbp); |
| 255 __ ret(0); | 249 __ ret(0); |
| 256 | 250 |
| 257 CodeDesc desc; | 251 CodeDesc desc; |
| 258 assm.GetCode(&desc); | 252 assm.GetCode(&desc); |
| 259 // Call the function from C++. | 253 // Call the function from C++. |
| 260 int result = FUNCTION_CAST<F2>(buffer)(3, 2); | 254 int result = FUNCTION_CAST<F2>(buffer)(3, 2); |
| 261 CHECK_EQ(3, result); | 255 CHECK_EQ(3, result); |
| 262 } | 256 } |
| 263 | 257 |
| 264 | 258 |
| 265 TEST(AssemblerX64LoopImmediates) { | 259 TEST(AssemblerX64LoopImmediates) { |
| 266 OS::SetUp(); | |
| 267 // Allocate an executable page of memory. | 260 // Allocate an executable page of memory. |
| 268 size_t actual_size; | 261 size_t actual_size; |
| 269 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 262 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 270 &actual_size, | 263 &actual_size, |
| 271 true)); | 264 true)); |
| 272 CHECK(buffer); | 265 CHECK(buffer); |
| 273 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); | 266 Assembler assm(Isolate::Current(), buffer, static_cast<int>(actual_size)); |
| 274 // 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. |
| 275 Label Fail; | 268 Label Fail; |
| 276 __ movq(rax, Immediate(-3)); | 269 __ movq(rax, Immediate(-3)); |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 | 511 |
| 519 // The mask should be 0b1000. | 512 // The mask should be 0b1000. |
| 520 CHECK_EQ(8, result->Int32Value()); | 513 CHECK_EQ(8, result->Int32Value()); |
| 521 } | 514 } |
| 522 | 515 |
| 523 #undef ELEMENT_COUNT | 516 #undef ELEMENT_COUNT |
| 524 #endif // __GNUC__ | 517 #endif // __GNUC__ |
| 525 | 518 |
| 526 | 519 |
| 527 #undef __ | 520 #undef __ |
| OLD | NEW |