yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
| 30 | #if defined(V8_TARGET_ARCH_IA32) |
| 31 | |
| 32 | #include "bootstrapper.h" |
danno@chromium.org | f005df6 | 2013-04-30 16:36:45 +0000 | [diff] [blame] | 33 | #include "builtins-decls.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 34 | #include "code-stubs.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 35 | #include "isolate.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 36 | #include "jsregexp.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 37 | #include "regexp-macro-assembler.h" |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 38 | #include "runtime.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 39 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 40 | #include "codegen.h" |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 41 | #include "runtime.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 42 | |
| 43 | namespace v8 { |
| 44 | namespace internal { |
| 45 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 46 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 47 | void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( |
| 48 | Isolate* isolate, |
| 49 | CodeStubInterfaceDescriptor* descriptor) { |
| 50 | static Register registers[] = { eax, ebx, ecx }; |
| 51 | descriptor->register_param_count_ = 3; |
| 52 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 53 | descriptor->deoptimization_handler_ = |
| 54 | Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; |
| 55 | } |
| 56 | |
| 57 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 58 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 59 | Isolate* isolate, |
| 60 | CodeStubInterfaceDescriptor* descriptor) { |
| 61 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 62 | descriptor->register_param_count_ = 4; |
| 63 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 64 | descriptor->deoptimization_handler_ = |
| 65 | Runtime::FunctionForId(Runtime::kCreateObjectLiteralShallow)->entry; |
| 66 | } |
| 67 | |
| 68 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 69 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 70 | Isolate* isolate, |
| 71 | CodeStubInterfaceDescriptor* descriptor) { |
| 72 | static Register registers[] = { edx, ecx }; |
| 73 | descriptor->register_param_count_ = 2; |
| 74 | descriptor->register_params_ = registers; |
| 75 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 76 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 80 | void LoadFieldStub::InitializeInterfaceDescriptor( |
| 81 | Isolate* isolate, |
| 82 | CodeStubInterfaceDescriptor* descriptor) { |
| 83 | static Register registers[] = { edx }; |
| 84 | descriptor->register_param_count_ = 1; |
| 85 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 86 | descriptor->deoptimization_handler_ = NULL; |
| 87 | } |
| 88 | |
| 89 | |
| 90 | void KeyedLoadFieldStub::InitializeInterfaceDescriptor( |
| 91 | Isolate* isolate, |
| 92 | CodeStubInterfaceDescriptor* descriptor) { |
| 93 | static Register registers[] = { edx }; |
| 94 | descriptor->register_param_count_ = 1; |
| 95 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 96 | descriptor->deoptimization_handler_ = NULL; |
| 97 | } |
| 98 | |
| 99 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 100 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 101 | Isolate* isolate, |
| 102 | CodeStubInterfaceDescriptor* descriptor) { |
| 103 | static Register registers[] = { edx, ecx, eax }; |
| 104 | descriptor->register_param_count_ = 3; |
| 105 | descriptor->register_params_ = registers; |
| 106 | descriptor->deoptimization_handler_ = |
| 107 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 108 | } |
| 109 | |
| 110 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 111 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 112 | Isolate* isolate, |
| 113 | CodeStubInterfaceDescriptor* descriptor) { |
| 114 | static Register registers[] = { eax, ebx }; |
| 115 | descriptor->register_param_count_ = 2; |
| 116 | descriptor->register_params_ = registers; |
| 117 | descriptor->deoptimization_handler_ = |
| 118 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 119 | } |
| 120 | |
| 121 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 122 | static void InitializeArrayConstructorDescriptor( |
| 123 | Isolate* isolate, |
| 124 | CodeStubInterfaceDescriptor* descriptor, |
| 125 | int constant_stack_parameter_count) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 126 | // register state |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 127 | // eax -- number of arguments |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 128 | // edi -- function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 129 | // ebx -- type info cell with elements kind |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 130 | static Register registers[] = { edi, ebx }; |
| 131 | descriptor->register_param_count_ = 2; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 132 | |
| 133 | if (constant_stack_parameter_count != 0) { |
| 134 | // stack param count needs (constructor pointer, and single argument) |
| 135 | descriptor->stack_parameter_count_ = &eax; |
| 136 | } |
| 137 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 138 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 139 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 140 | descriptor->deoptimization_handler_ = |
| 141 | FUNCTION_ADDR(ArrayConstructor_StubFailure); |
| 142 | } |
| 143 | |
| 144 | |
| 145 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 146 | Isolate* isolate, |
| 147 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 148 | InitializeArrayConstructorDescriptor(isolate, descriptor, 0); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | |
| 152 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 153 | Isolate* isolate, |
| 154 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 155 | InitializeArrayConstructorDescriptor(isolate, descriptor, 1); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | |
| 159 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 160 | Isolate* isolate, |
| 161 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 162 | InitializeArrayConstructorDescriptor(isolate, descriptor, -1); |
| 163 | } |
| 164 | |
| 165 | |
| 166 | void CompareNilICStub::InitializeInterfaceDescriptor( |
| 167 | Isolate* isolate, |
| 168 | CodeStubInterfaceDescriptor* descriptor) { |
| 169 | static Register registers[] = { eax }; |
| 170 | descriptor->register_param_count_ = 1; |
| 171 | descriptor->register_params_ = registers; |
| 172 | descriptor->deoptimization_handler_ = |
| 173 | FUNCTION_ADDR(CompareNilIC_Miss); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 174 | descriptor->SetMissHandler( |
| 175 | ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 176 | } |
| 177 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame^] | 178 | void ToBooleanStub::InitializeInterfaceDescriptor( |
| 179 | Isolate* isolate, |
| 180 | CodeStubInterfaceDescriptor* descriptor) { |
| 181 | static Register registers[] = { eax }; |
| 182 | descriptor->register_param_count_ = 1; |
| 183 | descriptor->register_params_ = registers; |
| 184 | descriptor->deoptimization_handler_ = |
| 185 | FUNCTION_ADDR(ToBooleanIC_Miss); |
| 186 | descriptor->SetMissHandler( |
| 187 | ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate)); |
| 188 | } |
| 189 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 190 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 191 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 192 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 193 | |
| 194 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
| 195 | // Update the static counter each time a new code stub is generated. |
| 196 | Isolate* isolate = masm->isolate(); |
| 197 | isolate->counters()->code_stubs()->Increment(); |
| 198 | |
| 199 | CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
| 200 | int param_count = descriptor->register_param_count_; |
| 201 | { |
| 202 | // Call the runtime system in a fresh internal frame. |
| 203 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 204 | ASSERT(descriptor->register_param_count_ == 0 || |
| 205 | eax.is(descriptor->register_params_[param_count - 1])); |
| 206 | // Push arguments |
| 207 | for (int i = 0; i < param_count; ++i) { |
| 208 | __ push(descriptor->register_params_[i]); |
| 209 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 210 | ExternalReference miss = descriptor->miss_handler(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 211 | __ CallExternalReference(miss, descriptor->register_param_count_); |
| 212 | } |
| 213 | |
| 214 | __ ret(0); |
| 215 | } |
| 216 | |
| 217 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 218 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 219 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 220 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 221 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 222 | __ ret(0); |
| 223 | |
| 224 | __ bind(&check_heap_number); |
| 225 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 226 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 227 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 228 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 229 | __ ret(0); |
| 230 | |
| 231 | __ bind(&call_builtin); |
| 232 | __ pop(ecx); // Pop return address. |
| 233 | __ push(eax); |
| 234 | __ push(ecx); // Push return address. |
| 235 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 236 | } |
| 237 | |
| 238 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 239 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 240 | // Create a new closure from the given function info in new |
| 241 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 242 | Counters* counters = masm->isolate()->counters(); |
| 243 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 244 | Label gc; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 245 | __ Allocate(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 246 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 247 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 248 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 249 | // Get the function info from the stack. |
| 250 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 251 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 252 | int map_index = Context::FunctionMapIndex(language_mode_, is_generator_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 253 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 254 | // Compute the function map in the current native context and set that |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 255 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 256 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 257 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 258 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 259 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 260 | |
| 261 | // Initialize the rest of the function. We don't have to update the |
| 262 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 263 | Factory* factory = masm->isolate()->factory(); |
| 264 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 265 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 266 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 267 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 268 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 269 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 270 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 271 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 272 | |
| 273 | // Initialize the code pointer in the function to be the one |
| 274 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 275 | // But first check if there is an optimized version for our context. |
| 276 | Label check_optimized; |
| 277 | Label install_unoptimized; |
| 278 | if (FLAG_cache_optimized_code) { |
| 279 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 280 | __ test(ebx, ebx); |
| 281 | __ j(not_zero, &check_optimized, Label::kNear); |
| 282 | } |
| 283 | __ bind(&install_unoptimized); |
| 284 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 285 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 286 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 287 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 288 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 289 | |
| 290 | // Return and remove the on-stack parameter. |
| 291 | __ ret(1 * kPointerSize); |
| 292 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 293 | __ bind(&check_optimized); |
| 294 | |
| 295 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 296 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 297 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 298 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 299 | // Map must never be empty, so check the first elements. |
| 300 | Label install_optimized; |
| 301 | // Speculatively move code object into edx. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 302 | __ mov(edx, FieldOperand(ebx, SharedFunctionInfo::kFirstCodeSlot)); |
| 303 | __ cmp(ecx, FieldOperand(ebx, SharedFunctionInfo::kFirstContextSlot)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 304 | __ j(equal, &install_optimized); |
| 305 | |
| 306 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 307 | Label loop; |
| 308 | Label restore; |
| 309 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 310 | __ bind(&loop); |
| 311 | // Do not double check first entry. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 312 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kSecondEntryIndex))); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 313 | __ j(equal, &restore); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 314 | __ sub(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 315 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 316 | __ j(not_equal, &loop, Label::kNear); |
| 317 | // Hit: fetch the optimized code. |
| 318 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 319 | |
| 320 | __ bind(&install_optimized); |
| 321 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 322 | |
| 323 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 324 | // map and either unmangle them on marking or do nothing as the whole map is |
| 325 | // discarded on major GC anyway. |
| 326 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 327 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 328 | |
| 329 | // Now link a function into a list of optimized functions. |
| 330 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 331 | |
| 332 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 333 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 334 | |
| 335 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 336 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 337 | // it clobbers all the registers passed. |
| 338 | __ mov(edx, eax); |
| 339 | __ RecordWriteContextSlot( |
| 340 | ecx, |
| 341 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 342 | edx, |
| 343 | ebx, |
| 344 | kDontSaveFPRegs); |
| 345 | |
| 346 | // Return and remove the on-stack parameter. |
| 347 | __ ret(1 * kPointerSize); |
| 348 | |
| 349 | __ bind(&restore); |
| 350 | // Restore SharedFunctionInfo into edx. |
| 351 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 352 | __ jmp(&install_unoptimized); |
| 353 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 354 | // Create a new closure through the slower runtime call. |
| 355 | __ bind(&gc); |
| 356 | __ pop(ecx); // Temporarily remove return address. |
| 357 | __ pop(edx); |
| 358 | __ push(esi); |
| 359 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 360 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 361 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 362 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | |
| 366 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 367 | // Try to allocate the context in new space. |
| 368 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 369 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 370 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 371 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 372 | |
| 373 | // Get the function from the stack. |
| 374 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 375 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 376 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 377 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 378 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 379 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 380 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 381 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 382 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 383 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 384 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 385 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 386 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 387 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 388 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 389 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 390 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 391 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 392 | |
| 393 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 394 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 395 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 396 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 397 | } |
| 398 | |
| 399 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 400 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 401 | __ ret(1 * kPointerSize); |
| 402 | |
| 403 | // Need to collect. Call into runtime system. |
| 404 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 405 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 409 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 410 | // Stack layout on entry: |
| 411 | // |
| 412 | // [esp + (1 * kPointerSize)]: function |
| 413 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 414 | |
| 415 | // Try to allocate the context in new space. |
| 416 | Label gc; |
| 417 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 418 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 419 | |
| 420 | // Get the function or sentinel from the stack. |
| 421 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 422 | |
| 423 | // Get the serialized scope info from the stack. |
| 424 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 425 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 426 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 427 | Factory* factory = masm->isolate()->factory(); |
| 428 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 429 | factory->block_context_map()); |
| 430 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 431 | Immediate(Smi::FromInt(length))); |
| 432 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 433 | // If this block context is nested in the native context we get a smi |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 434 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 435 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 436 | // we still have to look up. |
| 437 | Label after_sentinel; |
| 438 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 439 | if (FLAG_debug_code) { |
| 440 | const char* message = "Expected 0 as a Smi sentinel"; |
| 441 | __ cmp(ecx, 0); |
| 442 | __ Assert(equal, message); |
| 443 | } |
| 444 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 445 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 446 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 447 | __ bind(&after_sentinel); |
| 448 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 449 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 450 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 451 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 452 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 453 | |
| 454 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 455 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 456 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 457 | |
| 458 | // Initialize the rest of the slots to the hole value. |
| 459 | if (slots_ == 1) { |
| 460 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 461 | factory->the_hole_value()); |
| 462 | } else { |
| 463 | __ mov(ebx, factory->the_hole_value()); |
| 464 | for (int i = 0; i < slots_; i++) { |
| 465 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | // Return and remove the on-stack parameters. |
| 470 | __ mov(esi, eax); |
| 471 | __ ret(2 * kPointerSize); |
| 472 | |
| 473 | // Need to collect. Call into runtime system. |
| 474 | __ bind(&gc); |
| 475 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 476 | } |
| 477 | |
| 478 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 479 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 480 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 481 | // store the registers in any particular way, but we do have to store and |
| 482 | // restore them. |
| 483 | __ pushad(); |
| 484 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 485 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 486 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 487 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 488 | XMMRegister reg = XMMRegister::from_code(i); |
| 489 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 490 | } |
| 491 | } |
| 492 | const int argument_count = 1; |
| 493 | |
| 494 | AllowExternalCallThatCantCauseGC scope(masm); |
| 495 | __ PrepareCallCFunction(argument_count, ecx); |
| 496 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 497 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 498 | __ CallCFunction( |
| 499 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 500 | argument_count); |
| 501 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 502 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 503 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 504 | XMMRegister reg = XMMRegister::from_code(i); |
| 505 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 506 | } |
| 507 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 508 | } |
| 509 | __ popad(); |
| 510 | __ ret(0); |
| 511 | } |
| 512 | |
| 513 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 514 | class FloatingPointHelper : public AllStatic { |
| 515 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 516 | enum ArgLocation { |
| 517 | ARGS_ON_STACK, |
| 518 | ARGS_IN_REGISTERS |
| 519 | }; |
| 520 | |
| 521 | // Code pattern for loading a floating point value. Input value must |
| 522 | // be either a smi or a heap number object (fp value). Requirements: |
| 523 | // operand in register number. Returns operand as floating point number |
| 524 | // on FPU stack. |
| 525 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 526 | |
| 527 | // Code pattern for loading floating point values. Input values must |
| 528 | // be either smi or heap number objects (fp values). Requirements: |
| 529 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 530 | // Returns operands as floating point numbers on FPU stack. |
| 531 | static void LoadFloatOperands(MacroAssembler* masm, |
| 532 | Register scratch, |
| 533 | ArgLocation arg_location = ARGS_ON_STACK); |
| 534 | |
| 535 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 536 | // Expects operands in edx, eax. |
| 537 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 538 | |
| 539 | // Test if operands are smi or number objects (fp). Requirements: |
| 540 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 541 | // operands, jumps to the non_float label otherwise. |
| 542 | static void CheckFloatOperands(MacroAssembler* masm, |
| 543 | Label* non_float, |
| 544 | Register scratch); |
| 545 | |
| 546 | // Takes the operands in edx and eax and loads them as integers in eax |
| 547 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 548 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 549 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 550 | BinaryOpIC::TypeInfo left_type, |
| 551 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 552 | Label* operand_conversion_failure); |
| 553 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 554 | // Assumes that operands are smis or heap numbers and loads them |
| 555 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 556 | // Leaves operands unchanged. |
| 557 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 558 | |
| 559 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 560 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 561 | // either operand is not a number. Operands are in edx and eax. |
| 562 | // Leaves operands unchanged. |
| 563 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 564 | |
| 565 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 566 | // Expects operands in edx, eax. |
| 567 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 568 | |
| 569 | // Checks that the two floating point numbers loaded into xmm0 and xmm1 |
| 570 | // have int32 values. |
| 571 | static void CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 572 | Label* non_int32, |
| 573 | Register scratch); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 574 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 575 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 576 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 577 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 578 | Label* non_int32, |
| 579 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 580 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 581 | Register scratch, |
| 582 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 583 | }; |
| 584 | |
| 585 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 586 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 587 | // is faster than using the built-in instructions on floating point registers. |
| 588 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 589 | // trashed registers. |
| 590 | static void IntegerConvert(MacroAssembler* masm, |
| 591 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 592 | bool use_sse3, |
| 593 | Label* conversion_failure) { |
| 594 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 595 | Label done, right_exponent, normal_exponent; |
| 596 | Register scratch = ebx; |
| 597 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 598 | // Get exponent word. |
| 599 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 600 | // Get exponent alone in scratch2. |
| 601 | __ mov(scratch2, scratch); |
| 602 | __ and_(scratch2, HeapNumber::kExponentMask); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 603 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 604 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias)); |
| 605 | // Load ecx with zero. We use this either for the final shift or |
| 606 | // for the answer. |
| 607 | __ xor_(ecx, ecx); |
| 608 | // If the exponent is above 83, the number contains no significant |
| 609 | // bits in the range 0..2^31, so the result is zero. |
| 610 | static const uint32_t kResultIsZeroExponent = 83; |
| 611 | __ cmp(scratch2, Immediate(kResultIsZeroExponent)); |
| 612 | __ j(above, &done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 613 | if (use_sse3) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 614 | CpuFeatureScope scope(masm, SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 615 | // Check whether the exponent is too big for a 64 bit signed integer. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 616 | static const uint32_t kTooBigExponent = 63; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 617 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 618 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 619 | // Load x87 register with heap number. |
| 620 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 621 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 622 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 623 | // Do conversion, which cannot fail because we checked the exponent. |
| 624 | __ fisttp_d(Operand(esp, 0)); |
| 625 | __ mov(ecx, Operand(esp, 0)); // Load low word of answer into ecx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 626 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 627 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 628 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 629 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 630 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 631 | // also the highest exponent we can handle here. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 632 | const uint32_t non_smi_exponent = 30; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 633 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 634 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 635 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 636 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 637 | // If the exponent is higher than that then go to slow case. This catches |
| 638 | // numbers that don't fit in a signed int32, infinities and NaNs. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 639 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 640 | |
| 641 | { |
| 642 | // Handle a big exponent. The only reason we have this code is that the |
| 643 | // >>> operator has a tendency to generate numbers with an exponent of 31. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 644 | const uint32_t big_non_smi_exponent = 31; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 645 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 646 | __ j(not_equal, conversion_failure); |
| 647 | // We have the big exponent, typically from >>>. This means the number is |
| 648 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 649 | __ mov(scratch2, scratch); |
| 650 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 651 | // Put back the implicit 1. |
| 652 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 653 | // Shift up the mantissa bits to take up the space the exponent used to |
| 654 | // take. We just orred in the implicit bit so that took care of one and |
| 655 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 656 | // shift distance. |
| 657 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 658 | __ shl(scratch2, big_shift_distance); |
| 659 | // Get the second half of the double. |
| 660 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 661 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 662 | // mantissa word. |
| 663 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 664 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 665 | // We have the answer in ecx, but we may need to negate it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 666 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 667 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 668 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 669 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | __ bind(&normal_exponent); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 673 | // Exponent word in scratch, exponent in scratch2. Zero in ecx. |
| 674 | // We know that 0 <= exponent < 30. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 675 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 676 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 677 | |
| 678 | __ bind(&right_exponent); |
| 679 | // Here ecx is the shift, scratch is the exponent word. |
| 680 | // Get the top bits of the mantissa. |
| 681 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 682 | // Put back the implicit 1. |
| 683 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 684 | // Shift up the mantissa bits to take up the space the exponent used to |
| 685 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 686 | // word. Shift them to the top bits. |
| 687 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 688 | __ shl(scratch, shift_distance); |
| 689 | // Get the second half of the double. For some exponents we don't |
| 690 | // actually need this because the bits get shifted out again, but |
| 691 | // it's probably slower to test than just to do it. |
| 692 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 693 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 694 | // mantissa word. |
| 695 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 696 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 697 | // Move down according to the exponent. |
| 698 | __ shr_cl(scratch2); |
| 699 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 700 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 701 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 702 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 703 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 704 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 705 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 706 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 707 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 708 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 709 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 710 | __ bind(&done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 714 | // Uses SSE2 to convert the heap number in |source| to an integer. Jumps to |
| 715 | // |conversion_failure| if the heap number did not contain an int32 value. |
| 716 | // Result is in ecx. Trashes ebx, xmm0, and xmm1. |
| 717 | static void ConvertHeapNumberToInt32(MacroAssembler* masm, |
| 718 | Register source, |
| 719 | Label* conversion_failure) { |
| 720 | __ movdbl(xmm0, FieldOperand(source, HeapNumber::kValueOffset)); |
| 721 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 722 | masm, conversion_failure, xmm0, ecx, ebx, xmm1); |
| 723 | } |
| 724 | |
| 725 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 726 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 727 | const char* op_name = Token::Name(op_); |
| 728 | const char* overwrite_name = NULL; // Make g++ happy. |
| 729 | switch (mode_) { |
| 730 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 731 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 732 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 733 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 734 | op_name, |
| 735 | overwrite_name, |
| 736 | UnaryOpIC::GetName(operand_type_)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | |
| 740 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 741 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 742 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 743 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 744 | GenerateTypeTransition(masm); |
| 745 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 746 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 747 | GenerateSmiStub(masm); |
| 748 | break; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 749 | case UnaryOpIC::NUMBER: |
| 750 | GenerateNumberStub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 751 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 752 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 753 | GenerateGenericStub(masm); |
| 754 | break; |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 759 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 760 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 761 | |
| 762 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 763 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 764 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 765 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 766 | |
| 767 | __ push(ecx); // Push return address. |
| 768 | |
| 769 | // Patch the caller to an appropriate specialized stub and return the |
| 770 | // operation result to the caller of the stub. |
| 771 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 772 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | |
| 776 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 777 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 778 | switch (op_) { |
| 779 | case Token::SUB: |
| 780 | GenerateSmiStubSub(masm); |
| 781 | break; |
| 782 | case Token::BIT_NOT: |
| 783 | GenerateSmiStubBitNot(masm); |
| 784 | break; |
| 785 | default: |
| 786 | UNREACHABLE(); |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 791 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 792 | Label non_smi, undo, slow; |
| 793 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 794 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 795 | __ bind(&undo); |
| 796 | GenerateSmiCodeUndo(masm); |
| 797 | __ bind(&non_smi); |
| 798 | __ bind(&slow); |
| 799 | GenerateTypeTransition(masm); |
| 800 | } |
| 801 | |
| 802 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 803 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 804 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 805 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 806 | __ bind(&non_smi); |
| 807 | GenerateTypeTransition(masm); |
| 808 | } |
| 809 | |
| 810 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 811 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 812 | Label* non_smi, |
| 813 | Label* undo, |
| 814 | Label* slow, |
| 815 | Label::Distance non_smi_near, |
| 816 | Label::Distance undo_near, |
| 817 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 818 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 819 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 820 | |
| 821 | // We can't handle -0 with smis, so use a type transition for that case. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 822 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 823 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 824 | |
| 825 | // Try optimistic subtraction '0 - value', saving operand in eax for undo. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 826 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 827 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 828 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 829 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 830 | __ ret(0); |
| 831 | } |
| 832 | |
| 833 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 834 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 835 | MacroAssembler* masm, |
| 836 | Label* non_smi, |
| 837 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 838 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 839 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 840 | |
| 841 | // Flip bits and revert inverted smi-tag. |
| 842 | __ not_(eax); |
| 843 | __ and_(eax, ~kSmiTagMask); |
| 844 | __ ret(0); |
| 845 | } |
| 846 | |
| 847 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 848 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 849 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | |
| 853 | // TODO(svenpanne): Use virtual functions instead of switch. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 854 | void UnaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 855 | switch (op_) { |
| 856 | case Token::SUB: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 857 | GenerateNumberStubSub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 858 | break; |
| 859 | case Token::BIT_NOT: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 860 | GenerateNumberStubBitNot(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 861 | break; |
| 862 | default: |
| 863 | UNREACHABLE(); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 868 | void UnaryOpStub::GenerateNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 869 | Label non_smi, undo, slow, call_builtin; |
| 870 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 871 | __ bind(&non_smi); |
| 872 | GenerateHeapNumberCodeSub(masm, &slow); |
| 873 | __ bind(&undo); |
| 874 | GenerateSmiCodeUndo(masm); |
| 875 | __ bind(&slow); |
| 876 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 877 | __ bind(&call_builtin); |
| 878 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 882 | void UnaryOpStub::GenerateNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 883 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 884 | Label non_smi, slow; |
| 885 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 886 | __ bind(&non_smi); |
| 887 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 888 | __ bind(&slow); |
| 889 | GenerateTypeTransition(masm); |
| 890 | } |
| 891 | |
| 892 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 893 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 894 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 895 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 896 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 897 | __ j(not_equal, slow); |
| 898 | |
| 899 | if (mode_ == UNARY_OVERWRITE) { |
| 900 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 901 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 902 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 903 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 904 | // edx: operand |
| 905 | |
| 906 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 907 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 908 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 909 | |
| 910 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 911 | { |
| 912 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 913 | __ push(edx); |
| 914 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 915 | __ pop(edx); |
| 916 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 917 | |
| 918 | __ bind(&heapnumber_allocated); |
| 919 | // eax: allocated 'empty' number |
| 920 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 921 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 922 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 923 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 924 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 925 | } |
| 926 | __ ret(0); |
| 927 | } |
| 928 | |
| 929 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 930 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 931 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 932 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 933 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 934 | __ j(not_equal, slow); |
| 935 | |
| 936 | // Convert the heap number in eax to an untagged integer in ecx. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 937 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 938 | |
| 939 | // Do the bitwise operation and check if the result fits in a smi. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 940 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 941 | __ not_(ecx); |
| 942 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 943 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 944 | |
| 945 | // Tag the result as a smi and we're done. |
| 946 | STATIC_ASSERT(kSmiTagSize == 1); |
| 947 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 948 | __ ret(0); |
| 949 | |
| 950 | // Try to store the result in a heap number. |
| 951 | __ bind(&try_float); |
| 952 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 953 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 954 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 955 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 956 | __ jmp(&heapnumber_allocated); |
| 957 | |
| 958 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 959 | { |
| 960 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 961 | // Push the original HeapNumber on the stack. The integer value can't |
| 962 | // be stored since it's untagged and not in the smi range (so we can't |
| 963 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 964 | __ push(ebx); |
| 965 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 966 | // New HeapNumber is in eax. |
| 967 | __ pop(edx); |
| 968 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 969 | // IntegerConvert uses ebx and edi as scratch registers. |
| 970 | // This conversion won't go slow-case. |
| 971 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 972 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 973 | |
| 974 | __ bind(&heapnumber_allocated); |
| 975 | } |
| 976 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 977 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 978 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 979 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 980 | } else { |
| 981 | __ push(ecx); |
| 982 | __ fild_s(Operand(esp, 0)); |
| 983 | __ pop(ecx); |
| 984 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 985 | } |
| 986 | __ ret(0); |
| 987 | } |
| 988 | |
| 989 | |
| 990 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 991 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 992 | switch (op_) { |
| 993 | case Token::SUB: |
| 994 | GenerateGenericStubSub(masm); |
| 995 | break; |
| 996 | case Token::BIT_NOT: |
| 997 | GenerateGenericStubBitNot(masm); |
| 998 | break; |
| 999 | default: |
| 1000 | UNREACHABLE(); |
| 1001 | } |
| 1002 | } |
| 1003 | |
| 1004 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1005 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1006 | Label non_smi, undo, slow; |
| 1007 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1008 | __ bind(&non_smi); |
| 1009 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1010 | __ bind(&undo); |
| 1011 | GenerateSmiCodeUndo(masm); |
| 1012 | __ bind(&slow); |
| 1013 | GenerateGenericCodeFallback(masm); |
| 1014 | } |
| 1015 | |
| 1016 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1017 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1018 | Label non_smi, slow; |
| 1019 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1020 | __ bind(&non_smi); |
| 1021 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1022 | __ bind(&slow); |
| 1023 | GenerateGenericCodeFallback(masm); |
| 1024 | } |
| 1025 | |
| 1026 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1027 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1028 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1029 | __ pop(ecx); // pop return address. |
| 1030 | __ push(eax); |
| 1031 | __ push(ecx); // push return address |
| 1032 | switch (op_) { |
| 1033 | case Token::SUB: |
| 1034 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1035 | break; |
| 1036 | case Token::BIT_NOT: |
| 1037 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1038 | break; |
| 1039 | default: |
| 1040 | UNREACHABLE(); |
| 1041 | } |
| 1042 | } |
| 1043 | |
| 1044 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1045 | void BinaryOpStub::Initialize() { |
| 1046 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 1047 | } |
| 1048 | |
| 1049 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1050 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1051 | __ pop(ecx); // Save return address. |
| 1052 | __ push(edx); |
| 1053 | __ push(eax); |
| 1054 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1055 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1056 | |
| 1057 | __ push(ecx); // Push return address. |
| 1058 | |
| 1059 | // Patch the caller to an appropriate specialized stub and return the |
| 1060 | // operation result to the caller of the stub. |
| 1061 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1062 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1063 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1064 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1065 | 1); |
| 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | // Prepare for a type transition runtime call when the args are already on |
| 1070 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1071 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1072 | __ pop(ecx); // Save return address. |
| 1073 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1074 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1075 | |
| 1076 | __ push(ecx); // Push return address. |
| 1077 | |
| 1078 | // Patch the caller to an appropriate specialized stub and return the |
| 1079 | // operation result to the caller of the stub. |
| 1080 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1081 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1082 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1083 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1084 | 1); |
| 1085 | } |
| 1086 | |
| 1087 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1088 | static void BinaryOpStub_GenerateRegisterArgsPop(MacroAssembler* masm) { |
| 1089 | __ pop(ecx); |
| 1090 | __ pop(eax); |
| 1091 | __ pop(edx); |
| 1092 | __ push(ecx); |
| 1093 | } |
| 1094 | |
| 1095 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1096 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1097 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1098 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1099 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 1100 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1101 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1102 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1103 | Comment load_comment(masm, "-- Load arguments"); |
| 1104 | Register left = edx; |
| 1105 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1106 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1107 | left = eax; |
| 1108 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1109 | __ mov(ebx, eax); |
| 1110 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | |
| 1114 | // 2. Prepare the smi check of both operands by oring them together. |
| 1115 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1116 | Label not_smis; |
| 1117 | Register combined = ecx; |
| 1118 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1119 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1120 | case Token::BIT_OR: |
| 1121 | // Perform the operation into eax and smi check the result. Preserve |
| 1122 | // eax in case the result is not a smi. |
| 1123 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1124 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1125 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1126 | combined = right; |
| 1127 | break; |
| 1128 | |
| 1129 | case Token::BIT_XOR: |
| 1130 | case Token::BIT_AND: |
| 1131 | case Token::ADD: |
| 1132 | case Token::SUB: |
| 1133 | case Token::MUL: |
| 1134 | case Token::DIV: |
| 1135 | case Token::MOD: |
| 1136 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1137 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1138 | break; |
| 1139 | |
| 1140 | case Token::SHL: |
| 1141 | case Token::SAR: |
| 1142 | case Token::SHR: |
| 1143 | // Move the right operand into ecx for the shift operation, use eax |
| 1144 | // for the smi check register. |
| 1145 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1146 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1147 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1148 | combined = right; |
| 1149 | break; |
| 1150 | |
| 1151 | default: |
| 1152 | break; |
| 1153 | } |
| 1154 | |
| 1155 | // 3. Perform the smi check of the operands. |
| 1156 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1157 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1158 | |
| 1159 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1160 | // eax and check the result if necessary. |
| 1161 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1162 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1163 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1164 | case Token::BIT_OR: |
| 1165 | // Nothing to do. |
| 1166 | break; |
| 1167 | |
| 1168 | case Token::BIT_XOR: |
| 1169 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1170 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1171 | break; |
| 1172 | |
| 1173 | case Token::BIT_AND: |
| 1174 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1175 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1176 | break; |
| 1177 | |
| 1178 | case Token::SHL: |
| 1179 | // Remove tags from operands (but keep sign). |
| 1180 | __ SmiUntag(left); |
| 1181 | __ SmiUntag(ecx); |
| 1182 | // Perform the operation. |
| 1183 | __ shl_cl(left); |
| 1184 | // Check that the *signed* result fits in a smi. |
| 1185 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1186 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1187 | // Tag the result and store it in register eax. |
| 1188 | __ SmiTag(left); |
| 1189 | __ mov(eax, left); |
| 1190 | break; |
| 1191 | |
| 1192 | case Token::SAR: |
| 1193 | // Remove tags from operands (but keep sign). |
| 1194 | __ SmiUntag(left); |
| 1195 | __ SmiUntag(ecx); |
| 1196 | // Perform the operation. |
| 1197 | __ sar_cl(left); |
| 1198 | // Tag the result and store it in register eax. |
| 1199 | __ SmiTag(left); |
| 1200 | __ mov(eax, left); |
| 1201 | break; |
| 1202 | |
| 1203 | case Token::SHR: |
| 1204 | // Remove tags from operands (but keep sign). |
| 1205 | __ SmiUntag(left); |
| 1206 | __ SmiUntag(ecx); |
| 1207 | // Perform the operation. |
| 1208 | __ shr_cl(left); |
| 1209 | // Check that the *unsigned* result fits in a smi. |
| 1210 | // Neither of the two high-order bits can be set: |
| 1211 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1212 | // - 0x40000000: this number would convert to negative when |
| 1213 | // Smi tagging these two cases can only happen with shifts |
| 1214 | // by 0 or 1 when handed a valid smi. |
| 1215 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1216 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1217 | // Tag the result and store it in register eax. |
| 1218 | __ SmiTag(left); |
| 1219 | __ mov(eax, left); |
| 1220 | break; |
| 1221 | |
| 1222 | case Token::ADD: |
| 1223 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1224 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1225 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1226 | break; |
| 1227 | |
| 1228 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1229 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1230 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1231 | __ mov(eax, left); |
| 1232 | break; |
| 1233 | |
| 1234 | case Token::MUL: |
| 1235 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1236 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1237 | // We can't revert the multiplication if the result is not a smi |
| 1238 | // so save the right operand. |
| 1239 | __ mov(ebx, right); |
| 1240 | // Remove tag from one of the operands (but keep sign). |
| 1241 | __ SmiUntag(right); |
| 1242 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1243 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1244 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1245 | // Check for negative zero result. Use combined = left | right. |
| 1246 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1247 | break; |
| 1248 | |
| 1249 | case Token::DIV: |
| 1250 | // We can't revert the division if the result is not a smi so |
| 1251 | // save the left operand. |
| 1252 | __ mov(edi, left); |
| 1253 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1254 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1255 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1256 | // Sign extend left into edx:eax. |
| 1257 | ASSERT(left.is(eax)); |
| 1258 | __ cdq(); |
| 1259 | // Divide edx:eax by right. |
| 1260 | __ idiv(right); |
| 1261 | // Check for the corner case of dividing the most negative smi by |
| 1262 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1263 | // instruction. |
| 1264 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1265 | __ cmp(eax, 0x40000000); |
| 1266 | __ j(equal, &use_fp_on_smis); |
| 1267 | // Check for negative zero result. Use combined = left | right. |
| 1268 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1269 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1270 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1271 | __ j(not_zero, &use_fp_on_smis); |
| 1272 | // Tag the result and store it in register eax. |
| 1273 | __ SmiTag(eax); |
| 1274 | break; |
| 1275 | |
| 1276 | case Token::MOD: |
| 1277 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1278 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1279 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1280 | |
| 1281 | // Sign extend left into edx:eax. |
| 1282 | ASSERT(left.is(eax)); |
| 1283 | __ cdq(); |
| 1284 | // Divide edx:eax by right. |
| 1285 | __ idiv(right); |
| 1286 | // Check for negative zero result. Use combined = left | right. |
| 1287 | __ NegativeZeroTest(edx, combined, slow); |
| 1288 | // Move remainder to register eax. |
| 1289 | __ mov(eax, edx); |
| 1290 | break; |
| 1291 | |
| 1292 | default: |
| 1293 | UNREACHABLE(); |
| 1294 | } |
| 1295 | |
| 1296 | // 5. Emit return of result in eax. Some operations have registers pushed. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1297 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1298 | case Token::ADD: |
| 1299 | case Token::SUB: |
| 1300 | case Token::MUL: |
| 1301 | case Token::DIV: |
| 1302 | __ ret(0); |
| 1303 | break; |
| 1304 | case Token::MOD: |
| 1305 | case Token::BIT_OR: |
| 1306 | case Token::BIT_AND: |
| 1307 | case Token::BIT_XOR: |
| 1308 | case Token::SAR: |
| 1309 | case Token::SHL: |
| 1310 | case Token::SHR: |
| 1311 | __ ret(2 * kPointerSize); |
| 1312 | break; |
| 1313 | default: |
| 1314 | UNREACHABLE(); |
| 1315 | } |
| 1316 | |
| 1317 | // 6. For some operations emit inline code to perform floating point |
| 1318 | // operations on known smis (e.g., if the result of the operation |
| 1319 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1320 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1321 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1322 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1323 | // Undo the effects of some operations, and some register moves. |
| 1324 | case Token::SHL: |
| 1325 | // The arguments are saved on the stack, and only used from there. |
| 1326 | break; |
| 1327 | case Token::ADD: |
| 1328 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1329 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1330 | break; |
| 1331 | case Token::SUB: |
| 1332 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1333 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1334 | break; |
| 1335 | case Token::MUL: |
| 1336 | // Right was clobbered but a copy is in ebx. |
| 1337 | __ mov(right, ebx); |
| 1338 | break; |
| 1339 | case Token::DIV: |
| 1340 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1341 | // division. They should be in eax, ebx for jump to not_smi. |
| 1342 | __ mov(eax, edi); |
| 1343 | break; |
| 1344 | default: |
| 1345 | // No other operators jump to use_fp_on_smis. |
| 1346 | break; |
| 1347 | } |
| 1348 | __ jmp(¬_smis); |
| 1349 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1350 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1351 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1352 | case Token::SHL: |
| 1353 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1354 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1355 | __ bind(&use_fp_on_smis); |
| 1356 | // Result we want is in left == edx, so we can put the allocated heap |
| 1357 | // number in eax. |
| 1358 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1359 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1360 | // It's OK to overwrite the arguments on the stack because we |
| 1361 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1362 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1363 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1364 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1365 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1366 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1367 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1368 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1369 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1370 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1371 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1372 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1373 | } else { |
| 1374 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1375 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1376 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1377 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1378 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1379 | __ ret(2 * kPointerSize); |
| 1380 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | case Token::ADD: |
| 1384 | case Token::SUB: |
| 1385 | case Token::MUL: |
| 1386 | case Token::DIV: { |
| 1387 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1388 | __ bind(&use_fp_on_smis); |
| 1389 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1390 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1391 | case Token::ADD: |
| 1392 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1393 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1394 | break; |
| 1395 | case Token::SUB: |
| 1396 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1397 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1398 | break; |
| 1399 | case Token::MUL: |
| 1400 | // Right was clobbered but a copy is in ebx. |
| 1401 | __ mov(right, ebx); |
| 1402 | break; |
| 1403 | case Token::DIV: |
| 1404 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1405 | // division. |
| 1406 | __ mov(edx, edi); |
| 1407 | __ mov(eax, right); |
| 1408 | break; |
| 1409 | default: UNREACHABLE(); |
| 1410 | break; |
| 1411 | } |
| 1412 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1413 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1414 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1415 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1416 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1417 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1418 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1419 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1420 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1421 | default: UNREACHABLE(); |
| 1422 | } |
| 1423 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1424 | } else { // SSE2 not available, use FPU. |
| 1425 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1426 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1427 | case Token::ADD: __ faddp(1); break; |
| 1428 | case Token::SUB: __ fsubp(1); break; |
| 1429 | case Token::MUL: __ fmulp(1); break; |
| 1430 | case Token::DIV: __ fdivp(1); break; |
| 1431 | default: UNREACHABLE(); |
| 1432 | } |
| 1433 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1434 | } |
| 1435 | __ mov(eax, ecx); |
| 1436 | __ ret(0); |
| 1437 | break; |
| 1438 | } |
| 1439 | |
| 1440 | default: |
| 1441 | break; |
| 1442 | } |
| 1443 | } |
| 1444 | |
| 1445 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1446 | // edx and eax. |
| 1447 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1448 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1449 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1450 | case Token::BIT_OR: |
| 1451 | case Token::SHL: |
| 1452 | case Token::SAR: |
| 1453 | case Token::SHR: |
| 1454 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1455 | // check. |
| 1456 | __ mov(eax, ecx); |
| 1457 | break; |
| 1458 | |
| 1459 | case Token::DIV: |
| 1460 | case Token::MOD: |
| 1461 | // Operands are in eax, ebx at this point. |
| 1462 | __ mov(edx, eax); |
| 1463 | __ mov(eax, ebx); |
| 1464 | break; |
| 1465 | |
| 1466 | default: |
| 1467 | break; |
| 1468 | } |
| 1469 | } |
| 1470 | |
| 1471 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1472 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1473 | Label call_runtime; |
| 1474 | |
| 1475 | switch (op_) { |
| 1476 | case Token::ADD: |
| 1477 | case Token::SUB: |
| 1478 | case Token::MUL: |
| 1479 | case Token::DIV: |
| 1480 | break; |
| 1481 | case Token::MOD: |
| 1482 | case Token::BIT_OR: |
| 1483 | case Token::BIT_AND: |
| 1484 | case Token::BIT_XOR: |
| 1485 | case Token::SAR: |
| 1486 | case Token::SHL: |
| 1487 | case Token::SHR: |
| 1488 | GenerateRegisterArgsPush(masm); |
| 1489 | break; |
| 1490 | default: |
| 1491 | UNREACHABLE(); |
| 1492 | } |
| 1493 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1494 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1495 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1496 | BinaryOpStub_GenerateSmiCode( |
| 1497 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1498 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1499 | BinaryOpStub_GenerateSmiCode( |
| 1500 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1501 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1502 | |
| 1503 | // Code falls through if the result is not returned as either a smi or heap |
| 1504 | // number. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1505 | switch (op_) { |
| 1506 | case Token::ADD: |
| 1507 | case Token::SUB: |
| 1508 | case Token::MUL: |
| 1509 | case Token::DIV: |
| 1510 | GenerateTypeTransition(masm); |
| 1511 | break; |
| 1512 | case Token::MOD: |
| 1513 | case Token::BIT_OR: |
| 1514 | case Token::BIT_AND: |
| 1515 | case Token::BIT_XOR: |
| 1516 | case Token::SAR: |
| 1517 | case Token::SHL: |
| 1518 | case Token::SHR: |
| 1519 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1520 | break; |
| 1521 | default: |
| 1522 | UNREACHABLE(); |
| 1523 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1524 | |
| 1525 | __ bind(&call_runtime); |
| 1526 | switch (op_) { |
| 1527 | case Token::ADD: |
| 1528 | case Token::SUB: |
| 1529 | case Token::MUL: |
| 1530 | case Token::DIV: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1531 | break; |
| 1532 | case Token::MOD: |
| 1533 | case Token::BIT_OR: |
| 1534 | case Token::BIT_AND: |
| 1535 | case Token::BIT_XOR: |
| 1536 | case Token::SAR: |
| 1537 | case Token::SHL: |
| 1538 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1539 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1540 | break; |
| 1541 | default: |
| 1542 | UNREACHABLE(); |
| 1543 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1544 | |
| 1545 | { |
| 1546 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1547 | __ push(edx); |
| 1548 | __ push(eax); |
| 1549 | GenerateCallRuntime(masm); |
| 1550 | } |
| 1551 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1555 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1556 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1557 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1558 | ASSERT(op_ == Token::ADD); |
| 1559 | // If both arguments are strings, call the string add stub. |
| 1560 | // Otherwise, do a transition. |
| 1561 | |
| 1562 | // Registers containing left and right operands respectively. |
| 1563 | Register left = edx; |
| 1564 | Register right = eax; |
| 1565 | |
| 1566 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1567 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1568 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1569 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1570 | |
| 1571 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1572 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1573 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1574 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1575 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1576 | StringAddStub string_add_stub((StringAddFlags) |
| 1577 | (ERECT_FRAME | NO_STRING_CHECK_IN_STUB)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1578 | GenerateRegisterArgsPush(masm); |
| 1579 | __ TailCallStub(&string_add_stub); |
| 1580 | |
| 1581 | __ bind(&call_runtime); |
| 1582 | GenerateTypeTransition(masm); |
| 1583 | } |
| 1584 | |
| 1585 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1586 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1587 | Label* alloc_failure, |
| 1588 | OverwriteMode mode); |
| 1589 | |
| 1590 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1591 | // Input: |
| 1592 | // edx: left operand (tagged) |
| 1593 | // eax: right operand (tagged) |
| 1594 | // Output: |
| 1595 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1596 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1597 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1598 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1599 | |
| 1600 | // Floating point case. |
| 1601 | switch (op_) { |
| 1602 | case Token::ADD: |
| 1603 | case Token::SUB: |
| 1604 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1605 | case Token::DIV: |
| 1606 | case Token::MOD: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1607 | Label not_floats; |
| 1608 | Label not_int32; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1609 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1610 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1611 | // It could be that only SMIs have been seen at either the left |
| 1612 | // or the right operand. For precise type feedback, patch the IC |
| 1613 | // again if this changes. |
| 1614 | // In theory, we would need the same check in the non-SSE2 case, |
| 1615 | // but since we don't support Crankshaft on such hardware we can |
| 1616 | // afford not to care about precise type feedback. |
| 1617 | if (left_type_ == BinaryOpIC::SMI) { |
| 1618 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1619 | } |
| 1620 | if (right_type_ == BinaryOpIC::SMI) { |
| 1621 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1622 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1623 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1624 | FloatingPointHelper::CheckSSE2OperandsAreInt32(masm, ¬_int32, ecx); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1625 | if (op_ == Token::MOD) { |
| 1626 | GenerateRegisterArgsPush(masm); |
| 1627 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1628 | } else { |
| 1629 | switch (op_) { |
| 1630 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1631 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1632 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1633 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1634 | default: UNREACHABLE(); |
| 1635 | } |
| 1636 | // Check result type if it is currently Int32. |
| 1637 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1638 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1639 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1640 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1641 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1642 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1643 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1644 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1645 | } else { // SSE2 not available, use FPU. |
| 1646 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1647 | FloatingPointHelper::LoadFloatOperands( |
| 1648 | masm, |
| 1649 | ecx, |
| 1650 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1651 | if (op_ == Token::MOD) { |
| 1652 | // The operands are now on the FPU stack, but we don't need them. |
| 1653 | __ fstp(0); |
| 1654 | __ fstp(0); |
| 1655 | GenerateRegisterArgsPush(masm); |
| 1656 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1657 | } else { |
| 1658 | switch (op_) { |
| 1659 | case Token::ADD: __ faddp(1); break; |
| 1660 | case Token::SUB: __ fsubp(1); break; |
| 1661 | case Token::MUL: __ fmulp(1); break; |
| 1662 | case Token::DIV: __ fdivp(1); break; |
| 1663 | default: UNREACHABLE(); |
| 1664 | } |
| 1665 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1666 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1667 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1668 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1669 | __ ret(0); |
| 1670 | __ bind(&after_alloc_failure); |
| 1671 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1672 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1673 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | __ bind(¬_floats); |
| 1677 | __ bind(¬_int32); |
| 1678 | GenerateTypeTransition(masm); |
| 1679 | break; |
| 1680 | } |
| 1681 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1682 | case Token::BIT_OR: |
| 1683 | case Token::BIT_AND: |
| 1684 | case Token::BIT_XOR: |
| 1685 | case Token::SAR: |
| 1686 | case Token::SHL: |
| 1687 | case Token::SHR: { |
| 1688 | GenerateRegisterArgsPush(masm); |
| 1689 | Label not_floats; |
| 1690 | Label not_int32; |
| 1691 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1692 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1693 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1694 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1695 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1696 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1697 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1698 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1699 | case Token::SAR: __ sar_cl(eax); break; |
| 1700 | case Token::SHL: __ shl_cl(eax); break; |
| 1701 | case Token::SHR: __ shr_cl(eax); break; |
| 1702 | default: UNREACHABLE(); |
| 1703 | } |
| 1704 | if (op_ == Token::SHR) { |
| 1705 | // Check if result is non-negative and fits in a smi. |
| 1706 | __ test(eax, Immediate(0xc0000000)); |
| 1707 | __ j(not_zero, &call_runtime); |
| 1708 | } else { |
| 1709 | // Check if result fits in a smi. |
| 1710 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1711 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1712 | } |
| 1713 | // Tag smi result and return. |
| 1714 | __ SmiTag(eax); |
| 1715 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1716 | |
| 1717 | // All ops except SHR return a signed int32 that we load in |
| 1718 | // a HeapNumber. |
| 1719 | if (op_ != Token::SHR) { |
| 1720 | __ bind(&non_smi_result); |
| 1721 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1722 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1723 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1724 | switch (mode_) { |
| 1725 | case OVERWRITE_LEFT: |
| 1726 | case OVERWRITE_RIGHT: |
| 1727 | // If the operand was an object, we skip the |
| 1728 | // allocation of a heap number. |
| 1729 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1730 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1731 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1732 | // Fall through! |
| 1733 | case NO_OVERWRITE: |
| 1734 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1735 | __ bind(&skip_allocation); |
| 1736 | break; |
| 1737 | default: UNREACHABLE(); |
| 1738 | } |
| 1739 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1740 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1741 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1742 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1743 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1744 | } else { |
| 1745 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1746 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1747 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1748 | } |
| 1749 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1750 | } |
| 1751 | |
| 1752 | __ bind(¬_floats); |
| 1753 | __ bind(¬_int32); |
| 1754 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1755 | break; |
| 1756 | } |
| 1757 | default: UNREACHABLE(); break; |
| 1758 | } |
| 1759 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1760 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1761 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1762 | __ bind(&call_runtime); |
| 1763 | |
| 1764 | switch (op_) { |
| 1765 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1766 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1767 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1768 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1769 | break; |
| 1770 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1771 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1772 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1773 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1774 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1775 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1776 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1777 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1778 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1779 | break; |
| 1780 | default: |
| 1781 | UNREACHABLE(); |
| 1782 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1783 | |
| 1784 | { |
| 1785 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1786 | __ push(edx); |
| 1787 | __ push(eax); |
| 1788 | GenerateCallRuntime(masm); |
| 1789 | } |
| 1790 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1794 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1795 | if (op_ == Token::ADD) { |
| 1796 | // Handle string addition here, because it is the only operation |
| 1797 | // that does not do a ToNumber conversion on the operands. |
| 1798 | GenerateAddStrings(masm); |
| 1799 | } |
| 1800 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1801 | Factory* factory = masm->isolate()->factory(); |
| 1802 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1803 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1804 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1805 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1806 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1807 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1808 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1809 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1810 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1811 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1812 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1813 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1814 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1815 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1816 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1817 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1818 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1819 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1820 | } |
| 1821 | __ bind(&done); |
| 1822 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1823 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1827 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1828 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1829 | |
| 1830 | // Floating point case. |
| 1831 | switch (op_) { |
| 1832 | case Token::ADD: |
| 1833 | case Token::SUB: |
| 1834 | case Token::MUL: |
| 1835 | case Token::DIV: { |
| 1836 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1837 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1838 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1839 | |
| 1840 | // It could be that only SMIs have been seen at either the left |
| 1841 | // or the right operand. For precise type feedback, patch the IC |
| 1842 | // again if this changes. |
| 1843 | // In theory, we would need the same check in the non-SSE2 case, |
| 1844 | // but since we don't support Crankshaft on such hardware we can |
| 1845 | // afford not to care about precise type feedback. |
| 1846 | if (left_type_ == BinaryOpIC::SMI) { |
| 1847 | __ JumpIfNotSmi(edx, ¬_floats); |
| 1848 | } |
| 1849 | if (right_type_ == BinaryOpIC::SMI) { |
| 1850 | __ JumpIfNotSmi(eax, ¬_floats); |
| 1851 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1852 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1853 | if (left_type_ == BinaryOpIC::INT32) { |
| 1854 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1855 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1856 | } |
| 1857 | if (right_type_ == BinaryOpIC::INT32) { |
| 1858 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1859 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1860 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1861 | |
| 1862 | switch (op_) { |
| 1863 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1864 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1865 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1866 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1867 | default: UNREACHABLE(); |
| 1868 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1869 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1870 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1871 | __ ret(0); |
| 1872 | } else { // SSE2 not available, use FPU. |
| 1873 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1874 | FloatingPointHelper::LoadFloatOperands( |
| 1875 | masm, |
| 1876 | ecx, |
| 1877 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1878 | switch (op_) { |
| 1879 | case Token::ADD: __ faddp(1); break; |
| 1880 | case Token::SUB: __ fsubp(1); break; |
| 1881 | case Token::MUL: __ fmulp(1); break; |
| 1882 | case Token::DIV: __ fdivp(1); break; |
| 1883 | default: UNREACHABLE(); |
| 1884 | } |
| 1885 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1886 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1887 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1888 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1889 | __ ret(0); |
| 1890 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1891 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1892 | __ jmp(&call_runtime); |
| 1893 | } |
| 1894 | |
| 1895 | __ bind(¬_floats); |
| 1896 | GenerateTypeTransition(masm); |
| 1897 | break; |
| 1898 | } |
| 1899 | |
| 1900 | case Token::MOD: { |
| 1901 | // For MOD we go directly to runtime in the non-smi case. |
| 1902 | break; |
| 1903 | } |
| 1904 | case Token::BIT_OR: |
| 1905 | case Token::BIT_AND: |
| 1906 | case Token::BIT_XOR: |
| 1907 | case Token::SAR: |
| 1908 | case Token::SHL: |
| 1909 | case Token::SHR: { |
| 1910 | GenerateRegisterArgsPush(masm); |
| 1911 | Label not_floats; |
| 1912 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1913 | // We do not check the input arguments here, as any value is |
| 1914 | // unconditionally truncated to an int32 anyway. To get the |
| 1915 | // right optimized code, int32 type feedback is just right. |
| 1916 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1917 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1918 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1919 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1920 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1921 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1922 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1923 | case Token::SAR: __ sar_cl(eax); break; |
| 1924 | case Token::SHL: __ shl_cl(eax); break; |
| 1925 | case Token::SHR: __ shr_cl(eax); break; |
| 1926 | default: UNREACHABLE(); |
| 1927 | } |
| 1928 | if (op_ == Token::SHR) { |
| 1929 | // Check if result is non-negative and fits in a smi. |
| 1930 | __ test(eax, Immediate(0xc0000000)); |
| 1931 | __ j(not_zero, &call_runtime); |
| 1932 | } else { |
| 1933 | // Check if result fits in a smi. |
| 1934 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1935 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1936 | } |
| 1937 | // Tag smi result and return. |
| 1938 | __ SmiTag(eax); |
| 1939 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1940 | |
| 1941 | // All ops except SHR return a signed int32 that we load in |
| 1942 | // a HeapNumber. |
| 1943 | if (op_ != Token::SHR) { |
| 1944 | __ bind(&non_smi_result); |
| 1945 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1946 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1947 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1948 | switch (mode_) { |
| 1949 | case OVERWRITE_LEFT: |
| 1950 | case OVERWRITE_RIGHT: |
| 1951 | // If the operand was an object, we skip the |
| 1952 | // allocation of a heap number. |
| 1953 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1954 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1955 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1956 | // Fall through! |
| 1957 | case NO_OVERWRITE: |
| 1958 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1959 | __ bind(&skip_allocation); |
| 1960 | break; |
| 1961 | default: UNREACHABLE(); |
| 1962 | } |
| 1963 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1964 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1965 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1966 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1967 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1968 | } else { |
| 1969 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1970 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1971 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1972 | } |
| 1973 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1974 | } |
| 1975 | |
| 1976 | __ bind(¬_floats); |
| 1977 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1978 | break; |
| 1979 | } |
| 1980 | default: UNREACHABLE(); break; |
| 1981 | } |
| 1982 | |
| 1983 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 1984 | // use the runtime system to get the correct result. |
| 1985 | __ bind(&call_runtime); |
| 1986 | |
| 1987 | switch (op_) { |
| 1988 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1989 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1990 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1991 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1992 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1993 | break; |
| 1994 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1995 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1996 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1997 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1998 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1999 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2000 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2001 | break; |
| 2002 | default: |
| 2003 | UNREACHABLE(); |
| 2004 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2005 | |
| 2006 | { |
| 2007 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2008 | __ push(edx); |
| 2009 | __ push(eax); |
| 2010 | GenerateCallRuntime(masm); |
| 2011 | } |
| 2012 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2016 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2017 | Label call_runtime; |
| 2018 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2019 | Counters* counters = masm->isolate()->counters(); |
| 2020 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2021 | |
| 2022 | switch (op_) { |
| 2023 | case Token::ADD: |
| 2024 | case Token::SUB: |
| 2025 | case Token::MUL: |
| 2026 | case Token::DIV: |
| 2027 | break; |
| 2028 | case Token::MOD: |
| 2029 | case Token::BIT_OR: |
| 2030 | case Token::BIT_AND: |
| 2031 | case Token::BIT_XOR: |
| 2032 | case Token::SAR: |
| 2033 | case Token::SHL: |
| 2034 | case Token::SHR: |
| 2035 | GenerateRegisterArgsPush(masm); |
| 2036 | break; |
| 2037 | default: |
| 2038 | UNREACHABLE(); |
| 2039 | } |
| 2040 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2041 | BinaryOpStub_GenerateSmiCode( |
| 2042 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2043 | |
| 2044 | // Floating point case. |
| 2045 | switch (op_) { |
| 2046 | case Token::ADD: |
| 2047 | case Token::SUB: |
| 2048 | case Token::MUL: |
| 2049 | case Token::DIV: { |
| 2050 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2051 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2052 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2053 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2054 | |
| 2055 | switch (op_) { |
| 2056 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2057 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2058 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2059 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2060 | default: UNREACHABLE(); |
| 2061 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2062 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2063 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2064 | __ ret(0); |
| 2065 | } else { // SSE2 not available, use FPU. |
| 2066 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2067 | FloatingPointHelper::LoadFloatOperands( |
| 2068 | masm, |
| 2069 | ecx, |
| 2070 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2071 | switch (op_) { |
| 2072 | case Token::ADD: __ faddp(1); break; |
| 2073 | case Token::SUB: __ fsubp(1); break; |
| 2074 | case Token::MUL: __ fmulp(1); break; |
| 2075 | case Token::DIV: __ fdivp(1); break; |
| 2076 | default: UNREACHABLE(); |
| 2077 | } |
| 2078 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2079 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2080 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2081 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2082 | __ ret(0); |
| 2083 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2084 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2085 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2086 | } |
| 2087 | __ bind(¬_floats); |
| 2088 | break; |
| 2089 | } |
| 2090 | case Token::MOD: { |
| 2091 | // For MOD we go directly to runtime in the non-smi case. |
| 2092 | break; |
| 2093 | } |
| 2094 | case Token::BIT_OR: |
| 2095 | case Token::BIT_AND: |
| 2096 | case Token::BIT_XOR: |
| 2097 | case Token::SAR: |
| 2098 | case Token::SHL: |
| 2099 | case Token::SHR: { |
| 2100 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2101 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2102 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2103 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2104 | BinaryOpIC::GENERIC, |
| 2105 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2106 | &call_runtime); |
| 2107 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2108 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2109 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2110 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2111 | case Token::SAR: __ sar_cl(eax); break; |
| 2112 | case Token::SHL: __ shl_cl(eax); break; |
| 2113 | case Token::SHR: __ shr_cl(eax); break; |
| 2114 | default: UNREACHABLE(); |
| 2115 | } |
| 2116 | if (op_ == Token::SHR) { |
| 2117 | // Check if result is non-negative and fits in a smi. |
| 2118 | __ test(eax, Immediate(0xc0000000)); |
| 2119 | __ j(not_zero, &call_runtime); |
| 2120 | } else { |
| 2121 | // Check if result fits in a smi. |
| 2122 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2123 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2124 | } |
| 2125 | // Tag smi result and return. |
| 2126 | __ SmiTag(eax); |
| 2127 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2128 | |
| 2129 | // All ops except SHR return a signed int32 that we load in |
| 2130 | // a HeapNumber. |
| 2131 | if (op_ != Token::SHR) { |
| 2132 | __ bind(&non_smi_result); |
| 2133 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2134 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2135 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2136 | switch (mode_) { |
| 2137 | case OVERWRITE_LEFT: |
| 2138 | case OVERWRITE_RIGHT: |
| 2139 | // If the operand was an object, we skip the |
| 2140 | // allocation of a heap number. |
| 2141 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2142 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2143 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2144 | // Fall through! |
| 2145 | case NO_OVERWRITE: |
| 2146 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2147 | __ bind(&skip_allocation); |
| 2148 | break; |
| 2149 | default: UNREACHABLE(); |
| 2150 | } |
| 2151 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2152 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2153 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2154 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2155 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2156 | } else { |
| 2157 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2158 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2159 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2160 | } |
| 2161 | __ ret(2 * kPointerSize); |
| 2162 | } |
| 2163 | break; |
| 2164 | } |
| 2165 | default: UNREACHABLE(); break; |
| 2166 | } |
| 2167 | |
| 2168 | // If all else fails, use the runtime system to get the correct |
| 2169 | // result. |
| 2170 | __ bind(&call_runtime); |
| 2171 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2172 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2173 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2174 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2175 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2176 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2177 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2178 | break; |
| 2179 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2180 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2181 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2182 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2183 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2184 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2185 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2186 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2187 | break; |
| 2188 | default: |
| 2189 | UNREACHABLE(); |
| 2190 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2191 | |
| 2192 | { |
| 2193 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2194 | __ push(edx); |
| 2195 | __ push(eax); |
| 2196 | GenerateCallRuntime(masm); |
| 2197 | } |
| 2198 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2199 | } |
| 2200 | |
| 2201 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2202 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2203 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2204 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2205 | |
| 2206 | // Registers containing left and right operands respectively. |
| 2207 | Register left = edx; |
| 2208 | Register right = eax; |
| 2209 | |
| 2210 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2211 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2212 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2213 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2214 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2215 | StringAddStub string_add_left_stub((StringAddFlags) |
| 2216 | (ERECT_FRAME | NO_STRING_CHECK_LEFT_IN_STUB)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2217 | GenerateRegisterArgsPush(masm); |
| 2218 | __ TailCallStub(&string_add_left_stub); |
| 2219 | |
| 2220 | // Left operand is not a string, test right. |
| 2221 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2222 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2223 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2224 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2225 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2226 | StringAddStub string_add_right_stub((StringAddFlags) |
| 2227 | (ERECT_FRAME | NO_STRING_CHECK_RIGHT_IN_STUB)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2228 | GenerateRegisterArgsPush(masm); |
| 2229 | __ TailCallStub(&string_add_right_stub); |
| 2230 | |
| 2231 | // Neither argument is a string. |
| 2232 | __ bind(&call_runtime); |
| 2233 | } |
| 2234 | |
| 2235 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2236 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2237 | Label* alloc_failure, |
| 2238 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2239 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2240 | switch (mode) { |
| 2241 | case OVERWRITE_LEFT: { |
| 2242 | // If the argument in edx is already an object, we skip the |
| 2243 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2244 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2245 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2246 | // for the possible runtime call. |
| 2247 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2248 | // Now edx can be overwritten losing one of the arguments as we are |
| 2249 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2250 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2251 | __ bind(&skip_allocation); |
| 2252 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2253 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2254 | break; |
| 2255 | } |
| 2256 | case OVERWRITE_RIGHT: |
| 2257 | // If the argument in eax is already an object, we skip the |
| 2258 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2259 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2260 | // Fall through! |
| 2261 | case NO_OVERWRITE: |
| 2262 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2263 | // for the possible runtime call. |
| 2264 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2265 | // Now eax can be overwritten losing one of the arguments as we are |
| 2266 | // now done and will not need it any more. |
| 2267 | __ mov(eax, ebx); |
| 2268 | __ bind(&skip_allocation); |
| 2269 | break; |
| 2270 | default: UNREACHABLE(); |
| 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2275 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2276 | __ pop(ecx); |
| 2277 | __ push(edx); |
| 2278 | __ push(eax); |
| 2279 | __ push(ecx); |
| 2280 | } |
| 2281 | |
| 2282 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2283 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2284 | // TAGGED case: |
| 2285 | // Input: |
| 2286 | // esp[4]: tagged number input argument (should be number). |
| 2287 | // esp[0]: return address. |
| 2288 | // Output: |
| 2289 | // eax: tagged double result. |
| 2290 | // UNTAGGED case: |
| 2291 | // Input:: |
| 2292 | // esp[0]: return address. |
| 2293 | // xmm1: untagged double input argument |
| 2294 | // Output: |
| 2295 | // xmm1: untagged double result. |
| 2296 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2297 | Label runtime_call; |
| 2298 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2299 | Label skip_cache; |
| 2300 | const bool tagged = (argument_type_ == TAGGED); |
| 2301 | if (tagged) { |
| 2302 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2303 | Label input_not_smi; |
| 2304 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2305 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2306 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2307 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2308 | // Then load the low and high words of the double into ebx, edx. |
| 2309 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2310 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2311 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2312 | __ mov(Operand(esp, 0), eax); |
| 2313 | __ fild_s(Operand(esp, 0)); |
| 2314 | __ fst_d(Operand(esp, 0)); |
| 2315 | __ pop(edx); |
| 2316 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2317 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2318 | __ bind(&input_not_smi); |
| 2319 | // Check if input is a HeapNumber. |
| 2320 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2321 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2322 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2323 | __ j(not_equal, &runtime_call); |
| 2324 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2325 | // low and high words into ebx, edx. |
| 2326 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2327 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2328 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2329 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2330 | __ bind(&loaded); |
| 2331 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2332 | CpuFeatureScope scope(masm, SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2333 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2334 | CpuFeatureScope sse4_scope(masm, SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2335 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2336 | } else { |
| 2337 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2338 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2339 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2340 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2344 | // ebx = low 32 bits of double value |
| 2345 | // edx = high 32 bits of double value |
| 2346 | // Compute hash (the shifts are arithmetic): |
| 2347 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2348 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2349 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2350 | __ mov(eax, ecx); |
| 2351 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2352 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2353 | __ mov(eax, ecx); |
| 2354 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2355 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2356 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2357 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2358 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2359 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2360 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2361 | // ebx = low 32 bits of double value. |
| 2362 | // edx = high 32 bits of double value. |
| 2363 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2364 | ExternalReference cache_array = |
| 2365 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2366 | __ mov(eax, Immediate(cache_array)); |
| 2367 | int cache_array_index = |
| 2368 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2369 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2370 | // Eax points to the cache for the type type_. |
| 2371 | // If NULL, the cache hasn't been initialized yet, so go through runtime. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2372 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2373 | __ j(zero, &runtime_call_clear_stack); |
| 2374 | #ifdef DEBUG |
| 2375 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2376 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2377 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2378 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2379 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2380 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2381 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2382 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2383 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2384 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2385 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2386 | } |
| 2387 | #endif |
| 2388 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2389 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2390 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2391 | // Check if cache matches: Double value is stored in uint32_t[2] array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2392 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2393 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2394 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2395 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2396 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2397 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2398 | Counters* counters = masm->isolate()->counters(); |
| 2399 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2400 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2401 | if (tagged) { |
| 2402 | __ fstp(0); |
| 2403 | __ ret(kPointerSize); |
| 2404 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2405 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2406 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2407 | __ Ret(); |
| 2408 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2409 | |
| 2410 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2411 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2412 | // Update cache with new value. |
| 2413 | // We are short on registers, so use no_reg as scratch. |
| 2414 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2415 | if (tagged) { |
| 2416 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2417 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2418 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2419 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2420 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2421 | __ movdbl(Operand(esp, 0), xmm1); |
| 2422 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2423 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2424 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2425 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2426 | __ mov(Operand(ecx, 0), ebx); |
| 2427 | __ mov(Operand(ecx, kIntSize), edx); |
| 2428 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2429 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2430 | if (tagged) { |
| 2431 | __ ret(kPointerSize); |
| 2432 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2433 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2434 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2435 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2436 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2437 | // Skip cache and return answer directly, only in untagged case. |
| 2438 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2439 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2440 | __ movdbl(Operand(esp, 0), xmm1); |
| 2441 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2442 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2443 | __ fstp_d(Operand(esp, 0)); |
| 2444 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2445 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2446 | // We return the value in xmm1 without adding it to the cache, but |
| 2447 | // we cause a scavenging GC so that future allocations will succeed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2448 | { |
| 2449 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2450 | // Allocate an unused object bigger than a HeapNumber. |
| 2451 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2452 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2453 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2454 | __ Ret(); |
| 2455 | } |
| 2456 | |
| 2457 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2458 | if (tagged) { |
| 2459 | __ bind(&runtime_call_clear_stack); |
| 2460 | __ fstp(0); |
| 2461 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2462 | ExternalReference runtime = |
| 2463 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2464 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2465 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2466 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2467 | __ bind(&runtime_call_clear_stack); |
| 2468 | __ bind(&runtime_call); |
| 2469 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2470 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2471 | { |
| 2472 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2473 | __ push(eax); |
| 2474 | __ CallRuntime(RuntimeFunction(), 1); |
| 2475 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2476 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2477 | __ Ret(); |
| 2478 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | |
| 2482 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2483 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2484 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2485 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2486 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2487 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2488 | default: |
| 2489 | UNIMPLEMENTED(); |
| 2490 | return Runtime::kAbort; |
| 2491 | } |
| 2492 | } |
| 2493 | |
| 2494 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2495 | void TranscendentalCacheStub::GenerateOperation( |
| 2496 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2497 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2498 | // Input value is on FP stack, and also in ebx/edx. |
| 2499 | // Input value is possibly in xmm1. |
| 2500 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2501 | if (type == TranscendentalCache::SIN || |
| 2502 | type == TranscendentalCache::COS || |
| 2503 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2504 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2505 | // return NaN for infinities and NaN. They can share all code except |
| 2506 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2507 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2508 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2509 | // work. We must reduce it to the appropriate range. |
| 2510 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2511 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2512 | int supported_exponent_limit = |
| 2513 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2514 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2515 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2516 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2517 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2518 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2519 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2520 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2521 | __ fstp(0); |
| 2522 | // NaN is represented by 0x7ff8000000000000. |
| 2523 | __ push(Immediate(0x7ff80000)); |
| 2524 | __ push(Immediate(0)); |
| 2525 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2526 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2527 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2528 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2529 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2530 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2531 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2532 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2533 | __ fldpi(); |
| 2534 | __ fadd(0); |
| 2535 | __ fld(1); |
| 2536 | // FPU Stack: input, 2*pi, input. |
| 2537 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2538 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2539 | __ fwait(); |
| 2540 | __ fnstsw_ax(); |
| 2541 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2542 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2543 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2544 | __ fnclex(); |
| 2545 | __ bind(&no_exceptions); |
| 2546 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2547 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2548 | // Compute st(0) % st(1) |
| 2549 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2550 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2551 | __ bind(&partial_remainder_loop); |
| 2552 | __ fprem1(); |
| 2553 | __ fwait(); |
| 2554 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2555 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2556 | // If C2 is set, computation only has partial result. Loop to |
| 2557 | // continue computation. |
| 2558 | __ j(not_zero, &partial_remainder_loop); |
| 2559 | } |
| 2560 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2561 | __ fstp(2); |
| 2562 | __ fstp(0); |
| 2563 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2564 | |
| 2565 | // FPU Stack: input % 2*pi |
| 2566 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2567 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2568 | case TranscendentalCache::SIN: |
| 2569 | __ fsin(); |
| 2570 | break; |
| 2571 | case TranscendentalCache::COS: |
| 2572 | __ fcos(); |
| 2573 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2574 | case TranscendentalCache::TAN: |
| 2575 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2576 | // FP register stack. |
| 2577 | __ fptan(); |
| 2578 | __ fstp(0); // Pop FP register stack. |
| 2579 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2580 | default: |
| 2581 | UNREACHABLE(); |
| 2582 | } |
| 2583 | __ bind(&done); |
| 2584 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2585 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2586 | __ fldln2(); |
| 2587 | __ fxch(); |
| 2588 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2589 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2590 | } |
| 2591 | |
| 2592 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2593 | // Input: edx, eax are the left and right objects of a bit op. |
| 2594 | // Output: eax, ecx are left and right integers for a bit op. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2595 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2596 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2597 | MacroAssembler* masm, |
| 2598 | bool use_sse3, |
| 2599 | BinaryOpIC::TypeInfo left_type, |
| 2600 | BinaryOpIC::TypeInfo right_type, |
| 2601 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2602 | // Check float operands. |
| 2603 | Label arg1_is_object, check_undefined_arg1; |
| 2604 | Label arg2_is_object, check_undefined_arg2; |
| 2605 | Label load_arg2, done; |
| 2606 | |
| 2607 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2608 | if (left_type == BinaryOpIC::SMI) { |
| 2609 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2610 | } else { |
| 2611 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2612 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2613 | |
| 2614 | __ SmiUntag(edx); |
| 2615 | __ jmp(&load_arg2); |
| 2616 | |
| 2617 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2618 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2619 | Factory* factory = masm->isolate()->factory(); |
| 2620 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2621 | __ j(not_equal, conversion_failure); |
| 2622 | __ mov(edx, Immediate(0)); |
| 2623 | __ jmp(&load_arg2); |
| 2624 | |
| 2625 | __ bind(&arg1_is_object); |
| 2626 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2627 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2628 | __ j(not_equal, &check_undefined_arg1); |
| 2629 | |
| 2630 | // Get the untagged integer version of the edx heap number in ecx. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2631 | if (left_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2632 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2633 | ConvertHeapNumberToInt32(masm, edx, conversion_failure); |
| 2634 | } else { |
| 2635 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
| 2636 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2637 | __ mov(edx, ecx); |
| 2638 | |
| 2639 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2640 | __ bind(&load_arg2); |
| 2641 | |
| 2642 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2643 | if (right_type == BinaryOpIC::SMI) { |
| 2644 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2645 | } else { |
| 2646 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2647 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2648 | |
| 2649 | __ SmiUntag(eax); |
| 2650 | __ mov(ecx, eax); |
| 2651 | __ jmp(&done); |
| 2652 | |
| 2653 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2654 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2655 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2656 | __ j(not_equal, conversion_failure); |
| 2657 | __ mov(ecx, Immediate(0)); |
| 2658 | __ jmp(&done); |
| 2659 | |
| 2660 | __ bind(&arg2_is_object); |
| 2661 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2662 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2663 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2664 | // Get the untagged integer version of the eax heap number in ecx. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2665 | |
| 2666 | if (right_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2667 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2668 | ConvertHeapNumberToInt32(masm, eax, conversion_failure); |
| 2669 | } else { |
| 2670 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
| 2671 | } |
| 2672 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2673 | __ bind(&done); |
| 2674 | __ mov(eax, edx); |
| 2675 | } |
| 2676 | |
| 2677 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2678 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2679 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2680 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2681 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2682 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2683 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2684 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2685 | |
| 2686 | __ bind(&load_smi); |
| 2687 | __ SmiUntag(number); |
| 2688 | __ push(number); |
| 2689 | __ fild_s(Operand(esp, 0)); |
| 2690 | __ pop(number); |
| 2691 | |
| 2692 | __ bind(&done); |
| 2693 | } |
| 2694 | |
| 2695 | |
| 2696 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2697 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2698 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2699 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2700 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2701 | |
| 2702 | __ bind(&load_eax); |
| 2703 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2704 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2705 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2706 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2707 | |
| 2708 | __ bind(&load_smi_edx); |
| 2709 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2710 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2711 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2712 | __ jmp(&load_eax); |
| 2713 | |
| 2714 | __ bind(&load_smi_eax); |
| 2715 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2716 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2717 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2718 | |
| 2719 | __ bind(&done); |
| 2720 | } |
| 2721 | |
| 2722 | |
| 2723 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2724 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2725 | Label load_smi_edx, load_eax, load_smi_eax, load_float_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2726 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2727 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2728 | Factory* factory = masm->isolate()->factory(); |
| 2729 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2730 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2731 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2732 | __ bind(&load_eax); |
| 2733 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2734 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2735 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2736 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2737 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2738 | __ bind(&load_smi_edx); |
| 2739 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2740 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2741 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2742 | __ jmp(&load_eax); |
| 2743 | __ bind(&load_smi_eax); |
| 2744 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2745 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2746 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2747 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2748 | __ bind(&load_float_eax); |
| 2749 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2750 | __ bind(&done); |
| 2751 | } |
| 2752 | |
| 2753 | |
| 2754 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2755 | Register scratch) { |
| 2756 | const Register left = edx; |
| 2757 | const Register right = eax; |
| 2758 | __ mov(scratch, left); |
| 2759 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2760 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2761 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2762 | |
| 2763 | __ mov(scratch, right); |
| 2764 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2765 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
| 2768 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2769 | void FloatingPointHelper::CheckSSE2OperandsAreInt32(MacroAssembler* masm, |
| 2770 | Label* non_int32, |
| 2771 | Register scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2772 | CheckSSE2OperandIsInt32(masm, non_int32, xmm0, scratch, scratch, xmm2); |
| 2773 | CheckSSE2OperandIsInt32(masm, non_int32, xmm1, scratch, scratch, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
| 2776 | |
| 2777 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2778 | Label* non_int32, |
| 2779 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2780 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2781 | Register scratch, |
| 2782 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2783 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2784 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2785 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2786 | __ movmskps(scratch, xmm_scratch); |
| 2787 | // Two least significant bits should be both set. |
| 2788 | __ not_(scratch); |
| 2789 | __ test(scratch, Immediate(3)); |
| 2790 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
| 2793 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2794 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2795 | Register scratch, |
| 2796 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2797 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2798 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2799 | __ mov(scratch, edx); |
| 2800 | } else { |
| 2801 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2802 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2803 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2804 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2805 | __ bind(&done_load_1); |
| 2806 | |
| 2807 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2808 | __ mov(scratch, eax); |
| 2809 | } else { |
| 2810 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2811 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2812 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2813 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2814 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2815 | |
| 2816 | __ bind(&load_smi_1); |
| 2817 | __ SmiUntag(scratch); |
| 2818 | __ push(scratch); |
| 2819 | __ fild_s(Operand(esp, 0)); |
| 2820 | __ pop(scratch); |
| 2821 | __ jmp(&done_load_1); |
| 2822 | |
| 2823 | __ bind(&load_smi_2); |
| 2824 | __ SmiUntag(scratch); |
| 2825 | __ push(scratch); |
| 2826 | __ fild_s(Operand(esp, 0)); |
| 2827 | __ pop(scratch); |
| 2828 | |
| 2829 | __ bind(&done); |
| 2830 | } |
| 2831 | |
| 2832 | |
| 2833 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2834 | Register scratch) { |
| 2835 | const Register left = edx; |
| 2836 | const Register right = eax; |
| 2837 | __ mov(scratch, left); |
| 2838 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2839 | __ SmiUntag(scratch); |
| 2840 | __ push(scratch); |
| 2841 | __ fild_s(Operand(esp, 0)); |
| 2842 | |
| 2843 | __ mov(scratch, right); |
| 2844 | __ SmiUntag(scratch); |
| 2845 | __ mov(Operand(esp, 0), scratch); |
| 2846 | __ fild_s(Operand(esp, 0)); |
| 2847 | __ pop(scratch); |
| 2848 | } |
| 2849 | |
| 2850 | |
| 2851 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2852 | Label* non_float, |
| 2853 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2854 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2855 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2856 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2857 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2858 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2859 | Factory* factory = masm->isolate()->factory(); |
| 2860 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2861 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2862 | |
| 2863 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2864 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2865 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2866 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2867 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2868 | |
| 2869 | // Fall-through: Both operands are numbers. |
| 2870 | __ bind(&done); |
| 2871 | } |
| 2872 | |
| 2873 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2874 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2875 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2876 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2877 | const Register exponent = eax; |
| 2878 | const Register base = edx; |
| 2879 | const Register scratch = ecx; |
| 2880 | const XMMRegister double_result = xmm3; |
| 2881 | const XMMRegister double_base = xmm2; |
| 2882 | const XMMRegister double_exponent = xmm1; |
| 2883 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2884 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2885 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2886 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2887 | // Save 1 in double_result - we need this several times later on. |
| 2888 | __ mov(scratch, Immediate(1)); |
| 2889 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2890 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2891 | if (exponent_type_ == ON_STACK) { |
| 2892 | Label base_is_smi, unpack_exponent; |
| 2893 | // The exponent and base are supplied as arguments on the stack. |
| 2894 | // This can only happen if the stub is called from non-optimized code. |
| 2895 | // Load input parameters from stack. |
| 2896 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 2897 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 2898 | |
| 2899 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2900 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 2901 | factory->heap_number_map()); |
| 2902 | __ j(not_equal, &call_runtime); |
| 2903 | |
| 2904 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2905 | __ jmp(&unpack_exponent, Label::kNear); |
| 2906 | |
| 2907 | __ bind(&base_is_smi); |
| 2908 | __ SmiUntag(base); |
| 2909 | __ cvtsi2sd(double_base, base); |
| 2910 | |
| 2911 | __ bind(&unpack_exponent); |
| 2912 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2913 | __ SmiUntag(exponent); |
| 2914 | __ jmp(&int_exponent); |
| 2915 | |
| 2916 | __ bind(&exponent_not_smi); |
| 2917 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2918 | factory->heap_number_map()); |
| 2919 | __ j(not_equal, &call_runtime); |
| 2920 | __ movdbl(double_exponent, |
| 2921 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2922 | } else if (exponent_type_ == TAGGED) { |
| 2923 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2924 | __ SmiUntag(exponent); |
| 2925 | __ jmp(&int_exponent); |
| 2926 | |
| 2927 | __ bind(&exponent_not_smi); |
| 2928 | __ movdbl(double_exponent, |
| 2929 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2930 | } |
| 2931 | |
| 2932 | if (exponent_type_ != INTEGER) { |
| 2933 | Label fast_power; |
| 2934 | // Detect integer exponents stored as double. |
| 2935 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 2936 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 2937 | __ cmp(exponent, Immediate(0x80000000u)); |
| 2938 | __ j(equal, &call_runtime); |
| 2939 | __ cvtsi2sd(double_scratch, exponent); |
| 2940 | // Already ruled out NaNs for exponent. |
| 2941 | __ ucomisd(double_exponent, double_scratch); |
| 2942 | __ j(equal, &int_exponent); |
| 2943 | |
| 2944 | if (exponent_type_ == ON_STACK) { |
| 2945 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 2946 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 2947 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 2948 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 2949 | // Test for 0.5. |
| 2950 | // Load double_scratch with 0.5. |
| 2951 | __ mov(scratch, Immediate(0x3F000000u)); |
| 2952 | __ movd(double_scratch, scratch); |
| 2953 | __ cvtss2sd(double_scratch, double_scratch); |
| 2954 | // Already ruled out NaNs for exponent. |
| 2955 | __ ucomisd(double_scratch, double_exponent); |
| 2956 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 2957 | |
| 2958 | // Calculates square root of base. Check for the special case of |
| 2959 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 2960 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2961 | // 9 bits set and the lowest 23 bits cleared. |
| 2962 | __ mov(scratch, 0xFF800000u); |
| 2963 | __ movd(double_scratch, scratch); |
| 2964 | __ cvtss2sd(double_scratch, double_scratch); |
| 2965 | __ ucomisd(double_base, double_scratch); |
| 2966 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2967 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2968 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 2969 | __ j(carry, &continue_sqrt, Label::kNear); |
| 2970 | |
| 2971 | // Set result to Infinity in the special case. |
| 2972 | __ xorps(double_result, double_result); |
| 2973 | __ subsd(double_result, double_scratch); |
| 2974 | __ jmp(&done); |
| 2975 | |
| 2976 | __ bind(&continue_sqrt); |
| 2977 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2978 | __ xorps(double_scratch, double_scratch); |
| 2979 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 2980 | __ sqrtsd(double_result, double_scratch); |
| 2981 | __ jmp(&done); |
| 2982 | |
| 2983 | // Test for -0.5. |
| 2984 | __ bind(¬_plus_half); |
| 2985 | // Load double_exponent with -0.5 by substracting 1. |
| 2986 | __ subsd(double_scratch, double_result); |
| 2987 | // Already ruled out NaNs for exponent. |
| 2988 | __ ucomisd(double_scratch, double_exponent); |
| 2989 | __ j(not_equal, &fast_power, Label::kNear); |
| 2990 | |
| 2991 | // Calculates reciprocal of square root of base. Check for the special |
| 2992 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 2993 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2994 | // 9 bits set and the lowest 23 bits cleared. |
| 2995 | __ mov(scratch, 0xFF800000u); |
| 2996 | __ movd(double_scratch, scratch); |
| 2997 | __ cvtss2sd(double_scratch, double_scratch); |
| 2998 | __ ucomisd(double_base, double_scratch); |
| 2999 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3000 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3001 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3002 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3003 | |
| 3004 | // Set result to 0 in the special case. |
| 3005 | __ xorps(double_result, double_result); |
| 3006 | __ jmp(&done); |
| 3007 | |
| 3008 | __ bind(&continue_rsqrt); |
| 3009 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3010 | __ xorps(double_exponent, double_exponent); |
| 3011 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3012 | __ sqrtsd(double_exponent, double_exponent); |
| 3013 | __ divsd(double_result, double_exponent); |
| 3014 | __ jmp(&done); |
| 3015 | } |
| 3016 | |
| 3017 | // Using FPU instructions to calculate power. |
| 3018 | Label fast_power_failed; |
| 3019 | __ bind(&fast_power); |
| 3020 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3021 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3022 | __ sub(esp, Immediate(kDoubleSize)); |
| 3023 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3024 | __ fld_d(Operand(esp, 0)); // E |
| 3025 | __ movdbl(Operand(esp, 0), double_base); |
| 3026 | __ fld_d(Operand(esp, 0)); // B, E |
| 3027 | |
| 3028 | // Exponent is in st(1) and base is in st(0) |
| 3029 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3030 | // FYL2X calculates st(1) * log2(st(0)) |
| 3031 | __ fyl2x(); // X |
| 3032 | __ fld(0); // X, X |
| 3033 | __ frndint(); // rnd(X), X |
| 3034 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3035 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3036 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3037 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3038 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3039 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3040 | // FSCALE calculates st(0) * 2^st(1) |
| 3041 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3042 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3043 | // Bail out to runtime in case of exceptions in the status word. |
| 3044 | __ fnstsw_ax(); |
| 3045 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3046 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3047 | __ fstp_d(Operand(esp, 0)); |
| 3048 | __ movdbl(double_result, Operand(esp, 0)); |
| 3049 | __ add(esp, Immediate(kDoubleSize)); |
| 3050 | __ jmp(&done); |
| 3051 | |
| 3052 | __ bind(&fast_power_failed); |
| 3053 | __ fninit(); |
| 3054 | __ add(esp, Immediate(kDoubleSize)); |
| 3055 | __ jmp(&call_runtime); |
| 3056 | } |
| 3057 | |
| 3058 | // Calculate power with integer exponent. |
| 3059 | __ bind(&int_exponent); |
| 3060 | const XMMRegister double_scratch2 = double_exponent; |
| 3061 | __ mov(scratch, exponent); // Back up exponent. |
| 3062 | __ movsd(double_scratch, double_base); // Back up base. |
| 3063 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3064 | |
| 3065 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3066 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3067 | __ test(scratch, scratch); |
| 3068 | __ j(positive, &no_neg, Label::kNear); |
| 3069 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3070 | __ bind(&no_neg); |
| 3071 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3072 | __ j(zero, &while_false, Label::kNear); |
| 3073 | __ shr(scratch, 1); |
| 3074 | // Above condition means CF==0 && ZF==0. This means that the |
| 3075 | // bit that has been shifted out is 0 and the result is not 0. |
| 3076 | __ j(above, &while_true, Label::kNear); |
| 3077 | __ movsd(double_result, double_scratch); |
| 3078 | __ j(zero, &while_false, Label::kNear); |
| 3079 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3080 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3081 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3082 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3083 | __ j(above, &while_true, Label::kNear); |
| 3084 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3085 | __ j(not_zero, &while_true); |
| 3086 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3087 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3088 | // scratch has the original value of the exponent - if the exponent is |
| 3089 | // negative, return 1/result. |
| 3090 | __ test(exponent, exponent); |
| 3091 | __ j(positive, &done); |
| 3092 | __ divsd(double_scratch2, double_result); |
| 3093 | __ movsd(double_result, double_scratch2); |
| 3094 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3095 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3096 | __ xorps(double_scratch2, double_scratch2); |
| 3097 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3098 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3099 | // and may not have contained the exponent value in the first place when the |
| 3100 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3101 | __ j(not_equal, &done); |
| 3102 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3103 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3104 | // Returning or bailing out. |
| 3105 | Counters* counters = masm->isolate()->counters(); |
| 3106 | if (exponent_type_ == ON_STACK) { |
| 3107 | // The arguments are still on the stack. |
| 3108 | __ bind(&call_runtime); |
| 3109 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3110 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3111 | // The stub is called from non-optimized code, which expects the result |
| 3112 | // as heap number in exponent. |
| 3113 | __ bind(&done); |
| 3114 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3115 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3116 | __ IncrementCounter(counters->math_pow(), 1); |
| 3117 | __ ret(2 * kPointerSize); |
| 3118 | } else { |
| 3119 | __ bind(&call_runtime); |
| 3120 | { |
| 3121 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3122 | __ PrepareCallCFunction(4, scratch); |
| 3123 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3124 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3125 | __ CallCFunction( |
| 3126 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3127 | } |
| 3128 | // Return value is in st(0) on ia32. |
| 3129 | // Store it into the (fixed) result register. |
| 3130 | __ sub(esp, Immediate(kDoubleSize)); |
| 3131 | __ fstp_d(Operand(esp, 0)); |
| 3132 | __ movdbl(double_result, Operand(esp, 0)); |
| 3133 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3134 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3135 | __ bind(&done); |
| 3136 | __ IncrementCounter(counters->math_pow(), 1); |
| 3137 | __ ret(0); |
| 3138 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3142 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 3143 | // ----------- S t a t e ------------- |
| 3144 | // -- ecx : name |
| 3145 | // -- edx : receiver |
| 3146 | // -- esp[0] : return address |
| 3147 | // ----------------------------------- |
| 3148 | Label miss; |
| 3149 | |
| 3150 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3151 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3152 | __ j(not_equal, &miss); |
| 3153 | } |
| 3154 | |
| 3155 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 3156 | __ bind(&miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3157 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3158 | } |
| 3159 | |
| 3160 | |
| 3161 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 3162 | // ----------- S t a t e ------------- |
| 3163 | // -- ecx : name |
| 3164 | // -- edx : receiver |
| 3165 | // -- esp[0] : return address |
| 3166 | // ----------------------------------- |
| 3167 | Label miss; |
| 3168 | |
| 3169 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3170 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3171 | __ j(not_equal, &miss); |
| 3172 | } |
| 3173 | |
| 3174 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 3175 | support_wrapper_); |
| 3176 | __ bind(&miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3177 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3181 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3182 | // ----------- S t a t e ------------- |
| 3183 | // -- eax : value |
| 3184 | // -- ecx : name |
| 3185 | // -- edx : receiver |
| 3186 | // -- esp[0] : return address |
| 3187 | // ----------------------------------- |
| 3188 | // |
| 3189 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 3190 | // (currently anything except for external arrays which means anything with |
| 3191 | // elements of FixedArray type). Value must be a number, but only smis are |
| 3192 | // accepted as the most common case. |
| 3193 | |
| 3194 | Label miss; |
| 3195 | |
| 3196 | Register receiver = edx; |
| 3197 | Register value = eax; |
| 3198 | Register scratch = ebx; |
| 3199 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3200 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3201 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3202 | __ j(not_equal, &miss); |
| 3203 | } |
| 3204 | |
| 3205 | // Check that the receiver isn't a smi. |
| 3206 | __ JumpIfSmi(receiver, &miss); |
| 3207 | |
| 3208 | // Check that the object is a JS array. |
| 3209 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 3210 | __ j(not_equal, &miss); |
| 3211 | |
| 3212 | // Check that elements are FixedArray. |
| 3213 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 3214 | // fast elements (including COW). |
| 3215 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 3216 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 3217 | __ j(not_equal, &miss); |
| 3218 | |
| 3219 | // Check that the array has fast properties, otherwise the length |
| 3220 | // property might have been redefined. |
| 3221 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 3222 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 3223 | Heap::kHashTableMapRootIndex); |
| 3224 | __ j(equal, &miss); |
| 3225 | |
| 3226 | // Check that value is a smi. |
| 3227 | __ JumpIfNotSmi(value, &miss); |
| 3228 | |
| 3229 | // Prepare tail call to StoreIC_ArrayLength. |
| 3230 | __ pop(scratch); |
| 3231 | __ push(receiver); |
| 3232 | __ push(value); |
| 3233 | __ push(scratch); // return address |
| 3234 | |
| 3235 | ExternalReference ref = |
| 3236 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 3237 | __ TailCallExternalReference(ref, 2, 1); |
| 3238 | |
| 3239 | __ bind(&miss); |
| 3240 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3241 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3245 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3246 | // The key is in edx and the parameter count is in eax. |
| 3247 | |
| 3248 | // The displacement is used for skipping the frame pointer on the |
| 3249 | // stack. It is the offset of the last parameter (if any) relative |
| 3250 | // to the frame pointer. |
| 3251 | static const int kDisplacement = 1 * kPointerSize; |
| 3252 | |
| 3253 | // Check that the key is a smi. |
| 3254 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3255 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3256 | |
| 3257 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3258 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3259 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3260 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3261 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3262 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3263 | |
| 3264 | // Check index against formal parameters count limit passed in |
| 3265 | // through register eax. Use unsigned comparison to get negative |
| 3266 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3267 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3268 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3269 | |
| 3270 | // Read the argument from the stack and return it. |
| 3271 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3272 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3273 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3274 | __ neg(edx); |
| 3275 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3276 | __ ret(0); |
| 3277 | |
| 3278 | // Arguments adaptor case: Check index against actual arguments |
| 3279 | // limit found in the arguments adaptor frame. Use unsigned |
| 3280 | // comparison to get negative check for free. |
| 3281 | __ bind(&adaptor); |
| 3282 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3283 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3284 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3285 | |
| 3286 | // Read the argument from the stack and return it. |
| 3287 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3288 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3289 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3290 | __ neg(edx); |
| 3291 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3292 | __ ret(0); |
| 3293 | |
| 3294 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3295 | // by calling the runtime system. |
| 3296 | __ bind(&slow); |
| 3297 | __ pop(ebx); // Return address. |
| 3298 | __ push(edx); |
| 3299 | __ push(ebx); |
| 3300 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3301 | } |
| 3302 | |
| 3303 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3304 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3305 | // esp[0] : return address |
| 3306 | // esp[4] : number of parameters |
| 3307 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3308 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3309 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3310 | // Check if the calling frame is an arguments adaptor frame. |
| 3311 | Label runtime; |
| 3312 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3313 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3314 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3315 | __ j(not_equal, &runtime, Label::kNear); |
| 3316 | |
| 3317 | // Patch the arguments.length and the parameters pointer. |
| 3318 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3319 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3320 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3321 | StandardFrameConstants::kCallerSPOffset)); |
| 3322 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3323 | |
| 3324 | __ bind(&runtime); |
| 3325 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3326 | } |
| 3327 | |
| 3328 | |
| 3329 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3330 | // esp[0] : return address |
| 3331 | // esp[4] : number of parameters (tagged) |
| 3332 | // esp[8] : receiver displacement |
| 3333 | // esp[12] : function |
| 3334 | |
| 3335 | // ebx = parameter count (tagged) |
| 3336 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3337 | |
| 3338 | // Check if the calling frame is an arguments adaptor frame. |
| 3339 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3340 | // Generate* functions. |
| 3341 | Label runtime; |
| 3342 | Label adaptor_frame, try_allocate; |
| 3343 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3344 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3345 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3346 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3347 | |
| 3348 | // No adaptor, parameter count = argument count. |
| 3349 | __ mov(ecx, ebx); |
| 3350 | __ jmp(&try_allocate, Label::kNear); |
| 3351 | |
| 3352 | // We have an adaptor frame. Patch the parameters pointer. |
| 3353 | __ bind(&adaptor_frame); |
| 3354 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3355 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3356 | StandardFrameConstants::kCallerSPOffset)); |
| 3357 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3358 | |
| 3359 | // ebx = parameter count (tagged) |
| 3360 | // ecx = argument count (tagged) |
| 3361 | // esp[4] = parameter count (tagged) |
| 3362 | // esp[8] = address of receiver argument |
| 3363 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3364 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3365 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3366 | __ mov(ebx, ecx); |
| 3367 | |
| 3368 | __ bind(&try_allocate); |
| 3369 | |
| 3370 | // Save mapped parameter count. |
| 3371 | __ push(ebx); |
| 3372 | |
| 3373 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3374 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3375 | const int kParameterMapHeaderSize = |
| 3376 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3377 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3378 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3379 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3380 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3381 | __ bind(&no_parameter_map); |
| 3382 | |
| 3383 | // 2. Backing store. |
| 3384 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3385 | |
| 3386 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3387 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3388 | |
| 3389 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3390 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3391 | |
| 3392 | // eax = address of new object(s) (tagged) |
| 3393 | // ecx = argument count (tagged) |
| 3394 | // esp[0] = mapped parameter count (tagged) |
| 3395 | // esp[8] = parameter count (tagged) |
| 3396 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3397 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3398 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3399 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3400 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3401 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3402 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3403 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3404 | __ mov(edi, Operand(edi, |
| 3405 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3406 | __ jmp(©, Label::kNear); |
| 3407 | |
| 3408 | __ bind(&has_mapped_parameters); |
| 3409 | __ mov(edi, Operand(edi, |
| 3410 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3411 | __ bind(©); |
| 3412 | |
| 3413 | // eax = address of new object (tagged) |
| 3414 | // ebx = mapped parameter count (tagged) |
| 3415 | // ecx = argument count (tagged) |
| 3416 | // edi = address of boilerplate object (tagged) |
| 3417 | // esp[0] = mapped parameter count (tagged) |
| 3418 | // esp[8] = parameter count (tagged) |
| 3419 | // esp[12] = address of receiver argument |
| 3420 | // Copy the JS object part. |
| 3421 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3422 | __ mov(edx, FieldOperand(edi, i)); |
| 3423 | __ mov(FieldOperand(eax, i), edx); |
| 3424 | } |
| 3425 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3426 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3427 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3428 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3429 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3430 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3431 | edx); |
| 3432 | |
| 3433 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3434 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3435 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3436 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3437 | ecx); |
| 3438 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3439 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3440 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3441 | // backing store. |
| 3442 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3443 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3444 | |
| 3445 | // eax = address of new object (tagged) |
| 3446 | // ebx = mapped parameter count (tagged) |
| 3447 | // ecx = argument count (tagged) |
| 3448 | // edi = address of parameter map or backing store (tagged) |
| 3449 | // esp[0] = mapped parameter count (tagged) |
| 3450 | // esp[8] = parameter count (tagged) |
| 3451 | // esp[12] = address of receiver argument |
| 3452 | // Free a register. |
| 3453 | __ push(eax); |
| 3454 | |
| 3455 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3456 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3457 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3458 | __ j(zero, &skip_parameter_map); |
| 3459 | |
| 3460 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3461 | Immediate(FACTORY->non_strict_arguments_elements_map())); |
| 3462 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3463 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3464 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3465 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3466 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3467 | |
| 3468 | // Copy the parameter slots and the holes in the arguments. |
| 3469 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3470 | // where parameters are stored in reverse order, at |
| 3471 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3472 | // The mapped parameter thus need to get indices |
| 3473 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3474 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3475 | // We loop from right to left. |
| 3476 | Label parameters_loop, parameters_test; |
| 3477 | __ push(ecx); |
| 3478 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3479 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3480 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3481 | __ sub(ebx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3482 | __ mov(ecx, FACTORY->the_hole_value()); |
| 3483 | __ mov(edx, edi); |
| 3484 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3485 | // eax = loop variable (tagged) |
| 3486 | // ebx = mapping index (tagged) |
| 3487 | // ecx = the hole value |
| 3488 | // edx = address of parameter map (tagged) |
| 3489 | // edi = address of backing store (tagged) |
| 3490 | // esp[0] = argument count (tagged) |
| 3491 | // esp[4] = address of new object (tagged) |
| 3492 | // esp[8] = mapped parameter count (tagged) |
| 3493 | // esp[16] = parameter count (tagged) |
| 3494 | // esp[20] = address of receiver argument |
| 3495 | __ jmp(¶meters_test, Label::kNear); |
| 3496 | |
| 3497 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3498 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3499 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3500 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3501 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3502 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3503 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3504 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3505 | __ pop(ecx); |
| 3506 | |
| 3507 | __ bind(&skip_parameter_map); |
| 3508 | |
| 3509 | // ecx = argument count (tagged) |
| 3510 | // edi = address of backing store (tagged) |
| 3511 | // esp[0] = address of new object (tagged) |
| 3512 | // esp[4] = mapped parameter count (tagged) |
| 3513 | // esp[12] = parameter count (tagged) |
| 3514 | // esp[16] = address of receiver argument |
| 3515 | // Copy arguments header and remaining slots (if there are any). |
| 3516 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
| 3517 | Immediate(FACTORY->fixed_array_map())); |
| 3518 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3519 | |
| 3520 | Label arguments_loop, arguments_test; |
| 3521 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3522 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3523 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3524 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3525 | __ jmp(&arguments_test, Label::kNear); |
| 3526 | |
| 3527 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3528 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3529 | __ mov(eax, Operand(edx, 0)); |
| 3530 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3531 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3532 | |
| 3533 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3534 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3535 | __ j(less, &arguments_loop, Label::kNear); |
| 3536 | |
| 3537 | // Restore. |
| 3538 | __ pop(eax); // Address of arguments object. |
| 3539 | __ pop(ebx); // Parameter count. |
| 3540 | |
| 3541 | // Return and remove the on-stack parameters. |
| 3542 | __ ret(3 * kPointerSize); |
| 3543 | |
| 3544 | // Do the runtime call to allocate the arguments object. |
| 3545 | __ bind(&runtime); |
| 3546 | __ pop(eax); // Remove saved parameter count. |
| 3547 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3548 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3549 | } |
| 3550 | |
| 3551 | |
| 3552 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 3553 | // esp[0] : return address |
| 3554 | // esp[4] : number of parameters |
| 3555 | // esp[8] : receiver displacement |
| 3556 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3557 | |
| 3558 | // Check if the calling frame is an arguments adaptor frame. |
| 3559 | Label adaptor_frame, try_allocate, runtime; |
| 3560 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3561 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3562 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3563 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3564 | |
| 3565 | // Get the length from the frame. |
| 3566 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3567 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3568 | |
| 3569 | // Patch the arguments.length and the parameters pointer. |
| 3570 | __ bind(&adaptor_frame); |
| 3571 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3572 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3573 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3574 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3575 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3576 | |
| 3577 | // Try the new space allocation. Start out with computing the size of |
| 3578 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3579 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3580 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3581 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3582 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3583 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3584 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3585 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3586 | |
| 3587 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3588 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3589 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3590 | // Get the arguments boilerplate from the current native context. |
| 3591 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3592 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3593 | const int offset = |
| 3594 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3595 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3596 | |
| 3597 | // Copy the JS object part. |
| 3598 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3599 | __ mov(ebx, FieldOperand(edi, i)); |
| 3600 | __ mov(FieldOperand(eax, i), ebx); |
| 3601 | } |
| 3602 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3603 | // Get the length (smi tagged) and set that as an in-object property too. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3604 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3605 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3606 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3607 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3608 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3609 | |
| 3610 | // If there are no actual arguments, we're done. |
| 3611 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3612 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3613 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3614 | |
| 3615 | // Get the parameters pointer from the stack. |
| 3616 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3617 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3618 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3619 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3620 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3621 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3622 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3623 | Immediate(FACTORY->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3624 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3625 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3626 | // Untag the length for the loop below. |
| 3627 | __ SmiUntag(ecx); |
| 3628 | |
| 3629 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3630 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3631 | __ bind(&loop); |
| 3632 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3633 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3634 | __ add(edi, Immediate(kPointerSize)); |
| 3635 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3636 | __ dec(ecx); |
| 3637 | __ j(not_zero, &loop); |
| 3638 | |
| 3639 | // Return and remove the on-stack parameters. |
| 3640 | __ bind(&done); |
| 3641 | __ ret(3 * kPointerSize); |
| 3642 | |
| 3643 | // Do the runtime call to allocate the arguments object. |
| 3644 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3645 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | |
| 3649 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3650 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3651 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3652 | // at compilation. |
| 3653 | #ifdef V8_INTERPRETED_REGEXP |
| 3654 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3655 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3656 | |
| 3657 | // Stack frame on entry. |
| 3658 | // esp[0]: return address |
| 3659 | // esp[4]: last_match_info (expected JSArray) |
| 3660 | // esp[8]: previous index |
| 3661 | // esp[12]: subject string |
| 3662 | // esp[16]: JSRegExp object |
| 3663 | |
| 3664 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3665 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3666 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3667 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3668 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3669 | Label runtime; |
| 3670 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3671 | |
| 3672 | // Ensure that a RegExp stack is allocated. |
| 3673 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3674 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3675 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3676 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3677 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3678 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3679 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3680 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3681 | |
| 3682 | // Check that the first argument is a JSRegExp object. |
| 3683 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3684 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3685 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3686 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3687 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3688 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3689 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3690 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3691 | if (FLAG_debug_code) { |
| 3692 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3693 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3694 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3695 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3696 | } |
| 3697 | |
| 3698 | // ecx: RegExp data (FixedArray) |
| 3699 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3700 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3701 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3702 | __ j(not_equal, &runtime); |
| 3703 | |
| 3704 | // ecx: RegExp data (FixedArray) |
| 3705 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3706 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3707 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3708 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3709 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3710 | STATIC_ASSERT(kSmiTag == 0); |
| 3711 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3712 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3713 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3714 | __ j(above, &runtime); |
| 3715 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3716 | // Reset offset for possibly sliced string. |
| 3717 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3718 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3719 | __ JumpIfSmi(eax, &runtime); |
| 3720 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3721 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3722 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3723 | |
| 3724 | // eax: subject string |
| 3725 | // edx: subject string |
| 3726 | // ebx: subject string instance type |
| 3727 | // ecx: RegExp data (FixedArray) |
| 3728 | // Handle subject string according to its encoding and representation: |
| 3729 | // (1) Sequential two byte? If yes, go to (9). |
| 3730 | // (2) Sequential one byte? If yes, go to (6). |
| 3731 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3732 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3733 | // Otherwise bailout. |
| 3734 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3735 | // (5b) Is subject external? If yes, go to (8). |
| 3736 | // (6) One byte sequential. Load regexp code for one byte. |
| 3737 | // (E) Carry on. |
| 3738 | /// [...] |
| 3739 | |
| 3740 | // Deferred code at the end of the stub: |
| 3741 | // (7) Not a long external string? If yes, go to (10). |
| 3742 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3743 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3744 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3745 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3746 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3747 | |
| 3748 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3749 | external_string /* 8 */, check_underlying /* 5a */, |
| 3750 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3751 | not_long_external /* 10 */; |
| 3752 | |
| 3753 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3754 | __ and_(ebx, kIsNotStringMask | |
| 3755 | kStringRepresentationMask | |
| 3756 | kStringEncodingMask | |
| 3757 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3758 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3759 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3760 | |
| 3761 | // (2) Sequential one byte? If yes, go to (6). |
| 3762 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3763 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3764 | kStringRepresentationMask | |
| 3765 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3766 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3767 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3768 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3769 | // We check whether the subject string is a cons, since sequential strings |
| 3770 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3771 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3772 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3773 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3774 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3775 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3776 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3777 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3778 | // (4) Cons string. Check that it's flat. |
| 3779 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3780 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3781 | __ j(not_equal, &runtime); |
| 3782 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3783 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3784 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3785 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3786 | |
| 3787 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3788 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3789 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3790 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3791 | // (5b) Is subject external? If yes, go to (8). |
| 3792 | __ test_b(ebx, kStringRepresentationMask); |
| 3793 | // The underlying external string is never a short external string. |
| 3794 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3795 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3796 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3797 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3798 | // eax: sequential subject string (or look-alike, external string) |
| 3799 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3800 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3801 | // (6) One byte sequential. Load regexp code for one byte. |
| 3802 | __ bind(&seq_one_byte_string); |
| 3803 | // Load previous index and check range before edx is overwritten. We have |
| 3804 | // to use edx instead of eax here because it might have been only made to |
| 3805 | // look like a sequential string when it actually is an external string. |
| 3806 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3807 | __ JumpIfNotSmi(ebx, &runtime); |
| 3808 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3809 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3810 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3811 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3812 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3813 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3814 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3815 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3816 | // Check that the irregexp code has been generated for the actual string |
| 3817 | // encoding. If it has, the field contains a code object otherwise it contains |
jkummerow@chromium.org | ddda9e8 | 2011-07-06 11:27:02 +0000 | [diff] [blame] | 3818 | // a smi (code flushing support). |
| 3819 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3820 | |
| 3821 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3822 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3823 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3824 | // ecx: encoding of subject string (1 if ASCII, 0 if two_byte); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3825 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3826 | Counters* counters = masm->isolate()->counters(); |
| 3827 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3828 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3829 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3830 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3831 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3832 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3833 | // Argument 9: Pass current isolate address. |
| 3834 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3835 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3836 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3837 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3838 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3839 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3840 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3841 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3842 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3843 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3844 | |
| 3845 | // Argument 6: Set the number of capture registers to zero to force global |
| 3846 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3847 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3848 | |
| 3849 | // Argument 5: static offsets vector buffer. |
| 3850 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3851 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3852 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3853 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3854 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3855 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3856 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3857 | |
| 3858 | // Argument 1: Original subject string. |
| 3859 | // The original subject is in the previous stack frame. Therefore we have to |
| 3860 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3861 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3862 | // and thereby moves up esp by one kPointerSize.) |
| 3863 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3864 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3865 | |
| 3866 | // esi: original subject string |
| 3867 | // eax: underlying subject string |
| 3868 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3869 | // ecx: encoding of subject string (1 if ASCII 0 if two_byte); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3870 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3871 | // Argument 4: End of string data |
| 3872 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3873 | // Prepare start and end index of the input. |
| 3874 | // Load the length from the original sliced string if that is the case. |
| 3875 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3876 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3877 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3878 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3879 | |
| 3880 | // ebx: start index of the input string |
| 3881 | // esi: end index of the input string |
| 3882 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3883 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3884 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3885 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3886 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3887 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3888 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3889 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3890 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3891 | |
| 3892 | __ bind(&setup_two_byte); |
| 3893 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3894 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3895 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3896 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3897 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3898 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3899 | |
| 3900 | __ bind(&setup_rest); |
| 3901 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3902 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3903 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3904 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3905 | |
| 3906 | // Drop arguments and come back to JS mode. |
| 3907 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3908 | |
| 3909 | // Check the result. |
| 3910 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3911 | __ cmp(eax, 1); |
| 3912 | // We expect exactly one result since we force the called regexp to behave |
| 3913 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3914 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3915 | Label failure; |
| 3916 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3917 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3918 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3919 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3920 | __ j(not_equal, &runtime); |
| 3921 | // Result must now be exception. If there is no pending exception already a |
| 3922 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3923 | // haven't created the exception yet. Handle that in the runtime system. |
| 3924 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3925 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3926 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3927 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3928 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3929 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3930 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3931 | // For exception, throw the exception again. |
| 3932 | |
| 3933 | // Clear the pending exception variable. |
| 3934 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3935 | |
| 3936 | // Special handling of termination exceptions which are uncatchable |
| 3937 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3938 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3939 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3940 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3941 | |
| 3942 | // Handle normal exception by following handler chain. |
| 3943 | __ Throw(eax); |
| 3944 | |
| 3945 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3946 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3947 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3948 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3949 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3950 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3951 | __ ret(4 * kPointerSize); |
| 3952 | |
| 3953 | // Load RegExp data. |
| 3954 | __ bind(&success); |
| 3955 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3956 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3957 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3958 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3959 | STATIC_ASSERT(kSmiTag == 0); |
| 3960 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3961 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3962 | |
| 3963 | // edx: Number of capture registers |
| 3964 | // Load last_match_info which is still known to be a fast case JSArray. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3965 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3966 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3967 | __ JumpIfSmi(eax, &runtime); |
| 3968 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3969 | __ j(not_equal, &runtime); |
| 3970 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3971 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3972 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 3973 | __ cmp(eax, factory->fixed_array_map()); |
| 3974 | __ j(not_equal, &runtime); |
| 3975 | // Check that the last match info has space for the capture registers and the |
| 3976 | // additional information. |
| 3977 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3978 | __ SmiUntag(eax); |
| 3979 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3980 | __ cmp(edx, eax); |
| 3981 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3982 | |
| 3983 | // ebx: last_match_info backing store (FixedArray) |
| 3984 | // edx: number of capture registers |
| 3985 | // Store the capture count. |
| 3986 | __ SmiTag(edx); // Number of capture registers to smi. |
| 3987 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 3988 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 3989 | // Store last subject and last input. |
| 3990 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3991 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3992 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3993 | __ RecordWriteField(ebx, |
| 3994 | RegExpImpl::kLastSubjectOffset, |
| 3995 | eax, |
| 3996 | edi, |
| 3997 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3998 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3999 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4000 | __ RecordWriteField(ebx, |
| 4001 | RegExpImpl::kLastInputOffset, |
| 4002 | eax, |
| 4003 | edi, |
| 4004 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4005 | |
| 4006 | // Get the static offsets vector filled by the native regexp code. |
| 4007 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4008 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4009 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 4010 | |
| 4011 | // ebx: last_match_info backing store (FixedArray) |
| 4012 | // ecx: offsets vector |
| 4013 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4014 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4015 | // Capture register counter starts from number of capture registers and |
| 4016 | // counts down until wraping after zero. |
| 4017 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4018 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4019 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4020 | // Read the value from the static offsets vector buffer. |
| 4021 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 4022 | __ SmiTag(edi); |
| 4023 | // Store the smi value in the last match info. |
| 4024 | __ mov(FieldOperand(ebx, |
| 4025 | edx, |
| 4026 | times_pointer_size, |
| 4027 | RegExpImpl::kFirstCaptureOffset), |
| 4028 | edi); |
| 4029 | __ jmp(&next_capture); |
| 4030 | __ bind(&done); |
| 4031 | |
| 4032 | // Return last match info. |
| 4033 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4034 | __ ret(4 * kPointerSize); |
| 4035 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4036 | // Do the runtime call to execute the regexp. |
| 4037 | __ bind(&runtime); |
| 4038 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4039 | |
| 4040 | // Deferred code for string handling. |
| 4041 | // (7) Not a long external string? If yes, go to (10). |
| 4042 | __ bind(¬_seq_nor_cons); |
| 4043 | // Compare flags are still set from (3). |
| 4044 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 4045 | |
| 4046 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4047 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4048 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4049 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4050 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4051 | if (FLAG_debug_code) { |
| 4052 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4053 | // Sequential strings have already been ruled out. |
| 4054 | __ test_b(ebx, kIsIndirectStringMask); |
| 4055 | __ Assert(zero, "external string expected, but not found"); |
| 4056 | } |
| 4057 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4058 | // Move the pointer so that offset-wise, it looks like a sequential string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4059 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4060 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4061 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4062 | // (8a) Is the external string one byte? If yes, go to (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4063 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4064 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4065 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4066 | // eax: sequential subject string (or look-alike, external string) |
| 4067 | // edx: original subject string |
| 4068 | // ecx: RegExp data (FixedArray) |
| 4069 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 4070 | __ bind(&seq_two_byte_string); |
| 4071 | // Load previous index and check range before edx is overwritten. We have |
| 4072 | // to use edx instead of eax here because it might have been only made to |
| 4073 | // look like a sequential string when it actually is an external string. |
| 4074 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 4075 | __ JumpIfNotSmi(ebx, &runtime); |
| 4076 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 4077 | __ j(above_equal, &runtime); |
| 4078 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 4079 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 4080 | __ jmp(&check_code); // Go to (E). |
| 4081 | |
| 4082 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 4083 | __ bind(¬_long_external); |
| 4084 | // Catch non-string subject or short external string. |
| 4085 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 4086 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 4087 | __ j(not_zero, &runtime); |
| 4088 | |
| 4089 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 4090 | // Load offset into edi and replace subject string with parent. |
| 4091 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 4092 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 4093 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4094 | #endif // V8_INTERPRETED_REGEXP |
| 4095 | } |
| 4096 | |
| 4097 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4098 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4099 | const int kMaxInlineLength = 100; |
| 4100 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4101 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4102 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4103 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4104 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4105 | __ j(above, &slowcase); |
| 4106 | // Smi-tagging is equivalent to multiplying by 2. |
| 4107 | STATIC_ASSERT(kSmiTag == 0); |
| 4108 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4109 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4110 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4111 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4112 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 4113 | times_pointer_size, |
| 4114 | ebx, // In: Number of elements as a smi |
| 4115 | REGISTER_VALUE_IS_SMI, |
| 4116 | eax, // Out: Start of allocation (tagged). |
| 4117 | ecx, // Out: End of allocation. |
| 4118 | edx, // Scratch register |
| 4119 | &slowcase, |
| 4120 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4121 | // eax: Start of allocated area, object-tagged. |
| 4122 | |
| 4123 | // Set JSArray map to global.regexp_result_map(). |
| 4124 | // Set empty properties FixedArray. |
| 4125 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4126 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4127 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4128 | Factory* factory = masm->isolate()->factory(); |
| 4129 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4130 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4131 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4132 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4133 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4134 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4135 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4136 | |
| 4137 | // Set input, index and length fields from arguments. |
| 4138 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4139 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4140 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4141 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4142 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4143 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4144 | |
| 4145 | // Fill out the elements FixedArray. |
| 4146 | // eax: JSArray. |
| 4147 | // ebx: FixedArray. |
| 4148 | // ecx: Number of elements in array, as smi. |
| 4149 | |
| 4150 | // Set map. |
| 4151 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4152 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4153 | // Set length. |
| 4154 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4155 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4156 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4157 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4158 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4159 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4160 | // eax: JSArray. |
| 4161 | // ecx: Number of elements to fill. |
| 4162 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4163 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4164 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4165 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4166 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4167 | __ j(less_equal, &done, Label::kNear); // Jump if ecx is negative or zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4168 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4169 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4170 | __ jmp(&loop); |
| 4171 | |
| 4172 | __ bind(&done); |
| 4173 | __ ret(3 * kPointerSize); |
| 4174 | |
| 4175 | __ bind(&slowcase); |
| 4176 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4177 | } |
| 4178 | |
| 4179 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4180 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4181 | Register object, |
| 4182 | Register result, |
| 4183 | Register scratch1, |
| 4184 | Register scratch2, |
| 4185 | bool object_is_smi, |
| 4186 | Label* not_found) { |
| 4187 | // Use of registers. Register result is used as a temporary. |
| 4188 | Register number_string_cache = result; |
| 4189 | Register mask = scratch1; |
| 4190 | Register scratch = scratch2; |
| 4191 | |
| 4192 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4193 | ExternalReference roots_array_start = |
| 4194 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4195 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4196 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4197 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4198 | // Make the hash mask from the length of the number string cache. It |
| 4199 | // contains two elements (number and string) for each cache entry. |
| 4200 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4201 | __ shr(mask, kSmiTagSize + 1); // Untag length and divide it by two. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4202 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4203 | |
| 4204 | // Calculate the entry in the number string cache. The hash value in the |
| 4205 | // number string cache for smis is just the smi value, and the hash for |
| 4206 | // doubles is the xor of the upper and lower words. See |
| 4207 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4208 | Label smi_hash_calculated; |
| 4209 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4210 | if (object_is_smi) { |
| 4211 | __ mov(scratch, object); |
| 4212 | __ SmiUntag(scratch); |
| 4213 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4214 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4215 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4216 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4217 | __ mov(scratch, object); |
| 4218 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4219 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4220 | __ bind(¬_smi); |
| 4221 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4222 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4223 | __ j(not_equal, not_found); |
| 4224 | STATIC_ASSERT(8 == kDoubleSize); |
| 4225 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4226 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4227 | // Object is heap number and hash is now in scratch. Calculate cache index. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4228 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4229 | Register index = scratch; |
| 4230 | Register probe = mask; |
| 4231 | __ mov(probe, |
| 4232 | FieldOperand(number_string_cache, |
| 4233 | index, |
| 4234 | times_twice_pointer_size, |
| 4235 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4236 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4237 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4238 | CpuFeatureScope fscope(masm, SSE2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4239 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4240 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4241 | __ ucomisd(xmm0, xmm1); |
| 4242 | } else { |
| 4243 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4244 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4245 | __ FCmp(); |
| 4246 | } |
| 4247 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4248 | __ j(not_equal, not_found); // The cache did not contain this value. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4249 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | __ bind(&smi_hash_calculated); |
| 4253 | // Object is smi and hash is now in scratch. Calculate cache index. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4254 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4255 | Register index = scratch; |
| 4256 | // Check if the entry is the smi we are looking for. |
| 4257 | __ cmp(object, |
| 4258 | FieldOperand(number_string_cache, |
| 4259 | index, |
| 4260 | times_twice_pointer_size, |
| 4261 | FixedArray::kHeaderSize)); |
| 4262 | __ j(not_equal, not_found); |
| 4263 | |
| 4264 | // Get the result from the cache. |
| 4265 | __ bind(&load_result_from_cache); |
| 4266 | __ mov(result, |
| 4267 | FieldOperand(number_string_cache, |
| 4268 | index, |
| 4269 | times_twice_pointer_size, |
| 4270 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4271 | Counters* counters = masm->isolate()->counters(); |
| 4272 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4273 | } |
| 4274 | |
| 4275 | |
| 4276 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4277 | Label runtime; |
| 4278 | |
| 4279 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4280 | |
| 4281 | // Generate code to lookup number in the number string cache. |
| 4282 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4283 | __ ret(1 * kPointerSize); |
| 4284 | |
| 4285 | __ bind(&runtime); |
| 4286 | // Handle number to string in the runtime system if not found in the cache. |
| 4287 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4288 | } |
| 4289 | |
| 4290 | |
| 4291 | static int NegativeComparisonResult(Condition cc) { |
| 4292 | ASSERT(cc != equal); |
| 4293 | ASSERT((cc == less) || (cc == less_equal) |
| 4294 | || (cc == greater) || (cc == greater_equal)); |
| 4295 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4296 | } |
| 4297 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4298 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4299 | static void CheckInputType(MacroAssembler* masm, |
| 4300 | Register input, |
| 4301 | CompareIC::State expected, |
| 4302 | Label* fail) { |
| 4303 | Label ok; |
| 4304 | if (expected == CompareIC::SMI) { |
| 4305 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4306 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4307 | __ JumpIfSmi(input, &ok); |
| 4308 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4309 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4310 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4311 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4312 | // We could be strict about internalized/non-internalized here, but as long as |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4313 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4314 | __ bind(&ok); |
| 4315 | } |
| 4316 | |
| 4317 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4318 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 4319 | Label* label, |
| 4320 | Register object, |
| 4321 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4322 | __ JumpIfSmi(object, label); |
| 4323 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4324 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4325 | __ and_(scratch, kIsInternalizedMask | kIsNotStringMask); |
| 4326 | __ cmp(scratch, kInternalizedTag | kStringTag); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4327 | __ j(not_equal, label); |
| 4328 | } |
| 4329 | |
| 4330 | |
| 4331 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4332 | Label check_unequal_objects; |
| 4333 | Condition cc = GetCondition(); |
| 4334 | |
| 4335 | Label miss; |
| 4336 | CheckInputType(masm, edx, left_, &miss); |
| 4337 | CheckInputType(masm, eax, right_, &miss); |
| 4338 | |
| 4339 | // Compare two smis. |
| 4340 | Label non_smi, smi_done; |
| 4341 | __ mov(ecx, edx); |
| 4342 | __ or_(ecx, eax); |
| 4343 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4344 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4345 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4346 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4347 | __ bind(&smi_done); |
| 4348 | __ mov(eax, edx); |
| 4349 | __ ret(0); |
| 4350 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4351 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4352 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4353 | // it is certain that at least one operand isn't a smi. |
| 4354 | |
| 4355 | // Identical objects can be compared fast, but there are some tricky cases |
| 4356 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4357 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4358 | { |
| 4359 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4360 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4361 | __ j(not_equal, ¬_identical); |
| 4362 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4363 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4364 | // Check for undefined. undefined OP undefined is false even though |
| 4365 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4366 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4367 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4368 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4369 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4370 | __ ret(0); |
| 4371 | __ bind(&check_for_nan); |
| 4372 | } |
| 4373 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4374 | // Test for NaN. Compare heap numbers in a general way, |
| 4375 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4376 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4377 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4378 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4379 | if (cc != equal) { |
| 4380 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4381 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4382 | __ j(above_equal, ¬_identical); |
| 4383 | } |
| 4384 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4385 | __ ret(0); |
| 4386 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4387 | |
| 4388 | __ bind(¬_identical); |
| 4389 | } |
| 4390 | |
| 4391 | // Strict equality can quickly decide whether objects are equal. |
| 4392 | // Non-strict object equality is slower, so it is handled later in the stub. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4393 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4394 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4395 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4396 | // If we're doing a strict equality comparison, we don't have to do |
| 4397 | // type conversion, so we generate code to do fast comparison for objects |
| 4398 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4399 | // slow-case code. |
| 4400 | // If either is a Smi (we know that not both are), then they can only |
| 4401 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4402 | STATIC_ASSERT(kSmiTag == 0); |
| 4403 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4404 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4405 | __ and_(ecx, eax); |
| 4406 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4407 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4408 | // One operand is a smi. |
| 4409 | |
| 4410 | // Check whether the non-smi is a heap number. |
| 4411 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4412 | // ecx still holds eax & kSmiTag, which is either zero or one. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4413 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4414 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4415 | __ xor_(ebx, eax); |
| 4416 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4417 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4418 | // if eax was smi, ebx is now edx, else eax. |
| 4419 | |
| 4420 | // Check if the non-smi operand is a heap number. |
| 4421 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4422 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4423 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4424 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4425 | // Return non-equal (ebx is not zero) |
| 4426 | __ mov(eax, ebx); |
| 4427 | __ ret(0); |
| 4428 | |
| 4429 | __ bind(¬_smis); |
| 4430 | // If either operand is a JSObject or an oddball value, then they are not |
| 4431 | // equal since their pointers are different |
| 4432 | // There is no test for undetectability in strict equality. |
| 4433 | |
| 4434 | // Get the type of the first operand. |
| 4435 | // If the first object is a JS object, we have done pointer comparison. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4436 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4437 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4438 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4439 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4440 | |
| 4441 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4442 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4443 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4444 | __ bind(&return_not_equal); |
| 4445 | __ ret(0); |
| 4446 | |
| 4447 | __ bind(&first_non_object); |
| 4448 | // Check for oddballs: true, false, null, undefined. |
| 4449 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4450 | __ j(equal, &return_not_equal); |
| 4451 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4452 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4453 | __ j(above_equal, &return_not_equal); |
| 4454 | |
| 4455 | // Check for oddballs: true, false, null, undefined. |
| 4456 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4457 | __ j(equal, &return_not_equal); |
| 4458 | |
| 4459 | // Fall through to the general case. |
| 4460 | __ bind(&slow); |
| 4461 | } |
| 4462 | |
| 4463 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4464 | Label non_number_comparison; |
| 4465 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4466 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4467 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4468 | CpuFeatureScope use_sse2(masm, SSE2); |
| 4469 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4470 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4471 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4472 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4473 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4474 | // Don't base result on EFLAGS when a NaN is involved. |
| 4475 | __ j(parity_even, &unordered, Label::kNear); |
| 4476 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4477 | __ mov(eax, 0); // equal |
| 4478 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4479 | __ cmov(above, eax, ecx); |
| 4480 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4481 | __ cmov(below, eax, ecx); |
| 4482 | __ ret(0); |
| 4483 | } else { |
| 4484 | FloatingPointHelper::CheckFloatOperands( |
| 4485 | masm, &non_number_comparison, ebx); |
| 4486 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4487 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4488 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4489 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4490 | // Don't base result on EFLAGS when a NaN is involved. |
| 4491 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4492 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4493 | Label below_label, above_label; |
| 4494 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4495 | __ j(below, &below_label, Label::kNear); |
| 4496 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4497 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4498 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4499 | __ ret(0); |
| 4500 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4501 | __ bind(&below_label); |
| 4502 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4503 | __ ret(0); |
| 4504 | |
| 4505 | __ bind(&above_label); |
| 4506 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4507 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4508 | } |
| 4509 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4510 | // If one of the numbers was NaN, then the result is always false. |
| 4511 | // The cc is never not-equal. |
| 4512 | __ bind(&unordered); |
| 4513 | ASSERT(cc != not_equal); |
| 4514 | if (cc == less || cc == less_equal) { |
| 4515 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4516 | } else { |
| 4517 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4518 | } |
| 4519 | __ ret(0); |
| 4520 | |
| 4521 | // The number comparison code did not provide a valid result. |
| 4522 | __ bind(&non_number_comparison); |
| 4523 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4524 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4525 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4526 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4527 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 4528 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4529 | |
| 4530 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4531 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4532 | // non-zero value, which indicates not equal, so just return. |
| 4533 | __ ret(0); |
| 4534 | } |
| 4535 | |
| 4536 | __ bind(&check_for_strings); |
| 4537 | |
| 4538 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4539 | &check_unequal_objects); |
| 4540 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4541 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4542 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4543 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4544 | edx, |
| 4545 | eax, |
| 4546 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4547 | ebx); |
| 4548 | } else { |
| 4549 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4550 | edx, |
| 4551 | eax, |
| 4552 | ecx, |
| 4553 | ebx, |
| 4554 | edi); |
| 4555 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4556 | #ifdef DEBUG |
| 4557 | __ Abort("Unexpected fall-through from string comparison"); |
| 4558 | #endif |
| 4559 | |
| 4560 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4561 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4562 | // Non-strict equality. Objects are unequal if |
| 4563 | // they are both JSObjects and not undetectable, |
| 4564 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4565 | Label not_both_objects; |
| 4566 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4567 | // At most one is a smi, so we can test for smi by adding the two. |
| 4568 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4569 | // a heap object has the low bit clear. |
| 4570 | STATIC_ASSERT(kSmiTag == 0); |
| 4571 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4572 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4573 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4574 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4575 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4576 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4577 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4578 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4579 | // We do not bail out after this point. Both are JSObjects, and |
| 4580 | // they are equal if and only if both are undetectable. |
| 4581 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4582 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4583 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4584 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4585 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4586 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4587 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4588 | // The objects are both undetectable, so they both compare as the value |
| 4589 | // undefined, and are equal. |
| 4590 | __ Set(eax, Immediate(EQUAL)); |
| 4591 | __ bind(&return_unequal); |
| 4592 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4593 | // or return equal if we fell through to here. |
| 4594 | __ ret(0); // rax, rdx were pushed |
| 4595 | __ bind(¬_both_objects); |
| 4596 | } |
| 4597 | |
| 4598 | // Push arguments below the return address. |
| 4599 | __ pop(ecx); |
| 4600 | __ push(edx); |
| 4601 | __ push(eax); |
| 4602 | |
| 4603 | // Figure out which native to call and setup the arguments. |
| 4604 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4605 | if (cc == equal) { |
| 4606 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4607 | } else { |
| 4608 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4609 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | // Restore return address on the stack. |
| 4613 | __ push(ecx); |
| 4614 | |
| 4615 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4616 | // tagged as a small integer. |
| 4617 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4618 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4619 | __ bind(&miss); |
| 4620 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4621 | } |
| 4622 | |
| 4623 | |
| 4624 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4625 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4626 | } |
| 4627 | |
| 4628 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4629 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4630 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4631 | } |
| 4632 | |
| 4633 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4634 | static void GenerateRecordCallTargetNoArray(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4635 | // Cache the called function in a global property cell. Cache states |
| 4636 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4637 | // megamorphic. |
| 4638 | // ebx : cache cell for call target |
| 4639 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4640 | ASSERT(!FLAG_optimize_constructed_arrays); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4641 | Isolate* isolate = masm->isolate(); |
| 4642 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4643 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4644 | // Load the cache state into ecx. |
| 4645 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4646 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4647 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4648 | // function without changing the state. |
| 4649 | __ cmp(ecx, edi); |
| 4650 | __ j(equal, &done, Label::kNear); |
| 4651 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4652 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4653 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4654 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4655 | // megamorphic. |
| 4656 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4657 | __ j(equal, &initialize, Label::kNear); |
| 4658 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4659 | // write-barrier is needed. |
| 4660 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4661 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4662 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4663 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4664 | // An uninitialized cache is patched with the function. |
| 4665 | __ bind(&initialize); |
| 4666 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4667 | // No need for a write barrier here - cells are rescanned. |
| 4668 | |
| 4669 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4670 | } |
| 4671 | |
| 4672 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4673 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4674 | // Cache the called function in a global property cell. Cache states |
| 4675 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4676 | // megamorphic. |
| 4677 | // ebx : cache cell for call target |
| 4678 | // edi : the function to call |
| 4679 | ASSERT(FLAG_optimize_constructed_arrays); |
| 4680 | Isolate* isolate = masm->isolate(); |
| 4681 | Label initialize, done, miss, megamorphic, not_array_function; |
| 4682 | |
| 4683 | // Load the cache state into ecx. |
| 4684 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
| 4685 | |
| 4686 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4687 | // function without changing the state. |
| 4688 | __ cmp(ecx, edi); |
| 4689 | __ j(equal, &done); |
| 4690 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4691 | __ j(equal, &done); |
| 4692 | |
| 4693 | // Special handling of the Array() function, which caches not only the |
| 4694 | // monomorphic Array function but the initial ElementsKind with special |
| 4695 | // sentinels |
| 4696 | Handle<Object> terminal_kind_sentinel = |
| 4697 | TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
| 4698 | LAST_FAST_ELEMENTS_KIND); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4699 | __ JumpIfNotSmi(ecx, &miss); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4700 | __ cmp(ecx, Immediate(terminal_kind_sentinel)); |
| 4701 | __ j(above, &miss); |
| 4702 | // Load the global or builtins object from the current context |
| 4703 | __ LoadGlobalContext(ecx); |
| 4704 | // Make sure the function is the Array() function |
| 4705 | __ cmp(edi, Operand(ecx, |
| 4706 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4707 | __ j(not_equal, &megamorphic); |
| 4708 | __ jmp(&done); |
| 4709 | |
| 4710 | __ bind(&miss); |
| 4711 | |
| 4712 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4713 | // megamorphic. |
| 4714 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4715 | __ j(equal, &initialize); |
| 4716 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4717 | // write-barrier is needed. |
| 4718 | __ bind(&megamorphic); |
| 4719 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4720 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4721 | __ jmp(&done, Label::kNear); |
| 4722 | |
| 4723 | // An uninitialized cache is patched with the function or sentinel to |
| 4724 | // indicate the ElementsKind if function is the Array constructor. |
| 4725 | __ bind(&initialize); |
| 4726 | __ LoadGlobalContext(ecx); |
| 4727 | // Make sure the function is the Array() function |
| 4728 | __ cmp(edi, Operand(ecx, |
| 4729 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4730 | __ j(not_equal, ¬_array_function); |
| 4731 | |
| 4732 | // The target function is the Array constructor, install a sentinel value in |
| 4733 | // the constructor's type info cell that will track the initial ElementsKind |
| 4734 | // that should be used for the array when its constructed. |
| 4735 | Handle<Object> initial_kind_sentinel = |
| 4736 | TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
| 4737 | GetInitialFastElementsKind()); |
| 4738 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
| 4739 | Immediate(initial_kind_sentinel)); |
| 4740 | __ jmp(&done); |
| 4741 | |
| 4742 | __ bind(¬_array_function); |
| 4743 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), edi); |
| 4744 | // No need for a write barrier here - cells are rescanned. |
| 4745 | |
| 4746 | __ bind(&done); |
| 4747 | } |
| 4748 | |
| 4749 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4750 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4751 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4752 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4753 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4754 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4755 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4756 | // The receiver might implicitly be the global object. This is |
| 4757 | // indicated by passing the hole as the receiver to the call |
| 4758 | // function stub. |
| 4759 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4760 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4761 | // Get the receiver from the stack. |
| 4762 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4763 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4764 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4765 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4766 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4767 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4768 | __ mov(ecx, GlobalObjectOperand()); |
| 4769 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4770 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4771 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4772 | } |
| 4773 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4774 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4775 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4776 | // Goto slow case if we do not have a function. |
| 4777 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4778 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4779 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4780 | if (RecordCallTarget()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4781 | if (FLAG_optimize_constructed_arrays) { |
| 4782 | GenerateRecordCallTarget(masm); |
| 4783 | } else { |
| 4784 | GenerateRecordCallTargetNoArray(masm); |
| 4785 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4786 | } |
| 4787 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4788 | // Fast-case: Just invoke the function. |
| 4789 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4790 | |
| 4791 | if (ReceiverMightBeImplicit()) { |
| 4792 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4793 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4794 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4795 | __ InvokeFunction(edi, |
| 4796 | actual, |
| 4797 | JUMP_FUNCTION, |
| 4798 | NullCallWrapper(), |
| 4799 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4800 | __ bind(&call_as_function); |
| 4801 | } |
| 4802 | __ InvokeFunction(edi, |
| 4803 | actual, |
| 4804 | JUMP_FUNCTION, |
| 4805 | NullCallWrapper(), |
| 4806 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4807 | |
| 4808 | // Slow-case: Non-function called. |
| 4809 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4810 | if (RecordCallTarget()) { |
| 4811 | // If there is a call target cache, mark it megamorphic in the |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4812 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4813 | // object (undefined) so no write barrier is needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4814 | __ mov(FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4815 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4816 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4817 | // Check for function proxy. |
| 4818 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4819 | __ j(not_equal, &non_function); |
| 4820 | __ pop(ecx); |
| 4821 | __ push(edi); // put proxy as additional argument under return address |
| 4822 | __ push(ecx); |
| 4823 | __ Set(eax, Immediate(argc_ + 1)); |
| 4824 | __ Set(ebx, Immediate(0)); |
| 4825 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4826 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4827 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4828 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4829 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4830 | } |
| 4831 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4832 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4833 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4834 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4835 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4836 | __ Set(eax, Immediate(argc_)); |
| 4837 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4838 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4839 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4840 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4841 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4842 | } |
| 4843 | |
| 4844 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4845 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4846 | // eax : number of arguments |
| 4847 | // ebx : cache cell for call target |
| 4848 | // edi : constructor function |
| 4849 | Label slow, non_function_call; |
| 4850 | |
| 4851 | // Check that function is not a smi. |
| 4852 | __ JumpIfSmi(edi, &non_function_call); |
| 4853 | // Check that function is a JSFunction. |
| 4854 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4855 | __ j(not_equal, &slow); |
| 4856 | |
| 4857 | if (RecordCallTarget()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4858 | if (FLAG_optimize_constructed_arrays) { |
| 4859 | GenerateRecordCallTarget(masm); |
| 4860 | } else { |
| 4861 | GenerateRecordCallTargetNoArray(masm); |
| 4862 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4863 | } |
| 4864 | |
| 4865 | // Jump to the function-specific construct stub. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4866 | Register jmp_reg = FLAG_optimize_constructed_arrays ? ecx : ebx; |
| 4867 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4868 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 4869 | SharedFunctionInfo::kConstructStubOffset)); |
| 4870 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 4871 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4872 | |
| 4873 | // edi: called object |
| 4874 | // eax: number of arguments |
| 4875 | // ecx: object map |
| 4876 | Label do_call; |
| 4877 | __ bind(&slow); |
| 4878 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4879 | __ j(not_equal, &non_function_call); |
| 4880 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4881 | __ jmp(&do_call); |
| 4882 | |
| 4883 | __ bind(&non_function_call); |
| 4884 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4885 | __ bind(&do_call); |
| 4886 | // Set expected number of arguments to zero (not changing eax). |
| 4887 | __ Set(ebx, Immediate(0)); |
| 4888 | Handle<Code> arguments_adaptor = |
| 4889 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4890 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4891 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4892 | } |
| 4893 | |
| 4894 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4895 | bool CEntryStub::NeedsImmovableCode() { |
| 4896 | return false; |
| 4897 | } |
| 4898 | |
| 4899 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4900 | bool CEntryStub::IsPregenerated() { |
| 4901 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4902 | result_size_ == 1; |
| 4903 | } |
| 4904 | |
| 4905 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4906 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4907 | CEntryStub::GenerateAheadOfTime(isolate); |
| 4908 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4909 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4910 | // It is important that the store buffer overflow stubs are generated first. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4911 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4912 | if (FLAG_optimize_constructed_arrays) { |
| 4913 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
| 4914 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4915 | } |
| 4916 | |
| 4917 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4918 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4919 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4920 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4921 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4922 | // which would lead to code stub initialization state being messed up. |
| 4923 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4924 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 4925 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4926 | } |
| 4927 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4928 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4929 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4933 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4934 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4935 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4936 | code->set_is_pregenerated(true); |
| 4937 | } |
| 4938 | |
| 4939 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4940 | static void JumpIfOOM(MacroAssembler* masm, |
| 4941 | Register value, |
| 4942 | Register scratch, |
| 4943 | Label* oom_label) { |
| 4944 | __ mov(scratch, value); |
| 4945 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 4946 | STATIC_ASSERT(kFailureTag == 3); |
| 4947 | __ and_(scratch, 0xf); |
| 4948 | __ cmp(scratch, 0xf); |
| 4949 | __ j(equal, oom_label); |
| 4950 | } |
| 4951 | |
| 4952 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4953 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4954 | Label* throw_normal_exception, |
| 4955 | Label* throw_termination_exception, |
| 4956 | Label* throw_out_of_memory_exception, |
| 4957 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4958 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4959 | // eax: result parameter for PerformGC, if any |
| 4960 | // ebx: pointer to C function (C callee-saved) |
| 4961 | // ebp: frame pointer (restored after C call) |
| 4962 | // esp: stack pointer (restored after C call) |
| 4963 | // edi: number of arguments including receiver (C callee-saved) |
| 4964 | // esi: pointer to the first argument (C callee-saved) |
| 4965 | |
| 4966 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4967 | |
| 4968 | // Check stack alignment. |
| 4969 | if (FLAG_debug_code) { |
| 4970 | __ CheckStackAlignment(); |
| 4971 | } |
| 4972 | |
| 4973 | if (do_gc) { |
| 4974 | // Pass failure code returned from last attempt as first argument to |
| 4975 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4976 | // stack alignment is known to be correct. This function takes one argument |
| 4977 | // which is passed on the stack, and we know that the stack has been |
| 4978 | // prepared to pass at least one argument. |
| 4979 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4980 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4981 | } |
| 4982 | |
| 4983 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4984 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4985 | if (always_allocate_scope) { |
| 4986 | __ inc(Operand::StaticVariable(scope_depth)); |
| 4987 | } |
| 4988 | |
| 4989 | // Call C function. |
| 4990 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 4991 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4992 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4993 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4994 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4995 | // Result is in eax or edx:eax - do not destroy these registers! |
| 4996 | |
| 4997 | if (always_allocate_scope) { |
| 4998 | __ dec(Operand::StaticVariable(scope_depth)); |
| 4999 | } |
| 5000 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5001 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 5002 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5003 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5004 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5005 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5006 | __ j(not_equal, &okay, Label::kNear); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5007 | // TODO(wingo): Currently SuspendJSGeneratorObject returns the hole. Change |
| 5008 | // to return another sentinel like a harmony symbol. |
| 5009 | __ cmp(ebx, Immediate(ExternalReference( |
| 5010 | Runtime::kSuspendJSGeneratorObject, masm->isolate()))); |
| 5011 | __ j(equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5012 | __ int3(); |
| 5013 | __ bind(&okay); |
| 5014 | } |
| 5015 | |
| 5016 | // Check for failure result. |
| 5017 | Label failure_returned; |
| 5018 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 5019 | __ lea(ecx, Operand(eax, 1)); |
| 5020 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 5021 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5022 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5023 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5024 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5025 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5026 | |
| 5027 | // Check that there is no pending exception, otherwise we |
| 5028 | // should have returned some failure value. |
| 5029 | if (FLAG_debug_code) { |
| 5030 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5031 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5032 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5033 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 5034 | // Cannot use check here as it attempts to generate call into runtime. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5035 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5036 | __ int3(); |
| 5037 | __ bind(&okay); |
| 5038 | __ pop(edx); |
| 5039 | } |
| 5040 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5041 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5042 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5043 | __ ret(0); |
| 5044 | |
| 5045 | // Handling of failure. |
| 5046 | __ bind(&failure_returned); |
| 5047 | |
| 5048 | Label retry; |
| 5049 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 5050 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 5051 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5052 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5053 | |
| 5054 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5055 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5056 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5057 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5058 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5059 | |
| 5060 | // See if we just retrieved an OOM exception. |
| 5061 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 5062 | |
| 5063 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5064 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5065 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 5066 | |
| 5067 | // Special handling of termination exceptions which are uncatchable |
| 5068 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5069 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5070 | __ j(equal, throw_termination_exception); |
| 5071 | |
| 5072 | // Handle normal exception. |
| 5073 | __ jmp(throw_normal_exception); |
| 5074 | |
| 5075 | // Retry. |
| 5076 | __ bind(&retry); |
| 5077 | } |
| 5078 | |
| 5079 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5080 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 5081 | // eax: number of arguments including receiver |
| 5082 | // ebx: pointer to C function (C callee-saved) |
| 5083 | // ebp: frame pointer (restored after C call) |
| 5084 | // esp: stack pointer (restored after C call) |
| 5085 | // esi: current context (C callee-saved) |
| 5086 | // edi: JS function of the caller (C callee-saved) |
| 5087 | |
| 5088 | // NOTE: Invocations of builtins may return failure objects instead |
| 5089 | // of a proper result. The builtin entry handles this by performing |
| 5090 | // a garbage collection and retrying the builtin (twice). |
| 5091 | |
| 5092 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5093 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5094 | |
| 5095 | // eax: result parameter for PerformGC, if any (setup below) |
| 5096 | // ebx: pointer to builtin function (C callee-saved) |
| 5097 | // ebp: frame pointer (restored after C call) |
| 5098 | // esp: stack pointer (restored after C call) |
| 5099 | // edi: number of arguments including receiver (C callee-saved) |
| 5100 | // esi: argv pointer (C callee-saved) |
| 5101 | |
| 5102 | Label throw_normal_exception; |
| 5103 | Label throw_termination_exception; |
| 5104 | Label throw_out_of_memory_exception; |
| 5105 | |
| 5106 | // Call into the runtime system. |
| 5107 | GenerateCore(masm, |
| 5108 | &throw_normal_exception, |
| 5109 | &throw_termination_exception, |
| 5110 | &throw_out_of_memory_exception, |
| 5111 | false, |
| 5112 | false); |
| 5113 | |
| 5114 | // Do space-specific GC and retry runtime call. |
| 5115 | GenerateCore(masm, |
| 5116 | &throw_normal_exception, |
| 5117 | &throw_termination_exception, |
| 5118 | &throw_out_of_memory_exception, |
| 5119 | true, |
| 5120 | false); |
| 5121 | |
| 5122 | // Do full GC and retry runtime call one final time. |
| 5123 | Failure* failure = Failure::InternalError(); |
| 5124 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 5125 | GenerateCore(masm, |
| 5126 | &throw_normal_exception, |
| 5127 | &throw_termination_exception, |
| 5128 | &throw_out_of_memory_exception, |
| 5129 | true, |
| 5130 | true); |
| 5131 | |
| 5132 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5133 | // Set external caught exception to false. |
| 5134 | Isolate* isolate = masm->isolate(); |
| 5135 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 5136 | isolate); |
| 5137 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 5138 | |
| 5139 | // Set pending exception and eax to out of memory exception. |
| 5140 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 5141 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5142 | Label already_have_failure; |
| 5143 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 5144 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 5145 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5146 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5147 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5148 | |
| 5149 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5150 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5151 | |
| 5152 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5153 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5154 | } |
| 5155 | |
| 5156 | |
| 5157 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5158 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5159 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5160 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5161 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5162 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5163 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5164 | |
| 5165 | // Push marker in two places. |
| 5166 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 5167 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5168 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5169 | // Save callee-saved registers (C calling conventions). |
| 5170 | __ push(edi); |
| 5171 | __ push(esi); |
| 5172 | __ push(ebx); |
| 5173 | |
| 5174 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5175 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5176 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5177 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5178 | // If this is the outermost JS call, set js_entry_sp value. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5179 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5180 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5181 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5182 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5183 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5184 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5185 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5186 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5187 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5188 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5189 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5190 | // block that sets the pending exception. |
| 5191 | __ jmp(&invoke); |
| 5192 | __ bind(&handler_entry); |
| 5193 | handler_offset_ = handler_entry.pos(); |
| 5194 | // Caught exception: Store result (exception) in the pending exception |
| 5195 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5196 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5197 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5198 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5199 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5200 | __ jmp(&exit); |
| 5201 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5202 | // Invoke: Link this frame into the handler chain. There's only one |
| 5203 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5204 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5205 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5206 | |
| 5207 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5208 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5209 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5210 | |
| 5211 | // Fake a receiver (NULL). |
| 5212 | __ push(Immediate(0)); // receiver |
| 5213 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5214 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5215 | // pop the faked function when we return. Notice that we cannot store a |
| 5216 | // reference to the trampoline code directly in this stub, because the |
| 5217 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5218 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5219 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5220 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5221 | __ mov(edx, Immediate(construct_entry)); |
| 5222 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5223 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5224 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5225 | __ mov(edx, Immediate(entry)); |
| 5226 | } |
| 5227 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5228 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5229 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5230 | |
| 5231 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5232 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5233 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5234 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5235 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5236 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5237 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5238 | __ j(not_equal, ¬_outermost_js_2); |
| 5239 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5240 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5241 | |
| 5242 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5243 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5244 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5245 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5246 | |
| 5247 | // Restore callee-saved registers (C calling conventions). |
| 5248 | __ pop(ebx); |
| 5249 | __ pop(esi); |
| 5250 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5251 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5252 | |
| 5253 | // Restore frame pointer and return. |
| 5254 | __ pop(ebp); |
| 5255 | __ ret(0); |
| 5256 | } |
| 5257 | |
| 5258 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5259 | // Generate stub code for instanceof. |
| 5260 | // This code can patch a call site inlined cache of the instance of check, |
| 5261 | // which looks like this. |
| 5262 | // |
| 5263 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5264 | // 75 0a jne <some near label> |
| 5265 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5266 | // |
| 5267 | // If call site patching is requested the stack will have the delta from the |
| 5268 | // return address to the cmp instruction just below the return address. This |
| 5269 | // also means that call site patching can only take place with arguments in |
| 5270 | // registers. TOS looks like this when call site patching is requested |
| 5271 | // |
| 5272 | // esp[0] : return address |
| 5273 | // esp[4] : delta from return address to cmp instruction |
| 5274 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5275 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5276 | // Call site inlining and patching implies arguments in registers. |
| 5277 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5278 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5279 | // Fixed register usage throughout the stub. |
| 5280 | Register object = eax; // Object (lhs). |
| 5281 | Register map = ebx; // Map of the object. |
| 5282 | Register function = edx; // Function (rhs). |
| 5283 | Register prototype = edi; // Prototype of the function. |
| 5284 | Register scratch = ecx; |
| 5285 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5286 | // Constants describing the call site code to patch. |
| 5287 | static const int kDeltaToCmpImmediate = 2; |
| 5288 | static const int kDeltaToMov = 8; |
| 5289 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5290 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5291 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5292 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5293 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5294 | ExternalReference roots_array_start = |
| 5295 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5296 | |
| 5297 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5298 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5299 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5300 | // Get the object and function - they are always both needed. |
| 5301 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5302 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5303 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5304 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5305 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5306 | |
| 5307 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5308 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5309 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5310 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5311 | // If there is a call site cache don't look in the global cache, but do the |
| 5312 | // real lookup and update the call site cache. |
| 5313 | if (!HasCallSiteInlineCheck()) { |
| 5314 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5315 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5316 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5317 | __ cmp(function, Operand::StaticArray(scratch, |
| 5318 | times_pointer_size, |
| 5319 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5320 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5321 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5322 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5323 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5324 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5325 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5326 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5327 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5328 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5329 | __ bind(&miss); |
| 5330 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5331 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5332 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5333 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5334 | |
| 5335 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5336 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5337 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5338 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5339 | // Update the global instanceof or call site inlined cache with the current |
| 5340 | // map and function. The cached answer will be set when it is known below. |
| 5341 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5342 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5343 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5344 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5345 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5346 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5347 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5348 | } else { |
| 5349 | // The constants for the code patching are based on no push instructions |
| 5350 | // at the call site. |
| 5351 | ASSERT(HasArgsInRegisters()); |
| 5352 | // Get return address and delta to inlined map check. |
| 5353 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5354 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5355 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5356 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5357 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5358 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5359 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5360 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5361 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5362 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5363 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5364 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5365 | // Loop through the prototype chain of the object looking for the function |
| 5366 | // prototype. |
| 5367 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5368 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5369 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5370 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5371 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5372 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5373 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5374 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5375 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5376 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5377 | __ jmp(&loop); |
| 5378 | |
| 5379 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5380 | if (!HasCallSiteInlineCheck()) { |
| 5381 | __ Set(eax, Immediate(0)); |
| 5382 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5383 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5384 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5385 | } else { |
| 5386 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5387 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5388 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5389 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5390 | if (FLAG_debug_code) { |
| 5391 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5392 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5393 | } |
| 5394 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5395 | if (!ReturnTrueFalseObject()) { |
| 5396 | __ Set(eax, Immediate(0)); |
| 5397 | } |
| 5398 | } |
| 5399 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5400 | |
| 5401 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5402 | if (!HasCallSiteInlineCheck()) { |
| 5403 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5404 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5405 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5406 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5407 | } else { |
| 5408 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5409 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5410 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5411 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5412 | if (FLAG_debug_code) { |
| 5413 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5414 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5415 | } |
| 5416 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5417 | if (!ReturnTrueFalseObject()) { |
| 5418 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5419 | } |
| 5420 | } |
| 5421 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5422 | |
| 5423 | Label object_not_null, object_not_null_or_smi; |
| 5424 | __ bind(¬_js_object); |
| 5425 | // Before null, smi and string value checks, check that the rhs is a function |
| 5426 | // as for a non-function rhs an exception needs to be thrown. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5427 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5428 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5429 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5430 | |
| 5431 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5432 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5433 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5434 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5435 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5436 | |
| 5437 | __ bind(&object_not_null); |
| 5438 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5439 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5440 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5441 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5442 | |
| 5443 | __ bind(&object_not_null_or_smi); |
| 5444 | // String values is not instance of anything. |
| 5445 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5446 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5447 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5448 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5449 | |
| 5450 | // Slow-case: Go through the JavaScript implementation. |
| 5451 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5452 | if (!ReturnTrueFalseObject()) { |
| 5453 | // Tail call the builtin which returns 0 or 1. |
| 5454 | if (HasArgsInRegisters()) { |
| 5455 | // Push arguments below return address. |
| 5456 | __ pop(scratch); |
| 5457 | __ push(object); |
| 5458 | __ push(function); |
| 5459 | __ push(scratch); |
| 5460 | } |
| 5461 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5462 | } else { |
| 5463 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5464 | { |
| 5465 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5466 | __ push(object); |
| 5467 | __ push(function); |
| 5468 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5469 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5470 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5471 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5472 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5473 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5474 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5475 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5476 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5477 | __ bind(&done); |
| 5478 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5479 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5480 | } |
| 5481 | |
| 5482 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5483 | Register InstanceofStub::left() { return eax; } |
| 5484 | |
| 5485 | |
| 5486 | Register InstanceofStub::right() { return edx; } |
| 5487 | |
| 5488 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5489 | // ------------------------------------------------------------------------- |
| 5490 | // StringCharCodeAtGenerator |
| 5491 | |
| 5492 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5493 | // If the receiver is a smi trigger the non-string case. |
| 5494 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5495 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5496 | |
| 5497 | // Fetch the instance type of the receiver into result register. |
| 5498 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5499 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5500 | // If the receiver is not a string trigger the non-string case. |
| 5501 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5502 | __ j(not_zero, receiver_not_string_); |
| 5503 | |
| 5504 | // If the index is non-smi trigger the non-smi case. |
| 5505 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5506 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5507 | __ bind(&got_smi_index_); |
| 5508 | |
| 5509 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5510 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5511 | __ j(above_equal, index_out_of_range_); |
| 5512 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5513 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5514 | |
| 5515 | Factory* factory = masm->isolate()->factory(); |
| 5516 | StringCharLoadGenerator::Generate( |
| 5517 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5518 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5519 | __ SmiTag(result_); |
| 5520 | __ bind(&exit_); |
| 5521 | } |
| 5522 | |
| 5523 | |
| 5524 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5525 | MacroAssembler* masm, |
| 5526 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5527 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5528 | |
| 5529 | // Index is not a smi. |
| 5530 | __ bind(&index_not_smi_); |
| 5531 | // If index is a heap number, try converting it to an integer. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5532 | __ CheckMap(index_, |
| 5533 | masm->isolate()->factory()->heap_number_map(), |
| 5534 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5535 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5536 | call_helper.BeforeCall(masm); |
| 5537 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5538 | __ push(index_); // Consumed by runtime conversion function. |
| 5539 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5540 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5541 | } else { |
| 5542 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5543 | // NumberToSmi discards numbers that are not exact integers. |
| 5544 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5545 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5546 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5547 | // Save the conversion result before the pop instructions below |
| 5548 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5549 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5550 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5551 | __ pop(object_); |
| 5552 | // Reload the instance type. |
| 5553 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5554 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5555 | call_helper.AfterCall(masm); |
| 5556 | // If index is still not a smi, it must be out of range. |
| 5557 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5558 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5559 | // Otherwise, return to the fast path. |
| 5560 | __ jmp(&got_smi_index_); |
| 5561 | |
| 5562 | // Call runtime. We get here when the receiver is a string and the |
| 5563 | // index is a number, but the code of getting the actual character |
| 5564 | // is too complex (e.g., when the string needs to be flattened). |
| 5565 | __ bind(&call_runtime_); |
| 5566 | call_helper.BeforeCall(masm); |
| 5567 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5568 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5569 | __ push(index_); |
| 5570 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5571 | if (!result_.is(eax)) { |
| 5572 | __ mov(result_, eax); |
| 5573 | } |
| 5574 | call_helper.AfterCall(masm); |
| 5575 | __ jmp(&exit_); |
| 5576 | |
| 5577 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5578 | } |
| 5579 | |
| 5580 | |
| 5581 | // ------------------------------------------------------------------------- |
| 5582 | // StringCharFromCodeGenerator |
| 5583 | |
| 5584 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5585 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5586 | STATIC_ASSERT(kSmiTag == 0); |
| 5587 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5588 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5589 | __ test(code_, |
| 5590 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5591 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5592 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5593 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5594 | Factory* factory = masm->isolate()->factory(); |
| 5595 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5596 | STATIC_ASSERT(kSmiTag == 0); |
| 5597 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5598 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5599 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5600 | __ mov(result_, FieldOperand(result_, |
| 5601 | code_, times_half_pointer_size, |
| 5602 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5603 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5604 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5605 | __ bind(&exit_); |
| 5606 | } |
| 5607 | |
| 5608 | |
| 5609 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5610 | MacroAssembler* masm, |
| 5611 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5612 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5613 | |
| 5614 | __ bind(&slow_case_); |
| 5615 | call_helper.BeforeCall(masm); |
| 5616 | __ push(code_); |
| 5617 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5618 | if (!result_.is(eax)) { |
| 5619 | __ mov(result_, eax); |
| 5620 | } |
| 5621 | call_helper.AfterCall(masm); |
| 5622 | __ jmp(&exit_); |
| 5623 | |
| 5624 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5625 | } |
| 5626 | |
| 5627 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5628 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5629 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5630 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5631 | |
| 5632 | // Load the two arguments. |
| 5633 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5634 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5635 | |
| 5636 | // Make sure that both arguments are strings if not known in advance. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5637 | if ((flags_ & NO_STRING_ADD_FLAGS) != 0) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5638 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5639 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5640 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5641 | |
| 5642 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5643 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5644 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5645 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5646 | } else { |
| 5647 | // Here at least one of the arguments is definitely a string. |
| 5648 | // We convert the one that is not known to be a string. |
| 5649 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5650 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5651 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5652 | &call_builtin); |
| 5653 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5654 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5655 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5656 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5657 | &call_builtin); |
| 5658 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5659 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5660 | } |
| 5661 | |
| 5662 | // Both arguments are strings. |
| 5663 | // eax: first string |
| 5664 | // edx: second string |
| 5665 | // Check if either of the strings are empty. In that case return the other. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5666 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5667 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5668 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5669 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5670 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5671 | // Second string is empty, result is first string which is already in eax. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5672 | Counters* counters = masm->isolate()->counters(); |
| 5673 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5674 | __ ret(2 * kPointerSize); |
| 5675 | __ bind(&second_not_zero_length); |
| 5676 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5677 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5678 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5679 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5680 | // First string is empty, result is second string which is in edx. |
| 5681 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5682 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5683 | __ ret(2 * kPointerSize); |
| 5684 | |
| 5685 | // Both strings are non-empty. |
| 5686 | // eax: first string |
| 5687 | // ebx: length of first string as a smi |
| 5688 | // ecx: length of second string as a smi |
| 5689 | // edx: second string |
| 5690 | // Look at the length of the result of adding the two strings. |
| 5691 | Label string_add_flat_result, longer_than_two; |
| 5692 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5693 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5694 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5695 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5696 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5697 | // Use the string table when adding two one character strings, as it |
| 5698 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5699 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5700 | __ j(not_equal, &longer_than_two); |
| 5701 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5702 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5703 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5704 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5705 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5706 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5707 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5708 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5709 | // Try to lookup two character string in string table. If it is not found |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5710 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5711 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5712 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5713 | masm, ebx, ecx, eax, edx, edi, |
| 5714 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5715 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5716 | __ ret(2 * kPointerSize); |
| 5717 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5718 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5719 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5720 | // Reload the arguments. |
| 5721 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5722 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5723 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5724 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5725 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5726 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5727 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5728 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5729 | // Pack both characters in ebx. |
| 5730 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5731 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5732 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5733 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5734 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5735 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5736 | |
| 5737 | __ bind(&longer_than_two); |
| 5738 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5739 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5740 | __ j(below, &string_add_flat_result); |
| 5741 | |
| 5742 | // If result is not supposed to be flat allocate a cons string object. If both |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5743 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5744 | Label non_ascii, allocated, ascii_data; |
| 5745 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5746 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5747 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5748 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5749 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5750 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5751 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5752 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5753 | __ j(zero, &non_ascii); |
| 5754 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5755 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5756 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5757 | __ bind(&allocated); |
| 5758 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5759 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5760 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5761 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5762 | Immediate(String::kEmptyHashField)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5763 | |
| 5764 | Label skip_write_barrier, after_writing; |
| 5765 | ExternalReference high_promotion_mode = ExternalReference:: |
| 5766 | new_space_high_promotion_mode_active_address(masm->isolate()); |
| 5767 | __ test(Operand::StaticVariable(high_promotion_mode), Immediate(1)); |
| 5768 | __ j(zero, &skip_write_barrier); |
| 5769 | |
| 5770 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5771 | __ RecordWriteField(ecx, |
| 5772 | ConsString::kFirstOffset, |
| 5773 | eax, |
| 5774 | ebx, |
| 5775 | kDontSaveFPRegs); |
| 5776 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5777 | __ RecordWriteField(ecx, |
| 5778 | ConsString::kSecondOffset, |
| 5779 | edx, |
| 5780 | ebx, |
| 5781 | kDontSaveFPRegs); |
| 5782 | __ jmp(&after_writing); |
| 5783 | |
| 5784 | __ bind(&skip_write_barrier); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5785 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5786 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5787 | |
| 5788 | __ bind(&after_writing); |
| 5789 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5790 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5791 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5792 | __ ret(2 * kPointerSize); |
| 5793 | __ bind(&non_ascii); |
| 5794 | // At least one of the strings is two-byte. Check whether it happens |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5795 | // to contain only one byte characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5796 | // ecx: first instance type AND second instance type. |
| 5797 | // edi: second instance type. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5798 | __ test(ecx, Immediate(kOneByteDataHintMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5799 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5800 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5801 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5802 | __ xor_(edi, ecx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5803 | STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0); |
| 5804 | __ and_(edi, kOneByteStringTag | kOneByteDataHintTag); |
| 5805 | __ cmp(edi, kOneByteStringTag | kOneByteDataHintTag); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5806 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5807 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5808 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5809 | __ jmp(&allocated); |
| 5810 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5811 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5812 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5813 | // Handle creating a flat result from either external or sequential strings. |
| 5814 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5815 | // eax: first string |
| 5816 | // ebx: length of resulting flat string as a smi |
| 5817 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5818 | Label first_prepared, second_prepared; |
| 5819 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5820 | __ bind(&string_add_flat_result); |
| 5821 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5822 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5823 | // ecx: instance type of first string |
| 5824 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5825 | __ test_b(ecx, kStringRepresentationMask); |
| 5826 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5827 | // Rule out short external string and load string resource. |
| 5828 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5829 | __ test_b(ecx, kShortExternalStringMask); |
| 5830 | __ j(not_zero, &call_runtime); |
| 5831 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5832 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5833 | __ jmp(&first_prepared, Label::kNear); |
| 5834 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5835 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5836 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5837 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5838 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5839 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5840 | // Check whether both strings have same encoding. |
| 5841 | // edi: instance type of second string |
| 5842 | __ xor_(ecx, edi); |
| 5843 | __ test_b(ecx, kStringEncodingMask); |
| 5844 | __ j(not_zero, &call_runtime); |
| 5845 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5846 | __ test_b(edi, kStringRepresentationMask); |
| 5847 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5848 | // Rule out short external string and load string resource. |
| 5849 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5850 | __ test_b(edi, kShortExternalStringMask); |
| 5851 | __ j(not_zero, &call_runtime); |
| 5852 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5853 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5854 | __ jmp(&second_prepared, Label::kNear); |
| 5855 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5856 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5857 | __ bind(&second_prepared); |
| 5858 | |
| 5859 | // Push the addresses of both strings' first characters onto the stack. |
| 5860 | __ push(edx); |
| 5861 | __ push(eax); |
| 5862 | |
| 5863 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5864 | // edi: instance type of second string |
| 5865 | // First string and second string have the same encoding. |
| 5866 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5867 | __ test_b(edi, kStringEncodingMask); |
| 5868 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5869 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5870 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5871 | // ebx: length of resulting flat string as a smi |
| 5872 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5873 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5874 | // eax: result string |
| 5875 | __ mov(ecx, eax); |
| 5876 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5877 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5878 | // Load first argument's length and first character location. Account for |
| 5879 | // values currently on the stack when fetching arguments from it. |
| 5880 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5881 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5882 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5883 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5884 | // eax: result string |
| 5885 | // ecx: first character of result |
| 5886 | // edx: first char of first argument |
| 5887 | // edi: length of first argument |
| 5888 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5889 | // Load second argument's length and first character location. Account for |
| 5890 | // values currently on the stack when fetching arguments from it. |
| 5891 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5892 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5893 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5894 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5895 | // eax: result string |
| 5896 | // ecx: next character of result |
| 5897 | // edx: first char of second argument |
| 5898 | // edi: length of second argument |
| 5899 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5900 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5901 | __ ret(2 * kPointerSize); |
| 5902 | |
| 5903 | // Handle creating a flat two byte result. |
| 5904 | // eax: first string - known to be two byte |
| 5905 | // ebx: length of resulting flat string as a smi |
| 5906 | // edx: second string |
| 5907 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5908 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5909 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5910 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5911 | // eax: result string |
| 5912 | __ mov(ecx, eax); |
| 5913 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5914 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5915 | // Load second argument's length and first character location. Account for |
| 5916 | // values currently on the stack when fetching arguments from it. |
| 5917 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5918 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5919 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5920 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5921 | // eax: result string |
| 5922 | // ecx: first character of result |
| 5923 | // edx: first char of first argument |
| 5924 | // edi: length of first argument |
| 5925 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5926 | // Load second argument's length and first character location. Account for |
| 5927 | // values currently on the stack when fetching arguments from it. |
| 5928 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5929 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5930 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5931 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5932 | // eax: result string |
| 5933 | // ecx: next character of result |
| 5934 | // edx: first char of second argument |
| 5935 | // edi: length of second argument |
| 5936 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5937 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5938 | __ ret(2 * kPointerSize); |
| 5939 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5940 | // Recover stack pointer before jumping to runtime. |
| 5941 | __ bind(&call_runtime_drop_two); |
| 5942 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5943 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5944 | __ bind(&call_runtime); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5945 | if ((flags_ & ERECT_FRAME) != 0) { |
| 5946 | GenerateRegisterArgsPop(masm, ecx); |
| 5947 | // Build a frame |
| 5948 | { |
| 5949 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5950 | GenerateRegisterArgsPush(masm); |
| 5951 | __ CallRuntime(Runtime::kStringAdd, 2); |
| 5952 | } |
| 5953 | __ ret(0); |
| 5954 | } else { |
| 5955 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
| 5956 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5957 | |
| 5958 | if (call_builtin.is_linked()) { |
| 5959 | __ bind(&call_builtin); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5960 | if ((flags_ & ERECT_FRAME) != 0) { |
| 5961 | GenerateRegisterArgsPop(masm, ecx); |
| 5962 | // Build a frame |
| 5963 | { |
| 5964 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5965 | GenerateRegisterArgsPush(masm); |
| 5966 | __ InvokeBuiltin(builtin_id, CALL_FUNCTION); |
| 5967 | } |
| 5968 | __ ret(0); |
| 5969 | } else { |
| 5970 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5971 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5972 | } |
| 5973 | } |
| 5974 | |
| 5975 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5976 | void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
| 5977 | __ push(eax); |
| 5978 | __ push(edx); |
| 5979 | } |
| 5980 | |
| 5981 | |
| 5982 | void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm, |
| 5983 | Register temp) { |
| 5984 | __ pop(temp); |
| 5985 | __ pop(edx); |
| 5986 | __ pop(eax); |
| 5987 | __ push(temp); |
| 5988 | } |
| 5989 | |
| 5990 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5991 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5992 | int stack_offset, |
| 5993 | Register arg, |
| 5994 | Register scratch1, |
| 5995 | Register scratch2, |
| 5996 | Register scratch3, |
| 5997 | Label* slow) { |
| 5998 | // First check if the argument is already a string. |
| 5999 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6000 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6001 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 6002 | __ j(below, &done); |
| 6003 | |
| 6004 | // Check the number to string cache. |
| 6005 | Label not_cached; |
| 6006 | __ bind(¬_string); |
| 6007 | // Puts the cached result into scratch1. |
| 6008 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6009 | arg, |
| 6010 | scratch1, |
| 6011 | scratch2, |
| 6012 | scratch3, |
| 6013 | false, |
| 6014 | ¬_cached); |
| 6015 | __ mov(arg, scratch1); |
| 6016 | __ mov(Operand(esp, stack_offset), arg); |
| 6017 | __ jmp(&done); |
| 6018 | |
| 6019 | // Check if the argument is a safe string wrapper. |
| 6020 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6021 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6022 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 6023 | __ j(not_equal, slow); |
| 6024 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 6025 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 6026 | __ j(zero, slow); |
| 6027 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 6028 | __ mov(Operand(esp, stack_offset), arg); |
| 6029 | |
| 6030 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6031 | } |
| 6032 | |
| 6033 | |
| 6034 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 6035 | Register dest, |
| 6036 | Register src, |
| 6037 | Register count, |
| 6038 | Register scratch, |
| 6039 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6040 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6041 | __ bind(&loop); |
| 6042 | // This loop just copies one character at a time, as it is only used for very |
| 6043 | // short strings. |
| 6044 | if (ascii) { |
| 6045 | __ mov_b(scratch, Operand(src, 0)); |
| 6046 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6047 | __ add(src, Immediate(1)); |
| 6048 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6049 | } else { |
| 6050 | __ mov_w(scratch, Operand(src, 0)); |
| 6051 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6052 | __ add(src, Immediate(2)); |
| 6053 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6054 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6055 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6056 | __ j(not_zero, &loop); |
| 6057 | } |
| 6058 | |
| 6059 | |
| 6060 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 6061 | Register dest, |
| 6062 | Register src, |
| 6063 | Register count, |
| 6064 | Register scratch, |
| 6065 | bool ascii) { |
| 6066 | // Copy characters using rep movs of doublewords. |
| 6067 | // The destination is aligned on a 4 byte boundary because we are |
| 6068 | // copying to the beginning of a newly allocated string. |
| 6069 | ASSERT(dest.is(edi)); // rep movs destination |
| 6070 | ASSERT(src.is(esi)); // rep movs source |
| 6071 | ASSERT(count.is(ecx)); // rep movs count |
| 6072 | ASSERT(!scratch.is(dest)); |
| 6073 | ASSERT(!scratch.is(src)); |
| 6074 | ASSERT(!scratch.is(count)); |
| 6075 | |
| 6076 | // Nothing to do for zero characters. |
| 6077 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6078 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6079 | __ j(zero, &done); |
| 6080 | |
| 6081 | // Make count the number of bytes to copy. |
| 6082 | if (!ascii) { |
| 6083 | __ shl(count, 1); |
| 6084 | } |
| 6085 | |
| 6086 | // Don't enter the rep movs if there are less than 4 bytes to copy. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6087 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6088 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6089 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6090 | |
| 6091 | // Copy from edi to esi using rep movs instruction. |
| 6092 | __ mov(scratch, count); |
| 6093 | __ sar(count, 2); // Number of doublewords to copy. |
| 6094 | __ cld(); |
| 6095 | __ rep_movs(); |
| 6096 | |
| 6097 | // Find number of bytes left. |
| 6098 | __ mov(count, scratch); |
| 6099 | __ and_(count, 3); |
| 6100 | |
| 6101 | // Check if there are more bytes to copy. |
| 6102 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6103 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6104 | __ j(zero, &done); |
| 6105 | |
| 6106 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6107 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6108 | __ bind(&loop); |
| 6109 | __ mov_b(scratch, Operand(src, 0)); |
| 6110 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6111 | __ add(src, Immediate(1)); |
| 6112 | __ add(dest, Immediate(1)); |
| 6113 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6114 | __ j(not_zero, &loop); |
| 6115 | |
| 6116 | __ bind(&done); |
| 6117 | } |
| 6118 | |
| 6119 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6120 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6121 | Register c1, |
| 6122 | Register c2, |
| 6123 | Register scratch1, |
| 6124 | Register scratch2, |
| 6125 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6126 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6127 | Label* not_found) { |
| 6128 | // Register scratch3 is the general scratch register in this function. |
| 6129 | Register scratch = scratch3; |
| 6130 | |
| 6131 | // Make sure that both characters are not digits as such strings has a |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6132 | // different hash algorithm. Don't try to look for these in the string table. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6133 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6134 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6135 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6136 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6137 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6138 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6139 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6140 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6141 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6142 | |
| 6143 | __ bind(¬_array_index); |
| 6144 | // Calculate the two character string hash. |
| 6145 | Register hash = scratch1; |
| 6146 | GenerateHashInit(masm, hash, c1, scratch); |
| 6147 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 6148 | GenerateHashGetHash(masm, hash, scratch); |
| 6149 | |
| 6150 | // Collect the two characters in a register. |
| 6151 | Register chars = c1; |
| 6152 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6153 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6154 | |
| 6155 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6156 | // hash: hash of two character string. |
| 6157 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6158 | // Load the string table. |
| 6159 | Register string_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6160 | ExternalReference roots_array_start = |
| 6161 | ExternalReference::roots_array_start(masm->isolate()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6162 | __ mov(scratch, Immediate(Heap::kStringTableRootIndex)); |
| 6163 | __ mov(string_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6164 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6165 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6166 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6167 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6168 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6169 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6170 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6171 | |
| 6172 | // Registers |
| 6173 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6174 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6175 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6176 | // mask: capacity mask |
| 6177 | // scratch: - |
| 6178 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6179 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6180 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6181 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6182 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6183 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6184 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6185 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6186 | __ mov(scratch, hash); |
| 6187 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6188 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6189 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6190 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6191 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6192 | // Load the entry from the string table. |
| 6193 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6194 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6195 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6196 | scratch, |
| 6197 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6198 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6199 | |
| 6200 | // If entry is undefined no string with this hash can be found. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6201 | Factory* factory = masm->isolate()->factory(); |
| 6202 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6203 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6204 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6205 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6206 | |
| 6207 | // If length is not 2 the string is not a candidate. |
| 6208 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6209 | Immediate(Smi::FromInt(2))); |
| 6210 | __ j(not_equal, &next_probe[i]); |
| 6211 | |
| 6212 | // As we are out of registers save the mask on the stack and use that |
| 6213 | // register as a temporary. |
| 6214 | __ push(mask); |
| 6215 | Register temp = mask; |
| 6216 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6217 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6218 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6219 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6220 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6221 | temp, temp, &next_probe_pop_mask[i]); |
| 6222 | |
| 6223 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6224 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6225 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6226 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6227 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6228 | __ bind(&next_probe_pop_mask[i]); |
| 6229 | __ pop(mask); |
| 6230 | __ bind(&next_probe[i]); |
| 6231 | } |
| 6232 | |
| 6233 | // No matching 2 character string found by probing. |
| 6234 | __ jmp(not_found); |
| 6235 | |
| 6236 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6237 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6238 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6239 | __ pop(mask); // Pop saved mask from the stack. |
| 6240 | if (!result.is(eax)) { |
| 6241 | __ mov(eax, result); |
| 6242 | } |
| 6243 | } |
| 6244 | |
| 6245 | |
| 6246 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6247 | Register hash, |
| 6248 | Register character, |
| 6249 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6250 | // hash = (seed + character) + ((seed + character) << 10); |
| 6251 | if (Serializer::enabled()) { |
| 6252 | ExternalReference roots_array_start = |
| 6253 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6254 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6255 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6256 | times_pointer_size, |
| 6257 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6258 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6259 | __ add(scratch, character); |
| 6260 | __ mov(hash, scratch); |
| 6261 | __ shl(scratch, 10); |
| 6262 | __ add(hash, scratch); |
| 6263 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6264 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6265 | __ lea(scratch, Operand(character, seed)); |
| 6266 | __ shl(scratch, 10); |
| 6267 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6268 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6269 | // hash ^= hash >> 6; |
| 6270 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6271 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6272 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6273 | } |
| 6274 | |
| 6275 | |
| 6276 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6277 | Register hash, |
| 6278 | Register character, |
| 6279 | Register scratch) { |
| 6280 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6281 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6282 | // hash += hash << 10; |
| 6283 | __ mov(scratch, hash); |
| 6284 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6285 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6286 | // hash ^= hash >> 6; |
| 6287 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6288 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6289 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6290 | } |
| 6291 | |
| 6292 | |
| 6293 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6294 | Register hash, |
| 6295 | Register scratch) { |
| 6296 | // hash += hash << 3; |
| 6297 | __ mov(scratch, hash); |
| 6298 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6299 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6300 | // hash ^= hash >> 11; |
| 6301 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6302 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6303 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6304 | // hash += hash << 15; |
| 6305 | __ mov(scratch, hash); |
| 6306 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6307 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6308 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6309 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6310 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6311 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6312 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6313 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6314 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6315 | __ bind(&hash_not_zero); |
| 6316 | } |
| 6317 | |
| 6318 | |
| 6319 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6320 | Label runtime; |
| 6321 | |
| 6322 | // Stack frame on entry. |
| 6323 | // esp[0]: return address |
| 6324 | // esp[4]: to |
| 6325 | // esp[8]: from |
| 6326 | // esp[12]: string |
| 6327 | |
| 6328 | // Make sure first argument is a string. |
| 6329 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6330 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6331 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6332 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6333 | __ j(NegateCondition(is_string), &runtime); |
| 6334 | |
| 6335 | // eax: string |
| 6336 | // ebx: instance type |
| 6337 | |
| 6338 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6339 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6340 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6341 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6342 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6343 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6344 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6345 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6346 | // Shorter than original string's length: an actual substring. |
| 6347 | __ j(below, ¬_original_string, Label::kNear); |
| 6348 | // Longer than original string's length or negative: unsafe arguments. |
| 6349 | __ j(above, &runtime); |
| 6350 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6351 | Counters* counters = masm->isolate()->counters(); |
| 6352 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6353 | __ ret(3 * kPointerSize); |
| 6354 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6355 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6356 | Label single_char; |
| 6357 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 6358 | __ j(equal, &single_char); |
| 6359 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6360 | // eax: string |
| 6361 | // ebx: instance type |
| 6362 | // ecx: sub string length (smi) |
| 6363 | // edx: from index (smi) |
| 6364 | // Deal with different string types: update the index if necessary |
| 6365 | // and put the underlying string into edi. |
| 6366 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6367 | // If the string is not indirect, it can only be sequential or external. |
| 6368 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6369 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6370 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6371 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6372 | |
| 6373 | Factory* factory = masm->isolate()->factory(); |
| 6374 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6375 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6376 | // Cons string. Check whether it is flat, then fetch first part. |
| 6377 | // Flat cons strings have an empty second part. |
| 6378 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6379 | factory->empty_string()); |
| 6380 | __ j(not_equal, &runtime); |
| 6381 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6382 | // Update instance type. |
| 6383 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6384 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6385 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6386 | |
| 6387 | __ bind(&sliced_string); |
| 6388 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6389 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6390 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6391 | // Update instance type. |
| 6392 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6393 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6394 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6395 | |
| 6396 | __ bind(&seq_or_external_string); |
| 6397 | // Sequential or external string. Just move string to the expected register. |
| 6398 | __ mov(edi, eax); |
| 6399 | |
| 6400 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6401 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6402 | if (FLAG_string_slices) { |
| 6403 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6404 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6405 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6406 | // edx: adjusted start index (smi) |
| 6407 | // ecx: length (smi) |
| 6408 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6409 | // Short slice. Copy instead of slicing. |
| 6410 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6411 | // Allocate new sliced string. At this point we do not reload the instance |
| 6412 | // type including the string encoding because we simply rely on the info |
| 6413 | // provided by the original string. It does not matter if the original |
| 6414 | // string's encoding is wrong because we always have to recheck encoding of |
| 6415 | // the newly created string's parent anyways due to externalized strings. |
| 6416 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6417 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6418 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6419 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6420 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6421 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6422 | __ jmp(&set_slice_header, Label::kNear); |
| 6423 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6424 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6425 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6426 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6427 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6428 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6429 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6430 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6431 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6432 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6433 | |
| 6434 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6435 | } |
| 6436 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6437 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6438 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6439 | // edx: adjusted start index (smi) |
| 6440 | // ecx: length (smi) |
| 6441 | // The subject string can only be external or sequential string of either |
| 6442 | // encoding at this point. |
| 6443 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6444 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6445 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6446 | __ test_b(ebx, kExternalStringTag); |
| 6447 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6448 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6449 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6450 | // Rule out short external strings. |
| 6451 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6452 | __ test_b(ebx, kShortExternalStringMask); |
| 6453 | __ j(not_zero, &runtime); |
| 6454 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6455 | // Move the pointer so that offset-wise, it looks like a sequential string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6456 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6457 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6458 | |
| 6459 | __ bind(&sequential_string); |
| 6460 | // Stash away (adjusted) index and (underlying) string. |
| 6461 | __ push(edx); |
| 6462 | __ push(edi); |
| 6463 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6464 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6465 | __ test_b(ebx, kStringEncodingMask); |
| 6466 | __ j(zero, &two_byte_sequential); |
| 6467 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6468 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6469 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6470 | |
| 6471 | // eax: result string |
| 6472 | // ecx: result string length |
| 6473 | __ mov(edx, esi); // esi used by following code. |
| 6474 | // Locate first character of result. |
| 6475 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6476 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6477 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6478 | __ pop(esi); |
| 6479 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6480 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6481 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6482 | |
| 6483 | // eax: result string |
| 6484 | // ecx: result length |
| 6485 | // edx: original value of esi |
| 6486 | // edi: first character of result |
| 6487 | // esi: character of sub string start |
| 6488 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6489 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6490 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6491 | __ ret(3 * kPointerSize); |
| 6492 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6493 | __ bind(&two_byte_sequential); |
| 6494 | // Sequential two-byte string. Allocate the result. |
| 6495 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6496 | |
| 6497 | // eax: result string |
| 6498 | // ecx: result string length |
| 6499 | __ mov(edx, esi); // esi used by following code. |
| 6500 | // Locate first character of result. |
| 6501 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6502 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6503 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6504 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6505 | __ pop(esi); |
| 6506 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6507 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6508 | // byte character. |
| 6509 | STATIC_ASSERT(kSmiTag == 0); |
| 6510 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6511 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6512 | |
| 6513 | // eax: result string |
| 6514 | // ecx: result length |
| 6515 | // edx: original value of esi |
| 6516 | // edi: first character of result |
| 6517 | // esi: character of sub string start |
| 6518 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6519 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6520 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6521 | __ ret(3 * kPointerSize); |
| 6522 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6523 | // Drop pushed values on the stack before tail call. |
| 6524 | __ bind(&runtime_drop_two); |
| 6525 | __ Drop(2); |
| 6526 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6527 | // Just jump to runtime to create the sub string. |
| 6528 | __ bind(&runtime); |
| 6529 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6530 | |
| 6531 | __ bind(&single_char); |
| 6532 | // eax: string |
| 6533 | // ebx: instance type |
| 6534 | // ecx: sub string length (smi) |
| 6535 | // edx: from index (smi) |
| 6536 | StringCharAtGenerator generator( |
| 6537 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6538 | generator.GenerateFast(masm); |
| 6539 | __ ret(3 * kPointerSize); |
| 6540 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6541 | } |
| 6542 | |
| 6543 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6544 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6545 | Register left, |
| 6546 | Register right, |
| 6547 | Register scratch1, |
| 6548 | Register scratch2) { |
| 6549 | Register length = scratch1; |
| 6550 | |
| 6551 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6552 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6553 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6554 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6555 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6556 | __ bind(&strings_not_equal); |
| 6557 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6558 | __ ret(0); |
| 6559 | |
| 6560 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6561 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6562 | __ bind(&check_zero_length); |
| 6563 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6564 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6565 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6566 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6567 | __ ret(0); |
| 6568 | |
| 6569 | // Compare characters. |
| 6570 | __ bind(&compare_chars); |
| 6571 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6572 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6573 | |
| 6574 | // Characters are equal. |
| 6575 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6576 | __ ret(0); |
| 6577 | } |
| 6578 | |
| 6579 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6580 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6581 | Register left, |
| 6582 | Register right, |
| 6583 | Register scratch1, |
| 6584 | Register scratch2, |
| 6585 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6586 | Counters* counters = masm->isolate()->counters(); |
| 6587 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6588 | |
| 6589 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6590 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6591 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6592 | __ mov(scratch3, scratch1); |
| 6593 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6594 | |
| 6595 | Register length_delta = scratch3; |
| 6596 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6597 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6598 | // Right string is shorter. Change scratch1 to be length of right string. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6599 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6600 | __ bind(&left_shorter); |
| 6601 | |
| 6602 | Register min_length = scratch1; |
| 6603 | |
| 6604 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6605 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6606 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6607 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6608 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6609 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6610 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6611 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6612 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6613 | |
| 6614 | // Compare lengths - strings up to min-length are equal. |
| 6615 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6616 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6617 | Label length_not_equal; |
| 6618 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6619 | |
| 6620 | // Result is EQUAL. |
| 6621 | STATIC_ASSERT(EQUAL == 0); |
| 6622 | STATIC_ASSERT(kSmiTag == 0); |
| 6623 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6624 | __ ret(0); |
| 6625 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6626 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6627 | Label result_less; |
| 6628 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6629 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6630 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6631 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6632 | __ j(above, &result_greater, Label::kNear); |
| 6633 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6634 | |
| 6635 | // Result is LESS. |
| 6636 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6637 | __ ret(0); |
| 6638 | |
| 6639 | // Result is GREATER. |
| 6640 | __ bind(&result_greater); |
| 6641 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6642 | __ ret(0); |
| 6643 | } |
| 6644 | |
| 6645 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6646 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6647 | MacroAssembler* masm, |
| 6648 | Register left, |
| 6649 | Register right, |
| 6650 | Register length, |
| 6651 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6652 | Label* chars_not_equal, |
| 6653 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6654 | // Change index to run from -length to -1 by adding length to string |
| 6655 | // start. This means that loop ends when index reaches zero, which |
| 6656 | // doesn't need an additional compare. |
| 6657 | __ SmiUntag(length); |
| 6658 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6659 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6660 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6661 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6662 | __ neg(length); |
| 6663 | Register index = length; // index = -length; |
| 6664 | |
| 6665 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6666 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6667 | __ bind(&loop); |
| 6668 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6669 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6670 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6671 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6672 | __ j(not_zero, &loop); |
| 6673 | } |
| 6674 | |
| 6675 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6676 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6677 | Label runtime; |
| 6678 | |
| 6679 | // Stack frame on entry. |
| 6680 | // esp[0]: return address |
| 6681 | // esp[4]: right string |
| 6682 | // esp[8]: left string |
| 6683 | |
| 6684 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6685 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6686 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6687 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6688 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6689 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6690 | STATIC_ASSERT(EQUAL == 0); |
| 6691 | STATIC_ASSERT(kSmiTag == 0); |
| 6692 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6693 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6694 | __ ret(2 * kPointerSize); |
| 6695 | |
| 6696 | __ bind(¬_same); |
| 6697 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6698 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6699 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6700 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6701 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6702 | // Drop arguments from the stack. |
| 6703 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6704 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6705 | __ push(ecx); |
| 6706 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6707 | |
| 6708 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6709 | // tagged as a small integer. |
| 6710 | __ bind(&runtime); |
| 6711 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6712 | } |
| 6713 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6714 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6715 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6716 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6717 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6718 | __ mov(ecx, edx); |
| 6719 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6720 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6721 | |
| 6722 | if (GetCondition() == equal) { |
| 6723 | // For equality we do not care about the sign of the result. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6724 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6725 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6726 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6727 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6728 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6729 | // Correct sign of result in case of overflow. |
| 6730 | __ not_(edx); |
| 6731 | __ bind(&done); |
| 6732 | __ mov(eax, edx); |
| 6733 | } |
| 6734 | __ ret(0); |
| 6735 | |
| 6736 | __ bind(&miss); |
| 6737 | GenerateMiss(masm); |
| 6738 | } |
| 6739 | |
| 6740 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6741 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6742 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6743 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6744 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6745 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6746 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6747 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6748 | if (left_ == CompareIC::SMI) { |
| 6749 | __ JumpIfNotSmi(edx, &miss); |
| 6750 | } |
| 6751 | if (right_ == CompareIC::SMI) { |
| 6752 | __ JumpIfNotSmi(eax, &miss); |
| 6753 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6754 | |
| 6755 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6756 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6757 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6758 | CpuFeatureScope scope1(masm, SSE2); |
| 6759 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6760 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6761 | // Load left and right operand. |
| 6762 | Label done, left, left_smi, right_smi; |
| 6763 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6764 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6765 | masm->isolate()->factory()->heap_number_map()); |
| 6766 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6767 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6768 | __ jmp(&left, Label::kNear); |
| 6769 | __ bind(&right_smi); |
| 6770 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6771 | __ SmiUntag(ecx); |
| 6772 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6773 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6774 | __ bind(&left); |
| 6775 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6776 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6777 | masm->isolate()->factory()->heap_number_map()); |
| 6778 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6779 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6780 | __ jmp(&done); |
| 6781 | __ bind(&left_smi); |
| 6782 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6783 | __ SmiUntag(ecx); |
| 6784 | __ cvtsi2sd(xmm0, ecx); |
| 6785 | |
| 6786 | __ bind(&done); |
| 6787 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6788 | __ ucomisd(xmm0, xmm1); |
| 6789 | |
| 6790 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6791 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6792 | |
| 6793 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6794 | // Performing mov, because xor would destroy the flag register. |
| 6795 | __ mov(eax, 0); // equal |
| 6796 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6797 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6798 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6799 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6800 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6801 | } else { |
| 6802 | __ mov(ecx, edx); |
| 6803 | __ and_(ecx, eax); |
| 6804 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6805 | |
| 6806 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6807 | masm->isolate()->factory()->heap_number_map()); |
| 6808 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6809 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6810 | masm->isolate()->factory()->heap_number_map()); |
| 6811 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6812 | } |
| 6813 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6814 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6815 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6816 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6817 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6818 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6819 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6820 | __ bind(&maybe_undefined1); |
| 6821 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6822 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6823 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6824 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6825 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6826 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6827 | __ jmp(&unordered); |
| 6828 | } |
| 6829 | |
| 6830 | __ bind(&maybe_undefined2); |
| 6831 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6832 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6833 | __ j(equal, &unordered); |
| 6834 | } |
| 6835 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6836 | __ bind(&miss); |
| 6837 | GenerateMiss(masm); |
| 6838 | } |
| 6839 | |
| 6840 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6841 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 6842 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6843 | ASSERT(GetCondition() == equal); |
| 6844 | |
| 6845 | // Registers containing left and right operands respectively. |
| 6846 | Register left = edx; |
| 6847 | Register right = eax; |
| 6848 | Register tmp1 = ecx; |
| 6849 | Register tmp2 = ebx; |
| 6850 | |
| 6851 | // Check that both operands are heap objects. |
| 6852 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6853 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6854 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6855 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6856 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6857 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6858 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6859 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6860 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6861 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6862 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6863 | STATIC_ASSERT(kInternalizedTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6864 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6865 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6866 | __ j(zero, &miss, Label::kNear); |
| 6867 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6868 | // Internalized strings are compared by identity. |
| 6869 | Label done; |
| 6870 | __ cmp(left, right); |
| 6871 | // Make sure eax is non-zero. At this point input operands are |
| 6872 | // guaranteed to be non-zero. |
| 6873 | ASSERT(right.is(eax)); |
| 6874 | __ j(not_equal, &done, Label::kNear); |
| 6875 | STATIC_ASSERT(EQUAL == 0); |
| 6876 | STATIC_ASSERT(kSmiTag == 0); |
| 6877 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6878 | __ bind(&done); |
| 6879 | __ ret(0); |
| 6880 | |
| 6881 | __ bind(&miss); |
| 6882 | GenerateMiss(masm); |
| 6883 | } |
| 6884 | |
| 6885 | |
| 6886 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 6887 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 6888 | ASSERT(GetCondition() == equal); |
| 6889 | |
| 6890 | // Registers containing left and right operands respectively. |
| 6891 | Register left = edx; |
| 6892 | Register right = eax; |
| 6893 | Register tmp1 = ecx; |
| 6894 | Register tmp2 = ebx; |
| 6895 | |
| 6896 | // Check that both operands are heap objects. |
| 6897 | Label miss; |
| 6898 | __ mov(tmp1, left); |
| 6899 | STATIC_ASSERT(kSmiTag == 0); |
| 6900 | __ and_(tmp1, right); |
| 6901 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 6902 | |
| 6903 | // Check that both operands are unique names. This leaves the instance |
| 6904 | // types loaded in tmp1 and tmp2. |
| 6905 | STATIC_ASSERT(kInternalizedTag != 0); |
| 6906 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6907 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6908 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6909 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6910 | |
| 6911 | Label succeed1; |
| 6912 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
| 6913 | __ j(not_zero, &succeed1); |
| 6914 | __ cmpb(tmp1, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 6915 | __ j(not_equal, &miss); |
| 6916 | __ bind(&succeed1); |
| 6917 | |
| 6918 | Label succeed2; |
| 6919 | __ test(tmp2, Immediate(kIsInternalizedMask)); |
| 6920 | __ j(not_zero, &succeed2); |
| 6921 | __ cmpb(tmp2, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 6922 | __ j(not_equal, &miss); |
| 6923 | __ bind(&succeed2); |
| 6924 | |
| 6925 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6926 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6927 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6928 | // Make sure eax is non-zero. At this point input operands are |
| 6929 | // guaranteed to be non-zero. |
| 6930 | ASSERT(right.is(eax)); |
| 6931 | __ j(not_equal, &done, Label::kNear); |
| 6932 | STATIC_ASSERT(EQUAL == 0); |
| 6933 | STATIC_ASSERT(kSmiTag == 0); |
| 6934 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6935 | __ bind(&done); |
| 6936 | __ ret(0); |
| 6937 | |
| 6938 | __ bind(&miss); |
| 6939 | GenerateMiss(masm); |
| 6940 | } |
| 6941 | |
| 6942 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6943 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6944 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6945 | Label miss; |
| 6946 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6947 | bool equality = Token::IsEqualityOp(op_); |
| 6948 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6949 | // Registers containing left and right operands respectively. |
| 6950 | Register left = edx; |
| 6951 | Register right = eax; |
| 6952 | Register tmp1 = ecx; |
| 6953 | Register tmp2 = ebx; |
| 6954 | Register tmp3 = edi; |
| 6955 | |
| 6956 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6957 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6958 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6959 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6960 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6961 | |
| 6962 | // Check that both operands are strings. This leaves the instance |
| 6963 | // types loaded in tmp1 and tmp2. |
| 6964 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6965 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6966 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6967 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6968 | __ mov(tmp3, tmp1); |
| 6969 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6970 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6971 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6972 | __ j(not_zero, &miss); |
| 6973 | |
| 6974 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6975 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6976 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6977 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6978 | STATIC_ASSERT(EQUAL == 0); |
| 6979 | STATIC_ASSERT(kSmiTag == 0); |
| 6980 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6981 | __ ret(0); |
| 6982 | |
| 6983 | // Handle not identical strings. |
| 6984 | __ bind(¬_same); |
| 6985 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6986 | // Check that both strings are internalized. If they are, we're done |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6987 | // because we already know they are not identical. But in the case of |
| 6988 | // non-equality compare, we still need to determine the order. |
| 6989 | if (equality) { |
| 6990 | Label do_compare; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6991 | STATIC_ASSERT(kInternalizedTag != 0); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6992 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6993 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6994 | __ j(zero, &do_compare, Label::kNear); |
| 6995 | // Make sure eax is non-zero. At this point input operands are |
| 6996 | // guaranteed to be non-zero. |
| 6997 | ASSERT(right.is(eax)); |
| 6998 | __ ret(0); |
| 6999 | __ bind(&do_compare); |
| 7000 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7001 | |
| 7002 | // Check that both strings are sequential ASCII. |
| 7003 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7004 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 7005 | |
| 7006 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7007 | if (equality) { |
| 7008 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 7009 | masm, left, right, tmp1, tmp2); |
| 7010 | } else { |
| 7011 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 7012 | masm, left, right, tmp1, tmp2, tmp3); |
| 7013 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7014 | |
| 7015 | // Handle more complex cases in runtime. |
| 7016 | __ bind(&runtime); |
| 7017 | __ pop(tmp1); // Return address. |
| 7018 | __ push(left); |
| 7019 | __ push(right); |
| 7020 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7021 | if (equality) { |
| 7022 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 7023 | } else { |
| 7024 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 7025 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7026 | |
| 7027 | __ bind(&miss); |
| 7028 | GenerateMiss(masm); |
| 7029 | } |
| 7030 | |
| 7031 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7032 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7033 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7034 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7035 | __ mov(ecx, edx); |
| 7036 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 7037 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7038 | |
| 7039 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7040 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7041 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7042 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7043 | |
| 7044 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7045 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7046 | __ ret(0); |
| 7047 | |
| 7048 | __ bind(&miss); |
| 7049 | GenerateMiss(masm); |
| 7050 | } |
| 7051 | |
| 7052 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7053 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 7054 | Label miss; |
| 7055 | __ mov(ecx, edx); |
| 7056 | __ and_(ecx, eax); |
| 7057 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7058 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7059 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 7060 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 7061 | __ cmp(ecx, known_map_); |
| 7062 | __ j(not_equal, &miss, Label::kNear); |
| 7063 | __ cmp(ebx, known_map_); |
| 7064 | __ j(not_equal, &miss, Label::kNear); |
| 7065 | |
| 7066 | __ sub(eax, edx); |
| 7067 | __ ret(0); |
| 7068 | |
| 7069 | __ bind(&miss); |
| 7070 | GenerateMiss(masm); |
| 7071 | } |
| 7072 | |
| 7073 | |
| 7074 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7075 | { |
| 7076 | // Call the runtime system in a fresh internal frame. |
| 7077 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 7078 | masm->isolate()); |
| 7079 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7080 | __ push(edx); // Preserve edx and eax. |
| 7081 | __ push(eax); |
| 7082 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7083 | __ push(eax); |
| 7084 | __ push(Immediate(Smi::FromInt(op_))); |
| 7085 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7086 | // Compute the entry point of the rewritten stub. |
| 7087 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 7088 | __ pop(eax); |
| 7089 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7090 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7091 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7092 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7093 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7094 | } |
| 7095 | |
| 7096 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7097 | // Helper function used to check that the dictionary doesn't contain |
| 7098 | // the property. This function may return false negatives, so miss_label |
| 7099 | // must always call a backup property check that is complete. |
| 7100 | // This function is safe to call if the receiver has fast properties. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7101 | // Name must be a unique name and receiver must be a heap object. |
| 7102 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 7103 | Label* miss, |
| 7104 | Label* done, |
| 7105 | Register properties, |
| 7106 | Handle<Name> name, |
| 7107 | Register r0) { |
| 7108 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7109 | |
| 7110 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7111 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7112 | // undefined value), it guarantees the hash table doesn't contain the |
| 7113 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7114 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7115 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7116 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7117 | Register index = r0; |
| 7118 | // Capacity is smi 2^n. |
| 7119 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 7120 | __ dec(index); |
| 7121 | __ and_(index, |
| 7122 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7123 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7124 | |
| 7125 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7126 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7127 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 7128 | Register entity_name = r0; |
| 7129 | // Having undefined at this place means the name is not contained. |
| 7130 | ASSERT_EQ(kSmiTagSize, 1); |
| 7131 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 7132 | kElementsStartOffset - kHeapObjectTag)); |
| 7133 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 7134 | __ j(equal, done); |
| 7135 | |
| 7136 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7137 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7138 | __ j(equal, miss); |
| 7139 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7140 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7141 | // Check for the hole and skip. |
| 7142 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7143 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7144 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7145 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7146 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 7147 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7148 | kIsInternalizedMask); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7149 | __ j(not_zero, &good); |
| 7150 | __ cmpb(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 7151 | static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7152 | __ j(not_equal, miss); |
| 7153 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7154 | } |
| 7155 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7156 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7157 | __ push(Immediate(Handle<Object>(name))); |
| 7158 | __ push(Immediate(name->Hash())); |
| 7159 | __ CallStub(&stub); |
| 7160 | __ test(r0, r0); |
| 7161 | __ j(not_zero, miss); |
| 7162 | __ jmp(done); |
| 7163 | } |
| 7164 | |
| 7165 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7166 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7167 | // |done| label if a property with the given name is found leaving the |
| 7168 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 7169 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7170 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 7171 | Label* miss, |
| 7172 | Label* done, |
| 7173 | Register elements, |
| 7174 | Register name, |
| 7175 | Register r0, |
| 7176 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 7177 | ASSERT(!elements.is(r0)); |
| 7178 | ASSERT(!elements.is(r1)); |
| 7179 | ASSERT(!name.is(r0)); |
| 7180 | ASSERT(!name.is(r1)); |
| 7181 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7182 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7183 | |
| 7184 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 7185 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 7186 | __ dec(r1); |
| 7187 | |
| 7188 | // Generate an unrolled loop that performs a few probes before |
| 7189 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 7190 | // cover ~93% of loads from dictionaries. |
| 7191 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7192 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7193 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 7194 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7195 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7196 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7197 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7198 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7199 | |
| 7200 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7201 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7202 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 7203 | |
| 7204 | // Check if the key is identical to the name. |
| 7205 | __ cmp(name, Operand(elements, |
| 7206 | r0, |
| 7207 | times_4, |
| 7208 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7209 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7210 | } |
| 7211 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7212 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7213 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7214 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 7215 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7216 | __ push(r0); |
| 7217 | __ CallStub(&stub); |
| 7218 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7219 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7220 | __ j(zero, miss); |
| 7221 | __ jmp(done); |
| 7222 | } |
| 7223 | |
| 7224 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7225 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7226 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7227 | // we cannot call anything that could cause a GC from this stub. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7228 | // Stack frame on entry: |
| 7229 | // esp[0 * kPointerSize]: return address. |
| 7230 | // esp[1 * kPointerSize]: key's hash. |
| 7231 | // esp[2 * kPointerSize]: key. |
| 7232 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7233 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7234 | // result_: used as scratch. |
| 7235 | // index_: will hold an index of entry if lookup is successful. |
| 7236 | // might alias with result_. |
| 7237 | // Returns: |
| 7238 | // result_ is zero if lookup failed, non zero otherwise. |
| 7239 | |
| 7240 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7241 | |
| 7242 | Register scratch = result_; |
| 7243 | |
| 7244 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 7245 | __ dec(scratch); |
| 7246 | __ SmiUntag(scratch); |
| 7247 | __ push(scratch); |
| 7248 | |
| 7249 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7250 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7251 | // undefined value), it guarantees the hash table doesn't contain the |
| 7252 | // property. It's true even if some slots represent deleted properties |
| 7253 | // (their names are the null value). |
| 7254 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7255 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7256 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 7257 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7258 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7259 | } |
| 7260 | __ and_(scratch, Operand(esp, 0)); |
| 7261 | |
| 7262 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7263 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7264 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 7265 | |
| 7266 | // Having undefined at this place means the name is not contained. |
| 7267 | ASSERT_EQ(kSmiTagSize, 1); |
| 7268 | __ mov(scratch, Operand(dictionary_, |
| 7269 | index_, |
| 7270 | times_pointer_size, |
| 7271 | kElementsStartOffset - kHeapObjectTag)); |
| 7272 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 7273 | __ j(equal, ¬_in_dictionary); |
| 7274 | |
| 7275 | // Stop if found the property. |
| 7276 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 7277 | __ j(equal, &in_dictionary); |
| 7278 | |
| 7279 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7280 | // If we hit a key that is not a unique name during negative |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7281 | // lookup we have to bailout as this key might be equal to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7282 | // key we are looking for. |
| 7283 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7284 | // Check if the entry name is not a unique name. |
| 7285 | Label cont; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7286 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7287 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7288 | kIsInternalizedMask); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7289 | __ j(not_zero, &cont); |
| 7290 | __ cmpb(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7291 | static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7292 | __ j(not_equal, &maybe_in_dictionary); |
| 7293 | __ bind(&cont); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7294 | } |
| 7295 | } |
| 7296 | |
| 7297 | __ bind(&maybe_in_dictionary); |
| 7298 | // If we are doing negative lookup then probing failure should be |
| 7299 | // treated as a lookup success. For positive lookup probing failure |
| 7300 | // should be treated as lookup failure. |
| 7301 | if (mode_ == POSITIVE_LOOKUP) { |
| 7302 | __ mov(result_, Immediate(0)); |
| 7303 | __ Drop(1); |
| 7304 | __ ret(2 * kPointerSize); |
| 7305 | } |
| 7306 | |
| 7307 | __ bind(&in_dictionary); |
| 7308 | __ mov(result_, Immediate(1)); |
| 7309 | __ Drop(1); |
| 7310 | __ ret(2 * kPointerSize); |
| 7311 | |
| 7312 | __ bind(¬_in_dictionary); |
| 7313 | __ mov(result_, Immediate(0)); |
| 7314 | __ Drop(1); |
| 7315 | __ ret(2 * kPointerSize); |
| 7316 | } |
| 7317 | |
| 7318 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7319 | struct AheadOfTimeWriteBarrierStubList { |
| 7320 | Register object, value, address; |
| 7321 | RememberedSetAction action; |
| 7322 | }; |
| 7323 | |
| 7324 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7325 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7326 | |
| 7327 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7328 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7329 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7330 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7331 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7332 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7333 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7334 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7335 | // Used in StoreStubCompiler::CompileStoreField and |
| 7336 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7337 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7338 | // GenerateStoreField calls the stub with two different permutations of |
| 7339 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7340 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7341 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7342 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7343 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7344 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7345 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7346 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7347 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7348 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7349 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7350 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7351 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7352 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7353 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7354 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7355 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7356 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7357 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7358 | // FastNewClosureStub and StringAddStub::Generate |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7359 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7360 | // StringAddStub::Generate |
| 7361 | { REG(ecx), REG(eax), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7362 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7363 | { REG(no_reg), REG(no_reg), REG(no_reg), EMIT_REMEMBERED_SET} |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7364 | }; |
| 7365 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7366 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7367 | |
| 7368 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7369 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7370 | !entry->object.is(no_reg); |
| 7371 | entry++) { |
| 7372 | if (object_.is(entry->object) && |
| 7373 | value_.is(entry->value) && |
| 7374 | address_.is(entry->address) && |
| 7375 | remembered_set_action_ == entry->action && |
| 7376 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7377 | return true; |
| 7378 | } |
| 7379 | } |
| 7380 | return false; |
| 7381 | } |
| 7382 | |
| 7383 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7384 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 7385 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7386 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
| 7387 | stub.GetCode(isolate)->set_is_pregenerated(true); |
| 7388 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7389 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7390 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7391 | } |
| 7392 | } |
| 7393 | |
| 7394 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7395 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7396 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7397 | !entry->object.is(no_reg); |
| 7398 | entry++) { |
| 7399 | RecordWriteStub stub(entry->object, |
| 7400 | entry->value, |
| 7401 | entry->address, |
| 7402 | entry->action, |
| 7403 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7404 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7405 | } |
| 7406 | } |
| 7407 | |
| 7408 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7409 | bool CodeStub::CanUseFPRegisters() { |
| 7410 | return CpuFeatures::IsSupported(SSE2); |
| 7411 | } |
| 7412 | |
| 7413 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7414 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7415 | // the value has just been written into the object, now this stub makes sure |
| 7416 | // we keep the GC informed. The word in the object where the value has been |
| 7417 | // written is in the address register. |
| 7418 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7419 | Label skip_to_incremental_noncompacting; |
| 7420 | Label skip_to_incremental_compacting; |
| 7421 | |
| 7422 | // The first two instructions are generated with labels so as to get the |
| 7423 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7424 | // forth between a compare instructions (a nop in this position) and the |
| 7425 | // real branch when we start and stop incremental heap marking. |
| 7426 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7427 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7428 | |
| 7429 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7430 | __ RememberedSetHelper(object_, |
| 7431 | address_, |
| 7432 | value_, |
| 7433 | save_fp_regs_mode_, |
| 7434 | MacroAssembler::kReturnAtEnd); |
| 7435 | } else { |
| 7436 | __ ret(0); |
| 7437 | } |
| 7438 | |
| 7439 | __ bind(&skip_to_incremental_noncompacting); |
| 7440 | GenerateIncremental(masm, INCREMENTAL); |
| 7441 | |
| 7442 | __ bind(&skip_to_incremental_compacting); |
| 7443 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7444 | |
| 7445 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7446 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7447 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7448 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7449 | } |
| 7450 | |
| 7451 | |
| 7452 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7453 | regs_.Save(masm); |
| 7454 | |
| 7455 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7456 | Label dont_need_remembered_set; |
| 7457 | |
| 7458 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7459 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7460 | regs_.scratch0(), |
| 7461 | &dont_need_remembered_set); |
| 7462 | |
| 7463 | __ CheckPageFlag(regs_.object(), |
| 7464 | regs_.scratch0(), |
| 7465 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7466 | not_zero, |
| 7467 | &dont_need_remembered_set); |
| 7468 | |
| 7469 | // First notify the incremental marker if necessary, then update the |
| 7470 | // remembered set. |
| 7471 | CheckNeedsToInformIncrementalMarker( |
| 7472 | masm, |
| 7473 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7474 | mode); |
| 7475 | InformIncrementalMarker(masm, mode); |
| 7476 | regs_.Restore(masm); |
| 7477 | __ RememberedSetHelper(object_, |
| 7478 | address_, |
| 7479 | value_, |
| 7480 | save_fp_regs_mode_, |
| 7481 | MacroAssembler::kReturnAtEnd); |
| 7482 | |
| 7483 | __ bind(&dont_need_remembered_set); |
| 7484 | } |
| 7485 | |
| 7486 | CheckNeedsToInformIncrementalMarker( |
| 7487 | masm, |
| 7488 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7489 | mode); |
| 7490 | InformIncrementalMarker(masm, mode); |
| 7491 | regs_.Restore(masm); |
| 7492 | __ ret(0); |
| 7493 | } |
| 7494 | |
| 7495 | |
| 7496 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7497 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7498 | int argument_count = 3; |
| 7499 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7500 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7501 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7502 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 7503 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7504 | |
| 7505 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7506 | if (mode == INCREMENTAL_COMPACTION) { |
| 7507 | __ CallCFunction( |
| 7508 | ExternalReference::incremental_evacuation_record_write_function( |
| 7509 | masm->isolate()), |
| 7510 | argument_count); |
| 7511 | } else { |
| 7512 | ASSERT(mode == INCREMENTAL); |
| 7513 | __ CallCFunction( |
| 7514 | ExternalReference::incremental_marking_record_write_function( |
| 7515 | masm->isolate()), |
| 7516 | argument_count); |
| 7517 | } |
| 7518 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7519 | } |
| 7520 | |
| 7521 | |
| 7522 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7523 | MacroAssembler* masm, |
| 7524 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7525 | Mode mode) { |
| 7526 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7527 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7528 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7529 | __ and_(regs_.scratch0(), regs_.object()); |
| 7530 | __ mov(regs_.scratch1(), |
| 7531 | Operand(regs_.scratch0(), |
| 7532 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7533 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7534 | __ mov(Operand(regs_.scratch0(), |
| 7535 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7536 | regs_.scratch1()); |
| 7537 | __ j(negative, &need_incremental); |
| 7538 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7539 | // Let's look at the color of the object: If it is not black we don't have |
| 7540 | // to inform the incremental marker. |
| 7541 | __ JumpIfBlack(regs_.object(), |
| 7542 | regs_.scratch0(), |
| 7543 | regs_.scratch1(), |
| 7544 | &object_is_black, |
| 7545 | Label::kNear); |
| 7546 | |
| 7547 | regs_.Restore(masm); |
| 7548 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7549 | __ RememberedSetHelper(object_, |
| 7550 | address_, |
| 7551 | value_, |
| 7552 | save_fp_regs_mode_, |
| 7553 | MacroAssembler::kReturnAtEnd); |
| 7554 | } else { |
| 7555 | __ ret(0); |
| 7556 | } |
| 7557 | |
| 7558 | __ bind(&object_is_black); |
| 7559 | |
| 7560 | // Get the value from the slot. |
| 7561 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7562 | |
| 7563 | if (mode == INCREMENTAL_COMPACTION) { |
| 7564 | Label ensure_not_white; |
| 7565 | |
| 7566 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7567 | regs_.scratch1(), // Scratch. |
| 7568 | MemoryChunk::kEvacuationCandidateMask, |
| 7569 | zero, |
| 7570 | &ensure_not_white, |
| 7571 | Label::kNear); |
| 7572 | |
| 7573 | __ CheckPageFlag(regs_.object(), |
| 7574 | regs_.scratch1(), // Scratch. |
| 7575 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7576 | not_zero, |
| 7577 | &ensure_not_white, |
| 7578 | Label::kNear); |
| 7579 | |
| 7580 | __ jmp(&need_incremental); |
| 7581 | |
| 7582 | __ bind(&ensure_not_white); |
| 7583 | } |
| 7584 | |
| 7585 | // We need an extra register for this, so we push the object register |
| 7586 | // temporarily. |
| 7587 | __ push(regs_.object()); |
| 7588 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7589 | regs_.scratch1(), // Scratch. |
| 7590 | regs_.object(), // Scratch. |
| 7591 | &need_incremental_pop_object, |
| 7592 | Label::kNear); |
| 7593 | __ pop(regs_.object()); |
| 7594 | |
| 7595 | regs_.Restore(masm); |
| 7596 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7597 | __ RememberedSetHelper(object_, |
| 7598 | address_, |
| 7599 | value_, |
| 7600 | save_fp_regs_mode_, |
| 7601 | MacroAssembler::kReturnAtEnd); |
| 7602 | } else { |
| 7603 | __ ret(0); |
| 7604 | } |
| 7605 | |
| 7606 | __ bind(&need_incremental_pop_object); |
| 7607 | __ pop(regs_.object()); |
| 7608 | |
| 7609 | __ bind(&need_incremental); |
| 7610 | |
| 7611 | // Fall through when we need to inform the incremental marker. |
| 7612 | } |
| 7613 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7614 | |
| 7615 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7616 | // ----------- S t a t e ------------- |
| 7617 | // -- eax : element value to store |
| 7618 | // -- ebx : array literal |
| 7619 | // -- edi : map of array literal |
| 7620 | // -- ecx : element index as smi |
| 7621 | // -- edx : array literal index in function |
| 7622 | // -- esp[0] : return address |
| 7623 | // ----------------------------------- |
| 7624 | |
| 7625 | Label element_done; |
| 7626 | Label double_elements; |
| 7627 | Label smi_element; |
| 7628 | Label slow_elements; |
| 7629 | Label slow_elements_from_double; |
| 7630 | Label fast_elements; |
| 7631 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7632 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7633 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7634 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7635 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7636 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7637 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7638 | // Store into the array literal requires a elements transition. Call into |
| 7639 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7640 | |
| 7641 | __ bind(&slow_elements); |
| 7642 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7643 | // call. |
| 7644 | __ push(ebx); |
| 7645 | __ push(ecx); |
| 7646 | __ push(eax); |
| 7647 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7648 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7649 | __ push(edx); |
| 7650 | __ push(edi); // Return return address so that tail call returns to right |
| 7651 | // place. |
| 7652 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7653 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7654 | __ bind(&slow_elements_from_double); |
| 7655 | __ pop(edx); |
| 7656 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7657 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7658 | // Array literal has ElementsKind of FAST_*_ELEMENTS and value is an object. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7659 | __ bind(&fast_elements); |
| 7660 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7661 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7662 | FixedArrayBase::kHeaderSize)); |
| 7663 | __ mov(Operand(ecx, 0), eax); |
| 7664 | // Update the write barrier for the array store. |
| 7665 | __ RecordWrite(ebx, ecx, eax, |
| 7666 | kDontSaveFPRegs, |
| 7667 | EMIT_REMEMBERED_SET, |
| 7668 | OMIT_SMI_CHECK); |
| 7669 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7670 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7671 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7672 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7673 | __ bind(&smi_element); |
| 7674 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7675 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7676 | FixedArrayBase::kHeaderSize), eax); |
| 7677 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7678 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7679 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7680 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7681 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7682 | __ push(edx); |
| 7683 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7684 | __ StoreNumberToDoubleElements(eax, |
| 7685 | edx, |
| 7686 | ecx, |
| 7687 | edi, |
| 7688 | xmm0, |
| 7689 | &slow_elements_from_double, |
| 7690 | false); |
| 7691 | __ pop(edx); |
| 7692 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7693 | } |
| 7694 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7695 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7696 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7697 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7698 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7699 | int parameter_count_offset = |
| 7700 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7701 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7702 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7703 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7704 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 7705 | ? kPointerSize |
| 7706 | : 0; |
| 7707 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7708 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7709 | } |
| 7710 | |
| 7711 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7712 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7713 | if (entry_hook_ != NULL) { |
| 7714 | ProfileEntryHookStub stub; |
| 7715 | masm->CallStub(&stub); |
| 7716 | } |
| 7717 | } |
| 7718 | |
| 7719 | |
| 7720 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7721 | // Ecx is the only volatile register we must save. |
| 7722 | __ push(ecx); |
| 7723 | |
| 7724 | // Calculate and push the original stack pointer. |
| 7725 | __ lea(eax, Operand(esp, kPointerSize)); |
| 7726 | __ push(eax); |
| 7727 | |
| 7728 | // Calculate and push the function address. |
| 7729 | __ mov(eax, Operand(eax, 0)); |
| 7730 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7731 | __ push(eax); |
| 7732 | |
| 7733 | // Call the entry hook. |
| 7734 | int32_t hook_location = reinterpret_cast<int32_t>(&entry_hook_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 7735 | __ call(Operand(hook_location, RelocInfo::NONE32)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7736 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7737 | |
| 7738 | // Restore ecx. |
| 7739 | __ pop(ecx); |
| 7740 | __ ret(0); |
| 7741 | } |
| 7742 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7743 | |
| 7744 | template<class T> |
| 7745 | static void CreateArrayDispatch(MacroAssembler* masm) { |
| 7746 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7747 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7748 | for (int i = 0; i <= last_index; ++i) { |
| 7749 | Label next; |
| 7750 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7751 | __ cmp(edx, kind); |
| 7752 | __ j(not_equal, &next); |
| 7753 | T stub(kind); |
| 7754 | __ TailCallStub(&stub); |
| 7755 | __ bind(&next); |
| 7756 | } |
| 7757 | |
| 7758 | // If we reached this point there is a problem. |
| 7759 | __ Abort("Unexpected ElementsKind in array constructor"); |
| 7760 | } |
| 7761 | |
| 7762 | |
| 7763 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm) { |
| 7764 | // ebx - type info cell |
| 7765 | // edx - kind |
| 7766 | // eax - number of arguments |
| 7767 | // edi - constructor? |
| 7768 | // esp[0] - return address |
| 7769 | // esp[4] - last argument |
| 7770 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 7771 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 7772 | ASSERT(FAST_ELEMENTS == 2); |
| 7773 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 7774 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 7775 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 7776 | |
| 7777 | Handle<Object> undefined_sentinel( |
| 7778 | masm->isolate()->heap()->undefined_value(), |
| 7779 | masm->isolate()); |
| 7780 | |
| 7781 | // is the low bit set? If so, we are holey and that is good. |
| 7782 | __ test_b(edx, 1); |
| 7783 | Label normal_sequence; |
| 7784 | __ j(not_zero, &normal_sequence); |
| 7785 | |
| 7786 | // look at the first argument |
| 7787 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7788 | __ test(ecx, ecx); |
| 7789 | __ j(zero, &normal_sequence); |
| 7790 | |
| 7791 | // We are going to create a holey array, but our kind is non-holey. |
| 7792 | // Fix kind and retry |
| 7793 | __ inc(edx); |
| 7794 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7795 | __ j(equal, &normal_sequence); |
| 7796 | |
| 7797 | // Save the resulting elements kind in type info |
| 7798 | __ SmiTag(edx); |
| 7799 | __ mov(FieldOperand(ebx, kPointerSize), edx); |
| 7800 | __ SmiUntag(edx); |
| 7801 | |
| 7802 | __ bind(&normal_sequence); |
| 7803 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7804 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7805 | for (int i = 0; i <= last_index; ++i) { |
| 7806 | Label next; |
| 7807 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7808 | __ cmp(edx, kind); |
| 7809 | __ j(not_equal, &next); |
| 7810 | ArraySingleArgumentConstructorStub stub(kind); |
| 7811 | __ TailCallStub(&stub); |
| 7812 | __ bind(&next); |
| 7813 | } |
| 7814 | |
| 7815 | // If we reached this point there is a problem. |
| 7816 | __ Abort("Unexpected ElementsKind in array constructor"); |
| 7817 | } |
| 7818 | |
| 7819 | |
| 7820 | template<class T> |
| 7821 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 7822 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 7823 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7824 | for (int i = 0; i <= to_index; ++i) { |
| 7825 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7826 | T stub(kind); |
| 7827 | stub.GetCode(isolate)->set_is_pregenerated(true); |
| 7828 | } |
| 7829 | } |
| 7830 | |
| 7831 | |
| 7832 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 7833 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 7834 | isolate); |
| 7835 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 7836 | isolate); |
| 7837 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 7838 | isolate); |
| 7839 | } |
| 7840 | |
| 7841 | |
| 7842 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7843 | // ----------- S t a t e ------------- |
| 7844 | // -- eax : argc (only if argument_count_ == ANY) |
| 7845 | // -- ebx : type info cell |
| 7846 | // -- edi : constructor |
| 7847 | // -- esp[0] : return address |
| 7848 | // -- esp[4] : last argument |
| 7849 | // ----------------------------------- |
| 7850 | Handle<Object> undefined_sentinel( |
| 7851 | masm->isolate()->heap()->undefined_value(), |
| 7852 | masm->isolate()); |
| 7853 | |
| 7854 | if (FLAG_debug_code) { |
| 7855 | // The array construct code is only set for the global and natives |
| 7856 | // builtin Array functions which always have maps. |
| 7857 | |
| 7858 | // Initial map for the builtin Array function should be a map. |
| 7859 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7860 | // Will both indicate a NULL and a Smi. |
| 7861 | __ test(ecx, Immediate(kSmiTagMask)); |
| 7862 | __ Assert(not_zero, "Unexpected initial map for Array function"); |
| 7863 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 7864 | __ Assert(equal, "Unexpected initial map for Array function"); |
| 7865 | |
| 7866 | // We should either have undefined in ebx or a valid jsglobalpropertycell |
| 7867 | Label okay_here; |
| 7868 | Handle<Map> global_property_cell_map( |
| 7869 | masm->isolate()->heap()->global_property_cell_map()); |
| 7870 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7871 | __ j(equal, &okay_here); |
| 7872 | __ cmp(FieldOperand(ebx, 0), Immediate(global_property_cell_map)); |
| 7873 | __ Assert(equal, "Expected property cell in register ebx"); |
| 7874 | __ bind(&okay_here); |
| 7875 | } |
| 7876 | |
| 7877 | if (FLAG_optimize_constructed_arrays) { |
| 7878 | Label no_info, switch_ready; |
| 7879 | // Get the elements kind and case on that. |
| 7880 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7881 | __ j(equal, &no_info); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7882 | __ mov(edx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
| 7883 | __ JumpIfNotSmi(edx, &no_info); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7884 | __ SmiUntag(edx); |
| 7885 | __ jmp(&switch_ready); |
| 7886 | __ bind(&no_info); |
| 7887 | __ mov(edx, Immediate(GetInitialFastElementsKind())); |
| 7888 | __ bind(&switch_ready); |
| 7889 | |
| 7890 | if (argument_count_ == ANY) { |
| 7891 | Label not_zero_case, not_one_case; |
| 7892 | __ test(eax, eax); |
| 7893 | __ j(not_zero, ¬_zero_case); |
| 7894 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
| 7895 | |
| 7896 | __ bind(¬_zero_case); |
| 7897 | __ cmp(eax, 1); |
| 7898 | __ j(greater, ¬_one_case); |
| 7899 | CreateArrayDispatchOneArgument(masm); |
| 7900 | |
| 7901 | __ bind(¬_one_case); |
| 7902 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
| 7903 | } else if (argument_count_ == NONE) { |
| 7904 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
| 7905 | } else if (argument_count_ == ONE) { |
| 7906 | CreateArrayDispatchOneArgument(masm); |
| 7907 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 7908 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
| 7909 | } else { |
| 7910 | UNREACHABLE(); |
| 7911 | } |
| 7912 | } else { |
| 7913 | Label generic_constructor; |
| 7914 | // Run the native code for the Array function called as constructor. |
| 7915 | ArrayNativeCode(masm, true, &generic_constructor); |
| 7916 | |
| 7917 | // Jump to the generic construct code in case the specialized code cannot |
| 7918 | // handle the construction. |
| 7919 | __ bind(&generic_constructor); |
| 7920 | Handle<Code> generic_construct_stub = |
| 7921 | masm->isolate()->builtins()->JSConstructStubGeneric(); |
| 7922 | __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 7923 | } |
| 7924 | } |
| 7925 | |
| 7926 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7927 | #undef __ |
| 7928 | |
| 7929 | } } // namespace v8::internal |
| 7930 | |
| 7931 | #endif // V8_TARGET_ARCH_IA32 |