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" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 33 | #include "code-stubs.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 34 | #include "isolate.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 35 | #include "jsregexp.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 36 | #include "regexp-macro-assembler.h" |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 37 | #include "runtime.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 38 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 39 | #include "codegen.h" |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 40 | #include "runtime.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 41 | |
| 42 | namespace v8 { |
| 43 | namespace internal { |
| 44 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 45 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 46 | void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( |
| 47 | Isolate* isolate, |
| 48 | CodeStubInterfaceDescriptor* descriptor) { |
| 49 | static Register registers[] = { eax, ebx, ecx }; |
| 50 | descriptor->register_param_count_ = 3; |
| 51 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 52 | descriptor->deoptimization_handler_ = |
| 53 | Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; |
| 54 | } |
| 55 | |
| 56 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 57 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 58 | Isolate* isolate, |
| 59 | CodeStubInterfaceDescriptor* descriptor) { |
| 60 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 61 | descriptor->register_param_count_ = 4; |
| 62 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 63 | descriptor->deoptimization_handler_ = |
| 64 | Runtime::FunctionForId(Runtime::kCreateObjectLiteralShallow)->entry; |
| 65 | } |
| 66 | |
| 67 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 68 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 69 | Isolate* isolate, |
| 70 | CodeStubInterfaceDescriptor* descriptor) { |
| 71 | static Register registers[] = { edx, ecx }; |
| 72 | descriptor->register_param_count_ = 2; |
| 73 | descriptor->register_params_ = registers; |
| 74 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 75 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 79 | void LoadFieldStub::InitializeInterfaceDescriptor( |
| 80 | Isolate* isolate, |
| 81 | CodeStubInterfaceDescriptor* descriptor) { |
| 82 | static Register registers[] = { edx }; |
| 83 | descriptor->register_param_count_ = 1; |
| 84 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 85 | descriptor->deoptimization_handler_ = NULL; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | void KeyedLoadFieldStub::InitializeInterfaceDescriptor( |
| 90 | Isolate* isolate, |
| 91 | CodeStubInterfaceDescriptor* descriptor) { |
| 92 | static Register registers[] = { edx }; |
| 93 | descriptor->register_param_count_ = 1; |
| 94 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 95 | descriptor->deoptimization_handler_ = NULL; |
| 96 | } |
| 97 | |
| 98 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 99 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 100 | Isolate* isolate, |
| 101 | CodeStubInterfaceDescriptor* descriptor) { |
| 102 | static Register registers[] = { edx, ecx, eax }; |
| 103 | descriptor->register_param_count_ = 3; |
| 104 | descriptor->register_params_ = registers; |
| 105 | descriptor->deoptimization_handler_ = |
| 106 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 107 | } |
| 108 | |
| 109 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 110 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 111 | Isolate* isolate, |
| 112 | CodeStubInterfaceDescriptor* descriptor) { |
| 113 | static Register registers[] = { eax, ebx }; |
| 114 | descriptor->register_param_count_ = 2; |
| 115 | descriptor->register_params_ = registers; |
| 116 | descriptor->deoptimization_handler_ = |
| 117 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 118 | } |
| 119 | |
| 120 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 121 | static void InitializeArrayConstructorDescriptor( |
| 122 | Isolate* isolate, |
| 123 | CodeStubInterfaceDescriptor* descriptor, |
| 124 | int constant_stack_parameter_count) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 125 | // register state |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 126 | // eax -- number of arguments |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 127 | // edi -- function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 128 | // ebx -- type info cell with elements kind |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 129 | static Register registers[] = { edi, ebx }; |
| 130 | descriptor->register_param_count_ = 2; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 131 | |
| 132 | if (constant_stack_parameter_count != 0) { |
| 133 | // stack param count needs (constructor pointer, and single argument) |
| 134 | descriptor->stack_parameter_count_ = &eax; |
| 135 | } |
| 136 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 137 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 138 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 139 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 140 | Runtime::FunctionForId(Runtime::kArrayConstructor)->entry; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 144 | static void InitializeInternalArrayConstructorDescriptor( |
| 145 | Isolate* isolate, |
| 146 | CodeStubInterfaceDescriptor* descriptor, |
| 147 | int constant_stack_parameter_count) { |
| 148 | // register state |
| 149 | // eax -- number of arguments |
| 150 | // edi -- constructor function |
| 151 | static Register registers[] = { edi }; |
| 152 | descriptor->register_param_count_ = 1; |
| 153 | |
| 154 | if (constant_stack_parameter_count != 0) { |
| 155 | // stack param count needs (constructor pointer, and single argument) |
| 156 | descriptor->stack_parameter_count_ = &eax; |
| 157 | } |
| 158 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
| 159 | descriptor->register_params_ = registers; |
| 160 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
| 161 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 162 | Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 166 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 167 | Isolate* isolate, |
| 168 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 169 | InitializeArrayConstructorDescriptor(isolate, descriptor, 0); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | |
| 173 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 174 | Isolate* isolate, |
| 175 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 176 | InitializeArrayConstructorDescriptor(isolate, descriptor, 1); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | |
| 180 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 181 | Isolate* isolate, |
| 182 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 183 | InitializeArrayConstructorDescriptor(isolate, descriptor, -1); |
| 184 | } |
| 185 | |
| 186 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 187 | void InternalArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 188 | Isolate* isolate, |
| 189 | CodeStubInterfaceDescriptor* descriptor) { |
| 190 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 0); |
| 191 | } |
| 192 | |
| 193 | |
| 194 | void InternalArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 195 | Isolate* isolate, |
| 196 | CodeStubInterfaceDescriptor* descriptor) { |
| 197 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 1); |
| 198 | } |
| 199 | |
| 200 | |
| 201 | void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 202 | Isolate* isolate, |
| 203 | CodeStubInterfaceDescriptor* descriptor) { |
| 204 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, -1); |
| 205 | } |
| 206 | |
| 207 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 208 | void CompareNilICStub::InitializeInterfaceDescriptor( |
| 209 | Isolate* isolate, |
| 210 | CodeStubInterfaceDescriptor* descriptor) { |
| 211 | static Register registers[] = { eax }; |
| 212 | descriptor->register_param_count_ = 1; |
| 213 | descriptor->register_params_ = registers; |
| 214 | descriptor->deoptimization_handler_ = |
| 215 | FUNCTION_ADDR(CompareNilIC_Miss); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 216 | descriptor->SetMissHandler( |
| 217 | ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 218 | } |
| 219 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 220 | void ToBooleanStub::InitializeInterfaceDescriptor( |
| 221 | Isolate* isolate, |
| 222 | CodeStubInterfaceDescriptor* descriptor) { |
| 223 | static Register registers[] = { eax }; |
| 224 | descriptor->register_param_count_ = 1; |
| 225 | descriptor->register_params_ = registers; |
| 226 | descriptor->deoptimization_handler_ = |
| 227 | FUNCTION_ADDR(ToBooleanIC_Miss); |
| 228 | descriptor->SetMissHandler( |
| 229 | ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate)); |
| 230 | } |
| 231 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 232 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 233 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 234 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 235 | |
| 236 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
| 237 | // Update the static counter each time a new code stub is generated. |
| 238 | Isolate* isolate = masm->isolate(); |
| 239 | isolate->counters()->code_stubs()->Increment(); |
| 240 | |
| 241 | CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
| 242 | int param_count = descriptor->register_param_count_; |
| 243 | { |
| 244 | // Call the runtime system in a fresh internal frame. |
| 245 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 246 | ASSERT(descriptor->register_param_count_ == 0 || |
| 247 | eax.is(descriptor->register_params_[param_count - 1])); |
| 248 | // Push arguments |
| 249 | for (int i = 0; i < param_count; ++i) { |
| 250 | __ push(descriptor->register_params_[i]); |
| 251 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 252 | ExternalReference miss = descriptor->miss_handler(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 253 | __ CallExternalReference(miss, descriptor->register_param_count_); |
| 254 | } |
| 255 | |
| 256 | __ ret(0); |
| 257 | } |
| 258 | |
| 259 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 260 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 261 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 262 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 263 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 264 | __ ret(0); |
| 265 | |
| 266 | __ bind(&check_heap_number); |
| 267 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 268 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 269 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 270 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 271 | __ ret(0); |
| 272 | |
| 273 | __ bind(&call_builtin); |
| 274 | __ pop(ecx); // Pop return address. |
| 275 | __ push(eax); |
| 276 | __ push(ecx); // Push return address. |
| 277 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 278 | } |
| 279 | |
| 280 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 281 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 282 | // Create a new closure from the given function info in new |
| 283 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 284 | Counters* counters = masm->isolate()->counters(); |
| 285 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 286 | Label gc; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 287 | __ Allocate(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 288 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 289 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 290 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 291 | // Get the function info from the stack. |
| 292 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 293 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 294 | int map_index = Context::FunctionMapIndex(language_mode_, is_generator_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 295 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 296 | // 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] | 297 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 298 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 299 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 300 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 301 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 302 | |
| 303 | // Initialize the rest of the function. We don't have to update the |
| 304 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 305 | Factory* factory = masm->isolate()->factory(); |
| 306 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 307 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 308 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 309 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 310 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 311 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 312 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 313 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 314 | |
| 315 | // Initialize the code pointer in the function to be the one |
| 316 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 317 | // But first check if there is an optimized version for our context. |
| 318 | Label check_optimized; |
| 319 | Label install_unoptimized; |
| 320 | if (FLAG_cache_optimized_code) { |
| 321 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 322 | __ test(ebx, ebx); |
| 323 | __ j(not_zero, &check_optimized, Label::kNear); |
| 324 | } |
| 325 | __ bind(&install_unoptimized); |
| 326 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 327 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 328 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 329 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 330 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 331 | |
| 332 | // Return and remove the on-stack parameter. |
| 333 | __ ret(1 * kPointerSize); |
| 334 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 335 | __ bind(&check_optimized); |
| 336 | |
| 337 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 338 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 339 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 340 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 341 | // Map must never be empty, so check the first elements. |
| 342 | Label install_optimized; |
| 343 | // Speculatively move code object into edx. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 344 | __ mov(edx, FieldOperand(ebx, SharedFunctionInfo::kFirstCodeSlot)); |
| 345 | __ cmp(ecx, FieldOperand(ebx, SharedFunctionInfo::kFirstContextSlot)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 346 | __ j(equal, &install_optimized); |
| 347 | |
| 348 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 349 | Label loop; |
| 350 | Label restore; |
| 351 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 352 | __ bind(&loop); |
| 353 | // Do not double check first entry. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 354 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kSecondEntryIndex))); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 355 | __ j(equal, &restore); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 356 | __ sub(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 357 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 358 | __ j(not_equal, &loop, Label::kNear); |
| 359 | // Hit: fetch the optimized code. |
| 360 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 361 | |
| 362 | __ bind(&install_optimized); |
| 363 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 364 | |
| 365 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 366 | // map and either unmangle them on marking or do nothing as the whole map is |
| 367 | // discarded on major GC anyway. |
| 368 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 369 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 370 | |
| 371 | // Now link a function into a list of optimized functions. |
| 372 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 373 | |
| 374 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 375 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 376 | |
| 377 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 378 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 379 | // it clobbers all the registers passed. |
| 380 | __ mov(edx, eax); |
| 381 | __ RecordWriteContextSlot( |
| 382 | ecx, |
| 383 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 384 | edx, |
| 385 | ebx, |
| 386 | kDontSaveFPRegs); |
| 387 | |
| 388 | // Return and remove the on-stack parameter. |
| 389 | __ ret(1 * kPointerSize); |
| 390 | |
| 391 | __ bind(&restore); |
| 392 | // Restore SharedFunctionInfo into edx. |
| 393 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 394 | __ jmp(&install_unoptimized); |
| 395 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 396 | // Create a new closure through the slower runtime call. |
| 397 | __ bind(&gc); |
| 398 | __ pop(ecx); // Temporarily remove return address. |
| 399 | __ pop(edx); |
| 400 | __ push(esi); |
| 401 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 402 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 403 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 404 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | |
| 408 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 409 | // Try to allocate the context in new space. |
| 410 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 411 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 412 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 413 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 414 | |
| 415 | // Get the function from the stack. |
| 416 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 417 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 418 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 419 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 420 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 421 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 422 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 423 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 424 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 425 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 426 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 427 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 428 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 429 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 430 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 431 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 432 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 433 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 434 | |
| 435 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 436 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 437 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 438 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 439 | } |
| 440 | |
| 441 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 442 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 443 | __ ret(1 * kPointerSize); |
| 444 | |
| 445 | // Need to collect. Call into runtime system. |
| 446 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 447 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 451 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 452 | // Stack layout on entry: |
| 453 | // |
| 454 | // [esp + (1 * kPointerSize)]: function |
| 455 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 456 | |
| 457 | // Try to allocate the context in new space. |
| 458 | Label gc; |
| 459 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 460 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 461 | |
| 462 | // Get the function or sentinel from the stack. |
| 463 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 464 | |
| 465 | // Get the serialized scope info from the stack. |
| 466 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 467 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 468 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 469 | Factory* factory = masm->isolate()->factory(); |
| 470 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 471 | factory->block_context_map()); |
| 472 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 473 | Immediate(Smi::FromInt(length))); |
| 474 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 475 | // 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] | 476 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 477 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 478 | // we still have to look up. |
| 479 | Label after_sentinel; |
| 480 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 481 | if (FLAG_debug_code) { |
| 482 | const char* message = "Expected 0 as a Smi sentinel"; |
| 483 | __ cmp(ecx, 0); |
| 484 | __ Assert(equal, message); |
| 485 | } |
| 486 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 487 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 488 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 489 | __ bind(&after_sentinel); |
| 490 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 491 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 492 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 493 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 494 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 495 | |
| 496 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 497 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 498 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 499 | |
| 500 | // Initialize the rest of the slots to the hole value. |
| 501 | if (slots_ == 1) { |
| 502 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 503 | factory->the_hole_value()); |
| 504 | } else { |
| 505 | __ mov(ebx, factory->the_hole_value()); |
| 506 | for (int i = 0; i < slots_; i++) { |
| 507 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | // Return and remove the on-stack parameters. |
| 512 | __ mov(esi, eax); |
| 513 | __ ret(2 * kPointerSize); |
| 514 | |
| 515 | // Need to collect. Call into runtime system. |
| 516 | __ bind(&gc); |
| 517 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 518 | } |
| 519 | |
| 520 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 521 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 522 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 523 | // store the registers in any particular way, but we do have to store and |
| 524 | // restore them. |
| 525 | __ pushad(); |
| 526 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 527 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 528 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 529 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 530 | XMMRegister reg = XMMRegister::from_code(i); |
| 531 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 532 | } |
| 533 | } |
| 534 | const int argument_count = 1; |
| 535 | |
| 536 | AllowExternalCallThatCantCauseGC scope(masm); |
| 537 | __ PrepareCallCFunction(argument_count, ecx); |
| 538 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 539 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 540 | __ CallCFunction( |
| 541 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 542 | argument_count); |
| 543 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 544 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 545 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 546 | XMMRegister reg = XMMRegister::from_code(i); |
| 547 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 548 | } |
| 549 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 550 | } |
| 551 | __ popad(); |
| 552 | __ ret(0); |
| 553 | } |
| 554 | |
| 555 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 556 | class FloatingPointHelper : public AllStatic { |
| 557 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 558 | enum ArgLocation { |
| 559 | ARGS_ON_STACK, |
| 560 | ARGS_IN_REGISTERS |
| 561 | }; |
| 562 | |
| 563 | // Code pattern for loading a floating point value. Input value must |
| 564 | // be either a smi or a heap number object (fp value). Requirements: |
| 565 | // operand in register number. Returns operand as floating point number |
| 566 | // on FPU stack. |
| 567 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 568 | |
| 569 | // Code pattern for loading floating point values. Input values must |
| 570 | // be either smi or heap number objects (fp values). Requirements: |
| 571 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 572 | // Returns operands as floating point numbers on FPU stack. |
| 573 | static void LoadFloatOperands(MacroAssembler* masm, |
| 574 | Register scratch, |
| 575 | ArgLocation arg_location = ARGS_ON_STACK); |
| 576 | |
| 577 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 578 | // Expects operands in edx, eax. |
| 579 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 580 | |
| 581 | // Test if operands are smi or number objects (fp). Requirements: |
| 582 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 583 | // operands, jumps to the non_float label otherwise. |
| 584 | static void CheckFloatOperands(MacroAssembler* masm, |
| 585 | Label* non_float, |
| 586 | Register scratch); |
| 587 | |
| 588 | // Takes the operands in edx and eax and loads them as integers in eax |
| 589 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 590 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 591 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 592 | BinaryOpIC::TypeInfo left_type, |
| 593 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 594 | Label* operand_conversion_failure); |
| 595 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 596 | // Assumes that operands are smis or heap numbers and loads them |
| 597 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 598 | // Leaves operands unchanged. |
| 599 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 600 | |
| 601 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 602 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 603 | // either operand is not a number. Operands are in edx and eax. |
| 604 | // Leaves operands unchanged. |
| 605 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 606 | |
| 607 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 608 | // Expects operands in edx, eax. |
| 609 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 610 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 611 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 612 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 613 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 614 | Label* non_int32, |
| 615 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 616 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 617 | Register scratch, |
| 618 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 619 | }; |
| 620 | |
| 621 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 622 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 623 | // is faster than using the built-in instructions on floating point registers. |
| 624 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 625 | // trashed registers. |
| 626 | static void IntegerConvert(MacroAssembler* masm, |
| 627 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 628 | bool use_sse3, |
| 629 | Label* conversion_failure) { |
| 630 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 631 | Label done, right_exponent, normal_exponent; |
| 632 | Register scratch = ebx; |
| 633 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 634 | // Get exponent word. |
| 635 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 636 | // Get exponent alone in scratch2. |
| 637 | __ mov(scratch2, scratch); |
| 638 | __ and_(scratch2, HeapNumber::kExponentMask); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 639 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 640 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias)); |
| 641 | // Load ecx with zero. We use this either for the final shift or |
| 642 | // for the answer. |
| 643 | __ xor_(ecx, ecx); |
| 644 | // If the exponent is above 83, the number contains no significant |
| 645 | // bits in the range 0..2^31, so the result is zero. |
| 646 | static const uint32_t kResultIsZeroExponent = 83; |
| 647 | __ cmp(scratch2, Immediate(kResultIsZeroExponent)); |
| 648 | __ j(above, &done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 649 | if (use_sse3) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 650 | CpuFeatureScope scope(masm, SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 651 | // 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] | 652 | static const uint32_t kTooBigExponent = 63; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 653 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 654 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 655 | // Load x87 register with heap number. |
| 656 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 657 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 658 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 659 | // Do conversion, which cannot fail because we checked the exponent. |
| 660 | __ fisttp_d(Operand(esp, 0)); |
| 661 | __ 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] | 662 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 663 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 664 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 665 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 666 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 667 | // also the highest exponent we can handle here. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 668 | const uint32_t non_smi_exponent = 30; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 669 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 670 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 671 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 672 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 673 | // If the exponent is higher than that then go to slow case. This catches |
| 674 | // 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] | 675 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 676 | |
| 677 | { |
| 678 | // Handle a big exponent. The only reason we have this code is that the |
| 679 | // >>> 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] | 680 | const uint32_t big_non_smi_exponent = 31; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 681 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 682 | __ j(not_equal, conversion_failure); |
| 683 | // We have the big exponent, typically from >>>. This means the number is |
| 684 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 685 | __ mov(scratch2, scratch); |
| 686 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 687 | // Put back the implicit 1. |
| 688 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 689 | // Shift up the mantissa bits to take up the space the exponent used to |
| 690 | // take. We just orred in the implicit bit so that took care of one and |
| 691 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 692 | // shift distance. |
| 693 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 694 | __ shl(scratch2, big_shift_distance); |
| 695 | // Get the second half of the double. |
| 696 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 697 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 698 | // mantissa word. |
| 699 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 700 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 701 | // 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] | 702 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 703 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 704 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 705 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | __ bind(&normal_exponent); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 709 | // Exponent word in scratch, exponent in scratch2. Zero in ecx. |
| 710 | // We know that 0 <= exponent < 30. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 711 | __ mov(ecx, Immediate(30)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 712 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 713 | |
| 714 | __ bind(&right_exponent); |
| 715 | // Here ecx is the shift, scratch is the exponent word. |
| 716 | // Get the top bits of the mantissa. |
| 717 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 718 | // Put back the implicit 1. |
| 719 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 720 | // Shift up the mantissa bits to take up the space the exponent used to |
| 721 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 722 | // word. Shift them to the top bits. |
| 723 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 724 | __ shl(scratch, shift_distance); |
| 725 | // Get the second half of the double. For some exponents we don't |
| 726 | // actually need this because the bits get shifted out again, but |
| 727 | // it's probably slower to test than just to do it. |
| 728 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 729 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 730 | // mantissa word. |
| 731 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 732 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 733 | // Move down according to the exponent. |
| 734 | __ shr_cl(scratch2); |
| 735 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 736 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 737 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 738 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 739 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 740 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 741 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 742 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 743 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 744 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 745 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 746 | __ bind(&done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 750 | // Uses SSE2 to convert the heap number in |source| to an integer. Jumps to |
| 751 | // |conversion_failure| if the heap number did not contain an int32 value. |
| 752 | // Result is in ecx. Trashes ebx, xmm0, and xmm1. |
| 753 | static void ConvertHeapNumberToInt32(MacroAssembler* masm, |
| 754 | Register source, |
| 755 | Label* conversion_failure) { |
| 756 | __ movdbl(xmm0, FieldOperand(source, HeapNumber::kValueOffset)); |
| 757 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 758 | masm, conversion_failure, xmm0, ecx, ebx, xmm1); |
| 759 | } |
| 760 | |
| 761 | |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 762 | void UnaryOpStub::PrintName(StringStream* stream) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 763 | const char* op_name = Token::Name(op_); |
| 764 | const char* overwrite_name = NULL; // Make g++ happy. |
| 765 | switch (mode_) { |
| 766 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 767 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 768 | } |
whesse@chromium.org | 030d38e | 2011-07-13 13:23:34 +0000 | [diff] [blame] | 769 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 770 | op_name, |
| 771 | overwrite_name, |
| 772 | UnaryOpIC::GetName(operand_type_)); |
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::Generate(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 778 | switch (operand_type_) { |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 779 | case UnaryOpIC::UNINITIALIZED: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 780 | GenerateTypeTransition(masm); |
| 781 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 782 | case UnaryOpIC::SMI: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 783 | GenerateSmiStub(masm); |
| 784 | break; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 785 | case UnaryOpIC::NUMBER: |
| 786 | GenerateNumberStub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 787 | break; |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 788 | case UnaryOpIC::GENERIC: |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 789 | GenerateGenericStub(masm); |
| 790 | break; |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 795 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 796 | __ pop(ecx); // Save return address. |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 797 | |
| 798 | __ push(eax); // the operand |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 799 | __ push(Immediate(Smi::FromInt(op_))); |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 800 | __ push(Immediate(Smi::FromInt(mode_))); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 801 | __ push(Immediate(Smi::FromInt(operand_type_))); |
| 802 | |
| 803 | __ push(ecx); // Push return address. |
| 804 | |
| 805 | // Patch the caller to an appropriate specialized stub and return the |
| 806 | // operation result to the caller of the stub. |
| 807 | __ TailCallExternalReference( |
ricow@chromium.org | 4f693d6 | 2011-07-04 14:01:31 +0000 | [diff] [blame] | 808 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | |
| 812 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 813 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 814 | switch (op_) { |
| 815 | case Token::SUB: |
| 816 | GenerateSmiStubSub(masm); |
| 817 | break; |
| 818 | case Token::BIT_NOT: |
| 819 | GenerateSmiStubBitNot(masm); |
| 820 | break; |
| 821 | default: |
| 822 | UNREACHABLE(); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 827 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 828 | Label non_smi, undo, slow; |
| 829 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, |
| 830 | Label::kNear, Label::kNear, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 831 | __ bind(&undo); |
| 832 | GenerateSmiCodeUndo(masm); |
| 833 | __ bind(&non_smi); |
| 834 | __ bind(&slow); |
| 835 | GenerateTypeTransition(masm); |
| 836 | } |
| 837 | |
| 838 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 839 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 840 | Label non_smi; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 841 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 842 | __ bind(&non_smi); |
| 843 | GenerateTypeTransition(masm); |
| 844 | } |
| 845 | |
| 846 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 847 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 848 | Label* non_smi, |
| 849 | Label* undo, |
| 850 | Label* slow, |
| 851 | Label::Distance non_smi_near, |
| 852 | Label::Distance undo_near, |
| 853 | Label::Distance slow_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 854 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 855 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 856 | |
| 857 | // 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] | 858 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 859 | __ j(zero, slow, slow_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 860 | |
| 861 | // 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] | 862 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 863 | __ Set(eax, Immediate(0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 864 | __ sub(eax, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 865 | __ j(overflow, undo, undo_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 866 | __ ret(0); |
| 867 | } |
| 868 | |
| 869 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 870 | void UnaryOpStub::GenerateSmiCodeBitNot( |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 871 | MacroAssembler* masm, |
| 872 | Label* non_smi, |
| 873 | Label::Distance non_smi_near) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 874 | // Check whether the value is a smi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 875 | __ JumpIfNotSmi(eax, non_smi, non_smi_near); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 876 | |
| 877 | // Flip bits and revert inverted smi-tag. |
| 878 | __ not_(eax); |
| 879 | __ and_(eax, ~kSmiTagMask); |
| 880 | __ ret(0); |
| 881 | } |
| 882 | |
| 883 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 884 | void UnaryOpStub::GenerateSmiCodeUndo(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 885 | __ mov(eax, edx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | |
| 889 | // TODO(svenpanne): Use virtual functions instead of switch. |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 890 | void UnaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 891 | switch (op_) { |
| 892 | case Token::SUB: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 893 | GenerateNumberStubSub(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 894 | break; |
| 895 | case Token::BIT_NOT: |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 896 | GenerateNumberStubBitNot(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 897 | break; |
| 898 | default: |
| 899 | UNREACHABLE(); |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 904 | void UnaryOpStub::GenerateNumberStubSub(MacroAssembler* masm) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 905 | Label non_smi, undo, slow, call_builtin; |
| 906 | GenerateSmiCodeSub(masm, &non_smi, &undo, &call_builtin, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 907 | __ bind(&non_smi); |
| 908 | GenerateHeapNumberCodeSub(masm, &slow); |
| 909 | __ bind(&undo); |
| 910 | GenerateSmiCodeUndo(masm); |
| 911 | __ bind(&slow); |
| 912 | GenerateTypeTransition(masm); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 913 | __ bind(&call_builtin); |
| 914 | GenerateGenericCodeFallback(masm); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 915 | } |
| 916 | |
| 917 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 918 | void UnaryOpStub::GenerateNumberStubBitNot( |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 919 | MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 920 | Label non_smi, slow; |
| 921 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 922 | __ bind(&non_smi); |
| 923 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 924 | __ bind(&slow); |
| 925 | GenerateTypeTransition(masm); |
| 926 | } |
| 927 | |
| 928 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 929 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 930 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 931 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 932 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 933 | __ j(not_equal, slow); |
| 934 | |
| 935 | if (mode_ == UNARY_OVERWRITE) { |
| 936 | __ xor_(FieldOperand(eax, HeapNumber::kExponentOffset), |
| 937 | Immediate(HeapNumber::kSignMask)); // Flip sign. |
| 938 | } else { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 939 | __ mov(edx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 940 | // edx: operand |
| 941 | |
| 942 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 943 | __ AllocateHeapNumber(eax, ebx, ecx, &slow_allocate_heapnumber); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 944 | __ jmp(&heapnumber_allocated, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 945 | |
| 946 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 947 | { |
| 948 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 949 | __ push(edx); |
| 950 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 951 | __ pop(edx); |
| 952 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 953 | |
| 954 | __ bind(&heapnumber_allocated); |
| 955 | // eax: allocated 'empty' number |
| 956 | __ mov(ecx, FieldOperand(edx, HeapNumber::kExponentOffset)); |
| 957 | __ xor_(ecx, HeapNumber::kSignMask); // Flip sign. |
| 958 | __ mov(FieldOperand(eax, HeapNumber::kExponentOffset), ecx); |
| 959 | __ mov(ecx, FieldOperand(edx, HeapNumber::kMantissaOffset)); |
| 960 | __ mov(FieldOperand(eax, HeapNumber::kMantissaOffset), ecx); |
| 961 | } |
| 962 | __ ret(0); |
| 963 | } |
| 964 | |
| 965 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 966 | void UnaryOpStub::GenerateHeapNumberCodeBitNot(MacroAssembler* masm, |
| 967 | Label* slow) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 968 | __ mov(edx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 969 | __ cmp(edx, masm->isolate()->factory()->heap_number_map()); |
| 970 | __ j(not_equal, slow); |
| 971 | |
| 972 | // 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] | 973 | IntegerConvert(masm, eax, CpuFeatures::IsSupported(SSE3), slow); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 974 | |
| 975 | // 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] | 976 | Label try_float; |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 977 | __ not_(ecx); |
| 978 | __ cmp(ecx, 0xc0000000); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 979 | __ j(sign, &try_float, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 980 | |
| 981 | // Tag the result as a smi and we're done. |
| 982 | STATIC_ASSERT(kSmiTagSize == 1); |
| 983 | __ lea(eax, Operand(ecx, times_2, kSmiTag)); |
| 984 | __ ret(0); |
| 985 | |
| 986 | // Try to store the result in a heap number. |
| 987 | __ bind(&try_float); |
| 988 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 989 | Label slow_allocate_heapnumber, heapnumber_allocated; |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 990 | __ mov(ebx, eax); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 991 | __ AllocateHeapNumber(eax, edx, edi, &slow_allocate_heapnumber); |
| 992 | __ jmp(&heapnumber_allocated); |
| 993 | |
| 994 | __ bind(&slow_allocate_heapnumber); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 995 | { |
| 996 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 997 | // Push the original HeapNumber on the stack. The integer value can't |
| 998 | // be stored since it's untagged and not in the smi range (so we can't |
| 999 | // smi-tag it). We'll recalculate the value after the GC instead. |
| 1000 | __ push(ebx); |
| 1001 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1002 | // New HeapNumber is in eax. |
| 1003 | __ pop(edx); |
| 1004 | } |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 1005 | // IntegerConvert uses ebx and edi as scratch registers. |
| 1006 | // This conversion won't go slow-case. |
| 1007 | IntegerConvert(masm, edx, CpuFeatures::IsSupported(SSE3), slow); |
| 1008 | __ not_(ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1009 | |
| 1010 | __ bind(&heapnumber_allocated); |
| 1011 | } |
| 1012 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1013 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1014 | __ cvtsi2sd(xmm0, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1015 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1016 | } else { |
| 1017 | __ push(ecx); |
| 1018 | __ fild_s(Operand(esp, 0)); |
| 1019 | __ pop(ecx); |
| 1020 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1021 | } |
| 1022 | __ ret(0); |
| 1023 | } |
| 1024 | |
| 1025 | |
| 1026 | // TODO(svenpanne): Use virtual functions instead of switch. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1027 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1028 | switch (op_) { |
| 1029 | case Token::SUB: |
| 1030 | GenerateGenericStubSub(masm); |
| 1031 | break; |
| 1032 | case Token::BIT_NOT: |
| 1033 | GenerateGenericStubBitNot(masm); |
| 1034 | break; |
| 1035 | default: |
| 1036 | UNREACHABLE(); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1041 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1042 | Label non_smi, undo, slow; |
| 1043 | GenerateSmiCodeSub(masm, &non_smi, &undo, &slow, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1044 | __ bind(&non_smi); |
| 1045 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1046 | __ bind(&undo); |
| 1047 | GenerateSmiCodeUndo(masm); |
| 1048 | __ bind(&slow); |
| 1049 | GenerateGenericCodeFallback(masm); |
| 1050 | } |
| 1051 | |
| 1052 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1053 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1054 | Label non_smi, slow; |
| 1055 | GenerateSmiCodeBitNot(masm, &non_smi, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1056 | __ bind(&non_smi); |
| 1057 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1058 | __ bind(&slow); |
| 1059 | GenerateGenericCodeFallback(masm); |
| 1060 | } |
| 1061 | |
| 1062 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1063 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 1064 | // Handle the slow case by jumping to the corresponding JavaScript builtin. |
| 1065 | __ pop(ecx); // pop return address. |
| 1066 | __ push(eax); |
| 1067 | __ push(ecx); // push return address |
| 1068 | switch (op_) { |
| 1069 | case Token::SUB: |
| 1070 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1071 | break; |
| 1072 | case Token::BIT_NOT: |
| 1073 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1074 | break; |
| 1075 | default: |
| 1076 | UNREACHABLE(); |
| 1077 | } |
| 1078 | } |
| 1079 | |
| 1080 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1081 | void BinaryOpStub::Initialize() { |
| 1082 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 1083 | } |
| 1084 | |
| 1085 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1086 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1087 | __ pop(ecx); // Save return address. |
| 1088 | __ push(edx); |
| 1089 | __ push(eax); |
| 1090 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1091 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1092 | |
| 1093 | __ push(ecx); // Push return address. |
| 1094 | |
| 1095 | // Patch the caller to an appropriate specialized stub and return the |
| 1096 | // operation result to the caller of the stub. |
| 1097 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1098 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1099 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1100 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1101 | 1); |
| 1102 | } |
| 1103 | |
| 1104 | |
| 1105 | // Prepare for a type transition runtime call when the args are already on |
| 1106 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1107 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1108 | __ pop(ecx); // Save return address. |
| 1109 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1110 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1111 | |
| 1112 | __ push(ecx); // Push return address. |
| 1113 | |
| 1114 | // Patch the caller to an appropriate specialized stub and return the |
| 1115 | // operation result to the caller of the stub. |
| 1116 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1117 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1118 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1119 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1120 | 1); |
| 1121 | } |
| 1122 | |
| 1123 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1124 | static void BinaryOpStub_GenerateRegisterArgsPop(MacroAssembler* masm) { |
| 1125 | __ pop(ecx); |
| 1126 | __ pop(eax); |
| 1127 | __ pop(edx); |
| 1128 | __ push(ecx); |
| 1129 | } |
| 1130 | |
| 1131 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1132 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1133 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1134 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1135 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 1136 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1137 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 1138 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 1139 | Comment load_comment(masm, "-- Load arguments"); |
| 1140 | Register left = edx; |
| 1141 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1142 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1143 | left = eax; |
| 1144 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 1145 | __ mov(ebx, eax); |
| 1146 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | |
| 1150 | // 2. Prepare the smi check of both operands by oring them together. |
| 1151 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 1152 | Label not_smis; |
| 1153 | Register combined = ecx; |
| 1154 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1155 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1156 | case Token::BIT_OR: |
| 1157 | // Perform the operation into eax and smi check the result. Preserve |
| 1158 | // eax in case the result is not a smi. |
| 1159 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1160 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1161 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1162 | combined = right; |
| 1163 | break; |
| 1164 | |
| 1165 | case Token::BIT_XOR: |
| 1166 | case Token::BIT_AND: |
| 1167 | case Token::ADD: |
| 1168 | case Token::SUB: |
| 1169 | case Token::MUL: |
| 1170 | case Token::DIV: |
| 1171 | case Token::MOD: |
| 1172 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1173 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1174 | break; |
| 1175 | |
| 1176 | case Token::SHL: |
| 1177 | case Token::SAR: |
| 1178 | case Token::SHR: |
| 1179 | // Move the right operand into ecx for the shift operation, use eax |
| 1180 | // for the smi check register. |
| 1181 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 1182 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1183 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1184 | combined = right; |
| 1185 | break; |
| 1186 | |
| 1187 | default: |
| 1188 | break; |
| 1189 | } |
| 1190 | |
| 1191 | // 3. Perform the smi check of the operands. |
| 1192 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1193 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1194 | |
| 1195 | // 4. Operands are both smis, perform the operation leaving the result in |
| 1196 | // eax and check the result if necessary. |
| 1197 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 1198 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1199 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1200 | case Token::BIT_OR: |
| 1201 | // Nothing to do. |
| 1202 | break; |
| 1203 | |
| 1204 | case Token::BIT_XOR: |
| 1205 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1206 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1207 | break; |
| 1208 | |
| 1209 | case Token::BIT_AND: |
| 1210 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1211 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1212 | break; |
| 1213 | |
| 1214 | case Token::SHL: |
| 1215 | // Remove tags from operands (but keep sign). |
| 1216 | __ SmiUntag(left); |
| 1217 | __ SmiUntag(ecx); |
| 1218 | // Perform the operation. |
| 1219 | __ shl_cl(left); |
| 1220 | // Check that the *signed* result fits in a smi. |
| 1221 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1222 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1223 | // Tag the result and store it in register eax. |
| 1224 | __ SmiTag(left); |
| 1225 | __ mov(eax, left); |
| 1226 | break; |
| 1227 | |
| 1228 | case Token::SAR: |
| 1229 | // Remove tags from operands (but keep sign). |
| 1230 | __ SmiUntag(left); |
| 1231 | __ SmiUntag(ecx); |
| 1232 | // Perform the operation. |
| 1233 | __ sar_cl(left); |
| 1234 | // Tag the result and store it in register eax. |
| 1235 | __ SmiTag(left); |
| 1236 | __ mov(eax, left); |
| 1237 | break; |
| 1238 | |
| 1239 | case Token::SHR: |
| 1240 | // Remove tags from operands (but keep sign). |
| 1241 | __ SmiUntag(left); |
| 1242 | __ SmiUntag(ecx); |
| 1243 | // Perform the operation. |
| 1244 | __ shr_cl(left); |
| 1245 | // Check that the *unsigned* result fits in a smi. |
| 1246 | // Neither of the two high-order bits can be set: |
| 1247 | // - 0x80000000: high bit would be lost when smi tagging. |
| 1248 | // - 0x40000000: this number would convert to negative when |
| 1249 | // Smi tagging these two cases can only happen with shifts |
| 1250 | // by 0 or 1 when handed a valid smi. |
| 1251 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1252 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1253 | // Tag the result and store it in register eax. |
| 1254 | __ SmiTag(left); |
| 1255 | __ mov(eax, left); |
| 1256 | break; |
| 1257 | |
| 1258 | case Token::ADD: |
| 1259 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1260 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1261 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1262 | break; |
| 1263 | |
| 1264 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1265 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1266 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1267 | __ mov(eax, left); |
| 1268 | break; |
| 1269 | |
| 1270 | case Token::MUL: |
| 1271 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 1272 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 1273 | // We can't revert the multiplication if the result is not a smi |
| 1274 | // so save the right operand. |
| 1275 | __ mov(ebx, right); |
| 1276 | // Remove tag from one of the operands (but keep sign). |
| 1277 | __ SmiUntag(right); |
| 1278 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1279 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1280 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1281 | // Check for negative zero result. Use combined = left | right. |
| 1282 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1283 | break; |
| 1284 | |
| 1285 | case Token::DIV: |
| 1286 | // We can't revert the division if the result is not a smi so |
| 1287 | // save the left operand. |
| 1288 | __ mov(edi, left); |
| 1289 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1290 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1291 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1292 | // Sign extend left into edx:eax. |
| 1293 | ASSERT(left.is(eax)); |
| 1294 | __ cdq(); |
| 1295 | // Divide edx:eax by right. |
| 1296 | __ idiv(right); |
| 1297 | // Check for the corner case of dividing the most negative smi by |
| 1298 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1299 | // instruction. |
| 1300 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1301 | __ cmp(eax, 0x40000000); |
| 1302 | __ j(equal, &use_fp_on_smis); |
| 1303 | // Check for negative zero result. Use combined = left | right. |
| 1304 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1305 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1306 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1307 | __ j(not_zero, &use_fp_on_smis); |
| 1308 | // Tag the result and store it in register eax. |
| 1309 | __ SmiTag(eax); |
| 1310 | break; |
| 1311 | |
| 1312 | case Token::MOD: |
| 1313 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1314 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1315 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1316 | |
| 1317 | // Sign extend left into edx:eax. |
| 1318 | ASSERT(left.is(eax)); |
| 1319 | __ cdq(); |
| 1320 | // Divide edx:eax by right. |
| 1321 | __ idiv(right); |
| 1322 | // Check for negative zero result. Use combined = left | right. |
| 1323 | __ NegativeZeroTest(edx, combined, slow); |
| 1324 | // Move remainder to register eax. |
| 1325 | __ mov(eax, edx); |
| 1326 | break; |
| 1327 | |
| 1328 | default: |
| 1329 | UNREACHABLE(); |
| 1330 | } |
| 1331 | |
| 1332 | // 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] | 1333 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1334 | case Token::ADD: |
| 1335 | case Token::SUB: |
| 1336 | case Token::MUL: |
| 1337 | case Token::DIV: |
| 1338 | __ ret(0); |
| 1339 | break; |
| 1340 | case Token::MOD: |
| 1341 | case Token::BIT_OR: |
| 1342 | case Token::BIT_AND: |
| 1343 | case Token::BIT_XOR: |
| 1344 | case Token::SAR: |
| 1345 | case Token::SHL: |
| 1346 | case Token::SHR: |
| 1347 | __ ret(2 * kPointerSize); |
| 1348 | break; |
| 1349 | default: |
| 1350 | UNREACHABLE(); |
| 1351 | } |
| 1352 | |
| 1353 | // 6. For some operations emit inline code to perform floating point |
| 1354 | // operations on known smis (e.g., if the result of the operation |
| 1355 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1356 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1357 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1358 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1359 | // Undo the effects of some operations, and some register moves. |
| 1360 | case Token::SHL: |
| 1361 | // The arguments are saved on the stack, and only used from there. |
| 1362 | break; |
| 1363 | case Token::ADD: |
| 1364 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1365 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1366 | break; |
| 1367 | case Token::SUB: |
| 1368 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1369 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1370 | break; |
| 1371 | case Token::MUL: |
| 1372 | // Right was clobbered but a copy is in ebx. |
| 1373 | __ mov(right, ebx); |
| 1374 | break; |
| 1375 | case Token::DIV: |
| 1376 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1377 | // division. They should be in eax, ebx for jump to not_smi. |
| 1378 | __ mov(eax, edi); |
| 1379 | break; |
| 1380 | default: |
| 1381 | // No other operators jump to use_fp_on_smis. |
| 1382 | break; |
| 1383 | } |
| 1384 | __ jmp(¬_smis); |
| 1385 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1386 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1387 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1388 | case Token::SHL: |
| 1389 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1390 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1391 | __ bind(&use_fp_on_smis); |
| 1392 | // Result we want is in left == edx, so we can put the allocated heap |
| 1393 | // number in eax. |
| 1394 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1395 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1396 | // It's OK to overwrite the arguments on the stack because we |
| 1397 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1398 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1399 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1400 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1401 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1402 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1403 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1404 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1405 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1406 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1407 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1408 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1409 | } else { |
| 1410 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1411 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1412 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1413 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1414 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1415 | __ ret(2 * kPointerSize); |
| 1416 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | case Token::ADD: |
| 1420 | case Token::SUB: |
| 1421 | case Token::MUL: |
| 1422 | case Token::DIV: { |
| 1423 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1424 | __ bind(&use_fp_on_smis); |
| 1425 | // Restore arguments to edx, eax. |
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: |
| 1428 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1429 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1430 | break; |
| 1431 | case Token::SUB: |
| 1432 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1433 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1434 | break; |
| 1435 | case Token::MUL: |
| 1436 | // Right was clobbered but a copy is in ebx. |
| 1437 | __ mov(right, ebx); |
| 1438 | break; |
| 1439 | case Token::DIV: |
| 1440 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1441 | // division. |
| 1442 | __ mov(edx, edi); |
| 1443 | __ mov(eax, right); |
| 1444 | break; |
| 1445 | default: UNREACHABLE(); |
| 1446 | break; |
| 1447 | } |
| 1448 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1449 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1450 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1451 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1452 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1453 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1454 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1455 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1456 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1457 | default: UNREACHABLE(); |
| 1458 | } |
| 1459 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1460 | } else { // SSE2 not available, use FPU. |
| 1461 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1462 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1463 | case Token::ADD: __ faddp(1); break; |
| 1464 | case Token::SUB: __ fsubp(1); break; |
| 1465 | case Token::MUL: __ fmulp(1); break; |
| 1466 | case Token::DIV: __ fdivp(1); break; |
| 1467 | default: UNREACHABLE(); |
| 1468 | } |
| 1469 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1470 | } |
| 1471 | __ mov(eax, ecx); |
| 1472 | __ ret(0); |
| 1473 | break; |
| 1474 | } |
| 1475 | |
| 1476 | default: |
| 1477 | break; |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1482 | // edx and eax. |
| 1483 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1484 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1485 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1486 | case Token::BIT_OR: |
| 1487 | case Token::SHL: |
| 1488 | case Token::SAR: |
| 1489 | case Token::SHR: |
| 1490 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1491 | // check. |
| 1492 | __ mov(eax, ecx); |
| 1493 | break; |
| 1494 | |
| 1495 | case Token::DIV: |
| 1496 | case Token::MOD: |
| 1497 | // Operands are in eax, ebx at this point. |
| 1498 | __ mov(edx, eax); |
| 1499 | __ mov(eax, ebx); |
| 1500 | break; |
| 1501 | |
| 1502 | default: |
| 1503 | break; |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1508 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1509 | Label right_arg_changed, call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1510 | |
| 1511 | switch (op_) { |
| 1512 | case Token::ADD: |
| 1513 | case Token::SUB: |
| 1514 | case Token::MUL: |
| 1515 | case Token::DIV: |
| 1516 | break; |
| 1517 | case Token::MOD: |
| 1518 | case Token::BIT_OR: |
| 1519 | case Token::BIT_AND: |
| 1520 | case Token::BIT_XOR: |
| 1521 | case Token::SAR: |
| 1522 | case Token::SHL: |
| 1523 | case Token::SHR: |
| 1524 | GenerateRegisterArgsPush(masm); |
| 1525 | break; |
| 1526 | default: |
| 1527 | UNREACHABLE(); |
| 1528 | } |
| 1529 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1530 | if (op_ == Token::MOD && has_fixed_right_arg_) { |
| 1531 | // It is guaranteed that the value will fit into a Smi, because if it |
| 1532 | // didn't, we wouldn't be here, see BinaryOp_Patch. |
| 1533 | __ cmp(eax, Immediate(Smi::FromInt(fixed_right_arg_value()))); |
| 1534 | __ j(not_equal, &right_arg_changed); |
| 1535 | } |
| 1536 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1537 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1538 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1539 | BinaryOpStub_GenerateSmiCode( |
| 1540 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1541 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1542 | BinaryOpStub_GenerateSmiCode( |
| 1543 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1544 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1545 | |
| 1546 | // Code falls through if the result is not returned as either a smi or heap |
| 1547 | // number. |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1548 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1549 | switch (op_) { |
| 1550 | case Token::ADD: |
| 1551 | case Token::SUB: |
| 1552 | case Token::MUL: |
| 1553 | case Token::DIV: |
| 1554 | GenerateTypeTransition(masm); |
| 1555 | break; |
| 1556 | case Token::MOD: |
| 1557 | case Token::BIT_OR: |
| 1558 | case Token::BIT_AND: |
| 1559 | case Token::BIT_XOR: |
| 1560 | case Token::SAR: |
| 1561 | case Token::SHL: |
| 1562 | case Token::SHR: |
| 1563 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1564 | break; |
| 1565 | default: |
| 1566 | UNREACHABLE(); |
| 1567 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1568 | |
| 1569 | __ bind(&call_runtime); |
| 1570 | switch (op_) { |
| 1571 | case Token::ADD: |
| 1572 | case Token::SUB: |
| 1573 | case Token::MUL: |
| 1574 | case Token::DIV: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1575 | break; |
| 1576 | case Token::MOD: |
| 1577 | case Token::BIT_OR: |
| 1578 | case Token::BIT_AND: |
| 1579 | case Token::BIT_XOR: |
| 1580 | case Token::SAR: |
| 1581 | case Token::SHL: |
| 1582 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1583 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1584 | break; |
| 1585 | default: |
| 1586 | UNREACHABLE(); |
| 1587 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1588 | |
| 1589 | { |
| 1590 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1591 | __ push(edx); |
| 1592 | __ push(eax); |
| 1593 | GenerateCallRuntime(masm); |
| 1594 | } |
| 1595 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1596 | } |
| 1597 | |
| 1598 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1599 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1600 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1601 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1602 | ASSERT(op_ == Token::ADD); |
| 1603 | // If both arguments are strings, call the string add stub. |
| 1604 | // Otherwise, do a transition. |
| 1605 | |
| 1606 | // Registers containing left and right operands respectively. |
| 1607 | Register left = edx; |
| 1608 | Register right = eax; |
| 1609 | |
| 1610 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1611 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1612 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1613 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1614 | |
| 1615 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1616 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1617 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1618 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1619 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1620 | StringAddStub string_add_stub((StringAddFlags) |
| 1621 | (ERECT_FRAME | NO_STRING_CHECK_IN_STUB)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1622 | GenerateRegisterArgsPush(masm); |
| 1623 | __ TailCallStub(&string_add_stub); |
| 1624 | |
| 1625 | __ bind(&call_runtime); |
| 1626 | GenerateTypeTransition(masm); |
| 1627 | } |
| 1628 | |
| 1629 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1630 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1631 | Label* alloc_failure, |
| 1632 | OverwriteMode mode); |
| 1633 | |
| 1634 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1635 | // Input: |
| 1636 | // edx: left operand (tagged) |
| 1637 | // eax: right operand (tagged) |
| 1638 | // Output: |
| 1639 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1640 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1641 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1642 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1643 | |
| 1644 | // Floating point case. |
| 1645 | switch (op_) { |
| 1646 | case Token::ADD: |
| 1647 | case Token::SUB: |
| 1648 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1649 | case Token::DIV: |
| 1650 | case Token::MOD: { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1651 | Label not_floats, not_int32, right_arg_changed; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1652 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1653 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1654 | // It could be that only SMIs have been seen at either the left |
| 1655 | // or the right operand. For precise type feedback, patch the IC |
| 1656 | // again if this changes. |
| 1657 | // In theory, we would need the same check in the non-SSE2 case, |
| 1658 | // but since we don't support Crankshaft on such hardware we can |
| 1659 | // afford not to care about precise type feedback. |
| 1660 | if (left_type_ == BinaryOpIC::SMI) { |
| 1661 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1662 | } |
| 1663 | if (right_type_ == BinaryOpIC::SMI) { |
| 1664 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1665 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1666 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1667 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1668 | masm, ¬_int32, xmm0, ebx, ecx, xmm2); |
| 1669 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1670 | masm, ¬_int32, xmm1, edi, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1671 | if (op_ == Token::MOD) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1672 | if (has_fixed_right_arg_) { |
| 1673 | __ cmp(edi, Immediate(fixed_right_arg_value())); |
| 1674 | __ j(not_equal, &right_arg_changed); |
| 1675 | } |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1676 | GenerateRegisterArgsPush(masm); |
| 1677 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1678 | } else { |
| 1679 | switch (op_) { |
| 1680 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1681 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1682 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1683 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1684 | default: UNREACHABLE(); |
| 1685 | } |
| 1686 | // Check result type if it is currently Int32. |
| 1687 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1688 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1689 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1690 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1691 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1692 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1693 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1694 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1695 | } else { // SSE2 not available, use FPU. |
| 1696 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1697 | FloatingPointHelper::LoadFloatOperands( |
| 1698 | masm, |
| 1699 | ecx, |
| 1700 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1701 | if (op_ == Token::MOD) { |
| 1702 | // The operands are now on the FPU stack, but we don't need them. |
| 1703 | __ fstp(0); |
| 1704 | __ fstp(0); |
| 1705 | GenerateRegisterArgsPush(masm); |
| 1706 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1707 | } else { |
| 1708 | switch (op_) { |
| 1709 | case Token::ADD: __ faddp(1); break; |
| 1710 | case Token::SUB: __ fsubp(1); break; |
| 1711 | case Token::MUL: __ fmulp(1); break; |
| 1712 | case Token::DIV: __ fdivp(1); break; |
| 1713 | default: UNREACHABLE(); |
| 1714 | } |
| 1715 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1716 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1717 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1718 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1719 | __ ret(0); |
| 1720 | __ bind(&after_alloc_failure); |
| 1721 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1722 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1723 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1724 | } |
| 1725 | |
| 1726 | __ bind(¬_floats); |
| 1727 | __ bind(¬_int32); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1728 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1729 | GenerateTypeTransition(masm); |
| 1730 | break; |
| 1731 | } |
| 1732 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1733 | case Token::BIT_OR: |
| 1734 | case Token::BIT_AND: |
| 1735 | case Token::BIT_XOR: |
| 1736 | case Token::SAR: |
| 1737 | case Token::SHL: |
| 1738 | case Token::SHR: { |
| 1739 | GenerateRegisterArgsPush(masm); |
| 1740 | Label not_floats; |
| 1741 | Label not_int32; |
| 1742 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1743 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1744 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1745 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1746 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1747 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1748 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1749 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1750 | case Token::SAR: __ sar_cl(eax); break; |
| 1751 | case Token::SHL: __ shl_cl(eax); break; |
| 1752 | case Token::SHR: __ shr_cl(eax); break; |
| 1753 | default: UNREACHABLE(); |
| 1754 | } |
| 1755 | if (op_ == Token::SHR) { |
| 1756 | // Check if result is non-negative and fits in a smi. |
| 1757 | __ test(eax, Immediate(0xc0000000)); |
| 1758 | __ j(not_zero, &call_runtime); |
| 1759 | } else { |
| 1760 | // Check if result fits in a smi. |
| 1761 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1762 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1763 | } |
| 1764 | // Tag smi result and return. |
| 1765 | __ SmiTag(eax); |
| 1766 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1767 | |
| 1768 | // All ops except SHR return a signed int32 that we load in |
| 1769 | // a HeapNumber. |
| 1770 | if (op_ != Token::SHR) { |
| 1771 | __ bind(&non_smi_result); |
| 1772 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1773 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1774 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1775 | switch (mode_) { |
| 1776 | case OVERWRITE_LEFT: |
| 1777 | case OVERWRITE_RIGHT: |
| 1778 | // If the operand was an object, we skip the |
| 1779 | // allocation of a heap number. |
| 1780 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1781 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1782 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1783 | // Fall through! |
| 1784 | case NO_OVERWRITE: |
| 1785 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1786 | __ bind(&skip_allocation); |
| 1787 | break; |
| 1788 | default: UNREACHABLE(); |
| 1789 | } |
| 1790 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1791 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1792 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1793 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1794 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1795 | } else { |
| 1796 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1797 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1798 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1799 | } |
| 1800 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1801 | } |
| 1802 | |
| 1803 | __ bind(¬_floats); |
| 1804 | __ bind(¬_int32); |
| 1805 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1806 | break; |
| 1807 | } |
| 1808 | default: UNREACHABLE(); break; |
| 1809 | } |
| 1810 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1811 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1812 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1813 | __ bind(&call_runtime); |
| 1814 | |
| 1815 | switch (op_) { |
| 1816 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1817 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1818 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1819 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1820 | break; |
| 1821 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1822 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1823 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1824 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1825 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1826 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1827 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1828 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1829 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1830 | break; |
| 1831 | default: |
| 1832 | UNREACHABLE(); |
| 1833 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1834 | |
| 1835 | { |
| 1836 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1837 | __ push(edx); |
| 1838 | __ push(eax); |
| 1839 | GenerateCallRuntime(masm); |
| 1840 | } |
| 1841 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1842 | } |
| 1843 | |
| 1844 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1845 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1846 | if (op_ == Token::ADD) { |
| 1847 | // Handle string addition here, because it is the only operation |
| 1848 | // that does not do a ToNumber conversion on the operands. |
| 1849 | GenerateAddStrings(masm); |
| 1850 | } |
| 1851 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1852 | Factory* factory = masm->isolate()->factory(); |
| 1853 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1854 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1855 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1856 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1857 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1858 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1859 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1860 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1861 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1862 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1863 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1864 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1865 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1866 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1867 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1868 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1869 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1870 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1871 | } |
| 1872 | __ bind(&done); |
| 1873 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1874 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1875 | } |
| 1876 | |
| 1877 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1878 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1879 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1880 | |
| 1881 | // Floating point case. |
| 1882 | switch (op_) { |
| 1883 | case Token::ADD: |
| 1884 | case Token::SUB: |
| 1885 | case Token::MUL: |
| 1886 | case Token::DIV: { |
| 1887 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1888 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1889 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1890 | |
| 1891 | // It could be that only SMIs have been seen at either the left |
| 1892 | // or the right operand. For precise type feedback, patch the IC |
| 1893 | // again if this changes. |
| 1894 | // In theory, we would need the same check in the non-SSE2 case, |
| 1895 | // but since we don't support Crankshaft on such hardware we can |
| 1896 | // afford not to care about precise type feedback. |
| 1897 | if (left_type_ == BinaryOpIC::SMI) { |
| 1898 | __ JumpIfNotSmi(edx, ¬_floats); |
| 1899 | } |
| 1900 | if (right_type_ == BinaryOpIC::SMI) { |
| 1901 | __ JumpIfNotSmi(eax, ¬_floats); |
| 1902 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1903 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1904 | if (left_type_ == BinaryOpIC::INT32) { |
| 1905 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1906 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1907 | } |
| 1908 | if (right_type_ == BinaryOpIC::INT32) { |
| 1909 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1910 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1911 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1912 | |
| 1913 | switch (op_) { |
| 1914 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1915 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1916 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1917 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1918 | default: UNREACHABLE(); |
| 1919 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1920 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1921 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1922 | __ ret(0); |
| 1923 | } else { // SSE2 not available, use FPU. |
| 1924 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1925 | FloatingPointHelper::LoadFloatOperands( |
| 1926 | masm, |
| 1927 | ecx, |
| 1928 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1929 | switch (op_) { |
| 1930 | case Token::ADD: __ faddp(1); break; |
| 1931 | case Token::SUB: __ fsubp(1); break; |
| 1932 | case Token::MUL: __ fmulp(1); break; |
| 1933 | case Token::DIV: __ fdivp(1); break; |
| 1934 | default: UNREACHABLE(); |
| 1935 | } |
| 1936 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1937 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1938 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1939 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1940 | __ ret(0); |
| 1941 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1942 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1943 | __ jmp(&call_runtime); |
| 1944 | } |
| 1945 | |
| 1946 | __ bind(¬_floats); |
| 1947 | GenerateTypeTransition(masm); |
| 1948 | break; |
| 1949 | } |
| 1950 | |
| 1951 | case Token::MOD: { |
| 1952 | // For MOD we go directly to runtime in the non-smi case. |
| 1953 | break; |
| 1954 | } |
| 1955 | case Token::BIT_OR: |
| 1956 | case Token::BIT_AND: |
| 1957 | case Token::BIT_XOR: |
| 1958 | case Token::SAR: |
| 1959 | case Token::SHL: |
| 1960 | case Token::SHR: { |
| 1961 | GenerateRegisterArgsPush(masm); |
| 1962 | Label not_floats; |
| 1963 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1964 | // We do not check the input arguments here, as any value is |
| 1965 | // unconditionally truncated to an int32 anyway. To get the |
| 1966 | // right optimized code, int32 type feedback is just right. |
| 1967 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1968 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1969 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1970 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1971 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1972 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1973 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1974 | case Token::SAR: __ sar_cl(eax); break; |
| 1975 | case Token::SHL: __ shl_cl(eax); break; |
| 1976 | case Token::SHR: __ shr_cl(eax); break; |
| 1977 | default: UNREACHABLE(); |
| 1978 | } |
| 1979 | if (op_ == Token::SHR) { |
| 1980 | // Check if result is non-negative and fits in a smi. |
| 1981 | __ test(eax, Immediate(0xc0000000)); |
| 1982 | __ j(not_zero, &call_runtime); |
| 1983 | } else { |
| 1984 | // Check if result fits in a smi. |
| 1985 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1986 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1987 | } |
| 1988 | // Tag smi result and return. |
| 1989 | __ SmiTag(eax); |
| 1990 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1991 | |
| 1992 | // All ops except SHR return a signed int32 that we load in |
| 1993 | // a HeapNumber. |
| 1994 | if (op_ != Token::SHR) { |
| 1995 | __ bind(&non_smi_result); |
| 1996 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1997 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1998 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1999 | switch (mode_) { |
| 2000 | case OVERWRITE_LEFT: |
| 2001 | case OVERWRITE_RIGHT: |
| 2002 | // If the operand was an object, we skip the |
| 2003 | // allocation of a heap number. |
| 2004 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2005 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2006 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2007 | // Fall through! |
| 2008 | case NO_OVERWRITE: |
| 2009 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2010 | __ bind(&skip_allocation); |
| 2011 | break; |
| 2012 | default: UNREACHABLE(); |
| 2013 | } |
| 2014 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2015 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2016 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2017 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2018 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2019 | } else { |
| 2020 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2021 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2022 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2023 | } |
| 2024 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 2025 | } |
| 2026 | |
| 2027 | __ bind(¬_floats); |
| 2028 | GenerateTypeTransitionWithSavedArgs(masm); |
| 2029 | break; |
| 2030 | } |
| 2031 | default: UNREACHABLE(); break; |
| 2032 | } |
| 2033 | |
| 2034 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 2035 | // use the runtime system to get the correct result. |
| 2036 | __ bind(&call_runtime); |
| 2037 | |
| 2038 | switch (op_) { |
| 2039 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2040 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2041 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2042 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2043 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2044 | break; |
| 2045 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2046 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2047 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2048 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2049 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2050 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2051 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2052 | break; |
| 2053 | default: |
| 2054 | UNREACHABLE(); |
| 2055 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2056 | |
| 2057 | { |
| 2058 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2059 | __ push(edx); |
| 2060 | __ push(eax); |
| 2061 | GenerateCallRuntime(masm); |
| 2062 | } |
| 2063 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2064 | } |
| 2065 | |
| 2066 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2067 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2068 | Label call_runtime; |
| 2069 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2070 | Counters* counters = masm->isolate()->counters(); |
| 2071 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2072 | |
| 2073 | switch (op_) { |
| 2074 | case Token::ADD: |
| 2075 | case Token::SUB: |
| 2076 | case Token::MUL: |
| 2077 | case Token::DIV: |
| 2078 | break; |
| 2079 | case Token::MOD: |
| 2080 | case Token::BIT_OR: |
| 2081 | case Token::BIT_AND: |
| 2082 | case Token::BIT_XOR: |
| 2083 | case Token::SAR: |
| 2084 | case Token::SHL: |
| 2085 | case Token::SHR: |
| 2086 | GenerateRegisterArgsPush(masm); |
| 2087 | break; |
| 2088 | default: |
| 2089 | UNREACHABLE(); |
| 2090 | } |
| 2091 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2092 | BinaryOpStub_GenerateSmiCode( |
| 2093 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2094 | |
| 2095 | // Floating point case. |
| 2096 | switch (op_) { |
| 2097 | case Token::ADD: |
| 2098 | case Token::SUB: |
| 2099 | case Token::MUL: |
| 2100 | case Token::DIV: { |
| 2101 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2102 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2103 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2104 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 2105 | |
| 2106 | switch (op_) { |
| 2107 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 2108 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 2109 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 2110 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 2111 | default: UNREACHABLE(); |
| 2112 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2113 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2114 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2115 | __ ret(0); |
| 2116 | } else { // SSE2 not available, use FPU. |
| 2117 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 2118 | FloatingPointHelper::LoadFloatOperands( |
| 2119 | masm, |
| 2120 | ecx, |
| 2121 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 2122 | switch (op_) { |
| 2123 | case Token::ADD: __ faddp(1); break; |
| 2124 | case Token::SUB: __ fsubp(1); break; |
| 2125 | case Token::MUL: __ fmulp(1); break; |
| 2126 | case Token::DIV: __ fdivp(1); break; |
| 2127 | default: UNREACHABLE(); |
| 2128 | } |
| 2129 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2130 | BinaryOpStub_GenerateHeapResultAllocation( |
| 2131 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2132 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2133 | __ ret(0); |
| 2134 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 2135 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 2136 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2137 | } |
| 2138 | __ bind(¬_floats); |
| 2139 | break; |
| 2140 | } |
| 2141 | case Token::MOD: { |
| 2142 | // For MOD we go directly to runtime in the non-smi case. |
| 2143 | break; |
| 2144 | } |
| 2145 | case Token::BIT_OR: |
| 2146 | case Token::BIT_AND: |
| 2147 | case Token::BIT_XOR: |
| 2148 | case Token::SAR: |
| 2149 | case Token::SHL: |
| 2150 | case Token::SHR: { |
| 2151 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2152 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2153 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2154 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2155 | BinaryOpIC::GENERIC, |
| 2156 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2157 | &call_runtime); |
| 2158 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2159 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 2160 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 2161 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2162 | case Token::SAR: __ sar_cl(eax); break; |
| 2163 | case Token::SHL: __ shl_cl(eax); break; |
| 2164 | case Token::SHR: __ shr_cl(eax); break; |
| 2165 | default: UNREACHABLE(); |
| 2166 | } |
| 2167 | if (op_ == Token::SHR) { |
| 2168 | // Check if result is non-negative and fits in a smi. |
| 2169 | __ test(eax, Immediate(0xc0000000)); |
| 2170 | __ j(not_zero, &call_runtime); |
| 2171 | } else { |
| 2172 | // Check if result fits in a smi. |
| 2173 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2174 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2175 | } |
| 2176 | // Tag smi result and return. |
| 2177 | __ SmiTag(eax); |
| 2178 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 2179 | |
| 2180 | // All ops except SHR return a signed int32 that we load in |
| 2181 | // a HeapNumber. |
| 2182 | if (op_ != Token::SHR) { |
| 2183 | __ bind(&non_smi_result); |
| 2184 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2185 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2186 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2187 | switch (mode_) { |
| 2188 | case OVERWRITE_LEFT: |
| 2189 | case OVERWRITE_RIGHT: |
| 2190 | // If the operand was an object, we skip the |
| 2191 | // allocation of a heap number. |
| 2192 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 2193 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2194 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2195 | // Fall through! |
| 2196 | case NO_OVERWRITE: |
| 2197 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 2198 | __ bind(&skip_allocation); |
| 2199 | break; |
| 2200 | default: UNREACHABLE(); |
| 2201 | } |
| 2202 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2203 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2204 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2205 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2206 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 2207 | } else { |
| 2208 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 2209 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 2210 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2211 | } |
| 2212 | __ ret(2 * kPointerSize); |
| 2213 | } |
| 2214 | break; |
| 2215 | } |
| 2216 | default: UNREACHABLE(); break; |
| 2217 | } |
| 2218 | |
| 2219 | // If all else fails, use the runtime system to get the correct |
| 2220 | // result. |
| 2221 | __ bind(&call_runtime); |
| 2222 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2223 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2224 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2225 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2226 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2227 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2228 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2229 | break; |
| 2230 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2231 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2232 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2233 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2234 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2235 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2236 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2237 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2238 | break; |
| 2239 | default: |
| 2240 | UNREACHABLE(); |
| 2241 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2242 | |
| 2243 | { |
| 2244 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2245 | __ push(edx); |
| 2246 | __ push(eax); |
| 2247 | GenerateCallRuntime(masm); |
| 2248 | } |
| 2249 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2253 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 2254 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2255 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2256 | |
| 2257 | // Registers containing left and right operands respectively. |
| 2258 | Register left = edx; |
| 2259 | Register right = eax; |
| 2260 | |
| 2261 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2262 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2263 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2264 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2265 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2266 | StringAddStub string_add_left_stub((StringAddFlags) |
| 2267 | (ERECT_FRAME | NO_STRING_CHECK_LEFT_IN_STUB)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2268 | GenerateRegisterArgsPush(masm); |
| 2269 | __ TailCallStub(&string_add_left_stub); |
| 2270 | |
| 2271 | // Left operand is not a string, test right. |
| 2272 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2273 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2274 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2275 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2276 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 2277 | StringAddStub string_add_right_stub((StringAddFlags) |
| 2278 | (ERECT_FRAME | NO_STRING_CHECK_RIGHT_IN_STUB)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2279 | GenerateRegisterArgsPush(masm); |
| 2280 | __ TailCallStub(&string_add_right_stub); |
| 2281 | |
| 2282 | // Neither argument is a string. |
| 2283 | __ bind(&call_runtime); |
| 2284 | } |
| 2285 | |
| 2286 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2287 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2288 | Label* alloc_failure, |
| 2289 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2290 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2291 | switch (mode) { |
| 2292 | case OVERWRITE_LEFT: { |
| 2293 | // If the argument in edx is already an object, we skip the |
| 2294 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2295 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2296 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2297 | // for the possible runtime call. |
| 2298 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2299 | // Now edx can be overwritten losing one of the arguments as we are |
| 2300 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2301 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2302 | __ bind(&skip_allocation); |
| 2303 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2304 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2305 | break; |
| 2306 | } |
| 2307 | case OVERWRITE_RIGHT: |
| 2308 | // If the argument in eax is already an object, we skip the |
| 2309 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2310 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2311 | // Fall through! |
| 2312 | case NO_OVERWRITE: |
| 2313 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2314 | // for the possible runtime call. |
| 2315 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2316 | // Now eax can be overwritten losing one of the arguments as we are |
| 2317 | // now done and will not need it any more. |
| 2318 | __ mov(eax, ebx); |
| 2319 | __ bind(&skip_allocation); |
| 2320 | break; |
| 2321 | default: UNREACHABLE(); |
| 2322 | } |
| 2323 | } |
| 2324 | |
| 2325 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2326 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2327 | __ pop(ecx); |
| 2328 | __ push(edx); |
| 2329 | __ push(eax); |
| 2330 | __ push(ecx); |
| 2331 | } |
| 2332 | |
| 2333 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2334 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2335 | // TAGGED case: |
| 2336 | // Input: |
| 2337 | // esp[4]: tagged number input argument (should be number). |
| 2338 | // esp[0]: return address. |
| 2339 | // Output: |
| 2340 | // eax: tagged double result. |
| 2341 | // UNTAGGED case: |
| 2342 | // Input:: |
| 2343 | // esp[0]: return address. |
| 2344 | // xmm1: untagged double input argument |
| 2345 | // Output: |
| 2346 | // xmm1: untagged double result. |
| 2347 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2348 | Label runtime_call; |
| 2349 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2350 | Label skip_cache; |
| 2351 | const bool tagged = (argument_type_ == TAGGED); |
| 2352 | if (tagged) { |
| 2353 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2354 | Label input_not_smi; |
| 2355 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2356 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2357 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2358 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2359 | // Then load the low and high words of the double into ebx, edx. |
| 2360 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2361 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2362 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2363 | __ mov(Operand(esp, 0), eax); |
| 2364 | __ fild_s(Operand(esp, 0)); |
| 2365 | __ fst_d(Operand(esp, 0)); |
| 2366 | __ pop(edx); |
| 2367 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2368 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2369 | __ bind(&input_not_smi); |
| 2370 | // Check if input is a HeapNumber. |
| 2371 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2372 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2373 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2374 | __ j(not_equal, &runtime_call); |
| 2375 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2376 | // low and high words into ebx, edx. |
| 2377 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2378 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2379 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2380 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2381 | __ bind(&loaded); |
| 2382 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2383 | CpuFeatureScope scope(masm, SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2384 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2385 | CpuFeatureScope sse4_scope(masm, SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2386 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2387 | } else { |
| 2388 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2389 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2390 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2391 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2395 | // ebx = low 32 bits of double value |
| 2396 | // edx = high 32 bits of double value |
| 2397 | // Compute hash (the shifts are arithmetic): |
| 2398 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2399 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2400 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2401 | __ mov(eax, ecx); |
| 2402 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2403 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2404 | __ mov(eax, ecx); |
| 2405 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2406 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2407 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2408 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2409 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2410 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2411 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2412 | // ebx = low 32 bits of double value. |
| 2413 | // edx = high 32 bits of double value. |
| 2414 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2415 | ExternalReference cache_array = |
| 2416 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2417 | __ mov(eax, Immediate(cache_array)); |
| 2418 | int cache_array_index = |
| 2419 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2420 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2421 | // Eax points to the cache for the type type_. |
| 2422 | // 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] | 2423 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2424 | __ j(zero, &runtime_call_clear_stack); |
| 2425 | #ifdef DEBUG |
| 2426 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2427 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2428 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2429 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2430 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2431 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2432 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2433 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2434 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2435 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2436 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2437 | } |
| 2438 | #endif |
| 2439 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2440 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2441 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2442 | // 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] | 2443 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2444 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2445 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2446 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2447 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2448 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2449 | Counters* counters = masm->isolate()->counters(); |
| 2450 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2451 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2452 | if (tagged) { |
| 2453 | __ fstp(0); |
| 2454 | __ ret(kPointerSize); |
| 2455 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2456 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2457 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2458 | __ Ret(); |
| 2459 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2460 | |
| 2461 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2462 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2463 | // Update cache with new value. |
| 2464 | // We are short on registers, so use no_reg as scratch. |
| 2465 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2466 | if (tagged) { |
| 2467 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2468 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2469 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2470 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2471 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2472 | __ movdbl(Operand(esp, 0), xmm1); |
| 2473 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2474 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2475 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2476 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2477 | __ mov(Operand(ecx, 0), ebx); |
| 2478 | __ mov(Operand(ecx, kIntSize), edx); |
| 2479 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2480 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2481 | if (tagged) { |
| 2482 | __ ret(kPointerSize); |
| 2483 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2484 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2485 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2486 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2487 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2488 | // Skip cache and return answer directly, only in untagged case. |
| 2489 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2490 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2491 | __ movdbl(Operand(esp, 0), xmm1); |
| 2492 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2493 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2494 | __ fstp_d(Operand(esp, 0)); |
| 2495 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2496 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2497 | // We return the value in xmm1 without adding it to the cache, but |
| 2498 | // 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] | 2499 | { |
| 2500 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2501 | // Allocate an unused object bigger than a HeapNumber. |
| 2502 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2503 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2504 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2505 | __ Ret(); |
| 2506 | } |
| 2507 | |
| 2508 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2509 | if (tagged) { |
| 2510 | __ bind(&runtime_call_clear_stack); |
| 2511 | __ fstp(0); |
| 2512 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2513 | ExternalReference runtime = |
| 2514 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2515 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2516 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2517 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2518 | __ bind(&runtime_call_clear_stack); |
| 2519 | __ bind(&runtime_call); |
| 2520 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2521 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2522 | { |
| 2523 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2524 | __ push(eax); |
| 2525 | __ CallRuntime(RuntimeFunction(), 1); |
| 2526 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2527 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2528 | __ Ret(); |
| 2529 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | |
| 2533 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2534 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2535 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2536 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2537 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2538 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2539 | default: |
| 2540 | UNIMPLEMENTED(); |
| 2541 | return Runtime::kAbort; |
| 2542 | } |
| 2543 | } |
| 2544 | |
| 2545 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2546 | void TranscendentalCacheStub::GenerateOperation( |
| 2547 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2548 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2549 | // Input value is on FP stack, and also in ebx/edx. |
| 2550 | // Input value is possibly in xmm1. |
| 2551 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2552 | if (type == TranscendentalCache::SIN || |
| 2553 | type == TranscendentalCache::COS || |
| 2554 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2555 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2556 | // return NaN for infinities and NaN. They can share all code except |
| 2557 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2558 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2559 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2560 | // work. We must reduce it to the appropriate range. |
| 2561 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2562 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2563 | int supported_exponent_limit = |
| 2564 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2565 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2566 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2567 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2568 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2569 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2570 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2571 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2572 | __ fstp(0); |
| 2573 | // NaN is represented by 0x7ff8000000000000. |
| 2574 | __ push(Immediate(0x7ff80000)); |
| 2575 | __ push(Immediate(0)); |
| 2576 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2577 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2578 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2579 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2580 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2581 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2582 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2583 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2584 | __ fldpi(); |
| 2585 | __ fadd(0); |
| 2586 | __ fld(1); |
| 2587 | // FPU Stack: input, 2*pi, input. |
| 2588 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2589 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2590 | __ fwait(); |
| 2591 | __ fnstsw_ax(); |
| 2592 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2593 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2594 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2595 | __ fnclex(); |
| 2596 | __ bind(&no_exceptions); |
| 2597 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2598 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2599 | // Compute st(0) % st(1) |
| 2600 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2601 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2602 | __ bind(&partial_remainder_loop); |
| 2603 | __ fprem1(); |
| 2604 | __ fwait(); |
| 2605 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2606 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2607 | // If C2 is set, computation only has partial result. Loop to |
| 2608 | // continue computation. |
| 2609 | __ j(not_zero, &partial_remainder_loop); |
| 2610 | } |
| 2611 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2612 | __ fstp(2); |
| 2613 | __ fstp(0); |
| 2614 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2615 | |
| 2616 | // FPU Stack: input % 2*pi |
| 2617 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2618 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2619 | case TranscendentalCache::SIN: |
| 2620 | __ fsin(); |
| 2621 | break; |
| 2622 | case TranscendentalCache::COS: |
| 2623 | __ fcos(); |
| 2624 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2625 | case TranscendentalCache::TAN: |
| 2626 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2627 | // FP register stack. |
| 2628 | __ fptan(); |
| 2629 | __ fstp(0); // Pop FP register stack. |
| 2630 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2631 | default: |
| 2632 | UNREACHABLE(); |
| 2633 | } |
| 2634 | __ bind(&done); |
| 2635 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2636 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2637 | __ fldln2(); |
| 2638 | __ fxch(); |
| 2639 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2640 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2644 | // Input: edx, eax are the left and right objects of a bit op. |
| 2645 | // 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] | 2646 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2647 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2648 | MacroAssembler* masm, |
| 2649 | bool use_sse3, |
| 2650 | BinaryOpIC::TypeInfo left_type, |
| 2651 | BinaryOpIC::TypeInfo right_type, |
| 2652 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2653 | // Check float operands. |
| 2654 | Label arg1_is_object, check_undefined_arg1; |
| 2655 | Label arg2_is_object, check_undefined_arg2; |
| 2656 | Label load_arg2, done; |
| 2657 | |
| 2658 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2659 | if (left_type == BinaryOpIC::SMI) { |
| 2660 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2661 | } else { |
| 2662 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2663 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2664 | |
| 2665 | __ SmiUntag(edx); |
| 2666 | __ jmp(&load_arg2); |
| 2667 | |
| 2668 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2669 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2670 | Factory* factory = masm->isolate()->factory(); |
| 2671 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2672 | __ j(not_equal, conversion_failure); |
| 2673 | __ mov(edx, Immediate(0)); |
| 2674 | __ jmp(&load_arg2); |
| 2675 | |
| 2676 | __ bind(&arg1_is_object); |
| 2677 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2678 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2679 | __ j(not_equal, &check_undefined_arg1); |
| 2680 | |
| 2681 | // 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] | 2682 | if (left_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2683 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2684 | ConvertHeapNumberToInt32(masm, edx, conversion_failure); |
| 2685 | } else { |
| 2686 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
| 2687 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2688 | __ mov(edx, ecx); |
| 2689 | |
| 2690 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2691 | __ bind(&load_arg2); |
| 2692 | |
| 2693 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2694 | if (right_type == BinaryOpIC::SMI) { |
| 2695 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2696 | } else { |
| 2697 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2698 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2699 | |
| 2700 | __ SmiUntag(eax); |
| 2701 | __ mov(ecx, eax); |
| 2702 | __ jmp(&done); |
| 2703 | |
| 2704 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2705 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2706 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2707 | __ j(not_equal, conversion_failure); |
| 2708 | __ mov(ecx, Immediate(0)); |
| 2709 | __ jmp(&done); |
| 2710 | |
| 2711 | __ bind(&arg2_is_object); |
| 2712 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2713 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2714 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2715 | // 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] | 2716 | |
| 2717 | if (right_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2718 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2719 | ConvertHeapNumberToInt32(masm, eax, conversion_failure); |
| 2720 | } else { |
| 2721 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
| 2722 | } |
| 2723 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2724 | __ bind(&done); |
| 2725 | __ mov(eax, edx); |
| 2726 | } |
| 2727 | |
| 2728 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2729 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2730 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2731 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2732 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2733 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2734 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2735 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2736 | |
| 2737 | __ bind(&load_smi); |
| 2738 | __ SmiUntag(number); |
| 2739 | __ push(number); |
| 2740 | __ fild_s(Operand(esp, 0)); |
| 2741 | __ pop(number); |
| 2742 | |
| 2743 | __ bind(&done); |
| 2744 | } |
| 2745 | |
| 2746 | |
| 2747 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2748 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2749 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2750 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2751 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2752 | |
| 2753 | __ bind(&load_eax); |
| 2754 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2755 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2756 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2757 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2758 | |
| 2759 | __ bind(&load_smi_edx); |
| 2760 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2761 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2762 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2763 | __ jmp(&load_eax); |
| 2764 | |
| 2765 | __ bind(&load_smi_eax); |
| 2766 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2767 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2768 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2769 | |
| 2770 | __ bind(&done); |
| 2771 | } |
| 2772 | |
| 2773 | |
| 2774 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2775 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2776 | 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] | 2777 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2778 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2779 | Factory* factory = masm->isolate()->factory(); |
| 2780 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2781 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2782 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2783 | __ bind(&load_eax); |
| 2784 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2785 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2786 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2787 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2788 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2789 | __ bind(&load_smi_edx); |
| 2790 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2791 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2792 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2793 | __ jmp(&load_eax); |
| 2794 | __ bind(&load_smi_eax); |
| 2795 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2796 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2797 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2798 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2799 | __ bind(&load_float_eax); |
| 2800 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2801 | __ bind(&done); |
| 2802 | } |
| 2803 | |
| 2804 | |
| 2805 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2806 | Register scratch) { |
| 2807 | const Register left = edx; |
| 2808 | const Register right = eax; |
| 2809 | __ mov(scratch, left); |
| 2810 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2811 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2812 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2813 | |
| 2814 | __ mov(scratch, right); |
| 2815 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2816 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2817 | } |
| 2818 | |
| 2819 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2820 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2821 | Label* non_int32, |
| 2822 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2823 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2824 | Register scratch, |
| 2825 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2826 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2827 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2828 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2829 | __ movmskps(scratch, xmm_scratch); |
| 2830 | // Two least significant bits should be both set. |
| 2831 | __ not_(scratch); |
| 2832 | __ test(scratch, Immediate(3)); |
| 2833 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2837 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2838 | Register scratch, |
| 2839 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2840 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2841 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2842 | __ mov(scratch, edx); |
| 2843 | } else { |
| 2844 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2845 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2846 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2847 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2848 | __ bind(&done_load_1); |
| 2849 | |
| 2850 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2851 | __ mov(scratch, eax); |
| 2852 | } else { |
| 2853 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2854 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2855 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2856 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2857 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2858 | |
| 2859 | __ bind(&load_smi_1); |
| 2860 | __ SmiUntag(scratch); |
| 2861 | __ push(scratch); |
| 2862 | __ fild_s(Operand(esp, 0)); |
| 2863 | __ pop(scratch); |
| 2864 | __ jmp(&done_load_1); |
| 2865 | |
| 2866 | __ bind(&load_smi_2); |
| 2867 | __ SmiUntag(scratch); |
| 2868 | __ push(scratch); |
| 2869 | __ fild_s(Operand(esp, 0)); |
| 2870 | __ pop(scratch); |
| 2871 | |
| 2872 | __ bind(&done); |
| 2873 | } |
| 2874 | |
| 2875 | |
| 2876 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2877 | Register scratch) { |
| 2878 | const Register left = edx; |
| 2879 | const Register right = eax; |
| 2880 | __ mov(scratch, left); |
| 2881 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2882 | __ SmiUntag(scratch); |
| 2883 | __ push(scratch); |
| 2884 | __ fild_s(Operand(esp, 0)); |
| 2885 | |
| 2886 | __ mov(scratch, right); |
| 2887 | __ SmiUntag(scratch); |
| 2888 | __ mov(Operand(esp, 0), scratch); |
| 2889 | __ fild_s(Operand(esp, 0)); |
| 2890 | __ pop(scratch); |
| 2891 | } |
| 2892 | |
| 2893 | |
| 2894 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2895 | Label* non_float, |
| 2896 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2897 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2898 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2899 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2900 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2901 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2902 | Factory* factory = masm->isolate()->factory(); |
| 2903 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2904 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2905 | |
| 2906 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2907 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2908 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2909 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2910 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2911 | |
| 2912 | // Fall-through: Both operands are numbers. |
| 2913 | __ bind(&done); |
| 2914 | } |
| 2915 | |
| 2916 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2917 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2918 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2919 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2920 | const Register exponent = eax; |
| 2921 | const Register base = edx; |
| 2922 | const Register scratch = ecx; |
| 2923 | const XMMRegister double_result = xmm3; |
| 2924 | const XMMRegister double_base = xmm2; |
| 2925 | const XMMRegister double_exponent = xmm1; |
| 2926 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2927 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2928 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2929 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2930 | // Save 1 in double_result - we need this several times later on. |
| 2931 | __ mov(scratch, Immediate(1)); |
| 2932 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2933 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2934 | if (exponent_type_ == ON_STACK) { |
| 2935 | Label base_is_smi, unpack_exponent; |
| 2936 | // The exponent and base are supplied as arguments on the stack. |
| 2937 | // This can only happen if the stub is called from non-optimized code. |
| 2938 | // Load input parameters from stack. |
| 2939 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 2940 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 2941 | |
| 2942 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2943 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 2944 | factory->heap_number_map()); |
| 2945 | __ j(not_equal, &call_runtime); |
| 2946 | |
| 2947 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2948 | __ jmp(&unpack_exponent, Label::kNear); |
| 2949 | |
| 2950 | __ bind(&base_is_smi); |
| 2951 | __ SmiUntag(base); |
| 2952 | __ cvtsi2sd(double_base, base); |
| 2953 | |
| 2954 | __ bind(&unpack_exponent); |
| 2955 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2956 | __ SmiUntag(exponent); |
| 2957 | __ jmp(&int_exponent); |
| 2958 | |
| 2959 | __ bind(&exponent_not_smi); |
| 2960 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2961 | factory->heap_number_map()); |
| 2962 | __ j(not_equal, &call_runtime); |
| 2963 | __ movdbl(double_exponent, |
| 2964 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2965 | } else if (exponent_type_ == TAGGED) { |
| 2966 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2967 | __ SmiUntag(exponent); |
| 2968 | __ jmp(&int_exponent); |
| 2969 | |
| 2970 | __ bind(&exponent_not_smi); |
| 2971 | __ movdbl(double_exponent, |
| 2972 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2973 | } |
| 2974 | |
| 2975 | if (exponent_type_ != INTEGER) { |
| 2976 | Label fast_power; |
| 2977 | // Detect integer exponents stored as double. |
| 2978 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 2979 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 2980 | __ cmp(exponent, Immediate(0x80000000u)); |
| 2981 | __ j(equal, &call_runtime); |
| 2982 | __ cvtsi2sd(double_scratch, exponent); |
| 2983 | // Already ruled out NaNs for exponent. |
| 2984 | __ ucomisd(double_exponent, double_scratch); |
| 2985 | __ j(equal, &int_exponent); |
| 2986 | |
| 2987 | if (exponent_type_ == ON_STACK) { |
| 2988 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 2989 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 2990 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 2991 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 2992 | // Test for 0.5. |
| 2993 | // Load double_scratch with 0.5. |
| 2994 | __ mov(scratch, Immediate(0x3F000000u)); |
| 2995 | __ movd(double_scratch, scratch); |
| 2996 | __ cvtss2sd(double_scratch, double_scratch); |
| 2997 | // Already ruled out NaNs for exponent. |
| 2998 | __ ucomisd(double_scratch, double_exponent); |
| 2999 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 3000 | |
| 3001 | // Calculates square root of base. Check for the special case of |
| 3002 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 3003 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3004 | // 9 bits set and the lowest 23 bits cleared. |
| 3005 | __ mov(scratch, 0xFF800000u); |
| 3006 | __ movd(double_scratch, scratch); |
| 3007 | __ cvtss2sd(double_scratch, double_scratch); |
| 3008 | __ ucomisd(double_base, double_scratch); |
| 3009 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3010 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3011 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 3012 | __ j(carry, &continue_sqrt, Label::kNear); |
| 3013 | |
| 3014 | // Set result to Infinity in the special case. |
| 3015 | __ xorps(double_result, double_result); |
| 3016 | __ subsd(double_result, double_scratch); |
| 3017 | __ jmp(&done); |
| 3018 | |
| 3019 | __ bind(&continue_sqrt); |
| 3020 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3021 | __ xorps(double_scratch, double_scratch); |
| 3022 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 3023 | __ sqrtsd(double_result, double_scratch); |
| 3024 | __ jmp(&done); |
| 3025 | |
| 3026 | // Test for -0.5. |
| 3027 | __ bind(¬_plus_half); |
| 3028 | // Load double_exponent with -0.5 by substracting 1. |
| 3029 | __ subsd(double_scratch, double_result); |
| 3030 | // Already ruled out NaNs for exponent. |
| 3031 | __ ucomisd(double_scratch, double_exponent); |
| 3032 | __ j(not_equal, &fast_power, Label::kNear); |
| 3033 | |
| 3034 | // Calculates reciprocal of square root of base. Check for the special |
| 3035 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 3036 | // According to IEEE-754, single-precision -Infinity has the highest |
| 3037 | // 9 bits set and the lowest 23 bits cleared. |
| 3038 | __ mov(scratch, 0xFF800000u); |
| 3039 | __ movd(double_scratch, scratch); |
| 3040 | __ cvtss2sd(double_scratch, double_scratch); |
| 3041 | __ ucomisd(double_base, double_scratch); |
| 3042 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 3043 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 3044 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 3045 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 3046 | |
| 3047 | // Set result to 0 in the special case. |
| 3048 | __ xorps(double_result, double_result); |
| 3049 | __ jmp(&done); |
| 3050 | |
| 3051 | __ bind(&continue_rsqrt); |
| 3052 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 3053 | __ xorps(double_exponent, double_exponent); |
| 3054 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 3055 | __ sqrtsd(double_exponent, double_exponent); |
| 3056 | __ divsd(double_result, double_exponent); |
| 3057 | __ jmp(&done); |
| 3058 | } |
| 3059 | |
| 3060 | // Using FPU instructions to calculate power. |
| 3061 | Label fast_power_failed; |
| 3062 | __ bind(&fast_power); |
| 3063 | __ fnclex(); // Clear flags to catch exceptions later. |
| 3064 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 3065 | __ sub(esp, Immediate(kDoubleSize)); |
| 3066 | __ movdbl(Operand(esp, 0), double_exponent); |
| 3067 | __ fld_d(Operand(esp, 0)); // E |
| 3068 | __ movdbl(Operand(esp, 0), double_base); |
| 3069 | __ fld_d(Operand(esp, 0)); // B, E |
| 3070 | |
| 3071 | // Exponent is in st(1) and base is in st(0) |
| 3072 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 3073 | // FYL2X calculates st(1) * log2(st(0)) |
| 3074 | __ fyl2x(); // X |
| 3075 | __ fld(0); // X, X |
| 3076 | __ frndint(); // rnd(X), X |
| 3077 | __ fsub(1); // rnd(X), X-rnd(X) |
| 3078 | __ fxch(1); // X - rnd(X), rnd(X) |
| 3079 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 3080 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 3081 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3082 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3083 | // FSCALE calculates st(0) * 2^st(1) |
| 3084 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 3085 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3086 | // Bail out to runtime in case of exceptions in the status word. |
| 3087 | __ fnstsw_ax(); |
| 3088 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 3089 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 3090 | __ fstp_d(Operand(esp, 0)); |
| 3091 | __ movdbl(double_result, Operand(esp, 0)); |
| 3092 | __ add(esp, Immediate(kDoubleSize)); |
| 3093 | __ jmp(&done); |
| 3094 | |
| 3095 | __ bind(&fast_power_failed); |
| 3096 | __ fninit(); |
| 3097 | __ add(esp, Immediate(kDoubleSize)); |
| 3098 | __ jmp(&call_runtime); |
| 3099 | } |
| 3100 | |
| 3101 | // Calculate power with integer exponent. |
| 3102 | __ bind(&int_exponent); |
| 3103 | const XMMRegister double_scratch2 = double_exponent; |
| 3104 | __ mov(scratch, exponent); // Back up exponent. |
| 3105 | __ movsd(double_scratch, double_base); // Back up base. |
| 3106 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3107 | |
| 3108 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 3109 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3110 | __ test(scratch, scratch); |
| 3111 | __ j(positive, &no_neg, Label::kNear); |
| 3112 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3113 | __ bind(&no_neg); |
| 3114 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3115 | __ j(zero, &while_false, Label::kNear); |
| 3116 | __ shr(scratch, 1); |
| 3117 | // Above condition means CF==0 && ZF==0. This means that the |
| 3118 | // bit that has been shifted out is 0 and the result is not 0. |
| 3119 | __ j(above, &while_true, Label::kNear); |
| 3120 | __ movsd(double_result, double_scratch); |
| 3121 | __ j(zero, &while_false, Label::kNear); |
| 3122 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3123 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3124 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3125 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3126 | __ j(above, &while_true, Label::kNear); |
| 3127 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3128 | __ j(not_zero, &while_true); |
| 3129 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3130 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3131 | // scratch has the original value of the exponent - if the exponent is |
| 3132 | // negative, return 1/result. |
| 3133 | __ test(exponent, exponent); |
| 3134 | __ j(positive, &done); |
| 3135 | __ divsd(double_scratch2, double_result); |
| 3136 | __ movsd(double_result, double_scratch2); |
| 3137 | // Test whether result is zero. Bail out to check for subnormal result. |
| 3138 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 3139 | __ xorps(double_scratch2, double_scratch2); |
| 3140 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 3141 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 3142 | // and may not have contained the exponent value in the first place when the |
| 3143 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 3144 | __ j(not_equal, &done); |
| 3145 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3146 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3147 | // Returning or bailing out. |
| 3148 | Counters* counters = masm->isolate()->counters(); |
| 3149 | if (exponent_type_ == ON_STACK) { |
| 3150 | // The arguments are still on the stack. |
| 3151 | __ bind(&call_runtime); |
| 3152 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3153 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3154 | // The stub is called from non-optimized code, which expects the result |
| 3155 | // as heap number in exponent. |
| 3156 | __ bind(&done); |
| 3157 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 3158 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 3159 | __ IncrementCounter(counters->math_pow(), 1); |
| 3160 | __ ret(2 * kPointerSize); |
| 3161 | } else { |
| 3162 | __ bind(&call_runtime); |
| 3163 | { |
| 3164 | AllowExternalCallThatCantCauseGC scope(masm); |
| 3165 | __ PrepareCallCFunction(4, scratch); |
| 3166 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 3167 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 3168 | __ CallCFunction( |
| 3169 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 3170 | } |
| 3171 | // Return value is in st(0) on ia32. |
| 3172 | // Store it into the (fixed) result register. |
| 3173 | __ sub(esp, Immediate(kDoubleSize)); |
| 3174 | __ fstp_d(Operand(esp, 0)); |
| 3175 | __ movdbl(double_result, Operand(esp, 0)); |
| 3176 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3177 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3178 | __ bind(&done); |
| 3179 | __ IncrementCounter(counters->math_pow(), 1); |
| 3180 | __ ret(0); |
| 3181 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3185 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 3186 | // ----------- S t a t e ------------- |
| 3187 | // -- ecx : name |
| 3188 | // -- edx : receiver |
| 3189 | // -- esp[0] : return address |
| 3190 | // ----------------------------------- |
| 3191 | Label miss; |
| 3192 | |
| 3193 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3194 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3195 | __ j(not_equal, &miss); |
| 3196 | } |
| 3197 | |
| 3198 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 3199 | __ bind(&miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3200 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | |
| 3204 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 3205 | // ----------- S t a t e ------------- |
| 3206 | // -- ecx : name |
| 3207 | // -- edx : receiver |
| 3208 | // -- esp[0] : return address |
| 3209 | // ----------------------------------- |
| 3210 | Label miss; |
| 3211 | |
| 3212 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3213 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3214 | __ j(not_equal, &miss); |
| 3215 | } |
| 3216 | |
| 3217 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 3218 | support_wrapper_); |
| 3219 | __ bind(&miss); |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3220 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3224 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 3225 | // ----------- S t a t e ------------- |
| 3226 | // -- eax : value |
| 3227 | // -- ecx : name |
| 3228 | // -- edx : receiver |
| 3229 | // -- esp[0] : return address |
| 3230 | // ----------------------------------- |
| 3231 | // |
| 3232 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 3233 | // (currently anything except for external arrays which means anything with |
| 3234 | // elements of FixedArray type). Value must be a number, but only smis are |
| 3235 | // accepted as the most common case. |
| 3236 | |
| 3237 | Label miss; |
| 3238 | |
| 3239 | Register receiver = edx; |
| 3240 | Register value = eax; |
| 3241 | Register scratch = ebx; |
| 3242 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3243 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3244 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3245 | __ j(not_equal, &miss); |
| 3246 | } |
| 3247 | |
| 3248 | // Check that the receiver isn't a smi. |
| 3249 | __ JumpIfSmi(receiver, &miss); |
| 3250 | |
| 3251 | // Check that the object is a JS array. |
| 3252 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 3253 | __ j(not_equal, &miss); |
| 3254 | |
| 3255 | // Check that elements are FixedArray. |
| 3256 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 3257 | // fast elements (including COW). |
| 3258 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 3259 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 3260 | __ j(not_equal, &miss); |
| 3261 | |
| 3262 | // Check that the array has fast properties, otherwise the length |
| 3263 | // property might have been redefined. |
| 3264 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 3265 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 3266 | Heap::kHashTableMapRootIndex); |
| 3267 | __ j(equal, &miss); |
| 3268 | |
| 3269 | // Check that value is a smi. |
| 3270 | __ JumpIfNotSmi(value, &miss); |
| 3271 | |
| 3272 | // Prepare tail call to StoreIC_ArrayLength. |
| 3273 | __ pop(scratch); |
| 3274 | __ push(receiver); |
| 3275 | __ push(value); |
| 3276 | __ push(scratch); // return address |
| 3277 | |
| 3278 | ExternalReference ref = |
| 3279 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 3280 | __ TailCallExternalReference(ref, 2, 1); |
| 3281 | |
| 3282 | __ bind(&miss); |
| 3283 | |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 3284 | StubCompiler::TailCallBuiltin(masm, StubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3288 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3289 | // The key is in edx and the parameter count is in eax. |
| 3290 | |
| 3291 | // The displacement is used for skipping the frame pointer on the |
| 3292 | // stack. It is the offset of the last parameter (if any) relative |
| 3293 | // to the frame pointer. |
| 3294 | static const int kDisplacement = 1 * kPointerSize; |
| 3295 | |
| 3296 | // Check that the key is a smi. |
| 3297 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3298 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3299 | |
| 3300 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3301 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3302 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3303 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3304 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3305 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3306 | |
| 3307 | // Check index against formal parameters count limit passed in |
| 3308 | // through register eax. Use unsigned comparison to get negative |
| 3309 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3310 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3311 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3312 | |
| 3313 | // Read the argument from the stack and return it. |
| 3314 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3315 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3316 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3317 | __ neg(edx); |
| 3318 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3319 | __ ret(0); |
| 3320 | |
| 3321 | // Arguments adaptor case: Check index against actual arguments |
| 3322 | // limit found in the arguments adaptor frame. Use unsigned |
| 3323 | // comparison to get negative check for free. |
| 3324 | __ bind(&adaptor); |
| 3325 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3326 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3327 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3328 | |
| 3329 | // Read the argument from the stack and return it. |
| 3330 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3331 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3332 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3333 | __ neg(edx); |
| 3334 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3335 | __ ret(0); |
| 3336 | |
| 3337 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3338 | // by calling the runtime system. |
| 3339 | __ bind(&slow); |
| 3340 | __ pop(ebx); // Return address. |
| 3341 | __ push(edx); |
| 3342 | __ push(ebx); |
| 3343 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3344 | } |
| 3345 | |
| 3346 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3347 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3348 | // esp[0] : return address |
| 3349 | // esp[4] : number of parameters |
| 3350 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3351 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3352 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3353 | // Check if the calling frame is an arguments adaptor frame. |
| 3354 | Label runtime; |
| 3355 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3356 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3357 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3358 | __ j(not_equal, &runtime, Label::kNear); |
| 3359 | |
| 3360 | // Patch the arguments.length and the parameters pointer. |
| 3361 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3362 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3363 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3364 | StandardFrameConstants::kCallerSPOffset)); |
| 3365 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3366 | |
| 3367 | __ bind(&runtime); |
| 3368 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3369 | } |
| 3370 | |
| 3371 | |
| 3372 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3373 | Isolate* isolate = masm->isolate(); |
| 3374 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3375 | // esp[0] : return address |
| 3376 | // esp[4] : number of parameters (tagged) |
| 3377 | // esp[8] : receiver displacement |
| 3378 | // esp[12] : function |
| 3379 | |
| 3380 | // ebx = parameter count (tagged) |
| 3381 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3382 | |
| 3383 | // Check if the calling frame is an arguments adaptor frame. |
| 3384 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3385 | // Generate* functions. |
| 3386 | Label runtime; |
| 3387 | Label adaptor_frame, try_allocate; |
| 3388 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3389 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3390 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3391 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3392 | |
| 3393 | // No adaptor, parameter count = argument count. |
| 3394 | __ mov(ecx, ebx); |
| 3395 | __ jmp(&try_allocate, Label::kNear); |
| 3396 | |
| 3397 | // We have an adaptor frame. Patch the parameters pointer. |
| 3398 | __ bind(&adaptor_frame); |
| 3399 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3400 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3401 | StandardFrameConstants::kCallerSPOffset)); |
| 3402 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3403 | |
| 3404 | // ebx = parameter count (tagged) |
| 3405 | // ecx = argument count (tagged) |
| 3406 | // esp[4] = parameter count (tagged) |
| 3407 | // esp[8] = address of receiver argument |
| 3408 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3409 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3410 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3411 | __ mov(ebx, ecx); |
| 3412 | |
| 3413 | __ bind(&try_allocate); |
| 3414 | |
| 3415 | // Save mapped parameter count. |
| 3416 | __ push(ebx); |
| 3417 | |
| 3418 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3419 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3420 | const int kParameterMapHeaderSize = |
| 3421 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3422 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3423 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3424 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3425 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3426 | __ bind(&no_parameter_map); |
| 3427 | |
| 3428 | // 2. Backing store. |
| 3429 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3430 | |
| 3431 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3432 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3433 | |
| 3434 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3435 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3436 | |
| 3437 | // eax = address of new object(s) (tagged) |
| 3438 | // ecx = argument count (tagged) |
| 3439 | // esp[0] = mapped parameter count (tagged) |
| 3440 | // esp[8] = parameter count (tagged) |
| 3441 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3442 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3443 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3444 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3445 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3446 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3447 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3448 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3449 | __ mov(edi, Operand(edi, |
| 3450 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3451 | __ jmp(©, Label::kNear); |
| 3452 | |
| 3453 | __ bind(&has_mapped_parameters); |
| 3454 | __ mov(edi, Operand(edi, |
| 3455 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3456 | __ bind(©); |
| 3457 | |
| 3458 | // eax = address of new object (tagged) |
| 3459 | // ebx = mapped parameter count (tagged) |
| 3460 | // ecx = argument count (tagged) |
| 3461 | // edi = address of boilerplate object (tagged) |
| 3462 | // esp[0] = mapped parameter count (tagged) |
| 3463 | // esp[8] = parameter count (tagged) |
| 3464 | // esp[12] = address of receiver argument |
| 3465 | // Copy the JS object part. |
| 3466 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3467 | __ mov(edx, FieldOperand(edi, i)); |
| 3468 | __ mov(FieldOperand(eax, i), edx); |
| 3469 | } |
| 3470 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3471 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3472 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3473 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3474 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3475 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3476 | edx); |
| 3477 | |
| 3478 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3479 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3480 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3481 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3482 | ecx); |
| 3483 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3484 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3485 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3486 | // backing store. |
| 3487 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3488 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3489 | |
| 3490 | // eax = address of new object (tagged) |
| 3491 | // ebx = mapped parameter count (tagged) |
| 3492 | // ecx = argument count (tagged) |
| 3493 | // edi = address of parameter map or backing store (tagged) |
| 3494 | // esp[0] = mapped parameter count (tagged) |
| 3495 | // esp[8] = parameter count (tagged) |
| 3496 | // esp[12] = address of receiver argument |
| 3497 | // Free a register. |
| 3498 | __ push(eax); |
| 3499 | |
| 3500 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3501 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3502 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3503 | __ j(zero, &skip_parameter_map); |
| 3504 | |
| 3505 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3506 | Immediate(isolate->factory()->non_strict_arguments_elements_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3507 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3508 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3509 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3510 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3511 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3512 | |
| 3513 | // Copy the parameter slots and the holes in the arguments. |
| 3514 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3515 | // where parameters are stored in reverse order, at |
| 3516 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3517 | // The mapped parameter thus need to get indices |
| 3518 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3519 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3520 | // We loop from right to left. |
| 3521 | Label parameters_loop, parameters_test; |
| 3522 | __ push(ecx); |
| 3523 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3524 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3525 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3526 | __ sub(ebx, eax); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3527 | __ mov(ecx, isolate->factory()->the_hole_value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3528 | __ mov(edx, edi); |
| 3529 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3530 | // eax = loop variable (tagged) |
| 3531 | // ebx = mapping index (tagged) |
| 3532 | // ecx = the hole value |
| 3533 | // edx = address of parameter map (tagged) |
| 3534 | // edi = address of backing store (tagged) |
| 3535 | // esp[0] = argument count (tagged) |
| 3536 | // esp[4] = address of new object (tagged) |
| 3537 | // esp[8] = mapped parameter count (tagged) |
| 3538 | // esp[16] = parameter count (tagged) |
| 3539 | // esp[20] = address of receiver argument |
| 3540 | __ jmp(¶meters_test, Label::kNear); |
| 3541 | |
| 3542 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3543 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3544 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3545 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3546 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3547 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3548 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3549 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3550 | __ pop(ecx); |
| 3551 | |
| 3552 | __ bind(&skip_parameter_map); |
| 3553 | |
| 3554 | // ecx = argument count (tagged) |
| 3555 | // edi = address of backing store (tagged) |
| 3556 | // esp[0] = address of new object (tagged) |
| 3557 | // esp[4] = mapped parameter count (tagged) |
| 3558 | // esp[12] = parameter count (tagged) |
| 3559 | // esp[16] = address of receiver argument |
| 3560 | // Copy arguments header and remaining slots (if there are any). |
| 3561 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3562 | Immediate(isolate->factory()->fixed_array_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3563 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3564 | |
| 3565 | Label arguments_loop, arguments_test; |
| 3566 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3567 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3568 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3569 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3570 | __ jmp(&arguments_test, Label::kNear); |
| 3571 | |
| 3572 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3573 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3574 | __ mov(eax, Operand(edx, 0)); |
| 3575 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3576 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3577 | |
| 3578 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3579 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3580 | __ j(less, &arguments_loop, Label::kNear); |
| 3581 | |
| 3582 | // Restore. |
| 3583 | __ pop(eax); // Address of arguments object. |
| 3584 | __ pop(ebx); // Parameter count. |
| 3585 | |
| 3586 | // Return and remove the on-stack parameters. |
| 3587 | __ ret(3 * kPointerSize); |
| 3588 | |
| 3589 | // Do the runtime call to allocate the arguments object. |
| 3590 | __ bind(&runtime); |
| 3591 | __ pop(eax); // Remove saved parameter count. |
| 3592 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3593 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | |
| 3597 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3598 | Isolate* isolate = masm->isolate(); |
| 3599 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3600 | // esp[0] : return address |
| 3601 | // esp[4] : number of parameters |
| 3602 | // esp[8] : receiver displacement |
| 3603 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3604 | |
| 3605 | // Check if the calling frame is an arguments adaptor frame. |
| 3606 | Label adaptor_frame, try_allocate, runtime; |
| 3607 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3608 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3609 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3610 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3611 | |
| 3612 | // Get the length from the frame. |
| 3613 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3614 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3615 | |
| 3616 | // Patch the arguments.length and the parameters pointer. |
| 3617 | __ bind(&adaptor_frame); |
| 3618 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3619 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3620 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3621 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3622 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3623 | |
| 3624 | // Try the new space allocation. Start out with computing the size of |
| 3625 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3626 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3627 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3628 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3629 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3630 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3631 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3632 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3633 | |
| 3634 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3635 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3636 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3637 | // Get the arguments boilerplate from the current native context. |
| 3638 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3639 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3640 | const int offset = |
| 3641 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3642 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3643 | |
| 3644 | // Copy the JS object part. |
| 3645 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3646 | __ mov(ebx, FieldOperand(edi, i)); |
| 3647 | __ mov(FieldOperand(eax, i), ebx); |
| 3648 | } |
| 3649 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3650 | // 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] | 3651 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3652 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3653 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3654 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3655 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3656 | |
| 3657 | // If there are no actual arguments, we're done. |
| 3658 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3659 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3660 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3661 | |
| 3662 | // Get the parameters pointer from the stack. |
| 3663 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3664 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3665 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3666 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3667 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3668 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3669 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3670 | Immediate(isolate->factory()->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3671 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3672 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3673 | // Untag the length for the loop below. |
| 3674 | __ SmiUntag(ecx); |
| 3675 | |
| 3676 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3677 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3678 | __ bind(&loop); |
| 3679 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3680 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3681 | __ add(edi, Immediate(kPointerSize)); |
| 3682 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3683 | __ dec(ecx); |
| 3684 | __ j(not_zero, &loop); |
| 3685 | |
| 3686 | // Return and remove the on-stack parameters. |
| 3687 | __ bind(&done); |
| 3688 | __ ret(3 * kPointerSize); |
| 3689 | |
| 3690 | // Do the runtime call to allocate the arguments object. |
| 3691 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3692 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3693 | } |
| 3694 | |
| 3695 | |
| 3696 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3697 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3698 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3699 | // at compilation. |
| 3700 | #ifdef V8_INTERPRETED_REGEXP |
| 3701 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3702 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3703 | |
| 3704 | // Stack frame on entry. |
| 3705 | // esp[0]: return address |
| 3706 | // esp[4]: last_match_info (expected JSArray) |
| 3707 | // esp[8]: previous index |
| 3708 | // esp[12]: subject string |
| 3709 | // esp[16]: JSRegExp object |
| 3710 | |
| 3711 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3712 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3713 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3714 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3715 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3716 | Label runtime; |
| 3717 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3718 | |
| 3719 | // Ensure that a RegExp stack is allocated. |
| 3720 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3721 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3722 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3723 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3724 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3725 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3726 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3727 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3728 | |
| 3729 | // Check that the first argument is a JSRegExp object. |
| 3730 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3731 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3732 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3733 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3734 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3735 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3736 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3737 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3738 | if (FLAG_debug_code) { |
| 3739 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3740 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3741 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3742 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3743 | } |
| 3744 | |
| 3745 | // ecx: RegExp data (FixedArray) |
| 3746 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3747 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3748 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3749 | __ j(not_equal, &runtime); |
| 3750 | |
| 3751 | // ecx: RegExp data (FixedArray) |
| 3752 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3753 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3754 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3755 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3756 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3757 | STATIC_ASSERT(kSmiTag == 0); |
| 3758 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3759 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3760 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3761 | __ j(above, &runtime); |
| 3762 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3763 | // Reset offset for possibly sliced string. |
| 3764 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3765 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3766 | __ JumpIfSmi(eax, &runtime); |
| 3767 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3768 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3769 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3770 | |
| 3771 | // eax: subject string |
| 3772 | // edx: subject string |
| 3773 | // ebx: subject string instance type |
| 3774 | // ecx: RegExp data (FixedArray) |
| 3775 | // Handle subject string according to its encoding and representation: |
| 3776 | // (1) Sequential two byte? If yes, go to (9). |
| 3777 | // (2) Sequential one byte? If yes, go to (6). |
| 3778 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3779 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3780 | // Otherwise bailout. |
| 3781 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3782 | // (5b) Is subject external? If yes, go to (8). |
| 3783 | // (6) One byte sequential. Load regexp code for one byte. |
| 3784 | // (E) Carry on. |
| 3785 | /// [...] |
| 3786 | |
| 3787 | // Deferred code at the end of the stub: |
| 3788 | // (7) Not a long external string? If yes, go to (10). |
| 3789 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3790 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3791 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3792 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3793 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3794 | |
| 3795 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3796 | external_string /* 8 */, check_underlying /* 5a */, |
| 3797 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3798 | not_long_external /* 10 */; |
| 3799 | |
| 3800 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3801 | __ and_(ebx, kIsNotStringMask | |
| 3802 | kStringRepresentationMask | |
| 3803 | kStringEncodingMask | |
| 3804 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3805 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3806 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3807 | |
| 3808 | // (2) Sequential one byte? If yes, go to (6). |
| 3809 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3810 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3811 | kStringRepresentationMask | |
| 3812 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3813 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3814 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3815 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3816 | // We check whether the subject string is a cons, since sequential strings |
| 3817 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3818 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3819 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3820 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3821 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3822 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3823 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3824 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3825 | // (4) Cons string. Check that it's flat. |
| 3826 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3827 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3828 | __ j(not_equal, &runtime); |
| 3829 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3830 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3831 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3832 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3833 | |
| 3834 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3835 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3836 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3837 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3838 | // (5b) Is subject external? If yes, go to (8). |
| 3839 | __ test_b(ebx, kStringRepresentationMask); |
| 3840 | // The underlying external string is never a short external string. |
| 3841 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3842 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3843 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3844 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3845 | // eax: sequential subject string (or look-alike, external string) |
| 3846 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3847 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3848 | // (6) One byte sequential. Load regexp code for one byte. |
| 3849 | __ bind(&seq_one_byte_string); |
| 3850 | // Load previous index and check range before edx is overwritten. We have |
| 3851 | // to use edx instead of eax here because it might have been only made to |
| 3852 | // look like a sequential string when it actually is an external string. |
| 3853 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3854 | __ JumpIfNotSmi(ebx, &runtime); |
| 3855 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3856 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3857 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3858 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3859 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3860 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3861 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3862 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3863 | // Check that the irregexp code has been generated for the actual string |
| 3864 | // 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] | 3865 | // a smi (code flushing support). |
| 3866 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3867 | |
| 3868 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3869 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3870 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3871 | // 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] | 3872 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3873 | Counters* counters = masm->isolate()->counters(); |
| 3874 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3875 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3876 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3877 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3878 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3879 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3880 | // Argument 9: Pass current isolate address. |
| 3881 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3882 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3883 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3884 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3885 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3886 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3887 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3888 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3889 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3890 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3891 | |
| 3892 | // Argument 6: Set the number of capture registers to zero to force global |
| 3893 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3894 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3895 | |
| 3896 | // Argument 5: static offsets vector buffer. |
| 3897 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3898 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3899 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3900 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3901 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3902 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3903 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3904 | |
| 3905 | // Argument 1: Original subject string. |
| 3906 | // The original subject is in the previous stack frame. Therefore we have to |
| 3907 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3908 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3909 | // and thereby moves up esp by one kPointerSize.) |
| 3910 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3911 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3912 | |
| 3913 | // esi: original subject string |
| 3914 | // eax: underlying subject string |
| 3915 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3916 | // 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] | 3917 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3918 | // Argument 4: End of string data |
| 3919 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3920 | // Prepare start and end index of the input. |
| 3921 | // Load the length from the original sliced string if that is the case. |
| 3922 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3923 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3924 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3925 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3926 | |
| 3927 | // ebx: start index of the input string |
| 3928 | // esi: end index of the input string |
| 3929 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3930 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3931 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3932 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3933 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3934 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3935 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3936 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3937 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3938 | |
| 3939 | __ bind(&setup_two_byte); |
| 3940 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3941 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3942 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3943 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3944 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3945 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3946 | |
| 3947 | __ bind(&setup_rest); |
| 3948 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3949 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3950 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3951 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3952 | |
| 3953 | // Drop arguments and come back to JS mode. |
| 3954 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3955 | |
| 3956 | // Check the result. |
| 3957 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3958 | __ cmp(eax, 1); |
| 3959 | // We expect exactly one result since we force the called regexp to behave |
| 3960 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3961 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3962 | Label failure; |
| 3963 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3964 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3965 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3966 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3967 | __ j(not_equal, &runtime); |
| 3968 | // Result must now be exception. If there is no pending exception already a |
| 3969 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3970 | // haven't created the exception yet. Handle that in the runtime system. |
| 3971 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3972 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3973 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3974 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3975 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3976 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3977 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3978 | // For exception, throw the exception again. |
| 3979 | |
| 3980 | // Clear the pending exception variable. |
| 3981 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3982 | |
| 3983 | // Special handling of termination exceptions which are uncatchable |
| 3984 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3985 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3986 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3987 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3988 | |
| 3989 | // Handle normal exception by following handler chain. |
| 3990 | __ Throw(eax); |
| 3991 | |
| 3992 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3993 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3994 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3995 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3996 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3997 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3998 | __ ret(4 * kPointerSize); |
| 3999 | |
| 4000 | // Load RegExp data. |
| 4001 | __ bind(&success); |
| 4002 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 4003 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 4004 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4005 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 4006 | STATIC_ASSERT(kSmiTag == 0); |
| 4007 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4008 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4009 | |
| 4010 | // edx: Number of capture registers |
| 4011 | // 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] | 4012 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4013 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4014 | __ JumpIfSmi(eax, &runtime); |
| 4015 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 4016 | __ j(not_equal, &runtime); |
| 4017 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4018 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4019 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 4020 | __ cmp(eax, factory->fixed_array_map()); |
| 4021 | __ j(not_equal, &runtime); |
| 4022 | // Check that the last match info has space for the capture registers and the |
| 4023 | // additional information. |
| 4024 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 4025 | __ SmiUntag(eax); |
| 4026 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 4027 | __ cmp(edx, eax); |
| 4028 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4029 | |
| 4030 | // ebx: last_match_info backing store (FixedArray) |
| 4031 | // edx: number of capture registers |
| 4032 | // Store the capture count. |
| 4033 | __ SmiTag(edx); // Number of capture registers to smi. |
| 4034 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 4035 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 4036 | // Store last subject and last input. |
| 4037 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4038 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4039 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4040 | __ RecordWriteField(ebx, |
| 4041 | RegExpImpl::kLastSubjectOffset, |
| 4042 | eax, |
| 4043 | edi, |
| 4044 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4045 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4046 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4047 | __ RecordWriteField(ebx, |
| 4048 | RegExpImpl::kLastInputOffset, |
| 4049 | eax, |
| 4050 | edi, |
| 4051 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4052 | |
| 4053 | // Get the static offsets vector filled by the native regexp code. |
| 4054 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4055 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4056 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 4057 | |
| 4058 | // ebx: last_match_info backing store (FixedArray) |
| 4059 | // ecx: offsets vector |
| 4060 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4061 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4062 | // Capture register counter starts from number of capture registers and |
| 4063 | // counts down until wraping after zero. |
| 4064 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4065 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4066 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4067 | // Read the value from the static offsets vector buffer. |
| 4068 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 4069 | __ SmiTag(edi); |
| 4070 | // Store the smi value in the last match info. |
| 4071 | __ mov(FieldOperand(ebx, |
| 4072 | edx, |
| 4073 | times_pointer_size, |
| 4074 | RegExpImpl::kFirstCaptureOffset), |
| 4075 | edi); |
| 4076 | __ jmp(&next_capture); |
| 4077 | __ bind(&done); |
| 4078 | |
| 4079 | // Return last match info. |
| 4080 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 4081 | __ ret(4 * kPointerSize); |
| 4082 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4083 | // Do the runtime call to execute the regexp. |
| 4084 | __ bind(&runtime); |
| 4085 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4086 | |
| 4087 | // Deferred code for string handling. |
| 4088 | // (7) Not a long external string? If yes, go to (10). |
| 4089 | __ bind(¬_seq_nor_cons); |
| 4090 | // Compare flags are still set from (3). |
| 4091 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 4092 | |
| 4093 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4094 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4095 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4096 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4097 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4098 | if (FLAG_debug_code) { |
| 4099 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 4100 | // Sequential strings have already been ruled out. |
| 4101 | __ test_b(ebx, kIsIndirectStringMask); |
| 4102 | __ Assert(zero, "external string expected, but not found"); |
| 4103 | } |
| 4104 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 4105 | // 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] | 4106 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4107 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4108 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4109 | // (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] | 4110 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4111 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 4112 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 4113 | // eax: sequential subject string (or look-alike, external string) |
| 4114 | // edx: original subject string |
| 4115 | // ecx: RegExp data (FixedArray) |
| 4116 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 4117 | __ bind(&seq_two_byte_string); |
| 4118 | // Load previous index and check range before edx is overwritten. We have |
| 4119 | // to use edx instead of eax here because it might have been only made to |
| 4120 | // look like a sequential string when it actually is an external string. |
| 4121 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 4122 | __ JumpIfNotSmi(ebx, &runtime); |
| 4123 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 4124 | __ j(above_equal, &runtime); |
| 4125 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 4126 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 4127 | __ jmp(&check_code); // Go to (E). |
| 4128 | |
| 4129 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 4130 | __ bind(¬_long_external); |
| 4131 | // Catch non-string subject or short external string. |
| 4132 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 4133 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 4134 | __ j(not_zero, &runtime); |
| 4135 | |
| 4136 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 4137 | // Load offset into edi and replace subject string with parent. |
| 4138 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 4139 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 4140 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4141 | #endif // V8_INTERPRETED_REGEXP |
| 4142 | } |
| 4143 | |
| 4144 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4145 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4146 | const int kMaxInlineLength = 100; |
| 4147 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4148 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4149 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4150 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4151 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4152 | __ j(above, &slowcase); |
| 4153 | // Smi-tagging is equivalent to multiplying by 2. |
| 4154 | STATIC_ASSERT(kSmiTag == 0); |
| 4155 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4156 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4157 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4158 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4159 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 4160 | times_pointer_size, |
| 4161 | ebx, // In: Number of elements as a smi |
| 4162 | REGISTER_VALUE_IS_SMI, |
| 4163 | eax, // Out: Start of allocation (tagged). |
| 4164 | ecx, // Out: End of allocation. |
| 4165 | edx, // Scratch register |
| 4166 | &slowcase, |
| 4167 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4168 | // eax: Start of allocated area, object-tagged. |
| 4169 | |
| 4170 | // Set JSArray map to global.regexp_result_map(). |
| 4171 | // Set empty properties FixedArray. |
| 4172 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4173 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4174 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4175 | Factory* factory = masm->isolate()->factory(); |
| 4176 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4177 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 4178 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4179 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 4180 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 4181 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4182 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 4183 | |
| 4184 | // Set input, index and length fields from arguments. |
| 4185 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 4186 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 4187 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 4188 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 4189 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 4190 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 4191 | |
| 4192 | // Fill out the elements FixedArray. |
| 4193 | // eax: JSArray. |
| 4194 | // ebx: FixedArray. |
| 4195 | // ecx: Number of elements in array, as smi. |
| 4196 | |
| 4197 | // Set map. |
| 4198 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4199 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4200 | // Set length. |
| 4201 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4202 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4203 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4204 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4205 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4206 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4207 | // eax: JSArray. |
| 4208 | // ecx: Number of elements to fill. |
| 4209 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 4210 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4211 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4212 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4213 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4214 | __ 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] | 4215 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4216 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 4217 | __ jmp(&loop); |
| 4218 | |
| 4219 | __ bind(&done); |
| 4220 | __ ret(3 * kPointerSize); |
| 4221 | |
| 4222 | __ bind(&slowcase); |
| 4223 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4224 | } |
| 4225 | |
| 4226 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4227 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 4228 | Register object, |
| 4229 | Register result, |
| 4230 | Register scratch1, |
| 4231 | Register scratch2, |
| 4232 | bool object_is_smi, |
| 4233 | Label* not_found) { |
| 4234 | // Use of registers. Register result is used as a temporary. |
| 4235 | Register number_string_cache = result; |
| 4236 | Register mask = scratch1; |
| 4237 | Register scratch = scratch2; |
| 4238 | |
| 4239 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4240 | ExternalReference roots_array_start = |
| 4241 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4242 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 4243 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4244 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4245 | // Make the hash mask from the length of the number string cache. It |
| 4246 | // contains two elements (number and string) for each cache entry. |
| 4247 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 4248 | __ 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] | 4249 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4250 | |
| 4251 | // Calculate the entry in the number string cache. The hash value in the |
| 4252 | // number string cache for smis is just the smi value, and the hash for |
| 4253 | // doubles is the xor of the upper and lower words. See |
| 4254 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4255 | Label smi_hash_calculated; |
| 4256 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4257 | if (object_is_smi) { |
| 4258 | __ mov(scratch, object); |
| 4259 | __ SmiUntag(scratch); |
| 4260 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4261 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4262 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4263 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4264 | __ mov(scratch, object); |
| 4265 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4266 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4267 | __ bind(¬_smi); |
| 4268 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4269 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4270 | __ j(not_equal, not_found); |
| 4271 | STATIC_ASSERT(8 == kDoubleSize); |
| 4272 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4273 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4274 | // 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] | 4275 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4276 | Register index = scratch; |
| 4277 | Register probe = mask; |
| 4278 | __ mov(probe, |
| 4279 | FieldOperand(number_string_cache, |
| 4280 | index, |
| 4281 | times_twice_pointer_size, |
| 4282 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4283 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4284 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4285 | CpuFeatureScope fscope(masm, SSE2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4286 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4287 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4288 | __ ucomisd(xmm0, xmm1); |
| 4289 | } else { |
| 4290 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4291 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4292 | __ FCmp(); |
| 4293 | } |
| 4294 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4295 | __ 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] | 4296 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4297 | } |
| 4298 | |
| 4299 | __ bind(&smi_hash_calculated); |
| 4300 | // 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] | 4301 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4302 | Register index = scratch; |
| 4303 | // Check if the entry is the smi we are looking for. |
| 4304 | __ cmp(object, |
| 4305 | FieldOperand(number_string_cache, |
| 4306 | index, |
| 4307 | times_twice_pointer_size, |
| 4308 | FixedArray::kHeaderSize)); |
| 4309 | __ j(not_equal, not_found); |
| 4310 | |
| 4311 | // Get the result from the cache. |
| 4312 | __ bind(&load_result_from_cache); |
| 4313 | __ mov(result, |
| 4314 | FieldOperand(number_string_cache, |
| 4315 | index, |
| 4316 | times_twice_pointer_size, |
| 4317 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4318 | Counters* counters = masm->isolate()->counters(); |
| 4319 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4320 | } |
| 4321 | |
| 4322 | |
| 4323 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4324 | Label runtime; |
| 4325 | |
| 4326 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4327 | |
| 4328 | // Generate code to lookup number in the number string cache. |
| 4329 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4330 | __ ret(1 * kPointerSize); |
| 4331 | |
| 4332 | __ bind(&runtime); |
| 4333 | // Handle number to string in the runtime system if not found in the cache. |
| 4334 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4335 | } |
| 4336 | |
| 4337 | |
| 4338 | static int NegativeComparisonResult(Condition cc) { |
| 4339 | ASSERT(cc != equal); |
| 4340 | ASSERT((cc == less) || (cc == less_equal) |
| 4341 | || (cc == greater) || (cc == greater_equal)); |
| 4342 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4343 | } |
| 4344 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4345 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4346 | static void CheckInputType(MacroAssembler* masm, |
| 4347 | Register input, |
| 4348 | CompareIC::State expected, |
| 4349 | Label* fail) { |
| 4350 | Label ok; |
| 4351 | if (expected == CompareIC::SMI) { |
| 4352 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4353 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4354 | __ JumpIfSmi(input, &ok); |
| 4355 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4356 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4357 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4358 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4359 | // 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] | 4360 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4361 | __ bind(&ok); |
| 4362 | } |
| 4363 | |
| 4364 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4365 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 4366 | Label* label, |
| 4367 | Register object, |
| 4368 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4369 | __ JumpIfSmi(object, label); |
| 4370 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4371 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4372 | __ and_(scratch, kIsInternalizedMask | kIsNotStringMask); |
| 4373 | __ cmp(scratch, kInternalizedTag | kStringTag); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4374 | __ j(not_equal, label); |
| 4375 | } |
| 4376 | |
| 4377 | |
| 4378 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4379 | Label check_unequal_objects; |
| 4380 | Condition cc = GetCondition(); |
| 4381 | |
| 4382 | Label miss; |
| 4383 | CheckInputType(masm, edx, left_, &miss); |
| 4384 | CheckInputType(masm, eax, right_, &miss); |
| 4385 | |
| 4386 | // Compare two smis. |
| 4387 | Label non_smi, smi_done; |
| 4388 | __ mov(ecx, edx); |
| 4389 | __ or_(ecx, eax); |
| 4390 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4391 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4392 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4393 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4394 | __ bind(&smi_done); |
| 4395 | __ mov(eax, edx); |
| 4396 | __ ret(0); |
| 4397 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4398 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4399 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4400 | // it is certain that at least one operand isn't a smi. |
| 4401 | |
| 4402 | // Identical objects can be compared fast, but there are some tricky cases |
| 4403 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4404 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4405 | { |
| 4406 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4407 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4408 | __ j(not_equal, ¬_identical); |
| 4409 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4410 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4411 | // Check for undefined. undefined OP undefined is false even though |
| 4412 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4413 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4414 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4415 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4416 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4417 | __ ret(0); |
| 4418 | __ bind(&check_for_nan); |
| 4419 | } |
| 4420 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4421 | // Test for NaN. Compare heap numbers in a general way, |
| 4422 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4423 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4424 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4425 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4426 | if (cc != equal) { |
| 4427 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4428 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4429 | __ j(above_equal, ¬_identical); |
| 4430 | } |
| 4431 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4432 | __ ret(0); |
| 4433 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4434 | |
| 4435 | __ bind(¬_identical); |
| 4436 | } |
| 4437 | |
| 4438 | // Strict equality can quickly decide whether objects are equal. |
| 4439 | // 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] | 4440 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4441 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4442 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4443 | // If we're doing a strict equality comparison, we don't have to do |
| 4444 | // type conversion, so we generate code to do fast comparison for objects |
| 4445 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4446 | // slow-case code. |
| 4447 | // If either is a Smi (we know that not both are), then they can only |
| 4448 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4449 | STATIC_ASSERT(kSmiTag == 0); |
| 4450 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4451 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4452 | __ and_(ecx, eax); |
| 4453 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4454 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4455 | // One operand is a smi. |
| 4456 | |
| 4457 | // Check whether the non-smi is a heap number. |
| 4458 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4459 | // 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] | 4460 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4461 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4462 | __ xor_(ebx, eax); |
| 4463 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4464 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4465 | // if eax was smi, ebx is now edx, else eax. |
| 4466 | |
| 4467 | // Check if the non-smi operand is a heap number. |
| 4468 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4469 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4470 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4471 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4472 | // Return non-equal (ebx is not zero) |
| 4473 | __ mov(eax, ebx); |
| 4474 | __ ret(0); |
| 4475 | |
| 4476 | __ bind(¬_smis); |
| 4477 | // If either operand is a JSObject or an oddball value, then they are not |
| 4478 | // equal since their pointers are different |
| 4479 | // There is no test for undetectability in strict equality. |
| 4480 | |
| 4481 | // Get the type of the first operand. |
| 4482 | // 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] | 4483 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4484 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4485 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4486 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4487 | |
| 4488 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4489 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4490 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4491 | __ bind(&return_not_equal); |
| 4492 | __ ret(0); |
| 4493 | |
| 4494 | __ bind(&first_non_object); |
| 4495 | // Check for oddballs: true, false, null, undefined. |
| 4496 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4497 | __ j(equal, &return_not_equal); |
| 4498 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4499 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4500 | __ j(above_equal, &return_not_equal); |
| 4501 | |
| 4502 | // Check for oddballs: true, false, null, undefined. |
| 4503 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4504 | __ j(equal, &return_not_equal); |
| 4505 | |
| 4506 | // Fall through to the general case. |
| 4507 | __ bind(&slow); |
| 4508 | } |
| 4509 | |
| 4510 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4511 | Label non_number_comparison; |
| 4512 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4513 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4514 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4515 | CpuFeatureScope use_sse2(masm, SSE2); |
| 4516 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4517 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4518 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4519 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4520 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4521 | // Don't base result on EFLAGS when a NaN is involved. |
| 4522 | __ j(parity_even, &unordered, Label::kNear); |
| 4523 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4524 | __ mov(eax, 0); // equal |
| 4525 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4526 | __ cmov(above, eax, ecx); |
| 4527 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4528 | __ cmov(below, eax, ecx); |
| 4529 | __ ret(0); |
| 4530 | } else { |
| 4531 | FloatingPointHelper::CheckFloatOperands( |
| 4532 | masm, &non_number_comparison, ebx); |
| 4533 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4534 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4535 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4536 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4537 | // Don't base result on EFLAGS when a NaN is involved. |
| 4538 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4539 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4540 | Label below_label, above_label; |
| 4541 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4542 | __ j(below, &below_label, Label::kNear); |
| 4543 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4544 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4545 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4546 | __ ret(0); |
| 4547 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4548 | __ bind(&below_label); |
| 4549 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4550 | __ ret(0); |
| 4551 | |
| 4552 | __ bind(&above_label); |
| 4553 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4554 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4555 | } |
| 4556 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4557 | // If one of the numbers was NaN, then the result is always false. |
| 4558 | // The cc is never not-equal. |
| 4559 | __ bind(&unordered); |
| 4560 | ASSERT(cc != not_equal); |
| 4561 | if (cc == less || cc == less_equal) { |
| 4562 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4563 | } else { |
| 4564 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4565 | } |
| 4566 | __ ret(0); |
| 4567 | |
| 4568 | // The number comparison code did not provide a valid result. |
| 4569 | __ bind(&non_number_comparison); |
| 4570 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4571 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4572 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4573 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4574 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 4575 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4576 | |
| 4577 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4578 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4579 | // non-zero value, which indicates not equal, so just return. |
| 4580 | __ ret(0); |
| 4581 | } |
| 4582 | |
| 4583 | __ bind(&check_for_strings); |
| 4584 | |
| 4585 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4586 | &check_unequal_objects); |
| 4587 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4588 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4589 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4590 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4591 | edx, |
| 4592 | eax, |
| 4593 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4594 | ebx); |
| 4595 | } else { |
| 4596 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4597 | edx, |
| 4598 | eax, |
| 4599 | ecx, |
| 4600 | ebx, |
| 4601 | edi); |
| 4602 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4603 | #ifdef DEBUG |
| 4604 | __ Abort("Unexpected fall-through from string comparison"); |
| 4605 | #endif |
| 4606 | |
| 4607 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4608 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4609 | // Non-strict equality. Objects are unequal if |
| 4610 | // they are both JSObjects and not undetectable, |
| 4611 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4612 | Label not_both_objects; |
| 4613 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4614 | // At most one is a smi, so we can test for smi by adding the two. |
| 4615 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4616 | // a heap object has the low bit clear. |
| 4617 | STATIC_ASSERT(kSmiTag == 0); |
| 4618 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4619 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4620 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4621 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4622 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4623 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4624 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4625 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4626 | // We do not bail out after this point. Both are JSObjects, and |
| 4627 | // they are equal if and only if both are undetectable. |
| 4628 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4629 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4630 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4631 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4632 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4633 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4634 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4635 | // The objects are both undetectable, so they both compare as the value |
| 4636 | // undefined, and are equal. |
| 4637 | __ Set(eax, Immediate(EQUAL)); |
| 4638 | __ bind(&return_unequal); |
| 4639 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4640 | // or return equal if we fell through to here. |
| 4641 | __ ret(0); // rax, rdx were pushed |
| 4642 | __ bind(¬_both_objects); |
| 4643 | } |
| 4644 | |
| 4645 | // Push arguments below the return address. |
| 4646 | __ pop(ecx); |
| 4647 | __ push(edx); |
| 4648 | __ push(eax); |
| 4649 | |
| 4650 | // Figure out which native to call and setup the arguments. |
| 4651 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4652 | if (cc == equal) { |
| 4653 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4654 | } else { |
| 4655 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4656 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4657 | } |
| 4658 | |
| 4659 | // Restore return address on the stack. |
| 4660 | __ push(ecx); |
| 4661 | |
| 4662 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4663 | // tagged as a small integer. |
| 4664 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4665 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4666 | __ bind(&miss); |
| 4667 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | |
| 4671 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4672 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4673 | } |
| 4674 | |
| 4675 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4676 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4677 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4678 | } |
| 4679 | |
| 4680 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4681 | static void GenerateRecordCallTargetNoArray(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4682 | // Cache the called function in a global property cell. Cache states |
| 4683 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4684 | // megamorphic. |
| 4685 | // ebx : cache cell for call target |
| 4686 | // edi : the function to call |
| 4687 | Isolate* isolate = masm->isolate(); |
| 4688 | Label initialize, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4689 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4690 | // Load the cache state into ecx. |
| 4691 | __ mov(ecx, FieldOperand(ebx, JSGlobalPropertyCell::kValueOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4692 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4693 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4694 | // function without changing the state. |
| 4695 | __ cmp(ecx, edi); |
| 4696 | __ j(equal, &done, Label::kNear); |
| 4697 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4698 | __ j(equal, &done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4699 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4700 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4701 | // megamorphic. |
| 4702 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4703 | __ j(equal, &initialize, Label::kNear); |
| 4704 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4705 | // write-barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 4706 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4707 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4708 | __ jmp(&done, Label::kNear); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4709 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4710 | // An uninitialized cache is patched with the function. |
| 4711 | __ bind(&initialize); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 4712 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4713 | // No need for a write barrier here - cells are rescanned. |
| 4714 | |
| 4715 | __ bind(&done); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4716 | } |
| 4717 | |
| 4718 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4719 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4720 | // Cache the called function in a global property cell. Cache states |
| 4721 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4722 | // megamorphic. |
| 4723 | // ebx : cache cell for call target |
| 4724 | // edi : the function to call |
| 4725 | ASSERT(FLAG_optimize_constructed_arrays); |
| 4726 | Isolate* isolate = masm->isolate(); |
| 4727 | Label initialize, done, miss, megamorphic, not_array_function; |
| 4728 | |
| 4729 | // Load the cache state into ecx. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 4730 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4731 | |
| 4732 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4733 | // function without changing the state. |
| 4734 | __ cmp(ecx, edi); |
| 4735 | __ j(equal, &done); |
| 4736 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4737 | __ j(equal, &done); |
| 4738 | |
| 4739 | // Special handling of the Array() function, which caches not only the |
| 4740 | // monomorphic Array function but the initial ElementsKind with special |
| 4741 | // sentinels |
| 4742 | Handle<Object> terminal_kind_sentinel = |
| 4743 | TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
| 4744 | LAST_FAST_ELEMENTS_KIND); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 4745 | __ JumpIfNotSmi(ecx, &miss); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4746 | __ cmp(ecx, Immediate(terminal_kind_sentinel)); |
| 4747 | __ j(above, &miss); |
| 4748 | // Load the global or builtins object from the current context |
| 4749 | __ LoadGlobalContext(ecx); |
| 4750 | // Make sure the function is the Array() function |
| 4751 | __ cmp(edi, Operand(ecx, |
| 4752 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4753 | __ j(not_equal, &megamorphic); |
| 4754 | __ jmp(&done); |
| 4755 | |
| 4756 | __ bind(&miss); |
| 4757 | |
| 4758 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4759 | // megamorphic. |
| 4760 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4761 | __ j(equal, &initialize); |
| 4762 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4763 | // write-barrier is needed. |
| 4764 | __ bind(&megamorphic); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 4765 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4766 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4767 | __ jmp(&done, Label::kNear); |
| 4768 | |
| 4769 | // An uninitialized cache is patched with the function or sentinel to |
| 4770 | // indicate the ElementsKind if function is the Array constructor. |
| 4771 | __ bind(&initialize); |
| 4772 | __ LoadGlobalContext(ecx); |
| 4773 | // Make sure the function is the Array() function |
| 4774 | __ cmp(edi, Operand(ecx, |
| 4775 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4776 | __ j(not_equal, ¬_array_function); |
| 4777 | |
| 4778 | // The target function is the Array constructor, install a sentinel value in |
| 4779 | // the constructor's type info cell that will track the initial ElementsKind |
| 4780 | // that should be used for the array when its constructed. |
| 4781 | Handle<Object> initial_kind_sentinel = |
| 4782 | TypeFeedbackCells::MonomorphicArraySentinel(isolate, |
| 4783 | GetInitialFastElementsKind()); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 4784 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4785 | Immediate(initial_kind_sentinel)); |
| 4786 | __ jmp(&done); |
| 4787 | |
| 4788 | __ bind(¬_array_function); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 4789 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4790 | // No need for a write barrier here - cells are rescanned. |
| 4791 | |
| 4792 | __ bind(&done); |
| 4793 | } |
| 4794 | |
| 4795 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4796 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4797 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4798 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4799 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4800 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4801 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4802 | // The receiver might implicitly be the global object. This is |
| 4803 | // indicated by passing the hole as the receiver to the call |
| 4804 | // function stub. |
| 4805 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4806 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4807 | // Get the receiver from the stack. |
| 4808 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4809 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4810 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4811 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4812 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4813 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4814 | __ mov(ecx, GlobalObjectOperand()); |
| 4815 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4816 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4817 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4818 | } |
| 4819 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4820 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4821 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4822 | // Goto slow case if we do not have a function. |
| 4823 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4824 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4825 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4826 | if (RecordCallTarget()) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 4827 | if (FLAG_optimize_constructed_arrays) { |
| 4828 | GenerateRecordCallTarget(masm); |
| 4829 | } else { |
| 4830 | GenerateRecordCallTargetNoArray(masm); |
| 4831 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4832 | } |
| 4833 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4834 | // Fast-case: Just invoke the function. |
| 4835 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4836 | |
| 4837 | if (ReceiverMightBeImplicit()) { |
| 4838 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4839 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4840 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4841 | __ InvokeFunction(edi, |
| 4842 | actual, |
| 4843 | JUMP_FUNCTION, |
| 4844 | NullCallWrapper(), |
| 4845 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4846 | __ bind(&call_as_function); |
| 4847 | } |
| 4848 | __ InvokeFunction(edi, |
| 4849 | actual, |
| 4850 | JUMP_FUNCTION, |
| 4851 | NullCallWrapper(), |
| 4852 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4853 | |
| 4854 | // Slow-case: Non-function called. |
| 4855 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4856 | if (RecordCallTarget()) { |
| 4857 | // 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] | 4858 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4859 | // object (undefined) so no write barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 4860 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4861 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4862 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4863 | // Check for function proxy. |
| 4864 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4865 | __ j(not_equal, &non_function); |
| 4866 | __ pop(ecx); |
| 4867 | __ push(edi); // put proxy as additional argument under return address |
| 4868 | __ push(ecx); |
| 4869 | __ Set(eax, Immediate(argc_ + 1)); |
| 4870 | __ Set(ebx, Immediate(0)); |
| 4871 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4872 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4873 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4874 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4875 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4876 | } |
| 4877 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4878 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4879 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4880 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4881 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4882 | __ Set(eax, Immediate(argc_)); |
| 4883 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4884 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4885 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4886 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4887 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4888 | } |
| 4889 | |
| 4890 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4891 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4892 | // eax : number of arguments |
| 4893 | // ebx : cache cell for call target |
| 4894 | // edi : constructor function |
| 4895 | Label slow, non_function_call; |
| 4896 | |
| 4897 | // Check that function is not a smi. |
| 4898 | __ JumpIfSmi(edi, &non_function_call); |
| 4899 | // Check that function is a JSFunction. |
| 4900 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4901 | __ j(not_equal, &slow); |
| 4902 | |
| 4903 | if (RecordCallTarget()) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4904 | if (FLAG_optimize_constructed_arrays) { |
| 4905 | GenerateRecordCallTarget(masm); |
| 4906 | } else { |
| 4907 | GenerateRecordCallTargetNoArray(masm); |
| 4908 | } |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4909 | } |
| 4910 | |
| 4911 | // Jump to the function-specific construct stub. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4912 | Register jmp_reg = FLAG_optimize_constructed_arrays ? ecx : ebx; |
| 4913 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4914 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 4915 | SharedFunctionInfo::kConstructStubOffset)); |
| 4916 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 4917 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4918 | |
| 4919 | // edi: called object |
| 4920 | // eax: number of arguments |
| 4921 | // ecx: object map |
| 4922 | Label do_call; |
| 4923 | __ bind(&slow); |
| 4924 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4925 | __ j(not_equal, &non_function_call); |
| 4926 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4927 | __ jmp(&do_call); |
| 4928 | |
| 4929 | __ bind(&non_function_call); |
| 4930 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4931 | __ bind(&do_call); |
| 4932 | // Set expected number of arguments to zero (not changing eax). |
| 4933 | __ Set(ebx, Immediate(0)); |
| 4934 | Handle<Code> arguments_adaptor = |
| 4935 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4936 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4937 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4938 | } |
| 4939 | |
| 4940 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4941 | bool CEntryStub::NeedsImmovableCode() { |
| 4942 | return false; |
| 4943 | } |
| 4944 | |
| 4945 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4946 | bool CEntryStub::IsPregenerated() { |
| 4947 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4948 | result_size_ == 1; |
| 4949 | } |
| 4950 | |
| 4951 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4952 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4953 | CEntryStub::GenerateAheadOfTime(isolate); |
| 4954 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4955 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4956 | // 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] | 4957 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4958 | if (FLAG_optimize_constructed_arrays) { |
| 4959 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
| 4960 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4964 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4965 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4966 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4967 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4968 | // which would lead to code stub initialization state being messed up. |
| 4969 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4970 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 4971 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4972 | } |
| 4973 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4974 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4975 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4979 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4980 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4981 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4982 | code->set_is_pregenerated(true); |
| 4983 | } |
| 4984 | |
| 4985 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4986 | static void JumpIfOOM(MacroAssembler* masm, |
| 4987 | Register value, |
| 4988 | Register scratch, |
| 4989 | Label* oom_label) { |
| 4990 | __ mov(scratch, value); |
| 4991 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 4992 | STATIC_ASSERT(kFailureTag == 3); |
| 4993 | __ and_(scratch, 0xf); |
| 4994 | __ cmp(scratch, 0xf); |
| 4995 | __ j(equal, oom_label); |
| 4996 | } |
| 4997 | |
| 4998 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4999 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 5000 | Label* throw_normal_exception, |
| 5001 | Label* throw_termination_exception, |
| 5002 | Label* throw_out_of_memory_exception, |
| 5003 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 5004 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5005 | // eax: result parameter for PerformGC, if any |
| 5006 | // ebx: pointer to C function (C callee-saved) |
| 5007 | // ebp: frame pointer (restored after C call) |
| 5008 | // esp: stack pointer (restored after C call) |
| 5009 | // edi: number of arguments including receiver (C callee-saved) |
| 5010 | // esi: pointer to the first argument (C callee-saved) |
| 5011 | |
| 5012 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 5013 | |
| 5014 | // Check stack alignment. |
| 5015 | if (FLAG_debug_code) { |
| 5016 | __ CheckStackAlignment(); |
| 5017 | } |
| 5018 | |
| 5019 | if (do_gc) { |
| 5020 | // Pass failure code returned from last attempt as first argument to |
| 5021 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 5022 | // stack alignment is known to be correct. This function takes one argument |
| 5023 | // which is passed on the stack, and we know that the stack has been |
| 5024 | // prepared to pass at least one argument. |
| 5025 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 5026 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 5027 | } |
| 5028 | |
| 5029 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5030 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5031 | if (always_allocate_scope) { |
| 5032 | __ inc(Operand::StaticVariable(scope_depth)); |
| 5033 | } |
| 5034 | |
| 5035 | // Call C function. |
| 5036 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 5037 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5038 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5039 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5040 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5041 | // Result is in eax or edx:eax - do not destroy these registers! |
| 5042 | |
| 5043 | if (always_allocate_scope) { |
| 5044 | __ dec(Operand::StaticVariable(scope_depth)); |
| 5045 | } |
| 5046 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5047 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 5048 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5049 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5050 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5051 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5052 | __ j(not_equal, &okay, Label::kNear); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5053 | // TODO(wingo): Currently SuspendJSGeneratorObject returns the hole. Change |
| 5054 | // to return another sentinel like a harmony symbol. |
| 5055 | __ cmp(ebx, Immediate(ExternalReference( |
| 5056 | Runtime::kSuspendJSGeneratorObject, masm->isolate()))); |
| 5057 | __ j(equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5058 | __ int3(); |
| 5059 | __ bind(&okay); |
| 5060 | } |
| 5061 | |
| 5062 | // Check for failure result. |
| 5063 | Label failure_returned; |
| 5064 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 5065 | __ lea(ecx, Operand(eax, 1)); |
| 5066 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 5067 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5068 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5069 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5070 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5071 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5072 | |
| 5073 | // Check that there is no pending exception, otherwise we |
| 5074 | // should have returned some failure value. |
| 5075 | if (FLAG_debug_code) { |
| 5076 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5077 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5078 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5079 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 5080 | // 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] | 5081 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 5082 | __ int3(); |
| 5083 | __ bind(&okay); |
| 5084 | __ pop(edx); |
| 5085 | } |
| 5086 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5087 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5088 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5089 | __ ret(0); |
| 5090 | |
| 5091 | // Handling of failure. |
| 5092 | __ bind(&failure_returned); |
| 5093 | |
| 5094 | Label retry; |
| 5095 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 5096 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 5097 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5098 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5099 | |
| 5100 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5101 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5102 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5103 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5104 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5105 | |
| 5106 | // See if we just retrieved an OOM exception. |
| 5107 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 5108 | |
| 5109 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5110 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5111 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 5112 | |
| 5113 | // Special handling of termination exceptions which are uncatchable |
| 5114 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5115 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5116 | __ j(equal, throw_termination_exception); |
| 5117 | |
| 5118 | // Handle normal exception. |
| 5119 | __ jmp(throw_normal_exception); |
| 5120 | |
| 5121 | // Retry. |
| 5122 | __ bind(&retry); |
| 5123 | } |
| 5124 | |
| 5125 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5126 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 5127 | // eax: number of arguments including receiver |
| 5128 | // ebx: pointer to C function (C callee-saved) |
| 5129 | // ebp: frame pointer (restored after C call) |
| 5130 | // esp: stack pointer (restored after C call) |
| 5131 | // esi: current context (C callee-saved) |
| 5132 | // edi: JS function of the caller (C callee-saved) |
| 5133 | |
| 5134 | // NOTE: Invocations of builtins may return failure objects instead |
| 5135 | // of a proper result. The builtin entry handles this by performing |
| 5136 | // a garbage collection and retrying the builtin (twice). |
| 5137 | |
| 5138 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5139 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5140 | |
| 5141 | // eax: result parameter for PerformGC, if any (setup below) |
| 5142 | // ebx: pointer to builtin function (C callee-saved) |
| 5143 | // ebp: frame pointer (restored after C call) |
| 5144 | // esp: stack pointer (restored after C call) |
| 5145 | // edi: number of arguments including receiver (C callee-saved) |
| 5146 | // esi: argv pointer (C callee-saved) |
| 5147 | |
| 5148 | Label throw_normal_exception; |
| 5149 | Label throw_termination_exception; |
| 5150 | Label throw_out_of_memory_exception; |
| 5151 | |
| 5152 | // Call into the runtime system. |
| 5153 | GenerateCore(masm, |
| 5154 | &throw_normal_exception, |
| 5155 | &throw_termination_exception, |
| 5156 | &throw_out_of_memory_exception, |
| 5157 | false, |
| 5158 | false); |
| 5159 | |
| 5160 | // Do space-specific GC and retry runtime call. |
| 5161 | GenerateCore(masm, |
| 5162 | &throw_normal_exception, |
| 5163 | &throw_termination_exception, |
| 5164 | &throw_out_of_memory_exception, |
| 5165 | true, |
| 5166 | false); |
| 5167 | |
| 5168 | // Do full GC and retry runtime call one final time. |
| 5169 | Failure* failure = Failure::InternalError(); |
| 5170 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 5171 | GenerateCore(masm, |
| 5172 | &throw_normal_exception, |
| 5173 | &throw_termination_exception, |
| 5174 | &throw_out_of_memory_exception, |
| 5175 | true, |
| 5176 | true); |
| 5177 | |
| 5178 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5179 | // Set external caught exception to false. |
| 5180 | Isolate* isolate = masm->isolate(); |
| 5181 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 5182 | isolate); |
| 5183 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 5184 | |
| 5185 | // Set pending exception and eax to out of memory exception. |
| 5186 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 5187 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5188 | Label already_have_failure; |
| 5189 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 5190 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 5191 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5192 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5193 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5194 | |
| 5195 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5196 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5197 | |
| 5198 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 5199 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5200 | } |
| 5201 | |
| 5202 | |
| 5203 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5204 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5205 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5206 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5207 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5208 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5209 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5210 | |
| 5211 | // Push marker in two places. |
| 5212 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 5213 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 5214 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 5215 | // Save callee-saved registers (C calling conventions). |
| 5216 | __ push(edi); |
| 5217 | __ push(esi); |
| 5218 | __ push(ebx); |
| 5219 | |
| 5220 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5221 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5222 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 5223 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5224 | // 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] | 5225 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5226 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5227 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5228 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5229 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5230 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 5231 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5232 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5233 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5234 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5235 | // Jump to a faked try block that does the invoke, with a faked catch |
| 5236 | // block that sets the pending exception. |
| 5237 | __ jmp(&invoke); |
| 5238 | __ bind(&handler_entry); |
| 5239 | handler_offset_ = handler_entry.pos(); |
| 5240 | // Caught exception: Store result (exception) in the pending exception |
| 5241 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5242 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5243 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5244 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 5245 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 5246 | __ jmp(&exit); |
| 5247 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5248 | // Invoke: Link this frame into the handler chain. There's only one |
| 5249 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5250 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 5251 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5252 | |
| 5253 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5254 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5255 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 5256 | |
| 5257 | // Fake a receiver (NULL). |
| 5258 | __ push(Immediate(0)); // receiver |
| 5259 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5260 | // Invoke the function by calling through JS entry trampoline builtin and |
| 5261 | // pop the faked function when we return. Notice that we cannot store a |
| 5262 | // reference to the trampoline code directly in this stub, because the |
| 5263 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5264 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5265 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 5266 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5267 | __ mov(edx, Immediate(construct_entry)); |
| 5268 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5269 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5270 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5271 | __ mov(edx, Immediate(entry)); |
| 5272 | } |
| 5273 | __ mov(edx, Operand(edx, 0)); // deref address |
| 5274 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5275 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5276 | |
| 5277 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5278 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5279 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5280 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5281 | // Check if the current stack frame is marked as the outermost JS frame. |
| 5282 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5283 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5284 | __ j(not_equal, ¬_outermost_js_2); |
| 5285 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 5286 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5287 | |
| 5288 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5289 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 5290 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 5291 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5292 | |
| 5293 | // Restore callee-saved registers (C calling conventions). |
| 5294 | __ pop(ebx); |
| 5295 | __ pop(esi); |
| 5296 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5297 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5298 | |
| 5299 | // Restore frame pointer and return. |
| 5300 | __ pop(ebp); |
| 5301 | __ ret(0); |
| 5302 | } |
| 5303 | |
| 5304 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5305 | // Generate stub code for instanceof. |
| 5306 | // This code can patch a call site inlined cache of the instance of check, |
| 5307 | // which looks like this. |
| 5308 | // |
| 5309 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 5310 | // 75 0a jne <some near label> |
| 5311 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 5312 | // |
| 5313 | // If call site patching is requested the stack will have the delta from the |
| 5314 | // return address to the cmp instruction just below the return address. This |
| 5315 | // also means that call site patching can only take place with arguments in |
| 5316 | // registers. TOS looks like this when call site patching is requested |
| 5317 | // |
| 5318 | // esp[0] : return address |
| 5319 | // esp[4] : delta from return address to cmp instruction |
| 5320 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5321 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5322 | // Call site inlining and patching implies arguments in registers. |
| 5323 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5324 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5325 | // Fixed register usage throughout the stub. |
| 5326 | Register object = eax; // Object (lhs). |
| 5327 | Register map = ebx; // Map of the object. |
| 5328 | Register function = edx; // Function (rhs). |
| 5329 | Register prototype = edi; // Prototype of the function. |
| 5330 | Register scratch = ecx; |
| 5331 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5332 | // Constants describing the call site code to patch. |
| 5333 | static const int kDeltaToCmpImmediate = 2; |
| 5334 | static const int kDeltaToMov = 8; |
| 5335 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5336 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5337 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5338 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5339 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5340 | ExternalReference roots_array_start = |
| 5341 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5342 | |
| 5343 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5344 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5345 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5346 | // Get the object and function - they are always both needed. |
| 5347 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5348 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5349 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5350 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5351 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5352 | |
| 5353 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5354 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5355 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5356 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5357 | // If there is a call site cache don't look in the global cache, but do the |
| 5358 | // real lookup and update the call site cache. |
| 5359 | if (!HasCallSiteInlineCheck()) { |
| 5360 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5361 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5362 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5363 | __ cmp(function, Operand::StaticArray(scratch, |
| 5364 | times_pointer_size, |
| 5365 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5366 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5367 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5368 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5369 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5370 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5371 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5372 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5373 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5374 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5375 | __ bind(&miss); |
| 5376 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5377 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5378 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5379 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5380 | |
| 5381 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5382 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5383 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5384 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5385 | // Update the global instanceof or call site inlined cache with the current |
| 5386 | // map and function. The cached answer will be set when it is known below. |
| 5387 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5388 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5389 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5390 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5391 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5392 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5393 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5394 | } else { |
| 5395 | // The constants for the code patching are based on no push instructions |
| 5396 | // at the call site. |
| 5397 | ASSERT(HasArgsInRegisters()); |
| 5398 | // Get return address and delta to inlined map check. |
| 5399 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5400 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5401 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5402 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5403 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5404 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5405 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5406 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5407 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5408 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5409 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5410 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5411 | // Loop through the prototype chain of the object looking for the function |
| 5412 | // prototype. |
| 5413 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5414 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5415 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5416 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5417 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5418 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5419 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5420 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5421 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5422 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5423 | __ jmp(&loop); |
| 5424 | |
| 5425 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5426 | if (!HasCallSiteInlineCheck()) { |
| 5427 | __ Set(eax, Immediate(0)); |
| 5428 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5429 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5430 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5431 | } else { |
| 5432 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5433 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5434 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5435 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5436 | if (FLAG_debug_code) { |
| 5437 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5438 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5439 | } |
| 5440 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5441 | if (!ReturnTrueFalseObject()) { |
| 5442 | __ Set(eax, Immediate(0)); |
| 5443 | } |
| 5444 | } |
| 5445 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5446 | |
| 5447 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5448 | if (!HasCallSiteInlineCheck()) { |
| 5449 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5450 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5451 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5452 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5453 | } else { |
| 5454 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5455 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5456 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5457 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5458 | if (FLAG_debug_code) { |
| 5459 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5460 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5461 | } |
| 5462 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5463 | if (!ReturnTrueFalseObject()) { |
| 5464 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5465 | } |
| 5466 | } |
| 5467 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5468 | |
| 5469 | Label object_not_null, object_not_null_or_smi; |
| 5470 | __ bind(¬_js_object); |
| 5471 | // Before null, smi and string value checks, check that the rhs is a function |
| 5472 | // 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] | 5473 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5474 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5475 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5476 | |
| 5477 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5478 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5479 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5480 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5481 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5482 | |
| 5483 | __ bind(&object_not_null); |
| 5484 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5485 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5486 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5487 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5488 | |
| 5489 | __ bind(&object_not_null_or_smi); |
| 5490 | // String values is not instance of anything. |
| 5491 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5492 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5493 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5494 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5495 | |
| 5496 | // Slow-case: Go through the JavaScript implementation. |
| 5497 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5498 | if (!ReturnTrueFalseObject()) { |
| 5499 | // Tail call the builtin which returns 0 or 1. |
| 5500 | if (HasArgsInRegisters()) { |
| 5501 | // Push arguments below return address. |
| 5502 | __ pop(scratch); |
| 5503 | __ push(object); |
| 5504 | __ push(function); |
| 5505 | __ push(scratch); |
| 5506 | } |
| 5507 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5508 | } else { |
| 5509 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5510 | { |
| 5511 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5512 | __ push(object); |
| 5513 | __ push(function); |
| 5514 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5515 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5516 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5517 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5518 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5519 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5520 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5521 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5522 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5523 | __ bind(&done); |
| 5524 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5525 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5526 | } |
| 5527 | |
| 5528 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5529 | Register InstanceofStub::left() { return eax; } |
| 5530 | |
| 5531 | |
| 5532 | Register InstanceofStub::right() { return edx; } |
| 5533 | |
| 5534 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5535 | // ------------------------------------------------------------------------- |
| 5536 | // StringCharCodeAtGenerator |
| 5537 | |
| 5538 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5539 | // If the receiver is a smi trigger the non-string case. |
| 5540 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5541 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5542 | |
| 5543 | // Fetch the instance type of the receiver into result register. |
| 5544 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5545 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5546 | // If the receiver is not a string trigger the non-string case. |
| 5547 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5548 | __ j(not_zero, receiver_not_string_); |
| 5549 | |
| 5550 | // If the index is non-smi trigger the non-smi case. |
| 5551 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5552 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5553 | __ bind(&got_smi_index_); |
| 5554 | |
| 5555 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5556 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5557 | __ j(above_equal, index_out_of_range_); |
| 5558 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5559 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5560 | |
| 5561 | Factory* factory = masm->isolate()->factory(); |
| 5562 | StringCharLoadGenerator::Generate( |
| 5563 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5564 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5565 | __ SmiTag(result_); |
| 5566 | __ bind(&exit_); |
| 5567 | } |
| 5568 | |
| 5569 | |
| 5570 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5571 | MacroAssembler* masm, |
| 5572 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5573 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5574 | |
| 5575 | // Index is not a smi. |
| 5576 | __ bind(&index_not_smi_); |
| 5577 | // 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] | 5578 | __ CheckMap(index_, |
| 5579 | masm->isolate()->factory()->heap_number_map(), |
| 5580 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5581 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5582 | call_helper.BeforeCall(masm); |
| 5583 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5584 | __ push(index_); // Consumed by runtime conversion function. |
| 5585 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5586 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5587 | } else { |
| 5588 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5589 | // NumberToSmi discards numbers that are not exact integers. |
| 5590 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5591 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5592 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5593 | // Save the conversion result before the pop instructions below |
| 5594 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5595 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5596 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5597 | __ pop(object_); |
| 5598 | // Reload the instance type. |
| 5599 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5600 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5601 | call_helper.AfterCall(masm); |
| 5602 | // If index is still not a smi, it must be out of range. |
| 5603 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5604 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5605 | // Otherwise, return to the fast path. |
| 5606 | __ jmp(&got_smi_index_); |
| 5607 | |
| 5608 | // Call runtime. We get here when the receiver is a string and the |
| 5609 | // index is a number, but the code of getting the actual character |
| 5610 | // is too complex (e.g., when the string needs to be flattened). |
| 5611 | __ bind(&call_runtime_); |
| 5612 | call_helper.BeforeCall(masm); |
| 5613 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5614 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5615 | __ push(index_); |
| 5616 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5617 | if (!result_.is(eax)) { |
| 5618 | __ mov(result_, eax); |
| 5619 | } |
| 5620 | call_helper.AfterCall(masm); |
| 5621 | __ jmp(&exit_); |
| 5622 | |
| 5623 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5624 | } |
| 5625 | |
| 5626 | |
| 5627 | // ------------------------------------------------------------------------- |
| 5628 | // StringCharFromCodeGenerator |
| 5629 | |
| 5630 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5631 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5632 | STATIC_ASSERT(kSmiTag == 0); |
| 5633 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5634 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5635 | __ test(code_, |
| 5636 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5637 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5638 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5639 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5640 | Factory* factory = masm->isolate()->factory(); |
| 5641 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5642 | STATIC_ASSERT(kSmiTag == 0); |
| 5643 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5644 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5645 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5646 | __ mov(result_, FieldOperand(result_, |
| 5647 | code_, times_half_pointer_size, |
| 5648 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5649 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5650 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5651 | __ bind(&exit_); |
| 5652 | } |
| 5653 | |
| 5654 | |
| 5655 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5656 | MacroAssembler* masm, |
| 5657 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5658 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5659 | |
| 5660 | __ bind(&slow_case_); |
| 5661 | call_helper.BeforeCall(masm); |
| 5662 | __ push(code_); |
| 5663 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5664 | if (!result_.is(eax)) { |
| 5665 | __ mov(result_, eax); |
| 5666 | } |
| 5667 | call_helper.AfterCall(masm); |
| 5668 | __ jmp(&exit_); |
| 5669 | |
| 5670 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5671 | } |
| 5672 | |
| 5673 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5674 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5675 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5676 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5677 | |
| 5678 | // Load the two arguments. |
| 5679 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5680 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5681 | |
| 5682 | // 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] | 5683 | if ((flags_ & NO_STRING_ADD_FLAGS) != 0) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5684 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5685 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5686 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5687 | |
| 5688 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5689 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5690 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5691 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5692 | } else { |
| 5693 | // Here at least one of the arguments is definitely a string. |
| 5694 | // We convert the one that is not known to be a string. |
| 5695 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5696 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5697 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5698 | &call_builtin); |
| 5699 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5700 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5701 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5702 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5703 | &call_builtin); |
| 5704 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5705 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5706 | } |
| 5707 | |
| 5708 | // Both arguments are strings. |
| 5709 | // eax: first string |
| 5710 | // edx: second string |
| 5711 | // 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] | 5712 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5713 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5714 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5715 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5716 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5717 | // 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] | 5718 | Counters* counters = masm->isolate()->counters(); |
| 5719 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5720 | __ ret(2 * kPointerSize); |
| 5721 | __ bind(&second_not_zero_length); |
| 5722 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5723 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5724 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5725 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5726 | // First string is empty, result is second string which is in edx. |
| 5727 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5728 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5729 | __ ret(2 * kPointerSize); |
| 5730 | |
| 5731 | // Both strings are non-empty. |
| 5732 | // eax: first string |
| 5733 | // ebx: length of first string as a smi |
| 5734 | // ecx: length of second string as a smi |
| 5735 | // edx: second string |
| 5736 | // Look at the length of the result of adding the two strings. |
| 5737 | Label string_add_flat_result, longer_than_two; |
| 5738 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5739 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5740 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5741 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5742 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5743 | // Use the string table when adding two one character strings, as it |
| 5744 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5745 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5746 | __ j(not_equal, &longer_than_two); |
| 5747 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5748 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5749 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5750 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5751 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5752 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5753 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5754 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5755 | // 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] | 5756 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5757 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5758 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5759 | masm, ebx, ecx, eax, edx, edi, |
| 5760 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5761 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5762 | __ ret(2 * kPointerSize); |
| 5763 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5764 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5765 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5766 | // Reload the arguments. |
| 5767 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5768 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5769 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5770 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5771 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5772 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5773 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5774 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5775 | // Pack both characters in ebx. |
| 5776 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5777 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5778 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5779 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5780 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5781 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5782 | |
| 5783 | __ bind(&longer_than_two); |
| 5784 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5785 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5786 | __ j(below, &string_add_flat_result); |
| 5787 | |
| 5788 | // 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] | 5789 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5790 | Label non_ascii, allocated, ascii_data; |
| 5791 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5792 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5793 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5794 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5795 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5796 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5797 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5798 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5799 | __ j(zero, &non_ascii); |
| 5800 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5801 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5802 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5803 | __ bind(&allocated); |
| 5804 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5805 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5806 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5807 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5808 | Immediate(String::kEmptyHashField)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5809 | |
| 5810 | Label skip_write_barrier, after_writing; |
| 5811 | ExternalReference high_promotion_mode = ExternalReference:: |
| 5812 | new_space_high_promotion_mode_active_address(masm->isolate()); |
| 5813 | __ test(Operand::StaticVariable(high_promotion_mode), Immediate(1)); |
| 5814 | __ j(zero, &skip_write_barrier); |
| 5815 | |
| 5816 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5817 | __ RecordWriteField(ecx, |
| 5818 | ConsString::kFirstOffset, |
| 5819 | eax, |
| 5820 | ebx, |
| 5821 | kDontSaveFPRegs); |
| 5822 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5823 | __ RecordWriteField(ecx, |
| 5824 | ConsString::kSecondOffset, |
| 5825 | edx, |
| 5826 | ebx, |
| 5827 | kDontSaveFPRegs); |
| 5828 | __ jmp(&after_writing); |
| 5829 | |
| 5830 | __ bind(&skip_write_barrier); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5831 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5832 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5833 | |
| 5834 | __ bind(&after_writing); |
| 5835 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5836 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5837 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5838 | __ ret(2 * kPointerSize); |
| 5839 | __ bind(&non_ascii); |
| 5840 | // 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] | 5841 | // to contain only one byte characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5842 | // ecx: first instance type AND second instance type. |
| 5843 | // edi: second instance type. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5844 | __ test(ecx, Immediate(kOneByteDataHintMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5845 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5846 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5847 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5848 | __ xor_(edi, ecx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5849 | STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0); |
| 5850 | __ and_(edi, kOneByteStringTag | kOneByteDataHintTag); |
| 5851 | __ cmp(edi, kOneByteStringTag | kOneByteDataHintTag); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5852 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5853 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5854 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5855 | __ jmp(&allocated); |
| 5856 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5857 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5858 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5859 | // Handle creating a flat result from either external or sequential strings. |
| 5860 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5861 | // eax: first string |
| 5862 | // ebx: length of resulting flat string as a smi |
| 5863 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5864 | Label first_prepared, second_prepared; |
| 5865 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5866 | __ bind(&string_add_flat_result); |
| 5867 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5868 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5869 | // ecx: instance type of first string |
| 5870 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5871 | __ test_b(ecx, kStringRepresentationMask); |
| 5872 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5873 | // Rule out short external string and load string resource. |
| 5874 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5875 | __ test_b(ecx, kShortExternalStringMask); |
| 5876 | __ j(not_zero, &call_runtime); |
| 5877 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5878 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5879 | __ jmp(&first_prepared, Label::kNear); |
| 5880 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5881 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5882 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5883 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5884 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5885 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5886 | // Check whether both strings have same encoding. |
| 5887 | // edi: instance type of second string |
| 5888 | __ xor_(ecx, edi); |
| 5889 | __ test_b(ecx, kStringEncodingMask); |
| 5890 | __ j(not_zero, &call_runtime); |
| 5891 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5892 | __ test_b(edi, kStringRepresentationMask); |
| 5893 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5894 | // Rule out short external string and load string resource. |
| 5895 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5896 | __ test_b(edi, kShortExternalStringMask); |
| 5897 | __ j(not_zero, &call_runtime); |
| 5898 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5899 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5900 | __ jmp(&second_prepared, Label::kNear); |
| 5901 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5902 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5903 | __ bind(&second_prepared); |
| 5904 | |
| 5905 | // Push the addresses of both strings' first characters onto the stack. |
| 5906 | __ push(edx); |
| 5907 | __ push(eax); |
| 5908 | |
| 5909 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5910 | // edi: instance type of second string |
| 5911 | // First string and second string have the same encoding. |
| 5912 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5913 | __ test_b(edi, kStringEncodingMask); |
| 5914 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5915 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5916 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5917 | // ebx: length of resulting flat string as a smi |
| 5918 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5919 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5920 | // eax: result string |
| 5921 | __ mov(ecx, eax); |
| 5922 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5923 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5924 | // Load first argument's length and first character location. Account for |
| 5925 | // values currently on the stack when fetching arguments from it. |
| 5926 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5927 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5928 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5929 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5930 | // eax: result string |
| 5931 | // ecx: first character of result |
| 5932 | // edx: first char of first argument |
| 5933 | // edi: length of first argument |
| 5934 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5935 | // Load second argument's length and first character location. Account for |
| 5936 | // values currently on the stack when fetching arguments from it. |
| 5937 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5938 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5939 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5940 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5941 | // eax: result string |
| 5942 | // ecx: next character of result |
| 5943 | // edx: first char of second argument |
| 5944 | // edi: length of second argument |
| 5945 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5946 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5947 | __ ret(2 * kPointerSize); |
| 5948 | |
| 5949 | // Handle creating a flat two byte result. |
| 5950 | // eax: first string - known to be two byte |
| 5951 | // ebx: length of resulting flat string as a smi |
| 5952 | // edx: second string |
| 5953 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5954 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5955 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5956 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5957 | // eax: result string |
| 5958 | __ mov(ecx, eax); |
| 5959 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5960 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5961 | // Load second argument's length and first character location. Account for |
| 5962 | // values currently on the stack when fetching arguments from it. |
| 5963 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5964 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5965 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5966 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5967 | // eax: result string |
| 5968 | // ecx: first character of result |
| 5969 | // edx: first char of first argument |
| 5970 | // edi: length of first argument |
| 5971 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5972 | // Load second argument's length and first character location. Account for |
| 5973 | // values currently on the stack when fetching arguments from it. |
| 5974 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5975 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5976 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5977 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5978 | // eax: result string |
| 5979 | // ecx: next character of result |
| 5980 | // edx: first char of second argument |
| 5981 | // edi: length of second argument |
| 5982 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5983 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5984 | __ ret(2 * kPointerSize); |
| 5985 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5986 | // Recover stack pointer before jumping to runtime. |
| 5987 | __ bind(&call_runtime_drop_two); |
| 5988 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5989 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5990 | __ bind(&call_runtime); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5991 | if ((flags_ & ERECT_FRAME) != 0) { |
| 5992 | GenerateRegisterArgsPop(masm, ecx); |
| 5993 | // Build a frame |
| 5994 | { |
| 5995 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5996 | GenerateRegisterArgsPush(masm); |
| 5997 | __ CallRuntime(Runtime::kStringAdd, 2); |
| 5998 | } |
| 5999 | __ ret(0); |
| 6000 | } else { |
| 6001 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
| 6002 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6003 | |
| 6004 | if (call_builtin.is_linked()) { |
| 6005 | __ bind(&call_builtin); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 6006 | if ((flags_ & ERECT_FRAME) != 0) { |
| 6007 | GenerateRegisterArgsPop(masm, ecx); |
| 6008 | // Build a frame |
| 6009 | { |
| 6010 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 6011 | GenerateRegisterArgsPush(masm); |
| 6012 | __ InvokeBuiltin(builtin_id, CALL_FUNCTION); |
| 6013 | } |
| 6014 | __ ret(0); |
| 6015 | } else { |
| 6016 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 6017 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6018 | } |
| 6019 | } |
| 6020 | |
| 6021 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 6022 | void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
| 6023 | __ push(eax); |
| 6024 | __ push(edx); |
| 6025 | } |
| 6026 | |
| 6027 | |
| 6028 | void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm, |
| 6029 | Register temp) { |
| 6030 | __ pop(temp); |
| 6031 | __ pop(edx); |
| 6032 | __ pop(eax); |
| 6033 | __ push(temp); |
| 6034 | } |
| 6035 | |
| 6036 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6037 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 6038 | int stack_offset, |
| 6039 | Register arg, |
| 6040 | Register scratch1, |
| 6041 | Register scratch2, |
| 6042 | Register scratch3, |
| 6043 | Label* slow) { |
| 6044 | // First check if the argument is already a string. |
| 6045 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6046 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6047 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 6048 | __ j(below, &done); |
| 6049 | |
| 6050 | // Check the number to string cache. |
| 6051 | Label not_cached; |
| 6052 | __ bind(¬_string); |
| 6053 | // Puts the cached result into scratch1. |
| 6054 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6055 | arg, |
| 6056 | scratch1, |
| 6057 | scratch2, |
| 6058 | scratch3, |
| 6059 | false, |
| 6060 | ¬_cached); |
| 6061 | __ mov(arg, scratch1); |
| 6062 | __ mov(Operand(esp, stack_offset), arg); |
| 6063 | __ jmp(&done); |
| 6064 | |
| 6065 | // Check if the argument is a safe string wrapper. |
| 6066 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6067 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6068 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 6069 | __ j(not_equal, slow); |
| 6070 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 6071 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 6072 | __ j(zero, slow); |
| 6073 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 6074 | __ mov(Operand(esp, stack_offset), arg); |
| 6075 | |
| 6076 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | |
| 6080 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 6081 | Register dest, |
| 6082 | Register src, |
| 6083 | Register count, |
| 6084 | Register scratch, |
| 6085 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6086 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6087 | __ bind(&loop); |
| 6088 | // This loop just copies one character at a time, as it is only used for very |
| 6089 | // short strings. |
| 6090 | if (ascii) { |
| 6091 | __ mov_b(scratch, Operand(src, 0)); |
| 6092 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6093 | __ add(src, Immediate(1)); |
| 6094 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6095 | } else { |
| 6096 | __ mov_w(scratch, Operand(src, 0)); |
| 6097 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6098 | __ add(src, Immediate(2)); |
| 6099 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6100 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6101 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6102 | __ j(not_zero, &loop); |
| 6103 | } |
| 6104 | |
| 6105 | |
| 6106 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 6107 | Register dest, |
| 6108 | Register src, |
| 6109 | Register count, |
| 6110 | Register scratch, |
| 6111 | bool ascii) { |
| 6112 | // Copy characters using rep movs of doublewords. |
| 6113 | // The destination is aligned on a 4 byte boundary because we are |
| 6114 | // copying to the beginning of a newly allocated string. |
| 6115 | ASSERT(dest.is(edi)); // rep movs destination |
| 6116 | ASSERT(src.is(esi)); // rep movs source |
| 6117 | ASSERT(count.is(ecx)); // rep movs count |
| 6118 | ASSERT(!scratch.is(dest)); |
| 6119 | ASSERT(!scratch.is(src)); |
| 6120 | ASSERT(!scratch.is(count)); |
| 6121 | |
| 6122 | // Nothing to do for zero characters. |
| 6123 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6124 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6125 | __ j(zero, &done); |
| 6126 | |
| 6127 | // Make count the number of bytes to copy. |
| 6128 | if (!ascii) { |
| 6129 | __ shl(count, 1); |
| 6130 | } |
| 6131 | |
| 6132 | // 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] | 6133 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6134 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6135 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6136 | |
| 6137 | // Copy from edi to esi using rep movs instruction. |
| 6138 | __ mov(scratch, count); |
| 6139 | __ sar(count, 2); // Number of doublewords to copy. |
| 6140 | __ cld(); |
| 6141 | __ rep_movs(); |
| 6142 | |
| 6143 | // Find number of bytes left. |
| 6144 | __ mov(count, scratch); |
| 6145 | __ and_(count, 3); |
| 6146 | |
| 6147 | // Check if there are more bytes to copy. |
| 6148 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6149 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6150 | __ j(zero, &done); |
| 6151 | |
| 6152 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6153 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6154 | __ bind(&loop); |
| 6155 | __ mov_b(scratch, Operand(src, 0)); |
| 6156 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6157 | __ add(src, Immediate(1)); |
| 6158 | __ add(dest, Immediate(1)); |
| 6159 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6160 | __ j(not_zero, &loop); |
| 6161 | |
| 6162 | __ bind(&done); |
| 6163 | } |
| 6164 | |
| 6165 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6166 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6167 | Register c1, |
| 6168 | Register c2, |
| 6169 | Register scratch1, |
| 6170 | Register scratch2, |
| 6171 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6172 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6173 | Label* not_found) { |
| 6174 | // Register scratch3 is the general scratch register in this function. |
| 6175 | Register scratch = scratch3; |
| 6176 | |
| 6177 | // 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] | 6178 | // 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] | 6179 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6180 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6181 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6182 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6183 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6184 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6185 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 6186 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 6187 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6188 | |
| 6189 | __ bind(¬_array_index); |
| 6190 | // Calculate the two character string hash. |
| 6191 | Register hash = scratch1; |
| 6192 | GenerateHashInit(masm, hash, c1, scratch); |
| 6193 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 6194 | GenerateHashGetHash(masm, hash, scratch); |
| 6195 | |
| 6196 | // Collect the two characters in a register. |
| 6197 | Register chars = c1; |
| 6198 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6199 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6200 | |
| 6201 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6202 | // hash: hash of two character string. |
| 6203 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6204 | // Load the string table. |
| 6205 | Register string_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6206 | ExternalReference roots_array_start = |
| 6207 | ExternalReference::roots_array_start(masm->isolate()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6208 | __ mov(scratch, Immediate(Heap::kStringTableRootIndex)); |
| 6209 | __ mov(string_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6210 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6211 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6212 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6213 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6214 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6215 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6216 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6217 | |
| 6218 | // Registers |
| 6219 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 6220 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6221 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6222 | // mask: capacity mask |
| 6223 | // scratch: - |
| 6224 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6225 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6226 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6227 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6228 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6229 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6230 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6231 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6232 | __ mov(scratch, hash); |
| 6233 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6234 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6235 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6236 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6237 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6238 | // Load the entry from the string table. |
| 6239 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6240 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6241 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6242 | scratch, |
| 6243 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6244 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6245 | |
| 6246 | // 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] | 6247 | Factory* factory = masm->isolate()->factory(); |
| 6248 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6249 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6250 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 6251 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6252 | |
| 6253 | // If length is not 2 the string is not a candidate. |
| 6254 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 6255 | Immediate(Smi::FromInt(2))); |
| 6256 | __ j(not_equal, &next_probe[i]); |
| 6257 | |
| 6258 | // As we are out of registers save the mask on the stack and use that |
| 6259 | // register as a temporary. |
| 6260 | __ push(mask); |
| 6261 | Register temp = mask; |
| 6262 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6263 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6264 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 6265 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 6266 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 6267 | temp, temp, &next_probe_pop_mask[i]); |
| 6268 | |
| 6269 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6270 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6271 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6272 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6273 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6274 | __ bind(&next_probe_pop_mask[i]); |
| 6275 | __ pop(mask); |
| 6276 | __ bind(&next_probe[i]); |
| 6277 | } |
| 6278 | |
| 6279 | // No matching 2 character string found by probing. |
| 6280 | __ jmp(not_found); |
| 6281 | |
| 6282 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6283 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6284 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6285 | __ pop(mask); // Pop saved mask from the stack. |
| 6286 | if (!result.is(eax)) { |
| 6287 | __ mov(eax, result); |
| 6288 | } |
| 6289 | } |
| 6290 | |
| 6291 | |
| 6292 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 6293 | Register hash, |
| 6294 | Register character, |
| 6295 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6296 | // hash = (seed + character) + ((seed + character) << 10); |
| 6297 | if (Serializer::enabled()) { |
| 6298 | ExternalReference roots_array_start = |
| 6299 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6300 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6301 | __ mov(scratch, Operand::StaticArray(scratch, |
| 6302 | times_pointer_size, |
| 6303 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6304 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6305 | __ add(scratch, character); |
| 6306 | __ mov(hash, scratch); |
| 6307 | __ shl(scratch, 10); |
| 6308 | __ add(hash, scratch); |
| 6309 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6310 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 6311 | __ lea(scratch, Operand(character, seed)); |
| 6312 | __ shl(scratch, 10); |
| 6313 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 6314 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6315 | // hash ^= hash >> 6; |
| 6316 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6317 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6318 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6319 | } |
| 6320 | |
| 6321 | |
| 6322 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6323 | Register hash, |
| 6324 | Register character, |
| 6325 | Register scratch) { |
| 6326 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6327 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6328 | // hash += hash << 10; |
| 6329 | __ mov(scratch, hash); |
| 6330 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6331 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6332 | // hash ^= hash >> 6; |
| 6333 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6334 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6335 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6336 | } |
| 6337 | |
| 6338 | |
| 6339 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6340 | Register hash, |
| 6341 | Register scratch) { |
| 6342 | // hash += hash << 3; |
| 6343 | __ mov(scratch, hash); |
| 6344 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6345 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6346 | // hash ^= hash >> 11; |
| 6347 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6348 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6349 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6350 | // hash += hash << 15; |
| 6351 | __ mov(scratch, hash); |
| 6352 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6353 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6354 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6355 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6356 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6357 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6358 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6359 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6360 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6361 | __ bind(&hash_not_zero); |
| 6362 | } |
| 6363 | |
| 6364 | |
| 6365 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6366 | Label runtime; |
| 6367 | |
| 6368 | // Stack frame on entry. |
| 6369 | // esp[0]: return address |
| 6370 | // esp[4]: to |
| 6371 | // esp[8]: from |
| 6372 | // esp[12]: string |
| 6373 | |
| 6374 | // Make sure first argument is a string. |
| 6375 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6376 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6377 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6378 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6379 | __ j(NegateCondition(is_string), &runtime); |
| 6380 | |
| 6381 | // eax: string |
| 6382 | // ebx: instance type |
| 6383 | |
| 6384 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6385 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6386 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6387 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6388 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6389 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6390 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6391 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6392 | // Shorter than original string's length: an actual substring. |
| 6393 | __ j(below, ¬_original_string, Label::kNear); |
| 6394 | // Longer than original string's length or negative: unsafe arguments. |
| 6395 | __ j(above, &runtime); |
| 6396 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6397 | Counters* counters = masm->isolate()->counters(); |
| 6398 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6399 | __ ret(3 * kPointerSize); |
| 6400 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6401 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6402 | Label single_char; |
| 6403 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 6404 | __ j(equal, &single_char); |
| 6405 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6406 | // eax: string |
| 6407 | // ebx: instance type |
| 6408 | // ecx: sub string length (smi) |
| 6409 | // edx: from index (smi) |
| 6410 | // Deal with different string types: update the index if necessary |
| 6411 | // and put the underlying string into edi. |
| 6412 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6413 | // If the string is not indirect, it can only be sequential or external. |
| 6414 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6415 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6416 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6417 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6418 | |
| 6419 | Factory* factory = masm->isolate()->factory(); |
| 6420 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6421 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6422 | // Cons string. Check whether it is flat, then fetch first part. |
| 6423 | // Flat cons strings have an empty second part. |
| 6424 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6425 | factory->empty_string()); |
| 6426 | __ j(not_equal, &runtime); |
| 6427 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6428 | // Update instance type. |
| 6429 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6430 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6431 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6432 | |
| 6433 | __ bind(&sliced_string); |
| 6434 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6435 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6436 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6437 | // Update instance type. |
| 6438 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6439 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6440 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6441 | |
| 6442 | __ bind(&seq_or_external_string); |
| 6443 | // Sequential or external string. Just move string to the expected register. |
| 6444 | __ mov(edi, eax); |
| 6445 | |
| 6446 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6447 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6448 | if (FLAG_string_slices) { |
| 6449 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6450 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6451 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6452 | // edx: adjusted start index (smi) |
| 6453 | // ecx: length (smi) |
| 6454 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6455 | // Short slice. Copy instead of slicing. |
| 6456 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6457 | // Allocate new sliced string. At this point we do not reload the instance |
| 6458 | // type including the string encoding because we simply rely on the info |
| 6459 | // provided by the original string. It does not matter if the original |
| 6460 | // string's encoding is wrong because we always have to recheck encoding of |
| 6461 | // the newly created string's parent anyways due to externalized strings. |
| 6462 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6463 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6464 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6465 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6466 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6467 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6468 | __ jmp(&set_slice_header, Label::kNear); |
| 6469 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6470 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6471 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6472 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6473 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6474 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6475 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6476 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6477 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6478 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6479 | |
| 6480 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6481 | } |
| 6482 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6483 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6484 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6485 | // edx: adjusted start index (smi) |
| 6486 | // ecx: length (smi) |
| 6487 | // The subject string can only be external or sequential string of either |
| 6488 | // encoding at this point. |
| 6489 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6490 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6491 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6492 | __ test_b(ebx, kExternalStringTag); |
| 6493 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6494 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6495 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6496 | // Rule out short external strings. |
| 6497 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6498 | __ test_b(ebx, kShortExternalStringMask); |
| 6499 | __ j(not_zero, &runtime); |
| 6500 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6501 | // 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] | 6502 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6503 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6504 | |
| 6505 | __ bind(&sequential_string); |
| 6506 | // Stash away (adjusted) index and (underlying) string. |
| 6507 | __ push(edx); |
| 6508 | __ push(edi); |
| 6509 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6510 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6511 | __ test_b(ebx, kStringEncodingMask); |
| 6512 | __ j(zero, &two_byte_sequential); |
| 6513 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6514 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6515 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6516 | |
| 6517 | // eax: result string |
| 6518 | // ecx: result string length |
| 6519 | __ mov(edx, esi); // esi used by following code. |
| 6520 | // Locate first character of result. |
| 6521 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6522 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6523 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6524 | __ pop(esi); |
| 6525 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6526 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6527 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6528 | |
| 6529 | // eax: result string |
| 6530 | // ecx: result length |
| 6531 | // edx: original value of esi |
| 6532 | // edi: first character of result |
| 6533 | // esi: character of sub string start |
| 6534 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6535 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6536 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6537 | __ ret(3 * kPointerSize); |
| 6538 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6539 | __ bind(&two_byte_sequential); |
| 6540 | // Sequential two-byte string. Allocate the result. |
| 6541 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6542 | |
| 6543 | // eax: result string |
| 6544 | // ecx: result string length |
| 6545 | __ mov(edx, esi); // esi used by following code. |
| 6546 | // Locate first character of result. |
| 6547 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6548 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6549 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6550 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6551 | __ pop(esi); |
| 6552 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6553 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6554 | // byte character. |
| 6555 | STATIC_ASSERT(kSmiTag == 0); |
| 6556 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6557 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6558 | |
| 6559 | // eax: result string |
| 6560 | // ecx: result length |
| 6561 | // edx: original value of esi |
| 6562 | // edi: first character of result |
| 6563 | // esi: character of sub string start |
| 6564 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6565 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6566 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6567 | __ ret(3 * kPointerSize); |
| 6568 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6569 | // Drop pushed values on the stack before tail call. |
| 6570 | __ bind(&runtime_drop_two); |
| 6571 | __ Drop(2); |
| 6572 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6573 | // Just jump to runtime to create the sub string. |
| 6574 | __ bind(&runtime); |
| 6575 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6576 | |
| 6577 | __ bind(&single_char); |
| 6578 | // eax: string |
| 6579 | // ebx: instance type |
| 6580 | // ecx: sub string length (smi) |
| 6581 | // edx: from index (smi) |
| 6582 | StringCharAtGenerator generator( |
| 6583 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6584 | generator.GenerateFast(masm); |
| 6585 | __ ret(3 * kPointerSize); |
| 6586 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6587 | } |
| 6588 | |
| 6589 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6590 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6591 | Register left, |
| 6592 | Register right, |
| 6593 | Register scratch1, |
| 6594 | Register scratch2) { |
| 6595 | Register length = scratch1; |
| 6596 | |
| 6597 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6598 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6599 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6600 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6601 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6602 | __ bind(&strings_not_equal); |
| 6603 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6604 | __ ret(0); |
| 6605 | |
| 6606 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6607 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6608 | __ bind(&check_zero_length); |
| 6609 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6610 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6611 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6612 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6613 | __ ret(0); |
| 6614 | |
| 6615 | // Compare characters. |
| 6616 | __ bind(&compare_chars); |
| 6617 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6618 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6619 | |
| 6620 | // Characters are equal. |
| 6621 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6622 | __ ret(0); |
| 6623 | } |
| 6624 | |
| 6625 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6626 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6627 | Register left, |
| 6628 | Register right, |
| 6629 | Register scratch1, |
| 6630 | Register scratch2, |
| 6631 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6632 | Counters* counters = masm->isolate()->counters(); |
| 6633 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6634 | |
| 6635 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6636 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6637 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6638 | __ mov(scratch3, scratch1); |
| 6639 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6640 | |
| 6641 | Register length_delta = scratch3; |
| 6642 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6643 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6644 | // 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] | 6645 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6646 | __ bind(&left_shorter); |
| 6647 | |
| 6648 | Register min_length = scratch1; |
| 6649 | |
| 6650 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6651 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6652 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6653 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6654 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6655 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6656 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6657 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6658 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6659 | |
| 6660 | // Compare lengths - strings up to min-length are equal. |
| 6661 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6662 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6663 | Label length_not_equal; |
| 6664 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6665 | |
| 6666 | // Result is EQUAL. |
| 6667 | STATIC_ASSERT(EQUAL == 0); |
| 6668 | STATIC_ASSERT(kSmiTag == 0); |
| 6669 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6670 | __ ret(0); |
| 6671 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6672 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6673 | Label result_less; |
| 6674 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6675 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6676 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6677 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6678 | __ j(above, &result_greater, Label::kNear); |
| 6679 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6680 | |
| 6681 | // Result is LESS. |
| 6682 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6683 | __ ret(0); |
| 6684 | |
| 6685 | // Result is GREATER. |
| 6686 | __ bind(&result_greater); |
| 6687 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6688 | __ ret(0); |
| 6689 | } |
| 6690 | |
| 6691 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6692 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6693 | MacroAssembler* masm, |
| 6694 | Register left, |
| 6695 | Register right, |
| 6696 | Register length, |
| 6697 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6698 | Label* chars_not_equal, |
| 6699 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6700 | // Change index to run from -length to -1 by adding length to string |
| 6701 | // start. This means that loop ends when index reaches zero, which |
| 6702 | // doesn't need an additional compare. |
| 6703 | __ SmiUntag(length); |
| 6704 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6705 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6706 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6707 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6708 | __ neg(length); |
| 6709 | Register index = length; // index = -length; |
| 6710 | |
| 6711 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6712 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6713 | __ bind(&loop); |
| 6714 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6715 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6716 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6717 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6718 | __ j(not_zero, &loop); |
| 6719 | } |
| 6720 | |
| 6721 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6722 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6723 | Label runtime; |
| 6724 | |
| 6725 | // Stack frame on entry. |
| 6726 | // esp[0]: return address |
| 6727 | // esp[4]: right string |
| 6728 | // esp[8]: left string |
| 6729 | |
| 6730 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6731 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6732 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6733 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6734 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6735 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6736 | STATIC_ASSERT(EQUAL == 0); |
| 6737 | STATIC_ASSERT(kSmiTag == 0); |
| 6738 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6739 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6740 | __ ret(2 * kPointerSize); |
| 6741 | |
| 6742 | __ bind(¬_same); |
| 6743 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6744 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6745 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6746 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6747 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6748 | // Drop arguments from the stack. |
| 6749 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6750 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6751 | __ push(ecx); |
| 6752 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6753 | |
| 6754 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6755 | // tagged as a small integer. |
| 6756 | __ bind(&runtime); |
| 6757 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6758 | } |
| 6759 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6760 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6761 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6762 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6763 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6764 | __ mov(ecx, edx); |
| 6765 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6766 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6767 | |
| 6768 | if (GetCondition() == equal) { |
| 6769 | // 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] | 6770 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6771 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6772 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6773 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6774 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6775 | // Correct sign of result in case of overflow. |
| 6776 | __ not_(edx); |
| 6777 | __ bind(&done); |
| 6778 | __ mov(eax, edx); |
| 6779 | } |
| 6780 | __ ret(0); |
| 6781 | |
| 6782 | __ bind(&miss); |
| 6783 | GenerateMiss(masm); |
| 6784 | } |
| 6785 | |
| 6786 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6787 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6788 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6789 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6790 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6791 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6792 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6793 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6794 | if (left_ == CompareIC::SMI) { |
| 6795 | __ JumpIfNotSmi(edx, &miss); |
| 6796 | } |
| 6797 | if (right_ == CompareIC::SMI) { |
| 6798 | __ JumpIfNotSmi(eax, &miss); |
| 6799 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6800 | |
| 6801 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6802 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6803 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6804 | CpuFeatureScope scope1(masm, SSE2); |
| 6805 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6806 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6807 | // Load left and right operand. |
| 6808 | Label done, left, left_smi, right_smi; |
| 6809 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6810 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6811 | masm->isolate()->factory()->heap_number_map()); |
| 6812 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6813 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6814 | __ jmp(&left, Label::kNear); |
| 6815 | __ bind(&right_smi); |
| 6816 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6817 | __ SmiUntag(ecx); |
| 6818 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6819 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6820 | __ bind(&left); |
| 6821 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6822 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6823 | masm->isolate()->factory()->heap_number_map()); |
| 6824 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6825 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6826 | __ jmp(&done); |
| 6827 | __ bind(&left_smi); |
| 6828 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6829 | __ SmiUntag(ecx); |
| 6830 | __ cvtsi2sd(xmm0, ecx); |
| 6831 | |
| 6832 | __ bind(&done); |
| 6833 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6834 | __ ucomisd(xmm0, xmm1); |
| 6835 | |
| 6836 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6837 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6838 | |
| 6839 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6840 | // Performing mov, because xor would destroy the flag register. |
| 6841 | __ mov(eax, 0); // equal |
| 6842 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6843 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6844 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6845 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6846 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6847 | } else { |
| 6848 | __ mov(ecx, edx); |
| 6849 | __ and_(ecx, eax); |
| 6850 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6851 | |
| 6852 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6853 | masm->isolate()->factory()->heap_number_map()); |
| 6854 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6855 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6856 | masm->isolate()->factory()->heap_number_map()); |
| 6857 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6858 | } |
| 6859 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6860 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6861 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6862 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6863 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6864 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6865 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6866 | __ bind(&maybe_undefined1); |
| 6867 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6868 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6869 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6870 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6871 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6872 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6873 | __ jmp(&unordered); |
| 6874 | } |
| 6875 | |
| 6876 | __ bind(&maybe_undefined2); |
| 6877 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6878 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6879 | __ j(equal, &unordered); |
| 6880 | } |
| 6881 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6882 | __ bind(&miss); |
| 6883 | GenerateMiss(masm); |
| 6884 | } |
| 6885 | |
| 6886 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6887 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 6888 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6889 | ASSERT(GetCondition() == equal); |
| 6890 | |
| 6891 | // Registers containing left and right operands respectively. |
| 6892 | Register left = edx; |
| 6893 | Register right = eax; |
| 6894 | Register tmp1 = ecx; |
| 6895 | Register tmp2 = ebx; |
| 6896 | |
| 6897 | // Check that both operands are heap objects. |
| 6898 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6899 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6900 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6901 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6902 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6903 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6904 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6905 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6906 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6907 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6908 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6909 | STATIC_ASSERT(kInternalizedTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6910 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6911 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6912 | __ j(zero, &miss, Label::kNear); |
| 6913 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6914 | // Internalized strings are compared by identity. |
| 6915 | Label done; |
| 6916 | __ cmp(left, right); |
| 6917 | // Make sure eax is non-zero. At this point input operands are |
| 6918 | // guaranteed to be non-zero. |
| 6919 | ASSERT(right.is(eax)); |
| 6920 | __ j(not_equal, &done, Label::kNear); |
| 6921 | STATIC_ASSERT(EQUAL == 0); |
| 6922 | STATIC_ASSERT(kSmiTag == 0); |
| 6923 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6924 | __ bind(&done); |
| 6925 | __ ret(0); |
| 6926 | |
| 6927 | __ bind(&miss); |
| 6928 | GenerateMiss(masm); |
| 6929 | } |
| 6930 | |
| 6931 | |
| 6932 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 6933 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 6934 | ASSERT(GetCondition() == equal); |
| 6935 | |
| 6936 | // Registers containing left and right operands respectively. |
| 6937 | Register left = edx; |
| 6938 | Register right = eax; |
| 6939 | Register tmp1 = ecx; |
| 6940 | Register tmp2 = ebx; |
| 6941 | |
| 6942 | // Check that both operands are heap objects. |
| 6943 | Label miss; |
| 6944 | __ mov(tmp1, left); |
| 6945 | STATIC_ASSERT(kSmiTag == 0); |
| 6946 | __ and_(tmp1, right); |
| 6947 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 6948 | |
| 6949 | // Check that both operands are unique names. This leaves the instance |
| 6950 | // types loaded in tmp1 and tmp2. |
| 6951 | STATIC_ASSERT(kInternalizedTag != 0); |
| 6952 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6953 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6954 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6955 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6956 | |
| 6957 | Label succeed1; |
| 6958 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
| 6959 | __ j(not_zero, &succeed1); |
| 6960 | __ cmpb(tmp1, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 6961 | __ j(not_equal, &miss); |
| 6962 | __ bind(&succeed1); |
| 6963 | |
| 6964 | Label succeed2; |
| 6965 | __ test(tmp2, Immediate(kIsInternalizedMask)); |
| 6966 | __ j(not_zero, &succeed2); |
| 6967 | __ cmpb(tmp2, static_cast<uint8_t>(SYMBOL_TYPE)); |
| 6968 | __ j(not_equal, &miss); |
| 6969 | __ bind(&succeed2); |
| 6970 | |
| 6971 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6972 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6973 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6974 | // Make sure eax is non-zero. At this point input operands are |
| 6975 | // guaranteed to be non-zero. |
| 6976 | ASSERT(right.is(eax)); |
| 6977 | __ j(not_equal, &done, Label::kNear); |
| 6978 | STATIC_ASSERT(EQUAL == 0); |
| 6979 | STATIC_ASSERT(kSmiTag == 0); |
| 6980 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6981 | __ bind(&done); |
| 6982 | __ ret(0); |
| 6983 | |
| 6984 | __ bind(&miss); |
| 6985 | GenerateMiss(masm); |
| 6986 | } |
| 6987 | |
| 6988 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6989 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6990 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6991 | Label miss; |
| 6992 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6993 | bool equality = Token::IsEqualityOp(op_); |
| 6994 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6995 | // Registers containing left and right operands respectively. |
| 6996 | Register left = edx; |
| 6997 | Register right = eax; |
| 6998 | Register tmp1 = ecx; |
| 6999 | Register tmp2 = ebx; |
| 7000 | Register tmp3 = edi; |
| 7001 | |
| 7002 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7003 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7004 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7005 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 7006 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7007 | |
| 7008 | // Check that both operands are strings. This leaves the instance |
| 7009 | // types loaded in tmp1 and tmp2. |
| 7010 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 7011 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 7012 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 7013 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 7014 | __ mov(tmp3, tmp1); |
| 7015 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7016 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7017 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 7018 | __ j(not_zero, &miss); |
| 7019 | |
| 7020 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7021 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7022 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7023 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7024 | STATIC_ASSERT(EQUAL == 0); |
| 7025 | STATIC_ASSERT(kSmiTag == 0); |
| 7026 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 7027 | __ ret(0); |
| 7028 | |
| 7029 | // Handle not identical strings. |
| 7030 | __ bind(¬_same); |
| 7031 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7032 | // 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] | 7033 | // because we already know they are not identical. But in the case of |
| 7034 | // non-equality compare, we still need to determine the order. |
| 7035 | if (equality) { |
| 7036 | Label do_compare; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7037 | STATIC_ASSERT(kInternalizedTag != 0); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7038 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7039 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7040 | __ j(zero, &do_compare, Label::kNear); |
| 7041 | // Make sure eax is non-zero. At this point input operands are |
| 7042 | // guaranteed to be non-zero. |
| 7043 | ASSERT(right.is(eax)); |
| 7044 | __ ret(0); |
| 7045 | __ bind(&do_compare); |
| 7046 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7047 | |
| 7048 | // Check that both strings are sequential ASCII. |
| 7049 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7050 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 7051 | |
| 7052 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7053 | if (equality) { |
| 7054 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 7055 | masm, left, right, tmp1, tmp2); |
| 7056 | } else { |
| 7057 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 7058 | masm, left, right, tmp1, tmp2, tmp3); |
| 7059 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7060 | |
| 7061 | // Handle more complex cases in runtime. |
| 7062 | __ bind(&runtime); |
| 7063 | __ pop(tmp1); // Return address. |
| 7064 | __ push(left); |
| 7065 | __ push(right); |
| 7066 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 7067 | if (equality) { |
| 7068 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 7069 | } else { |
| 7070 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 7071 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7072 | |
| 7073 | __ bind(&miss); |
| 7074 | GenerateMiss(masm); |
| 7075 | } |
| 7076 | |
| 7077 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7078 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 7079 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 7080 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7081 | __ mov(ecx, edx); |
| 7082 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 7083 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7084 | |
| 7085 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7086 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7087 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7088 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7089 | |
| 7090 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7091 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7092 | __ ret(0); |
| 7093 | |
| 7094 | __ bind(&miss); |
| 7095 | GenerateMiss(masm); |
| 7096 | } |
| 7097 | |
| 7098 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7099 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 7100 | Label miss; |
| 7101 | __ mov(ecx, edx); |
| 7102 | __ and_(ecx, eax); |
| 7103 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7104 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7105 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 7106 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 7107 | __ cmp(ecx, known_map_); |
| 7108 | __ j(not_equal, &miss, Label::kNear); |
| 7109 | __ cmp(ebx, known_map_); |
| 7110 | __ j(not_equal, &miss, Label::kNear); |
| 7111 | |
| 7112 | __ sub(eax, edx); |
| 7113 | __ ret(0); |
| 7114 | |
| 7115 | __ bind(&miss); |
| 7116 | GenerateMiss(masm); |
| 7117 | } |
| 7118 | |
| 7119 | |
| 7120 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7121 | { |
| 7122 | // Call the runtime system in a fresh internal frame. |
| 7123 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 7124 | masm->isolate()); |
| 7125 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7126 | __ push(edx); // Preserve edx and eax. |
| 7127 | __ push(eax); |
| 7128 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7129 | __ push(eax); |
| 7130 | __ push(Immediate(Smi::FromInt(op_))); |
| 7131 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 7132 | // Compute the entry point of the rewritten stub. |
| 7133 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 7134 | __ pop(eax); |
| 7135 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7136 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7137 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7138 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7139 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 7140 | } |
| 7141 | |
| 7142 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7143 | // Helper function used to check that the dictionary doesn't contain |
| 7144 | // the property. This function may return false negatives, so miss_label |
| 7145 | // must always call a backup property check that is complete. |
| 7146 | // 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] | 7147 | // Name must be a unique name and receiver must be a heap object. |
| 7148 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 7149 | Label* miss, |
| 7150 | Label* done, |
| 7151 | Register properties, |
| 7152 | Handle<Name> name, |
| 7153 | Register r0) { |
| 7154 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7155 | |
| 7156 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7157 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7158 | // undefined value), it guarantees the hash table doesn't contain the |
| 7159 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7160 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7161 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7162 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7163 | Register index = r0; |
| 7164 | // Capacity is smi 2^n. |
| 7165 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 7166 | __ dec(index); |
| 7167 | __ and_(index, |
| 7168 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7169 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7170 | |
| 7171 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7172 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7173 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 7174 | Register entity_name = r0; |
| 7175 | // Having undefined at this place means the name is not contained. |
| 7176 | ASSERT_EQ(kSmiTagSize, 1); |
| 7177 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 7178 | kElementsStartOffset - kHeapObjectTag)); |
| 7179 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 7180 | __ j(equal, done); |
| 7181 | |
| 7182 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7183 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7184 | __ j(equal, miss); |
| 7185 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7186 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7187 | // Check for the hole and skip. |
| 7188 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7189 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 7190 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7191 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7192 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
| 7193 | __ test_b(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7194 | kIsInternalizedMask); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7195 | __ j(not_zero, &good); |
| 7196 | __ cmpb(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 7197 | static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7198 | __ j(not_equal, miss); |
| 7199 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7200 | } |
| 7201 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7202 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7203 | __ push(Immediate(Handle<Object>(name))); |
| 7204 | __ push(Immediate(name->Hash())); |
| 7205 | __ CallStub(&stub); |
| 7206 | __ test(r0, r0); |
| 7207 | __ j(not_zero, miss); |
| 7208 | __ jmp(done); |
| 7209 | } |
| 7210 | |
| 7211 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7212 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7213 | // |done| label if a property with the given name is found leaving the |
| 7214 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 7215 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7216 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 7217 | Label* miss, |
| 7218 | Label* done, |
| 7219 | Register elements, |
| 7220 | Register name, |
| 7221 | Register r0, |
| 7222 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 7223 | ASSERT(!elements.is(r0)); |
| 7224 | ASSERT(!elements.is(r1)); |
| 7225 | ASSERT(!name.is(r0)); |
| 7226 | ASSERT(!name.is(r1)); |
| 7227 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7228 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7229 | |
| 7230 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 7231 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 7232 | __ dec(r1); |
| 7233 | |
| 7234 | // Generate an unrolled loop that performs a few probes before |
| 7235 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 7236 | // cover ~93% of loads from dictionaries. |
| 7237 | for (int i = 0; i < kInlinedProbes; i++) { |
| 7238 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7239 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 7240 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7241 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7242 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7243 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7244 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7245 | |
| 7246 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7247 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7248 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 7249 | |
| 7250 | // Check if the key is identical to the name. |
| 7251 | __ cmp(name, Operand(elements, |
| 7252 | r0, |
| 7253 | times_4, |
| 7254 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 7255 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7256 | } |
| 7257 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7258 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7259 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7260 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 7261 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7262 | __ push(r0); |
| 7263 | __ CallStub(&stub); |
| 7264 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7265 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7266 | __ j(zero, miss); |
| 7267 | __ jmp(done); |
| 7268 | } |
| 7269 | |
| 7270 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7271 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7272 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 7273 | // 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] | 7274 | // Stack frame on entry: |
| 7275 | // esp[0 * kPointerSize]: return address. |
| 7276 | // esp[1 * kPointerSize]: key's hash. |
| 7277 | // esp[2 * kPointerSize]: key. |
| 7278 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7279 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7280 | // result_: used as scratch. |
| 7281 | // index_: will hold an index of entry if lookup is successful. |
| 7282 | // might alias with result_. |
| 7283 | // Returns: |
| 7284 | // result_ is zero if lookup failed, non zero otherwise. |
| 7285 | |
| 7286 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 7287 | |
| 7288 | Register scratch = result_; |
| 7289 | |
| 7290 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 7291 | __ dec(scratch); |
| 7292 | __ SmiUntag(scratch); |
| 7293 | __ push(scratch); |
| 7294 | |
| 7295 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 7296 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 7297 | // undefined value), it guarantees the hash table doesn't contain the |
| 7298 | // property. It's true even if some slots represent deleted properties |
| 7299 | // (their names are the null value). |
| 7300 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 7301 | // Compute the masked index: (hash + i + i * i) & mask. |
| 7302 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 7303 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7304 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7305 | } |
| 7306 | __ and_(scratch, Operand(esp, 0)); |
| 7307 | |
| 7308 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7309 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7310 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 7311 | |
| 7312 | // Having undefined at this place means the name is not contained. |
| 7313 | ASSERT_EQ(kSmiTagSize, 1); |
| 7314 | __ mov(scratch, Operand(dictionary_, |
| 7315 | index_, |
| 7316 | times_pointer_size, |
| 7317 | kElementsStartOffset - kHeapObjectTag)); |
| 7318 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 7319 | __ j(equal, ¬_in_dictionary); |
| 7320 | |
| 7321 | // Stop if found the property. |
| 7322 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 7323 | __ j(equal, &in_dictionary); |
| 7324 | |
| 7325 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7326 | // 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] | 7327 | // 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] | 7328 | // key we are looking for. |
| 7329 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7330 | // Check if the entry name is not a unique name. |
| 7331 | Label cont; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7332 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 7333 | __ test_b(FieldOperand(scratch, Map::kInstanceTypeOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 7334 | kIsInternalizedMask); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7335 | __ j(not_zero, &cont); |
| 7336 | __ cmpb(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7337 | static_cast<uint8_t>(SYMBOL_TYPE)); |
| 7338 | __ j(not_equal, &maybe_in_dictionary); |
| 7339 | __ bind(&cont); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7340 | } |
| 7341 | } |
| 7342 | |
| 7343 | __ bind(&maybe_in_dictionary); |
| 7344 | // If we are doing negative lookup then probing failure should be |
| 7345 | // treated as a lookup success. For positive lookup probing failure |
| 7346 | // should be treated as lookup failure. |
| 7347 | if (mode_ == POSITIVE_LOOKUP) { |
| 7348 | __ mov(result_, Immediate(0)); |
| 7349 | __ Drop(1); |
| 7350 | __ ret(2 * kPointerSize); |
| 7351 | } |
| 7352 | |
| 7353 | __ bind(&in_dictionary); |
| 7354 | __ mov(result_, Immediate(1)); |
| 7355 | __ Drop(1); |
| 7356 | __ ret(2 * kPointerSize); |
| 7357 | |
| 7358 | __ bind(¬_in_dictionary); |
| 7359 | __ mov(result_, Immediate(0)); |
| 7360 | __ Drop(1); |
| 7361 | __ ret(2 * kPointerSize); |
| 7362 | } |
| 7363 | |
| 7364 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7365 | struct AheadOfTimeWriteBarrierStubList { |
| 7366 | Register object, value, address; |
| 7367 | RememberedSetAction action; |
| 7368 | }; |
| 7369 | |
| 7370 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7371 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7372 | |
| 7373 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7374 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7375 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7376 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7377 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7378 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7379 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7380 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7381 | // Used in StoreStubCompiler::CompileStoreField and |
| 7382 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7383 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7384 | // GenerateStoreField calls the stub with two different permutations of |
| 7385 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7386 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7387 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7388 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7389 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7390 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7391 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7392 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7393 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7394 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7395 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7396 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7397 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7398 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7399 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7400 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7401 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7402 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7403 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7404 | // FastNewClosureStub and StringAddStub::Generate |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7405 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7406 | // StringAddStub::Generate |
| 7407 | { REG(ecx), REG(eax), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7408 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7409 | { 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] | 7410 | }; |
| 7411 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7412 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7413 | |
| 7414 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7415 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7416 | !entry->object.is(no_reg); |
| 7417 | entry++) { |
| 7418 | if (object_.is(entry->object) && |
| 7419 | value_.is(entry->value) && |
| 7420 | address_.is(entry->address) && |
| 7421 | remembered_set_action_ == entry->action && |
| 7422 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7423 | return true; |
| 7424 | } |
| 7425 | } |
| 7426 | return false; |
| 7427 | } |
| 7428 | |
| 7429 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7430 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 7431 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7432 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
| 7433 | stub.GetCode(isolate)->set_is_pregenerated(true); |
| 7434 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7435 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7436 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7437 | } |
| 7438 | } |
| 7439 | |
| 7440 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7441 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7442 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7443 | !entry->object.is(no_reg); |
| 7444 | entry++) { |
| 7445 | RecordWriteStub stub(entry->object, |
| 7446 | entry->value, |
| 7447 | entry->address, |
| 7448 | entry->action, |
| 7449 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7450 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7451 | } |
| 7452 | } |
| 7453 | |
| 7454 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7455 | bool CodeStub::CanUseFPRegisters() { |
| 7456 | return CpuFeatures::IsSupported(SSE2); |
| 7457 | } |
| 7458 | |
| 7459 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7460 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7461 | // the value has just been written into the object, now this stub makes sure |
| 7462 | // we keep the GC informed. The word in the object where the value has been |
| 7463 | // written is in the address register. |
| 7464 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7465 | Label skip_to_incremental_noncompacting; |
| 7466 | Label skip_to_incremental_compacting; |
| 7467 | |
| 7468 | // The first two instructions are generated with labels so as to get the |
| 7469 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7470 | // forth between a compare instructions (a nop in this position) and the |
| 7471 | // real branch when we start and stop incremental heap marking. |
| 7472 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7473 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7474 | |
| 7475 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7476 | __ RememberedSetHelper(object_, |
| 7477 | address_, |
| 7478 | value_, |
| 7479 | save_fp_regs_mode_, |
| 7480 | MacroAssembler::kReturnAtEnd); |
| 7481 | } else { |
| 7482 | __ ret(0); |
| 7483 | } |
| 7484 | |
| 7485 | __ bind(&skip_to_incremental_noncompacting); |
| 7486 | GenerateIncremental(masm, INCREMENTAL); |
| 7487 | |
| 7488 | __ bind(&skip_to_incremental_compacting); |
| 7489 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7490 | |
| 7491 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7492 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7493 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7494 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7495 | } |
| 7496 | |
| 7497 | |
| 7498 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7499 | regs_.Save(masm); |
| 7500 | |
| 7501 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7502 | Label dont_need_remembered_set; |
| 7503 | |
| 7504 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7505 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7506 | regs_.scratch0(), |
| 7507 | &dont_need_remembered_set); |
| 7508 | |
| 7509 | __ CheckPageFlag(regs_.object(), |
| 7510 | regs_.scratch0(), |
| 7511 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7512 | not_zero, |
| 7513 | &dont_need_remembered_set); |
| 7514 | |
| 7515 | // First notify the incremental marker if necessary, then update the |
| 7516 | // remembered set. |
| 7517 | CheckNeedsToInformIncrementalMarker( |
| 7518 | masm, |
| 7519 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7520 | mode); |
| 7521 | InformIncrementalMarker(masm, mode); |
| 7522 | regs_.Restore(masm); |
| 7523 | __ RememberedSetHelper(object_, |
| 7524 | address_, |
| 7525 | value_, |
| 7526 | save_fp_regs_mode_, |
| 7527 | MacroAssembler::kReturnAtEnd); |
| 7528 | |
| 7529 | __ bind(&dont_need_remembered_set); |
| 7530 | } |
| 7531 | |
| 7532 | CheckNeedsToInformIncrementalMarker( |
| 7533 | masm, |
| 7534 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7535 | mode); |
| 7536 | InformIncrementalMarker(masm, mode); |
| 7537 | regs_.Restore(masm); |
| 7538 | __ ret(0); |
| 7539 | } |
| 7540 | |
| 7541 | |
| 7542 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7543 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7544 | int argument_count = 3; |
| 7545 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7546 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7547 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7548 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 7549 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7550 | |
| 7551 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7552 | if (mode == INCREMENTAL_COMPACTION) { |
| 7553 | __ CallCFunction( |
| 7554 | ExternalReference::incremental_evacuation_record_write_function( |
| 7555 | masm->isolate()), |
| 7556 | argument_count); |
| 7557 | } else { |
| 7558 | ASSERT(mode == INCREMENTAL); |
| 7559 | __ CallCFunction( |
| 7560 | ExternalReference::incremental_marking_record_write_function( |
| 7561 | masm->isolate()), |
| 7562 | argument_count); |
| 7563 | } |
| 7564 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7565 | } |
| 7566 | |
| 7567 | |
| 7568 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7569 | MacroAssembler* masm, |
| 7570 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7571 | Mode mode) { |
| 7572 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7573 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7574 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7575 | __ and_(regs_.scratch0(), regs_.object()); |
| 7576 | __ mov(regs_.scratch1(), |
| 7577 | Operand(regs_.scratch0(), |
| 7578 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7579 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7580 | __ mov(Operand(regs_.scratch0(), |
| 7581 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7582 | regs_.scratch1()); |
| 7583 | __ j(negative, &need_incremental); |
| 7584 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7585 | // Let's look at the color of the object: If it is not black we don't have |
| 7586 | // to inform the incremental marker. |
| 7587 | __ JumpIfBlack(regs_.object(), |
| 7588 | regs_.scratch0(), |
| 7589 | regs_.scratch1(), |
| 7590 | &object_is_black, |
| 7591 | Label::kNear); |
| 7592 | |
| 7593 | regs_.Restore(masm); |
| 7594 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7595 | __ RememberedSetHelper(object_, |
| 7596 | address_, |
| 7597 | value_, |
| 7598 | save_fp_regs_mode_, |
| 7599 | MacroAssembler::kReturnAtEnd); |
| 7600 | } else { |
| 7601 | __ ret(0); |
| 7602 | } |
| 7603 | |
| 7604 | __ bind(&object_is_black); |
| 7605 | |
| 7606 | // Get the value from the slot. |
| 7607 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7608 | |
| 7609 | if (mode == INCREMENTAL_COMPACTION) { |
| 7610 | Label ensure_not_white; |
| 7611 | |
| 7612 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7613 | regs_.scratch1(), // Scratch. |
| 7614 | MemoryChunk::kEvacuationCandidateMask, |
| 7615 | zero, |
| 7616 | &ensure_not_white, |
| 7617 | Label::kNear); |
| 7618 | |
| 7619 | __ CheckPageFlag(regs_.object(), |
| 7620 | regs_.scratch1(), // Scratch. |
| 7621 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7622 | not_zero, |
| 7623 | &ensure_not_white, |
| 7624 | Label::kNear); |
| 7625 | |
| 7626 | __ jmp(&need_incremental); |
| 7627 | |
| 7628 | __ bind(&ensure_not_white); |
| 7629 | } |
| 7630 | |
| 7631 | // We need an extra register for this, so we push the object register |
| 7632 | // temporarily. |
| 7633 | __ push(regs_.object()); |
| 7634 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7635 | regs_.scratch1(), // Scratch. |
| 7636 | regs_.object(), // Scratch. |
| 7637 | &need_incremental_pop_object, |
| 7638 | Label::kNear); |
| 7639 | __ pop(regs_.object()); |
| 7640 | |
| 7641 | regs_.Restore(masm); |
| 7642 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7643 | __ RememberedSetHelper(object_, |
| 7644 | address_, |
| 7645 | value_, |
| 7646 | save_fp_regs_mode_, |
| 7647 | MacroAssembler::kReturnAtEnd); |
| 7648 | } else { |
| 7649 | __ ret(0); |
| 7650 | } |
| 7651 | |
| 7652 | __ bind(&need_incremental_pop_object); |
| 7653 | __ pop(regs_.object()); |
| 7654 | |
| 7655 | __ bind(&need_incremental); |
| 7656 | |
| 7657 | // Fall through when we need to inform the incremental marker. |
| 7658 | } |
| 7659 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7660 | |
| 7661 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7662 | // ----------- S t a t e ------------- |
| 7663 | // -- eax : element value to store |
| 7664 | // -- ebx : array literal |
| 7665 | // -- edi : map of array literal |
| 7666 | // -- ecx : element index as smi |
| 7667 | // -- edx : array literal index in function |
| 7668 | // -- esp[0] : return address |
| 7669 | // ----------------------------------- |
| 7670 | |
| 7671 | Label element_done; |
| 7672 | Label double_elements; |
| 7673 | Label smi_element; |
| 7674 | Label slow_elements; |
| 7675 | Label slow_elements_from_double; |
| 7676 | Label fast_elements; |
| 7677 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7678 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7679 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7680 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7681 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7682 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7683 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7684 | // Store into the array literal requires a elements transition. Call into |
| 7685 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7686 | |
| 7687 | __ bind(&slow_elements); |
| 7688 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7689 | // call. |
| 7690 | __ push(ebx); |
| 7691 | __ push(ecx); |
| 7692 | __ push(eax); |
| 7693 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7694 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7695 | __ push(edx); |
| 7696 | __ push(edi); // Return return address so that tail call returns to right |
| 7697 | // place. |
| 7698 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7699 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7700 | __ bind(&slow_elements_from_double); |
| 7701 | __ pop(edx); |
| 7702 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7703 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7704 | // 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] | 7705 | __ bind(&fast_elements); |
| 7706 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7707 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7708 | FixedArrayBase::kHeaderSize)); |
| 7709 | __ mov(Operand(ecx, 0), eax); |
| 7710 | // Update the write barrier for the array store. |
| 7711 | __ RecordWrite(ebx, ecx, eax, |
| 7712 | kDontSaveFPRegs, |
| 7713 | EMIT_REMEMBERED_SET, |
| 7714 | OMIT_SMI_CHECK); |
| 7715 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7716 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7717 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7718 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7719 | __ bind(&smi_element); |
| 7720 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7721 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7722 | FixedArrayBase::kHeaderSize), eax); |
| 7723 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7724 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7725 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7726 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7727 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7728 | __ push(edx); |
| 7729 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7730 | __ StoreNumberToDoubleElements(eax, |
| 7731 | edx, |
| 7732 | ecx, |
| 7733 | edi, |
| 7734 | xmm0, |
| 7735 | &slow_elements_from_double, |
| 7736 | false); |
| 7737 | __ pop(edx); |
| 7738 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7739 | } |
| 7740 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7741 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7742 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7743 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7744 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7745 | int parameter_count_offset = |
| 7746 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7747 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7748 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7749 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7750 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 7751 | ? kPointerSize |
| 7752 | : 0; |
| 7753 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7754 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7755 | } |
| 7756 | |
| 7757 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7758 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
| 7759 | if (entry_hook_ != NULL) { |
| 7760 | ProfileEntryHookStub stub; |
| 7761 | masm->CallStub(&stub); |
| 7762 | } |
| 7763 | } |
| 7764 | |
| 7765 | |
| 7766 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
| 7767 | // Ecx is the only volatile register we must save. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7768 | const int kNumSavedRegisters = 1; |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7769 | __ push(ecx); |
| 7770 | |
| 7771 | // Calculate and push the original stack pointer. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7772 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7773 | __ push(eax); |
| 7774 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7775 | // Retrieve our return address and use it to calculate the calling |
| 7776 | // function's address. |
| 7777 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7778 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7779 | __ push(eax); |
| 7780 | |
| 7781 | // Call the entry hook. |
| 7782 | int32_t hook_location = reinterpret_cast<int32_t>(&entry_hook_); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 7783 | __ call(Operand(hook_location, RelocInfo::NONE32)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7784 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7785 | |
| 7786 | // Restore ecx. |
| 7787 | __ pop(ecx); |
| 7788 | __ ret(0); |
| 7789 | } |
| 7790 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7791 | |
| 7792 | template<class T> |
| 7793 | static void CreateArrayDispatch(MacroAssembler* masm) { |
| 7794 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7795 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7796 | for (int i = 0; i <= last_index; ++i) { |
| 7797 | Label next; |
| 7798 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7799 | __ cmp(edx, kind); |
| 7800 | __ j(not_equal, &next); |
| 7801 | T stub(kind); |
| 7802 | __ TailCallStub(&stub); |
| 7803 | __ bind(&next); |
| 7804 | } |
| 7805 | |
| 7806 | // If we reached this point there is a problem. |
| 7807 | __ Abort("Unexpected ElementsKind in array constructor"); |
| 7808 | } |
| 7809 | |
| 7810 | |
| 7811 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm) { |
| 7812 | // ebx - type info cell |
| 7813 | // edx - kind |
| 7814 | // eax - number of arguments |
| 7815 | // edi - constructor? |
| 7816 | // esp[0] - return address |
| 7817 | // esp[4] - last argument |
| 7818 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 7819 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 7820 | ASSERT(FAST_ELEMENTS == 2); |
| 7821 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 7822 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 7823 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 7824 | |
| 7825 | Handle<Object> undefined_sentinel( |
| 7826 | masm->isolate()->heap()->undefined_value(), |
| 7827 | masm->isolate()); |
| 7828 | |
| 7829 | // is the low bit set? If so, we are holey and that is good. |
| 7830 | __ test_b(edx, 1); |
| 7831 | Label normal_sequence; |
| 7832 | __ j(not_zero, &normal_sequence); |
| 7833 | |
| 7834 | // look at the first argument |
| 7835 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7836 | __ test(ecx, ecx); |
| 7837 | __ j(zero, &normal_sequence); |
| 7838 | |
| 7839 | // We are going to create a holey array, but our kind is non-holey. |
| 7840 | // Fix kind and retry |
| 7841 | __ inc(edx); |
| 7842 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7843 | __ j(equal, &normal_sequence); |
| 7844 | |
| 7845 | // Save the resulting elements kind in type info |
| 7846 | __ SmiTag(edx); |
| 7847 | __ mov(FieldOperand(ebx, kPointerSize), edx); |
| 7848 | __ SmiUntag(edx); |
| 7849 | |
| 7850 | __ bind(&normal_sequence); |
| 7851 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7852 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7853 | for (int i = 0; i <= last_index; ++i) { |
| 7854 | Label next; |
| 7855 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7856 | __ cmp(edx, kind); |
| 7857 | __ j(not_equal, &next); |
| 7858 | ArraySingleArgumentConstructorStub stub(kind); |
| 7859 | __ TailCallStub(&stub); |
| 7860 | __ bind(&next); |
| 7861 | } |
| 7862 | |
| 7863 | // If we reached this point there is a problem. |
| 7864 | __ Abort("Unexpected ElementsKind in array constructor"); |
| 7865 | } |
| 7866 | |
| 7867 | |
| 7868 | template<class T> |
| 7869 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 7870 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 7871 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7872 | for (int i = 0; i <= to_index; ++i) { |
| 7873 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7874 | T stub(kind, false); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7875 | stub.GetCode(isolate)->set_is_pregenerated(true); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7876 | if (AllocationSiteInfo::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
| 7877 | T stub1(kind, true); |
| 7878 | stub1.GetCode(isolate)->set_is_pregenerated(true); |
| 7879 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7880 | } |
| 7881 | } |
| 7882 | |
| 7883 | |
| 7884 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 7885 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 7886 | isolate); |
| 7887 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 7888 | isolate); |
| 7889 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 7890 | isolate); |
| 7891 | } |
| 7892 | |
| 7893 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7894 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 7895 | Isolate* isolate) { |
| 7896 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 7897 | for (int i = 0; i < 2; i++) { |
| 7898 | // For internal arrays we only need a few things |
| 7899 | InternalArrayNoArgumentConstructorStub stubh1(kinds[i]); |
| 7900 | stubh1.GetCode(isolate)->set_is_pregenerated(true); |
| 7901 | InternalArraySingleArgumentConstructorStub stubh2(kinds[i]); |
| 7902 | stubh2.GetCode(isolate)->set_is_pregenerated(true); |
| 7903 | InternalArrayNArgumentsConstructorStub stubh3(kinds[i]); |
| 7904 | stubh3.GetCode(isolate)->set_is_pregenerated(true); |
| 7905 | } |
| 7906 | } |
| 7907 | |
| 7908 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7909 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7910 | // ----------- S t a t e ------------- |
| 7911 | // -- eax : argc (only if argument_count_ == ANY) |
| 7912 | // -- ebx : type info cell |
| 7913 | // -- edi : constructor |
| 7914 | // -- esp[0] : return address |
| 7915 | // -- esp[4] : last argument |
| 7916 | // ----------------------------------- |
| 7917 | Handle<Object> undefined_sentinel( |
| 7918 | masm->isolate()->heap()->undefined_value(), |
| 7919 | masm->isolate()); |
| 7920 | |
| 7921 | if (FLAG_debug_code) { |
| 7922 | // The array construct code is only set for the global and natives |
| 7923 | // builtin Array functions which always have maps. |
| 7924 | |
| 7925 | // Initial map for the builtin Array function should be a map. |
| 7926 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7927 | // Will both indicate a NULL and a Smi. |
| 7928 | __ test(ecx, Immediate(kSmiTagMask)); |
| 7929 | __ Assert(not_zero, "Unexpected initial map for Array function"); |
| 7930 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 7931 | __ Assert(equal, "Unexpected initial map for Array function"); |
| 7932 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 7933 | // We should either have undefined in ebx or a valid cell |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7934 | Label okay_here; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 7935 | Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7936 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7937 | __ j(equal, &okay_here); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 7938 | __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7939 | __ Assert(equal, "Expected property cell in register ebx"); |
| 7940 | __ bind(&okay_here); |
| 7941 | } |
| 7942 | |
| 7943 | if (FLAG_optimize_constructed_arrays) { |
| 7944 | Label no_info, switch_ready; |
| 7945 | // Get the elements kind and case on that. |
| 7946 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7947 | __ j(equal, &no_info); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame^] | 7948 | __ mov(edx, FieldOperand(ebx, Cell::kValueOffset)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7949 | __ JumpIfNotSmi(edx, &no_info); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7950 | __ SmiUntag(edx); |
| 7951 | __ jmp(&switch_ready); |
| 7952 | __ bind(&no_info); |
| 7953 | __ mov(edx, Immediate(GetInitialFastElementsKind())); |
| 7954 | __ bind(&switch_ready); |
| 7955 | |
| 7956 | if (argument_count_ == ANY) { |
| 7957 | Label not_zero_case, not_one_case; |
| 7958 | __ test(eax, eax); |
| 7959 | __ j(not_zero, ¬_zero_case); |
| 7960 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
| 7961 | |
| 7962 | __ bind(¬_zero_case); |
| 7963 | __ cmp(eax, 1); |
| 7964 | __ j(greater, ¬_one_case); |
| 7965 | CreateArrayDispatchOneArgument(masm); |
| 7966 | |
| 7967 | __ bind(¬_one_case); |
| 7968 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
| 7969 | } else if (argument_count_ == NONE) { |
| 7970 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
| 7971 | } else if (argument_count_ == ONE) { |
| 7972 | CreateArrayDispatchOneArgument(masm); |
| 7973 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 7974 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
| 7975 | } else { |
| 7976 | UNREACHABLE(); |
| 7977 | } |
| 7978 | } else { |
| 7979 | Label generic_constructor; |
| 7980 | // Run the native code for the Array function called as constructor. |
| 7981 | ArrayNativeCode(masm, true, &generic_constructor); |
| 7982 | |
| 7983 | // Jump to the generic construct code in case the specialized code cannot |
| 7984 | // handle the construction. |
| 7985 | __ bind(&generic_constructor); |
| 7986 | Handle<Code> generic_construct_stub = |
| 7987 | masm->isolate()->builtins()->JSConstructStubGeneric(); |
| 7988 | __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 7989 | } |
| 7990 | } |
| 7991 | |
| 7992 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7993 | void InternalArrayConstructorStub::GenerateCase( |
| 7994 | MacroAssembler* masm, ElementsKind kind) { |
| 7995 | Label not_zero_case, not_one_case; |
| 7996 | Label normal_sequence; |
| 7997 | |
| 7998 | __ test(eax, eax); |
| 7999 | __ j(not_zero, ¬_zero_case); |
| 8000 | InternalArrayNoArgumentConstructorStub stub0(kind); |
| 8001 | __ TailCallStub(&stub0); |
| 8002 | |
| 8003 | __ bind(¬_zero_case); |
| 8004 | __ cmp(eax, 1); |
| 8005 | __ j(greater, ¬_one_case); |
| 8006 | |
| 8007 | if (IsFastPackedElementsKind(kind)) { |
| 8008 | // We might need to create a holey array |
| 8009 | // look at the first argument |
| 8010 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 8011 | __ test(ecx, ecx); |
| 8012 | __ j(zero, &normal_sequence); |
| 8013 | |
| 8014 | InternalArraySingleArgumentConstructorStub |
| 8015 | stub1_holey(GetHoleyElementsKind(kind)); |
| 8016 | __ TailCallStub(&stub1_holey); |
| 8017 | } |
| 8018 | |
| 8019 | __ bind(&normal_sequence); |
| 8020 | InternalArraySingleArgumentConstructorStub stub1(kind); |
| 8021 | __ TailCallStub(&stub1); |
| 8022 | |
| 8023 | __ bind(¬_one_case); |
| 8024 | InternalArrayNArgumentsConstructorStub stubN(kind); |
| 8025 | __ TailCallStub(&stubN); |
| 8026 | } |
| 8027 | |
| 8028 | |
| 8029 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 8030 | // ----------- S t a t e ------------- |
| 8031 | // -- eax : argc |
| 8032 | // -- ebx : type info cell |
| 8033 | // -- edi : constructor |
| 8034 | // -- esp[0] : return address |
| 8035 | // -- esp[4] : last argument |
| 8036 | // ----------------------------------- |
| 8037 | |
| 8038 | if (FLAG_debug_code) { |
| 8039 | // The array construct code is only set for the global and natives |
| 8040 | // builtin Array functions which always have maps. |
| 8041 | |
| 8042 | // Initial map for the builtin Array function should be a map. |
| 8043 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 8044 | // Will both indicate a NULL and a Smi. |
| 8045 | __ test(ecx, Immediate(kSmiTagMask)); |
| 8046 | __ Assert(not_zero, "Unexpected initial map for Array function"); |
| 8047 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 8048 | __ Assert(equal, "Unexpected initial map for Array function"); |
| 8049 | } |
| 8050 | |
| 8051 | if (FLAG_optimize_constructed_arrays) { |
| 8052 | // Figure out the right elements kind |
| 8053 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 8054 | |
| 8055 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 8056 | // but the following masking takes care of that anyway. |
| 8057 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 8058 | // Retrieve elements_kind from bit field 2. |
| 8059 | __ and_(ecx, Map::kElementsKindMask); |
| 8060 | __ shr(ecx, Map::kElementsKindShift); |
| 8061 | |
| 8062 | if (FLAG_debug_code) { |
| 8063 | Label done; |
| 8064 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 8065 | __ j(equal, &done); |
| 8066 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 8067 | __ Assert(equal, |
| 8068 | "Invalid ElementsKind for InternalArray or InternalPackedArray"); |
| 8069 | __ bind(&done); |
| 8070 | } |
| 8071 | |
| 8072 | Label fast_elements_case; |
| 8073 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 8074 | __ j(equal, &fast_elements_case); |
| 8075 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 8076 | |
| 8077 | __ bind(&fast_elements_case); |
| 8078 | GenerateCase(masm, FAST_ELEMENTS); |
| 8079 | } else { |
| 8080 | Label generic_constructor; |
| 8081 | // Run the native code for the Array function called as constructor. |
| 8082 | ArrayNativeCode(masm, true, &generic_constructor); |
| 8083 | |
| 8084 | // Jump to the generic construct code in case the specialized code cannot |
| 8085 | // handle the construction. |
| 8086 | __ bind(&generic_constructor); |
| 8087 | Handle<Code> generic_construct_stub = |
| 8088 | masm->isolate()->builtins()->JSConstructStubGeneric(); |
| 8089 | __ jmp(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 8090 | } |
| 8091 | } |
| 8092 | |
| 8093 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 8094 | #undef __ |
| 8095 | |
| 8096 | } } // namespace v8::internal |
| 8097 | |
| 8098 | #endif // V8_TARGET_ARCH_IA32 |