| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" | 5 #include "vm/globals.h" |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/assembler.h" | 8 #include "vm/assembler.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 __ movq(RBX, FieldAddress(R10, ArgumentsDescriptor::count_offset())); | 776 __ movq(RBX, FieldAddress(R10, ArgumentsDescriptor::count_offset())); |
| 777 __ SmiUntag(RBX); | 777 __ SmiUntag(RBX); |
| 778 | 778 |
| 779 // Compute address of 'arguments array' data area into RDX. | 779 // Compute address of 'arguments array' data area into RDX. |
| 780 __ movq(RDX, Address(kArgsReg, VMHandles::kOffsetOfRawPtrInHandle)); | 780 __ movq(RDX, Address(kArgsReg, VMHandles::kOffsetOfRawPtrInHandle)); |
| 781 __ leaq(RDX, FieldAddress(RDX, Array::data_offset())); | 781 __ leaq(RDX, FieldAddress(RDX, Array::data_offset())); |
| 782 | 782 |
| 783 // Set up arguments for the Dart call. | 783 // Set up arguments for the Dart call. |
| 784 Label push_arguments; | 784 Label push_arguments; |
| 785 Label done_push_arguments; | 785 Label done_push_arguments; |
| 786 __ testq(RBX, RBX); // check if there are arguments. | |
| 787 __ j(ZERO, &done_push_arguments, Assembler::kNearJump); | 786 __ j(ZERO, &done_push_arguments, Assembler::kNearJump); |
| 788 __ movq(RAX, Immediate(0)); | 787 __ movq(RAX, Immediate(0)); |
| 789 __ Bind(&push_arguments); | 788 __ Bind(&push_arguments); |
| 790 __ pushq(Address(RDX, RAX, TIMES_8, 0)); | 789 __ pushq(Address(RDX, RAX, TIMES_8, 0)); |
| 791 __ incq(RAX); | 790 __ incq(RAX); |
| 792 __ cmpq(RAX, RBX); | 791 __ cmpq(RAX, RBX); |
| 793 __ j(LESS, &push_arguments, Assembler::kNearJump); | 792 __ j(LESS, &push_arguments, Assembler::kNearJump); |
| 794 __ Bind(&done_push_arguments); | 793 __ Bind(&done_push_arguments); |
| 795 | 794 |
| 796 // Call the Dart code entrypoint. | 795 // Call the Dart code entrypoint. |
| (...skipping 1289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2086 void StubCode::EmitMegamorphicLookup(Assembler* assembler) { | 2085 void StubCode::EmitMegamorphicLookup(Assembler* assembler) { |
| 2087 __ LoadTaggedClassIdMayBeSmi(RAX, RDI); | 2086 __ LoadTaggedClassIdMayBeSmi(RAX, RDI); |
| 2088 // RAX: class ID of the receiver (smi). | 2087 // RAX: class ID of the receiver (smi). |
| 2089 __ movq(R10, | 2088 __ movq(R10, |
| 2090 FieldAddress(RBX, MegamorphicCache::arguments_descriptor_offset())); | 2089 FieldAddress(RBX, MegamorphicCache::arguments_descriptor_offset())); |
| 2091 __ movq(RDI, FieldAddress(RBX, MegamorphicCache::buckets_offset())); | 2090 __ movq(RDI, FieldAddress(RBX, MegamorphicCache::buckets_offset())); |
| 2092 __ movq(R9, FieldAddress(RBX, MegamorphicCache::mask_offset())); | 2091 __ movq(R9, FieldAddress(RBX, MegamorphicCache::mask_offset())); |
| 2093 // R10: arguments descriptor (result). | 2092 // R10: arguments descriptor (result). |
| 2094 // RDI: cache buckets array. | 2093 // RDI: cache buckets array. |
| 2095 // RBX: mask. | 2094 // RBX: mask. |
| 2096 __ movq(RCX, RAX); | 2095 |
| 2097 __ imulq(RCX, Immediate(MegamorphicCache::kSpreadFactor)); | 2096 // Compute the table index. |
| 2097 ASSERT(MegamorphicCache::kSpreadFactor == 7); |
| 2098 // Use leaq and subq multiply with 7 == 8 - 1. |
| 2099 __ leaq(RCX, Address(RAX, TIMES_8, 0)); |
| 2100 __ subq(RCX, RAX); |
| 2098 | 2101 |
| 2099 Label loop, update, load_target_function; | 2102 Label loop, update, load_target_function; |
| 2100 __ jmp(&loop); | 2103 __ jmp(&loop); |
| 2101 | 2104 |
| 2102 __ Bind(&update); | 2105 __ Bind(&update); |
| 2103 __ AddImmediate(RCX, Immediate(Smi::RawValue(1))); | 2106 __ AddImmediate(RCX, Immediate(Smi::RawValue(1))); |
| 2104 __ Bind(&loop); | 2107 __ Bind(&loop); |
| 2105 __ andq(RCX, R9); | 2108 __ andq(RCX, R9); |
| 2106 const intptr_t base = Array::data_offset(); | 2109 const intptr_t base = Array::data_offset(); |
| 2107 // RCX is smi tagged, but table entries are two words, so TIMES_8. | 2110 // RCX is smi tagged, but table entries are two words, so TIMES_8. |
| 2108 __ movq(RDX, FieldAddress(RDI, RCX, TIMES_8, base)); | 2111 __ movq(RDX, FieldAddress(RDI, RCX, TIMES_8, base)); |
| 2109 | 2112 |
| 2110 ASSERT(kIllegalCid == 0); | 2113 ASSERT(kIllegalCid == 0); |
| 2114 // Check for the uncommon case, a miss in the cache. |
| 2111 __ testq(RDX, RDX); | 2115 __ testq(RDX, RDX); |
| 2112 __ j(ZERO, &load_target_function, Assembler::kNearJump); | 2116 __ j(ZERO, &load_target_function, Assembler::kNearJump); |
| 2117 |
| 2113 __ cmpq(RDX, RAX); | 2118 __ cmpq(RDX, RAX); |
| 2114 __ j(NOT_EQUAL, &update, Assembler::kNearJump); | 2119 __ j(NOT_EQUAL, &update, Assembler::kNearJump); |
| 2115 | 2120 |
| 2116 __ Bind(&load_target_function); | 2121 __ Bind(&load_target_function); |
| 2117 // Call the target found in the cache. For a class id match, this is a | 2122 // Call the target found in the cache. For a class id match, this is a |
| 2118 // proper target for the given name and arguments descriptor. If the | 2123 // proper target for the given name and arguments descriptor. If the |
| 2119 // illegal class id was found, the target is a cache miss handler that can | 2124 // illegal class id was found, the target is a cache miss handler that can |
| 2120 // be invoked as a normal Dart function. | 2125 // be invoked as a normal Dart function. |
| 2121 __ movq(RAX, FieldAddress(RDI, RCX, TIMES_8, base + kWordSize)); | 2126 __ movq(RAX, FieldAddress(RDI, RCX, TIMES_8, base + kWordSize)); |
| 2122 __ movq(RCX, FieldAddress(RAX, Function::entry_point_offset())); | 2127 __ movq(RCX, FieldAddress(RAX, Function::entry_point_offset())); |
| 2123 __ movq(CODE_REG, FieldAddress(RAX, Function::code_offset())); | 2128 __ movq(CODE_REG, FieldAddress(RAX, Function::code_offset())); |
| 2124 } | 2129 } |
| 2125 | 2130 |
| 2126 | 2131 |
| 2127 // Called from megamorphic calls. | 2132 // Called from megamorphic calls. |
| 2128 // RDI: receiver | 2133 // RDI: receiver |
| 2129 // RBX: MegamorphicCache (preserved) | 2134 // RBX: MegamorphicCache (preserved) |
| 2130 // Result: | 2135 // Result: |
| 2131 // RCX: target entry point | 2136 // RCX: target entry point |
| 2132 // CODE_REG: target Code | 2137 // CODE_REG: target Code |
| 2133 // R10: arguments descriptor | 2138 // R10: arguments descriptor |
| 2134 void StubCode::GenerateMegamorphicLookupStub(Assembler* assembler) { | 2139 void StubCode::GenerateMegamorphicLookupStub(Assembler* assembler) { |
| 2135 EmitMegamorphicLookup(assembler); | 2140 // Jump if receiver is a smi. |
| 2141 Label smi_case; |
| 2142 __ testq(RDI, Immediate(kSmiTagMask)); |
| 2143 // Jump out of line for smi case. |
| 2144 __ j(ZERO, &smi_case, Assembler::kNearJump); |
| 2145 |
| 2146 // Loads the cid of the object. |
| 2147 __ LoadClassId(RAX, RDI); |
| 2148 |
| 2149 Label cid_loaded; |
| 2150 __ Bind(&cid_loaded); |
| 2151 __ movq(R9, FieldAddress(RBX, MegamorphicCache::mask_offset())); |
| 2152 __ movq(RDI, FieldAddress(RBX, MegamorphicCache::buckets_offset())); |
| 2153 // R10: arguments descriptor (result). |
| 2154 // RDI: cache buckets array. |
| 2155 // RBX: mask. |
| 2156 |
| 2157 // Tag cid as a smi. |
| 2158 __ addq(RAX, RAX); |
| 2159 |
| 2160 // Compute the table index. |
| 2161 ASSERT(MegamorphicCache::kSpreadFactor == 7); |
| 2162 // Use leaq and subq multiply with 7 == 8 - 1. |
| 2163 __ leaq(RCX, Address(RAX, TIMES_8, 0)); |
| 2164 __ subq(RCX, RAX); |
| 2165 |
| 2166 Label loop; |
| 2167 __ Bind(&loop); |
| 2168 __ andq(RCX, R9); |
| 2169 |
| 2170 const intptr_t base = Array::data_offset(); |
| 2171 // RCX is smi tagged, but table entries are two words, so TIMES_8. |
| 2172 Label probe_failed; |
| 2173 __ cmpq(RAX, FieldAddress(RDI, RCX, TIMES_8, base)); |
| 2174 __ j(NOT_EQUAL, &probe_failed, Assembler::kNearJump); |
| 2175 |
| 2176 Label load_target; |
| 2177 __ Bind(&load_target); |
| 2178 // Call the target found in the cache. For a class id match, this is a |
| 2179 // proper target for the given name and arguments descriptor. If the |
| 2180 // illegal class id was found, the target is a cache miss handler that can |
| 2181 // be invoked as a normal Dart function. |
| 2182 __ movq(RAX, FieldAddress(RDI, RCX, TIMES_8, base + kWordSize)); |
| 2183 __ movq(R10, |
| 2184 FieldAddress(RBX, MegamorphicCache::arguments_descriptor_offset())); |
| 2185 __ movq(RCX, FieldAddress(RAX, Function::entry_point_offset())); |
| 2186 __ movq(CODE_REG, FieldAddress(RAX, Function::code_offset())); |
| 2187 |
| 2136 __ ret(); | 2188 __ ret(); |
| 2189 |
| 2190 // Probe failed, check if it is a miss. |
| 2191 __ Bind(&probe_failed); |
| 2192 __ cmpq(FieldAddress(RDI, RCX, TIMES_8, base), Immediate(kIllegalCid)); |
| 2193 __ j(ZERO, &load_target, Assembler::kNearJump); |
| 2194 |
| 2195 // Try next extry in the table. |
| 2196 __ AddImmediate(RCX, Immediate(Smi::RawValue(1))); |
| 2197 __ jmp(&loop); |
| 2198 |
| 2199 // Load cid for the Smi case. |
| 2200 __ Bind(&smi_case); |
| 2201 __ movq(RAX, Immediate(kSmiCid)); |
| 2202 __ jmp(&cid_loaded); |
| 2137 } | 2203 } |
| 2138 | 2204 |
| 2139 | 2205 |
| 2140 // Called from switchable IC calls. | 2206 // Called from switchable IC calls. |
| 2141 // RDI: receiver | 2207 // RDI: receiver |
| 2142 // RBX: ICData (preserved) | 2208 // RBX: ICData (preserved) |
| 2143 // Result: | 2209 // Result: |
| 2144 // RCX: target entry point | 2210 // RCX: target entry point |
| 2145 // CODE_REG: target Code object | 2211 // CODE_REG: target Code object |
| 2146 // R10: arguments descriptor | 2212 // R10: arguments descriptor |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2220 } | 2286 } |
| 2221 | 2287 |
| 2222 | 2288 |
| 2223 void StubCode::GenerateFrameAwaitingMaterializationStub(Assembler* assembler) { | 2289 void StubCode::GenerateFrameAwaitingMaterializationStub(Assembler* assembler) { |
| 2224 __ int3(); | 2290 __ int3(); |
| 2225 } | 2291 } |
| 2226 | 2292 |
| 2227 } // namespace dart | 2293 } // namespace dart |
| 2228 | 2294 |
| 2229 #endif // defined TARGET_ARCH_X64 | 2295 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |