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 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 30 | #if V8_TARGET_ARCH_IA32 |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 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 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 68 | void CreateAllocationSiteStub::InitializeInterfaceDescriptor( |
| 69 | Isolate* isolate, |
| 70 | CodeStubInterfaceDescriptor* descriptor) { |
| 71 | static Register registers[] = { ebx }; |
| 72 | descriptor->register_param_count_ = 1; |
| 73 | descriptor->register_params_ = registers; |
| 74 | descriptor->deoptimization_handler_ = NULL; |
| 75 | } |
| 76 | |
| 77 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 78 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 79 | Isolate* isolate, |
| 80 | CodeStubInterfaceDescriptor* descriptor) { |
| 81 | static Register registers[] = { edx, ecx }; |
| 82 | descriptor->register_param_count_ = 2; |
| 83 | descriptor->register_params_ = registers; |
| 84 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 85 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 89 | void LoadFieldStub::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 | |
| 99 | void KeyedLoadFieldStub::InitializeInterfaceDescriptor( |
| 100 | Isolate* isolate, |
| 101 | CodeStubInterfaceDescriptor* descriptor) { |
| 102 | static Register registers[] = { edx }; |
| 103 | descriptor->register_param_count_ = 1; |
| 104 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 105 | descriptor->deoptimization_handler_ = NULL; |
| 106 | } |
| 107 | |
| 108 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 109 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 110 | Isolate* isolate, |
| 111 | CodeStubInterfaceDescriptor* descriptor) { |
| 112 | static Register registers[] = { edx, ecx, eax }; |
| 113 | descriptor->register_param_count_ = 3; |
| 114 | descriptor->register_params_ = registers; |
| 115 | descriptor->deoptimization_handler_ = |
| 116 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 117 | } |
| 118 | |
| 119 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 120 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 121 | Isolate* isolate, |
| 122 | CodeStubInterfaceDescriptor* descriptor) { |
| 123 | static Register registers[] = { eax, ebx }; |
| 124 | descriptor->register_param_count_ = 2; |
| 125 | descriptor->register_params_ = registers; |
| 126 | descriptor->deoptimization_handler_ = |
| 127 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 128 | } |
| 129 | |
| 130 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 131 | static void InitializeArrayConstructorDescriptor( |
| 132 | Isolate* isolate, |
| 133 | CodeStubInterfaceDescriptor* descriptor, |
| 134 | int constant_stack_parameter_count) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 135 | // register state |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 136 | // eax -- number of arguments |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 137 | // edi -- function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 138 | // ebx -- type info cell with elements kind |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 139 | static Register registers[] = { edi, ebx }; |
| 140 | descriptor->register_param_count_ = 2; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 141 | |
| 142 | if (constant_stack_parameter_count != 0) { |
| 143 | // stack param count needs (constructor pointer, and single argument) |
| 144 | descriptor->stack_parameter_count_ = &eax; |
| 145 | } |
| 146 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 147 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 148 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 149 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 150 | Runtime::FunctionForId(Runtime::kArrayConstructor)->entry; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 154 | static void InitializeInternalArrayConstructorDescriptor( |
| 155 | Isolate* isolate, |
| 156 | CodeStubInterfaceDescriptor* descriptor, |
| 157 | int constant_stack_parameter_count) { |
| 158 | // register state |
| 159 | // eax -- number of arguments |
| 160 | // edi -- constructor function |
| 161 | static Register registers[] = { edi }; |
| 162 | descriptor->register_param_count_ = 1; |
| 163 | |
| 164 | if (constant_stack_parameter_count != 0) { |
| 165 | // stack param count needs (constructor pointer, and single argument) |
| 166 | descriptor->stack_parameter_count_ = &eax; |
| 167 | } |
| 168 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
| 169 | descriptor->register_params_ = registers; |
| 170 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
| 171 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 172 | Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 176 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 177 | Isolate* isolate, |
| 178 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 179 | InitializeArrayConstructorDescriptor(isolate, descriptor, 0); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | |
| 183 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 184 | Isolate* isolate, |
| 185 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 186 | InitializeArrayConstructorDescriptor(isolate, descriptor, 1); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | |
| 190 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 191 | Isolate* isolate, |
| 192 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 193 | InitializeArrayConstructorDescriptor(isolate, descriptor, -1); |
| 194 | } |
| 195 | |
| 196 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 197 | void InternalArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 198 | Isolate* isolate, |
| 199 | CodeStubInterfaceDescriptor* descriptor) { |
| 200 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 0); |
| 201 | } |
| 202 | |
| 203 | |
| 204 | void InternalArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 205 | Isolate* isolate, |
| 206 | CodeStubInterfaceDescriptor* descriptor) { |
| 207 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 1); |
| 208 | } |
| 209 | |
| 210 | |
| 211 | void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 212 | Isolate* isolate, |
| 213 | CodeStubInterfaceDescriptor* descriptor) { |
| 214 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, -1); |
| 215 | } |
| 216 | |
| 217 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 218 | void CompareNilICStub::InitializeInterfaceDescriptor( |
| 219 | Isolate* isolate, |
| 220 | CodeStubInterfaceDescriptor* descriptor) { |
| 221 | static Register registers[] = { eax }; |
| 222 | descriptor->register_param_count_ = 1; |
| 223 | descriptor->register_params_ = registers; |
| 224 | descriptor->deoptimization_handler_ = |
| 225 | FUNCTION_ADDR(CompareNilIC_Miss); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 226 | descriptor->SetMissHandler( |
| 227 | ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 228 | } |
| 229 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 230 | void ToBooleanStub::InitializeInterfaceDescriptor( |
| 231 | Isolate* isolate, |
| 232 | CodeStubInterfaceDescriptor* descriptor) { |
| 233 | static Register registers[] = { eax }; |
| 234 | descriptor->register_param_count_ = 1; |
| 235 | descriptor->register_params_ = registers; |
| 236 | descriptor->deoptimization_handler_ = |
| 237 | FUNCTION_ADDR(ToBooleanIC_Miss); |
| 238 | descriptor->SetMissHandler( |
| 239 | ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate)); |
| 240 | } |
| 241 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 242 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 243 | void UnaryOpStub::InitializeInterfaceDescriptor( |
| 244 | Isolate* isolate, |
| 245 | CodeStubInterfaceDescriptor* descriptor) { |
| 246 | static Register registers[] = { eax }; |
| 247 | descriptor->register_param_count_ = 1; |
| 248 | descriptor->register_params_ = registers; |
| 249 | descriptor->deoptimization_handler_ = |
| 250 | FUNCTION_ADDR(UnaryOpIC_Miss); |
| 251 | } |
| 252 | |
| 253 | |
| 254 | void StoreGlobalStub::InitializeInterfaceDescriptor( |
| 255 | Isolate* isolate, |
| 256 | CodeStubInterfaceDescriptor* descriptor) { |
| 257 | static Register registers[] = { edx, ecx, eax }; |
| 258 | descriptor->register_param_count_ = 3; |
| 259 | descriptor->register_params_ = registers; |
| 260 | descriptor->deoptimization_handler_ = |
| 261 | FUNCTION_ADDR(StoreIC_MissFromStubFailure); |
| 262 | } |
| 263 | |
| 264 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 265 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 266 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 267 | |
| 268 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
| 269 | // Update the static counter each time a new code stub is generated. |
| 270 | Isolate* isolate = masm->isolate(); |
| 271 | isolate->counters()->code_stubs()->Increment(); |
| 272 | |
| 273 | CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
| 274 | int param_count = descriptor->register_param_count_; |
| 275 | { |
| 276 | // Call the runtime system in a fresh internal frame. |
| 277 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 278 | ASSERT(descriptor->register_param_count_ == 0 || |
| 279 | eax.is(descriptor->register_params_[param_count - 1])); |
| 280 | // Push arguments |
| 281 | for (int i = 0; i < param_count; ++i) { |
| 282 | __ push(descriptor->register_params_[i]); |
| 283 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 284 | ExternalReference miss = descriptor->miss_handler(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 285 | __ CallExternalReference(miss, descriptor->register_param_count_); |
| 286 | } |
| 287 | |
| 288 | __ ret(0); |
| 289 | } |
| 290 | |
| 291 | |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 292 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 293 | // The ToNumber stub takes one argument in eax. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 294 | Label check_heap_number, call_builtin; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 295 | __ JumpIfNotSmi(eax, &check_heap_number, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 296 | __ ret(0); |
| 297 | |
| 298 | __ bind(&check_heap_number); |
| 299 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 300 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 301 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 302 | __ j(not_equal, &call_builtin, Label::kNear); |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 303 | __ ret(0); |
| 304 | |
| 305 | __ bind(&call_builtin); |
| 306 | __ pop(ecx); // Pop return address. |
| 307 | __ push(eax); |
| 308 | __ push(ecx); // Push return address. |
| 309 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
| 310 | } |
| 311 | |
| 312 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 313 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 314 | // Create a new closure from the given function info in new |
| 315 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 316 | Counters* counters = masm->isolate()->counters(); |
| 317 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 318 | Label gc; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 319 | __ Allocate(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 320 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 321 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 322 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 323 | // Get the function info from the stack. |
| 324 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 325 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 326 | int map_index = Context::FunctionMapIndex(language_mode_, is_generator_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 327 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 328 | // 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] | 329 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 330 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 331 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 332 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 333 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 334 | |
| 335 | // Initialize the rest of the function. We don't have to update the |
| 336 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 337 | Factory* factory = masm->isolate()->factory(); |
| 338 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 339 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 340 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 341 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 342 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 343 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 344 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 345 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 346 | |
| 347 | // Initialize the code pointer in the function to be the one |
| 348 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 349 | // But first check if there is an optimized version for our context. |
| 350 | Label check_optimized; |
| 351 | Label install_unoptimized; |
| 352 | if (FLAG_cache_optimized_code) { |
| 353 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 354 | __ test(ebx, ebx); |
| 355 | __ j(not_zero, &check_optimized, Label::kNear); |
| 356 | } |
| 357 | __ bind(&install_unoptimized); |
| 358 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 359 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 360 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 361 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 362 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 363 | |
| 364 | // Return and remove the on-stack parameter. |
| 365 | __ ret(1 * kPointerSize); |
| 366 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 367 | __ bind(&check_optimized); |
| 368 | |
| 369 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 370 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 371 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 372 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 373 | // Map must never be empty, so check the first elements. |
| 374 | Label install_optimized; |
| 375 | // Speculatively move code object into edx. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 376 | __ mov(edx, FieldOperand(ebx, SharedFunctionInfo::kFirstCodeSlot)); |
| 377 | __ cmp(ecx, FieldOperand(ebx, SharedFunctionInfo::kFirstContextSlot)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 378 | __ j(equal, &install_optimized); |
| 379 | |
| 380 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 381 | Label loop; |
| 382 | Label restore; |
| 383 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 384 | __ bind(&loop); |
| 385 | // Do not double check first entry. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 386 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kSecondEntryIndex))); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 387 | __ j(equal, &restore); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 388 | __ sub(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 389 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 390 | __ j(not_equal, &loop, Label::kNear); |
| 391 | // Hit: fetch the optimized code. |
| 392 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 393 | |
| 394 | __ bind(&install_optimized); |
| 395 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 396 | |
| 397 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 398 | // map and either unmangle them on marking or do nothing as the whole map is |
| 399 | // discarded on major GC anyway. |
| 400 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 401 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 402 | |
| 403 | // Now link a function into a list of optimized functions. |
| 404 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 405 | |
| 406 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 407 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 408 | |
| 409 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 410 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 411 | // it clobbers all the registers passed. |
| 412 | __ mov(edx, eax); |
| 413 | __ RecordWriteContextSlot( |
| 414 | ecx, |
| 415 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 416 | edx, |
| 417 | ebx, |
| 418 | kDontSaveFPRegs); |
| 419 | |
| 420 | // Return and remove the on-stack parameter. |
| 421 | __ ret(1 * kPointerSize); |
| 422 | |
| 423 | __ bind(&restore); |
| 424 | // Restore SharedFunctionInfo into edx. |
| 425 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 426 | __ jmp(&install_unoptimized); |
| 427 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 428 | // Create a new closure through the slower runtime call. |
| 429 | __ bind(&gc); |
| 430 | __ pop(ecx); // Temporarily remove return address. |
| 431 | __ pop(edx); |
| 432 | __ push(esi); |
| 433 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 434 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 435 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 436 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | |
| 440 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 441 | // Try to allocate the context in new space. |
| 442 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 443 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 444 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 445 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 446 | |
| 447 | // Get the function from the stack. |
| 448 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 449 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 450 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 451 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 452 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 453 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 454 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 455 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 456 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 457 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 458 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 459 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 460 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 461 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 462 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 463 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 464 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 465 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 466 | |
| 467 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 468 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 469 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 470 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 471 | } |
| 472 | |
| 473 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 474 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 475 | __ ret(1 * kPointerSize); |
| 476 | |
| 477 | // Need to collect. Call into runtime system. |
| 478 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 479 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 483 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 484 | // Stack layout on entry: |
| 485 | // |
| 486 | // [esp + (1 * kPointerSize)]: function |
| 487 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 488 | |
| 489 | // Try to allocate the context in new space. |
| 490 | Label gc; |
| 491 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 492 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 493 | |
| 494 | // Get the function or sentinel from the stack. |
| 495 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 496 | |
| 497 | // Get the serialized scope info from the stack. |
| 498 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 499 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 500 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 501 | Factory* factory = masm->isolate()->factory(); |
| 502 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 503 | factory->block_context_map()); |
| 504 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 505 | Immediate(Smi::FromInt(length))); |
| 506 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 507 | // 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] | 508 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 509 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 510 | // we still have to look up. |
| 511 | Label after_sentinel; |
| 512 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 513 | if (FLAG_debug_code) { |
| 514 | const char* message = "Expected 0 as a Smi sentinel"; |
| 515 | __ cmp(ecx, 0); |
| 516 | __ Assert(equal, message); |
| 517 | } |
| 518 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 519 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 520 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 521 | __ bind(&after_sentinel); |
| 522 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 523 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 524 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 525 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 526 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 527 | |
| 528 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 529 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 530 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 531 | |
| 532 | // Initialize the rest of the slots to the hole value. |
| 533 | if (slots_ == 1) { |
| 534 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 535 | factory->the_hole_value()); |
| 536 | } else { |
| 537 | __ mov(ebx, factory->the_hole_value()); |
| 538 | for (int i = 0; i < slots_; i++) { |
| 539 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | // Return and remove the on-stack parameters. |
| 544 | __ mov(esi, eax); |
| 545 | __ ret(2 * kPointerSize); |
| 546 | |
| 547 | // Need to collect. Call into runtime system. |
| 548 | __ bind(&gc); |
| 549 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 550 | } |
| 551 | |
| 552 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 553 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 554 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 555 | // store the registers in any particular way, but we do have to store and |
| 556 | // restore them. |
| 557 | __ pushad(); |
| 558 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 559 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 560 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 561 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 562 | XMMRegister reg = XMMRegister::from_code(i); |
| 563 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 564 | } |
| 565 | } |
| 566 | const int argument_count = 1; |
| 567 | |
| 568 | AllowExternalCallThatCantCauseGC scope(masm); |
| 569 | __ PrepareCallCFunction(argument_count, ecx); |
| 570 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 571 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 572 | __ CallCFunction( |
| 573 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 574 | argument_count); |
| 575 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 576 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 577 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 578 | XMMRegister reg = XMMRegister::from_code(i); |
| 579 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 580 | } |
| 581 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 582 | } |
| 583 | __ popad(); |
| 584 | __ ret(0); |
| 585 | } |
| 586 | |
| 587 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 588 | class FloatingPointHelper : public AllStatic { |
| 589 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 590 | enum ArgLocation { |
| 591 | ARGS_ON_STACK, |
| 592 | ARGS_IN_REGISTERS |
| 593 | }; |
| 594 | |
| 595 | // Code pattern for loading a floating point value. Input value must |
| 596 | // be either a smi or a heap number object (fp value). Requirements: |
| 597 | // operand in register number. Returns operand as floating point number |
| 598 | // on FPU stack. |
| 599 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 600 | |
| 601 | // Code pattern for loading floating point values. Input values must |
| 602 | // be either smi or heap number objects (fp values). Requirements: |
| 603 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 604 | // Returns operands as floating point numbers on FPU stack. |
| 605 | static void LoadFloatOperands(MacroAssembler* masm, |
| 606 | Register scratch, |
| 607 | ArgLocation arg_location = ARGS_ON_STACK); |
| 608 | |
| 609 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 610 | // Expects operands in edx, eax. |
| 611 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 612 | |
| 613 | // Test if operands are smi or number objects (fp). Requirements: |
| 614 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 615 | // operands, jumps to the non_float label otherwise. |
| 616 | static void CheckFloatOperands(MacroAssembler* masm, |
| 617 | Label* non_float, |
| 618 | Register scratch); |
| 619 | |
| 620 | // Takes the operands in edx and eax and loads them as integers in eax |
| 621 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 622 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 623 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 624 | BinaryOpIC::TypeInfo left_type, |
| 625 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 626 | Label* operand_conversion_failure); |
| 627 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 628 | // Assumes that operands are smis or heap numbers and loads them |
| 629 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 630 | // Leaves operands unchanged. |
| 631 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 632 | |
| 633 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 634 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 635 | // either operand is not a number. Operands are in edx and eax. |
| 636 | // Leaves operands unchanged. |
| 637 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 638 | |
| 639 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 640 | // Expects operands in edx, eax. |
| 641 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 642 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 643 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 644 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 645 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 646 | Label* non_int32, |
| 647 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 648 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 649 | Register scratch, |
| 650 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 651 | }; |
| 652 | |
| 653 | |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 654 | // Get the integer part of a heap number. Surprisingly, all this bit twiddling |
| 655 | // is faster than using the built-in instructions on floating point registers. |
| 656 | // Trashes edi and ebx. Dest is ecx. Source cannot be ecx or one of the |
| 657 | // trashed registers. |
| 658 | static void IntegerConvert(MacroAssembler* masm, |
| 659 | Register source, |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 660 | bool use_sse3, |
| 661 | Label* conversion_failure) { |
| 662 | ASSERT(!source.is(ecx) && !source.is(edi) && !source.is(ebx)); |
| 663 | Label done, right_exponent, normal_exponent; |
| 664 | Register scratch = ebx; |
| 665 | Register scratch2 = edi; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 666 | // Get exponent word. |
| 667 | __ mov(scratch, FieldOperand(source, HeapNumber::kExponentOffset)); |
| 668 | // Get exponent alone in scratch2. |
| 669 | __ mov(scratch2, scratch); |
| 670 | __ and_(scratch2, HeapNumber::kExponentMask); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 671 | __ shr(scratch2, HeapNumber::kExponentShift); |
| 672 | __ sub(scratch2, Immediate(HeapNumber::kExponentBias)); |
| 673 | // Load ecx with zero. We use this either for the final shift or |
| 674 | // for the answer. |
| 675 | __ xor_(ecx, ecx); |
| 676 | // If the exponent is above 83, the number contains no significant |
| 677 | // bits in the range 0..2^31, so the result is zero. |
| 678 | static const uint32_t kResultIsZeroExponent = 83; |
| 679 | __ cmp(scratch2, Immediate(kResultIsZeroExponent)); |
| 680 | __ j(above, &done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 681 | if (use_sse3) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 682 | CpuFeatureScope scope(masm, SSE3); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 683 | // 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] | 684 | static const uint32_t kTooBigExponent = 63; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 685 | __ cmp(scratch2, Immediate(kTooBigExponent)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 686 | __ j(greater_equal, conversion_failure); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 687 | // Load x87 register with heap number. |
| 688 | __ fld_d(FieldOperand(source, HeapNumber::kValueOffset)); |
| 689 | // Reserve space for 64 bit answer. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 690 | __ sub(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 691 | // Do conversion, which cannot fail because we checked the exponent. |
| 692 | __ fisttp_d(Operand(esp, 0)); |
| 693 | __ 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] | 694 | __ add(esp, Immediate(sizeof(uint64_t))); // Nolint. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 695 | } else { |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 696 | // Check whether the exponent matches a 32 bit signed int that cannot be |
| 697 | // represented by a Smi. A non-smi 32 bit integer is 1.xxx * 2^30 so the |
| 698 | // exponent is 30 (biased). This is the exponent that we are fastest at and |
| 699 | // also the highest exponent we can handle here. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 700 | const uint32_t non_smi_exponent = 30; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 701 | __ cmp(scratch2, Immediate(non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 702 | // If we have a match of the int32-but-not-Smi exponent then skip some |
| 703 | // logic. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 704 | __ j(equal, &right_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 705 | // If the exponent is higher than that then go to slow case. This catches |
| 706 | // 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] | 707 | __ j(less, &normal_exponent, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 708 | |
| 709 | { |
| 710 | // Handle a big exponent. The only reason we have this code is that the |
| 711 | // >>> 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] | 712 | const uint32_t big_non_smi_exponent = 31; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 713 | __ cmp(scratch2, Immediate(big_non_smi_exponent)); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 714 | __ j(not_equal, conversion_failure); |
| 715 | // We have the big exponent, typically from >>>. This means the number is |
| 716 | // in the range 2^31 to 2^32 - 1. Get the top bits of the mantissa. |
| 717 | __ mov(scratch2, scratch); |
| 718 | __ and_(scratch2, HeapNumber::kMantissaMask); |
| 719 | // Put back the implicit 1. |
| 720 | __ or_(scratch2, 1 << HeapNumber::kExponentShift); |
| 721 | // Shift up the mantissa bits to take up the space the exponent used to |
| 722 | // take. We just orred in the implicit bit so that took care of one and |
| 723 | // we want to use the full unsigned range so we subtract 1 bit from the |
| 724 | // shift distance. |
| 725 | const int big_shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 1; |
| 726 | __ shl(scratch2, big_shift_distance); |
| 727 | // Get the second half of the double. |
| 728 | __ mov(ecx, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 729 | // Shift down 21 bits to get the most significant 11 bits or the low |
| 730 | // mantissa word. |
| 731 | __ shr(ecx, 32 - big_shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 732 | __ or_(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 733 | // 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] | 734 | __ test(scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 735 | __ j(positive, &done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 736 | __ neg(ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 737 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | __ bind(&normal_exponent); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 741 | // Exponent word in scratch, exponent in scratch2. Zero in ecx. |
| 742 | // We know that 0 <= exponent < 30. |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 743 | __ mov(ecx, Immediate(30)); |
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 | |
| 746 | __ bind(&right_exponent); |
| 747 | // Here ecx is the shift, scratch is the exponent word. |
| 748 | // Get the top bits of the mantissa. |
| 749 | __ and_(scratch, HeapNumber::kMantissaMask); |
| 750 | // Put back the implicit 1. |
| 751 | __ or_(scratch, 1 << HeapNumber::kExponentShift); |
| 752 | // Shift up the mantissa bits to take up the space the exponent used to |
| 753 | // take. We have kExponentShift + 1 significant bits int he low end of the |
| 754 | // word. Shift them to the top bits. |
| 755 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 756 | __ shl(scratch, shift_distance); |
| 757 | // Get the second half of the double. For some exponents we don't |
| 758 | // actually need this because the bits get shifted out again, but |
| 759 | // it's probably slower to test than just to do it. |
| 760 | __ mov(scratch2, FieldOperand(source, HeapNumber::kMantissaOffset)); |
| 761 | // Shift down 22 bits to get the most significant 10 bits or the low |
| 762 | // mantissa word. |
| 763 | __ shr(scratch2, 32 - shift_distance); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 764 | __ or_(scratch2, scratch); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 765 | // Move down according to the exponent. |
| 766 | __ shr_cl(scratch2); |
| 767 | // Now the unsigned answer is in scratch2. We need to move it to ecx and |
| 768 | // we may need to fix the sign. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 769 | Label negative; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 770 | __ xor_(ecx, ecx); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 771 | __ cmp(ecx, FieldOperand(source, HeapNumber::kExponentOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 772 | __ j(greater, &negative, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 773 | __ mov(ecx, scratch2); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 774 | __ jmp(&done, Label::kNear); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 775 | __ bind(&negative); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 776 | __ sub(ecx, scratch2); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 777 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 778 | __ bind(&done); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 782 | // Uses SSE2 to convert the heap number in |source| to an integer. Jumps to |
| 783 | // |conversion_failure| if the heap number did not contain an int32 value. |
| 784 | // Result is in ecx. Trashes ebx, xmm0, and xmm1. |
| 785 | static void ConvertHeapNumberToInt32(MacroAssembler* masm, |
| 786 | Register source, |
| 787 | Label* conversion_failure) { |
| 788 | __ movdbl(xmm0, FieldOperand(source, HeapNumber::kValueOffset)); |
| 789 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 790 | masm, conversion_failure, xmm0, ecx, ebx, xmm1); |
| 791 | } |
| 792 | |
| 793 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 794 | void BinaryOpStub::Initialize() { |
| 795 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 796 | } |
| 797 | |
| 798 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 799 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 800 | __ pop(ecx); // Save return address. |
| 801 | __ push(edx); |
| 802 | __ push(eax); |
| 803 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 804 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 805 | |
| 806 | __ push(ecx); // Push return address. |
| 807 | |
| 808 | // Patch the caller to an appropriate specialized stub and return the |
| 809 | // operation result to the caller of the stub. |
| 810 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 811 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 812 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 813 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 814 | 1); |
| 815 | } |
| 816 | |
| 817 | |
| 818 | // Prepare for a type transition runtime call when the args are already on |
| 819 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 820 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 821 | __ pop(ecx); // Save return address. |
| 822 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 823 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 824 | |
| 825 | __ push(ecx); // Push return address. |
| 826 | |
| 827 | // Patch the caller to an appropriate specialized stub and return the |
| 828 | // operation result to the caller of the stub. |
| 829 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 830 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 831 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 832 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 833 | 1); |
| 834 | } |
| 835 | |
| 836 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 837 | static void BinaryOpStub_GenerateRegisterArgsPop(MacroAssembler* masm) { |
| 838 | __ pop(ecx); |
| 839 | __ pop(eax); |
| 840 | __ pop(edx); |
| 841 | __ push(ecx); |
| 842 | } |
| 843 | |
| 844 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 845 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 846 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 847 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 848 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 849 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 850 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 851 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 852 | Comment load_comment(masm, "-- Load arguments"); |
| 853 | Register left = edx; |
| 854 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 855 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 856 | left = eax; |
| 857 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 858 | __ mov(ebx, eax); |
| 859 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | |
| 863 | // 2. Prepare the smi check of both operands by oring them together. |
| 864 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 865 | Label not_smis; |
| 866 | Register combined = ecx; |
| 867 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 868 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 869 | case Token::BIT_OR: |
| 870 | // Perform the operation into eax and smi check the result. Preserve |
| 871 | // eax in case the result is not a smi. |
| 872 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 873 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 874 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 875 | combined = right; |
| 876 | break; |
| 877 | |
| 878 | case Token::BIT_XOR: |
| 879 | case Token::BIT_AND: |
| 880 | case Token::ADD: |
| 881 | case Token::SUB: |
| 882 | case Token::MUL: |
| 883 | case Token::DIV: |
| 884 | case Token::MOD: |
| 885 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 886 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 887 | break; |
| 888 | |
| 889 | case Token::SHL: |
| 890 | case Token::SAR: |
| 891 | case Token::SHR: |
| 892 | // Move the right operand into ecx for the shift operation, use eax |
| 893 | // for the smi check register. |
| 894 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 895 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 896 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 897 | combined = right; |
| 898 | break; |
| 899 | |
| 900 | default: |
| 901 | break; |
| 902 | } |
| 903 | |
| 904 | // 3. Perform the smi check of the operands. |
| 905 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 906 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 907 | |
| 908 | // 4. Operands are both smis, perform the operation leaving the result in |
| 909 | // eax and check the result if necessary. |
| 910 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 911 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 912 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 913 | case Token::BIT_OR: |
| 914 | // Nothing to do. |
| 915 | break; |
| 916 | |
| 917 | case Token::BIT_XOR: |
| 918 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 919 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 920 | break; |
| 921 | |
| 922 | case Token::BIT_AND: |
| 923 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 924 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 925 | break; |
| 926 | |
| 927 | case Token::SHL: |
| 928 | // Remove tags from operands (but keep sign). |
| 929 | __ SmiUntag(left); |
| 930 | __ SmiUntag(ecx); |
| 931 | // Perform the operation. |
| 932 | __ shl_cl(left); |
| 933 | // Check that the *signed* result fits in a smi. |
| 934 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 935 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 936 | // Tag the result and store it in register eax. |
| 937 | __ SmiTag(left); |
| 938 | __ mov(eax, left); |
| 939 | break; |
| 940 | |
| 941 | case Token::SAR: |
| 942 | // Remove tags from operands (but keep sign). |
| 943 | __ SmiUntag(left); |
| 944 | __ SmiUntag(ecx); |
| 945 | // Perform the operation. |
| 946 | __ sar_cl(left); |
| 947 | // Tag the result and store it in register eax. |
| 948 | __ SmiTag(left); |
| 949 | __ mov(eax, left); |
| 950 | break; |
| 951 | |
| 952 | case Token::SHR: |
| 953 | // Remove tags from operands (but keep sign). |
| 954 | __ SmiUntag(left); |
| 955 | __ SmiUntag(ecx); |
| 956 | // Perform the operation. |
| 957 | __ shr_cl(left); |
| 958 | // Check that the *unsigned* result fits in a smi. |
| 959 | // Neither of the two high-order bits can be set: |
| 960 | // - 0x80000000: high bit would be lost when smi tagging. |
| 961 | // - 0x40000000: this number would convert to negative when |
| 962 | // Smi tagging these two cases can only happen with shifts |
| 963 | // by 0 or 1 when handed a valid smi. |
| 964 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 965 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 966 | // Tag the result and store it in register eax. |
| 967 | __ SmiTag(left); |
| 968 | __ mov(eax, left); |
| 969 | break; |
| 970 | |
| 971 | case Token::ADD: |
| 972 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 973 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 974 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 975 | break; |
| 976 | |
| 977 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 978 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 979 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 980 | __ mov(eax, left); |
| 981 | break; |
| 982 | |
| 983 | case Token::MUL: |
| 984 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 985 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 986 | // We can't revert the multiplication if the result is not a smi |
| 987 | // so save the right operand. |
| 988 | __ mov(ebx, right); |
| 989 | // Remove tag from one of the operands (but keep sign). |
| 990 | __ SmiUntag(right); |
| 991 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 992 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 993 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 994 | // Check for negative zero result. Use combined = left | right. |
| 995 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 996 | break; |
| 997 | |
| 998 | case Token::DIV: |
| 999 | // We can't revert the division if the result is not a smi so |
| 1000 | // save the left operand. |
| 1001 | __ mov(edi, left); |
| 1002 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1003 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1004 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1005 | // Sign extend left into edx:eax. |
| 1006 | ASSERT(left.is(eax)); |
| 1007 | __ cdq(); |
| 1008 | // Divide edx:eax by right. |
| 1009 | __ idiv(right); |
| 1010 | // Check for the corner case of dividing the most negative smi by |
| 1011 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1012 | // instruction. |
| 1013 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1014 | __ cmp(eax, 0x40000000); |
| 1015 | __ j(equal, &use_fp_on_smis); |
| 1016 | // Check for negative zero result. Use combined = left | right. |
| 1017 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1018 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1019 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1020 | __ j(not_zero, &use_fp_on_smis); |
| 1021 | // Tag the result and store it in register eax. |
| 1022 | __ SmiTag(eax); |
| 1023 | break; |
| 1024 | |
| 1025 | case Token::MOD: |
| 1026 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1027 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1028 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1029 | |
| 1030 | // Sign extend left into edx:eax. |
| 1031 | ASSERT(left.is(eax)); |
| 1032 | __ cdq(); |
| 1033 | // Divide edx:eax by right. |
| 1034 | __ idiv(right); |
| 1035 | // Check for negative zero result. Use combined = left | right. |
| 1036 | __ NegativeZeroTest(edx, combined, slow); |
| 1037 | // Move remainder to register eax. |
| 1038 | __ mov(eax, edx); |
| 1039 | break; |
| 1040 | |
| 1041 | default: |
| 1042 | UNREACHABLE(); |
| 1043 | } |
| 1044 | |
| 1045 | // 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] | 1046 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1047 | case Token::ADD: |
| 1048 | case Token::SUB: |
| 1049 | case Token::MUL: |
| 1050 | case Token::DIV: |
| 1051 | __ ret(0); |
| 1052 | break; |
| 1053 | case Token::MOD: |
| 1054 | case Token::BIT_OR: |
| 1055 | case Token::BIT_AND: |
| 1056 | case Token::BIT_XOR: |
| 1057 | case Token::SAR: |
| 1058 | case Token::SHL: |
| 1059 | case Token::SHR: |
| 1060 | __ ret(2 * kPointerSize); |
| 1061 | break; |
| 1062 | default: |
| 1063 | UNREACHABLE(); |
| 1064 | } |
| 1065 | |
| 1066 | // 6. For some operations emit inline code to perform floating point |
| 1067 | // operations on known smis (e.g., if the result of the operation |
| 1068 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1069 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1070 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1071 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1072 | // Undo the effects of some operations, and some register moves. |
| 1073 | case Token::SHL: |
| 1074 | // The arguments are saved on the stack, and only used from there. |
| 1075 | break; |
| 1076 | case Token::ADD: |
| 1077 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1078 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1079 | break; |
| 1080 | case Token::SUB: |
| 1081 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1082 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1083 | break; |
| 1084 | case Token::MUL: |
| 1085 | // Right was clobbered but a copy is in ebx. |
| 1086 | __ mov(right, ebx); |
| 1087 | break; |
| 1088 | case Token::DIV: |
| 1089 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1090 | // division. They should be in eax, ebx for jump to not_smi. |
| 1091 | __ mov(eax, edi); |
| 1092 | break; |
| 1093 | default: |
| 1094 | // No other operators jump to use_fp_on_smis. |
| 1095 | break; |
| 1096 | } |
| 1097 | __ jmp(¬_smis); |
| 1098 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1099 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1100 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1101 | case Token::SHL: |
| 1102 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1103 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1104 | __ bind(&use_fp_on_smis); |
| 1105 | // Result we want is in left == edx, so we can put the allocated heap |
| 1106 | // number in eax. |
| 1107 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1108 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1109 | // It's OK to overwrite the arguments on the stack because we |
| 1110 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1111 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1112 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1113 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1114 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1115 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1116 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1117 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1118 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1119 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1120 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1121 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1122 | } else { |
| 1123 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1124 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1125 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1126 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1127 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1128 | __ ret(2 * kPointerSize); |
| 1129 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | case Token::ADD: |
| 1133 | case Token::SUB: |
| 1134 | case Token::MUL: |
| 1135 | case Token::DIV: { |
| 1136 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1137 | __ bind(&use_fp_on_smis); |
| 1138 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1139 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1140 | case Token::ADD: |
| 1141 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1142 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1143 | break; |
| 1144 | case Token::SUB: |
| 1145 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1146 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1147 | break; |
| 1148 | case Token::MUL: |
| 1149 | // Right was clobbered but a copy is in ebx. |
| 1150 | __ mov(right, ebx); |
| 1151 | break; |
| 1152 | case Token::DIV: |
| 1153 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1154 | // division. |
| 1155 | __ mov(edx, edi); |
| 1156 | __ mov(eax, right); |
| 1157 | break; |
| 1158 | default: UNREACHABLE(); |
| 1159 | break; |
| 1160 | } |
| 1161 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1162 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1163 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1164 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1165 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1166 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1167 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1168 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1169 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1170 | default: UNREACHABLE(); |
| 1171 | } |
| 1172 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1173 | } else { // SSE2 not available, use FPU. |
| 1174 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1175 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1176 | case Token::ADD: __ faddp(1); break; |
| 1177 | case Token::SUB: __ fsubp(1); break; |
| 1178 | case Token::MUL: __ fmulp(1); break; |
| 1179 | case Token::DIV: __ fdivp(1); break; |
| 1180 | default: UNREACHABLE(); |
| 1181 | } |
| 1182 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1183 | } |
| 1184 | __ mov(eax, ecx); |
| 1185 | __ ret(0); |
| 1186 | break; |
| 1187 | } |
| 1188 | |
| 1189 | default: |
| 1190 | break; |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1195 | // edx and eax. |
| 1196 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1197 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1198 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1199 | case Token::BIT_OR: |
| 1200 | case Token::SHL: |
| 1201 | case Token::SAR: |
| 1202 | case Token::SHR: |
| 1203 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1204 | // check. |
| 1205 | __ mov(eax, ecx); |
| 1206 | break; |
| 1207 | |
| 1208 | case Token::DIV: |
| 1209 | case Token::MOD: |
| 1210 | // Operands are in eax, ebx at this point. |
| 1211 | __ mov(edx, eax); |
| 1212 | __ mov(eax, ebx); |
| 1213 | break; |
| 1214 | |
| 1215 | default: |
| 1216 | break; |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1221 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1222 | Label right_arg_changed, call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1223 | |
| 1224 | switch (op_) { |
| 1225 | case Token::ADD: |
| 1226 | case Token::SUB: |
| 1227 | case Token::MUL: |
| 1228 | case Token::DIV: |
| 1229 | break; |
| 1230 | case Token::MOD: |
| 1231 | case Token::BIT_OR: |
| 1232 | case Token::BIT_AND: |
| 1233 | case Token::BIT_XOR: |
| 1234 | case Token::SAR: |
| 1235 | case Token::SHL: |
| 1236 | case Token::SHR: |
| 1237 | GenerateRegisterArgsPush(masm); |
| 1238 | break; |
| 1239 | default: |
| 1240 | UNREACHABLE(); |
| 1241 | } |
| 1242 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1243 | if (op_ == Token::MOD && encoded_right_arg_.has_value) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1244 | // It is guaranteed that the value will fit into a Smi, because if it |
| 1245 | // didn't, we wouldn't be here, see BinaryOp_Patch. |
| 1246 | __ cmp(eax, Immediate(Smi::FromInt(fixed_right_arg_value()))); |
| 1247 | __ j(not_equal, &right_arg_changed); |
| 1248 | } |
| 1249 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1250 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1251 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1252 | BinaryOpStub_GenerateSmiCode( |
| 1253 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1254 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1255 | BinaryOpStub_GenerateSmiCode( |
| 1256 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1257 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1258 | |
| 1259 | // Code falls through if the result is not returned as either a smi or heap |
| 1260 | // number. |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1261 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1262 | switch (op_) { |
| 1263 | case Token::ADD: |
| 1264 | case Token::SUB: |
| 1265 | case Token::MUL: |
| 1266 | case Token::DIV: |
| 1267 | GenerateTypeTransition(masm); |
| 1268 | break; |
| 1269 | case Token::MOD: |
| 1270 | case Token::BIT_OR: |
| 1271 | case Token::BIT_AND: |
| 1272 | case Token::BIT_XOR: |
| 1273 | case Token::SAR: |
| 1274 | case Token::SHL: |
| 1275 | case Token::SHR: |
| 1276 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1277 | break; |
| 1278 | default: |
| 1279 | UNREACHABLE(); |
| 1280 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1281 | |
| 1282 | __ bind(&call_runtime); |
| 1283 | switch (op_) { |
| 1284 | case Token::ADD: |
| 1285 | case Token::SUB: |
| 1286 | case Token::MUL: |
| 1287 | case Token::DIV: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1288 | break; |
| 1289 | case Token::MOD: |
| 1290 | case Token::BIT_OR: |
| 1291 | case Token::BIT_AND: |
| 1292 | case Token::BIT_XOR: |
| 1293 | case Token::SAR: |
| 1294 | case Token::SHL: |
| 1295 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1296 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1297 | break; |
| 1298 | default: |
| 1299 | UNREACHABLE(); |
| 1300 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1301 | |
| 1302 | { |
| 1303 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1304 | __ push(edx); |
| 1305 | __ push(eax); |
| 1306 | GenerateCallRuntime(masm); |
| 1307 | } |
| 1308 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1312 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1313 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1314 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1315 | ASSERT(op_ == Token::ADD); |
| 1316 | // If both arguments are strings, call the string add stub. |
| 1317 | // Otherwise, do a transition. |
| 1318 | |
| 1319 | // Registers containing left and right operands respectively. |
| 1320 | Register left = edx; |
| 1321 | Register right = eax; |
| 1322 | |
| 1323 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1324 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1325 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1326 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1327 | |
| 1328 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1329 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1330 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1331 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1332 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1333 | StringAddStub string_add_stub((StringAddFlags) |
| 1334 | (ERECT_FRAME | NO_STRING_CHECK_IN_STUB)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1335 | GenerateRegisterArgsPush(masm); |
| 1336 | __ TailCallStub(&string_add_stub); |
| 1337 | |
| 1338 | __ bind(&call_runtime); |
| 1339 | GenerateTypeTransition(masm); |
| 1340 | } |
| 1341 | |
| 1342 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1343 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1344 | Label* alloc_failure, |
| 1345 | OverwriteMode mode); |
| 1346 | |
| 1347 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1348 | // Input: |
| 1349 | // edx: left operand (tagged) |
| 1350 | // eax: right operand (tagged) |
| 1351 | // Output: |
| 1352 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1353 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1354 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1355 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1356 | |
| 1357 | // Floating point case. |
| 1358 | switch (op_) { |
| 1359 | case Token::ADD: |
| 1360 | case Token::SUB: |
| 1361 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1362 | case Token::DIV: |
| 1363 | case Token::MOD: { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1364 | Label not_floats, not_int32, right_arg_changed; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1365 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1366 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1367 | // It could be that only SMIs have been seen at either the left |
| 1368 | // or the right operand. For precise type feedback, patch the IC |
| 1369 | // again if this changes. |
| 1370 | // In theory, we would need the same check in the non-SSE2 case, |
| 1371 | // but since we don't support Crankshaft on such hardware we can |
| 1372 | // afford not to care about precise type feedback. |
| 1373 | if (left_type_ == BinaryOpIC::SMI) { |
| 1374 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1375 | } |
| 1376 | if (right_type_ == BinaryOpIC::SMI) { |
| 1377 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1378 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1379 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1380 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1381 | masm, ¬_int32, xmm0, ebx, ecx, xmm2); |
| 1382 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1383 | masm, ¬_int32, xmm1, edi, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1384 | if (op_ == Token::MOD) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1385 | if (encoded_right_arg_.has_value) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1386 | __ cmp(edi, Immediate(fixed_right_arg_value())); |
| 1387 | __ j(not_equal, &right_arg_changed); |
| 1388 | } |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1389 | GenerateRegisterArgsPush(masm); |
| 1390 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1391 | } else { |
| 1392 | switch (op_) { |
| 1393 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1394 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1395 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1396 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1397 | default: UNREACHABLE(); |
| 1398 | } |
| 1399 | // Check result type if it is currently Int32. |
| 1400 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1401 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1402 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1403 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1404 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1405 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1406 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1407 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1408 | } else { // SSE2 not available, use FPU. |
| 1409 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1410 | FloatingPointHelper::LoadFloatOperands( |
| 1411 | masm, |
| 1412 | ecx, |
| 1413 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1414 | if (op_ == Token::MOD) { |
| 1415 | // The operands are now on the FPU stack, but we don't need them. |
| 1416 | __ fstp(0); |
| 1417 | __ fstp(0); |
| 1418 | GenerateRegisterArgsPush(masm); |
| 1419 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1420 | } else { |
| 1421 | switch (op_) { |
| 1422 | case Token::ADD: __ faddp(1); break; |
| 1423 | case Token::SUB: __ fsubp(1); break; |
| 1424 | case Token::MUL: __ fmulp(1); break; |
| 1425 | case Token::DIV: __ fdivp(1); break; |
| 1426 | default: UNREACHABLE(); |
| 1427 | } |
| 1428 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1429 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1430 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1431 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1432 | __ ret(0); |
| 1433 | __ bind(&after_alloc_failure); |
| 1434 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1435 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1436 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | __ bind(¬_floats); |
| 1440 | __ bind(¬_int32); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1441 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1442 | GenerateTypeTransition(masm); |
| 1443 | break; |
| 1444 | } |
| 1445 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1446 | case Token::BIT_OR: |
| 1447 | case Token::BIT_AND: |
| 1448 | case Token::BIT_XOR: |
| 1449 | case Token::SAR: |
| 1450 | case Token::SHL: |
| 1451 | case Token::SHR: { |
| 1452 | GenerateRegisterArgsPush(masm); |
| 1453 | Label not_floats; |
| 1454 | Label not_int32; |
| 1455 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1456 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1457 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1458 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1459 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1460 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1461 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1462 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1463 | case Token::SAR: __ sar_cl(eax); break; |
| 1464 | case Token::SHL: __ shl_cl(eax); break; |
| 1465 | case Token::SHR: __ shr_cl(eax); break; |
| 1466 | default: UNREACHABLE(); |
| 1467 | } |
| 1468 | if (op_ == Token::SHR) { |
| 1469 | // Check if result is non-negative and fits in a smi. |
| 1470 | __ test(eax, Immediate(0xc0000000)); |
| 1471 | __ j(not_zero, &call_runtime); |
| 1472 | } else { |
| 1473 | // Check if result fits in a smi. |
| 1474 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1475 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1476 | } |
| 1477 | // Tag smi result and return. |
| 1478 | __ SmiTag(eax); |
| 1479 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1480 | |
| 1481 | // All ops except SHR return a signed int32 that we load in |
| 1482 | // a HeapNumber. |
| 1483 | if (op_ != Token::SHR) { |
| 1484 | __ bind(&non_smi_result); |
| 1485 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1486 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1487 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1488 | switch (mode_) { |
| 1489 | case OVERWRITE_LEFT: |
| 1490 | case OVERWRITE_RIGHT: |
| 1491 | // If the operand was an object, we skip the |
| 1492 | // allocation of a heap number. |
| 1493 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1494 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1495 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1496 | // Fall through! |
| 1497 | case NO_OVERWRITE: |
| 1498 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1499 | __ bind(&skip_allocation); |
| 1500 | break; |
| 1501 | default: UNREACHABLE(); |
| 1502 | } |
| 1503 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1504 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1505 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1506 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1507 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1508 | } else { |
| 1509 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1510 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1511 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1512 | } |
| 1513 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1514 | } |
| 1515 | |
| 1516 | __ bind(¬_floats); |
| 1517 | __ bind(¬_int32); |
| 1518 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1519 | break; |
| 1520 | } |
| 1521 | default: UNREACHABLE(); break; |
| 1522 | } |
| 1523 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1524 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1525 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1526 | __ bind(&call_runtime); |
| 1527 | |
| 1528 | switch (op_) { |
| 1529 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1530 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1531 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1532 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1533 | break; |
| 1534 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1535 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1536 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1537 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1538 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1539 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1540 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1541 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1542 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1543 | break; |
| 1544 | default: |
| 1545 | UNREACHABLE(); |
| 1546 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1547 | |
| 1548 | { |
| 1549 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1550 | __ push(edx); |
| 1551 | __ push(eax); |
| 1552 | GenerateCallRuntime(masm); |
| 1553 | } |
| 1554 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1558 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1559 | if (op_ == Token::ADD) { |
| 1560 | // Handle string addition here, because it is the only operation |
| 1561 | // that does not do a ToNumber conversion on the operands. |
| 1562 | GenerateAddStrings(masm); |
| 1563 | } |
| 1564 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1565 | Factory* factory = masm->isolate()->factory(); |
| 1566 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1567 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1568 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1569 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1570 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1571 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1572 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1573 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1574 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1575 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1576 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1577 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1578 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1579 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1580 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1581 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1582 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1583 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1584 | } |
| 1585 | __ bind(&done); |
| 1586 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1587 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1591 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1592 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1593 | |
| 1594 | // Floating point case. |
| 1595 | switch (op_) { |
| 1596 | case Token::ADD: |
| 1597 | case Token::SUB: |
| 1598 | case Token::MUL: |
| 1599 | case Token::DIV: { |
| 1600 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1601 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1602 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1603 | |
| 1604 | // It could be that only SMIs have been seen at either the left |
| 1605 | // or the right operand. For precise type feedback, patch the IC |
| 1606 | // again if this changes. |
| 1607 | // In theory, we would need the same check in the non-SSE2 case, |
| 1608 | // but since we don't support Crankshaft on such hardware we can |
| 1609 | // afford not to care about precise type feedback. |
| 1610 | if (left_type_ == BinaryOpIC::SMI) { |
| 1611 | __ JumpIfNotSmi(edx, ¬_floats); |
| 1612 | } |
| 1613 | if (right_type_ == BinaryOpIC::SMI) { |
| 1614 | __ JumpIfNotSmi(eax, ¬_floats); |
| 1615 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1616 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1617 | if (left_type_ == BinaryOpIC::INT32) { |
| 1618 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1619 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1620 | } |
| 1621 | if (right_type_ == BinaryOpIC::INT32) { |
| 1622 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1623 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1624 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1625 | |
| 1626 | switch (op_) { |
| 1627 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1628 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1629 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1630 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1631 | default: UNREACHABLE(); |
| 1632 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1633 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1634 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1635 | __ ret(0); |
| 1636 | } else { // SSE2 not available, use FPU. |
| 1637 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1638 | FloatingPointHelper::LoadFloatOperands( |
| 1639 | masm, |
| 1640 | ecx, |
| 1641 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1642 | switch (op_) { |
| 1643 | case Token::ADD: __ faddp(1); break; |
| 1644 | case Token::SUB: __ fsubp(1); break; |
| 1645 | case Token::MUL: __ fmulp(1); break; |
| 1646 | case Token::DIV: __ fdivp(1); break; |
| 1647 | default: UNREACHABLE(); |
| 1648 | } |
| 1649 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1650 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1651 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1652 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1653 | __ ret(0); |
| 1654 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1655 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1656 | __ jmp(&call_runtime); |
| 1657 | } |
| 1658 | |
| 1659 | __ bind(¬_floats); |
| 1660 | GenerateTypeTransition(masm); |
| 1661 | break; |
| 1662 | } |
| 1663 | |
| 1664 | case Token::MOD: { |
| 1665 | // For MOD we go directly to runtime in the non-smi case. |
| 1666 | break; |
| 1667 | } |
| 1668 | case Token::BIT_OR: |
| 1669 | case Token::BIT_AND: |
| 1670 | case Token::BIT_XOR: |
| 1671 | case Token::SAR: |
| 1672 | case Token::SHL: |
| 1673 | case Token::SHR: { |
| 1674 | GenerateRegisterArgsPush(masm); |
| 1675 | Label not_floats; |
| 1676 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1677 | // We do not check the input arguments here, as any value is |
| 1678 | // unconditionally truncated to an int32 anyway. To get the |
| 1679 | // right optimized code, int32 type feedback is just right. |
| 1680 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1681 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1682 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1683 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1684 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1685 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1686 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1687 | case Token::SAR: __ sar_cl(eax); break; |
| 1688 | case Token::SHL: __ shl_cl(eax); break; |
| 1689 | case Token::SHR: __ shr_cl(eax); break; |
| 1690 | default: UNREACHABLE(); |
| 1691 | } |
| 1692 | if (op_ == Token::SHR) { |
| 1693 | // Check if result is non-negative and fits in a smi. |
| 1694 | __ test(eax, Immediate(0xc0000000)); |
| 1695 | __ j(not_zero, &call_runtime); |
| 1696 | } else { |
| 1697 | // Check if result fits in a smi. |
| 1698 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1699 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1700 | } |
| 1701 | // Tag smi result and return. |
| 1702 | __ SmiTag(eax); |
| 1703 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1704 | |
| 1705 | // All ops except SHR return a signed int32 that we load in |
| 1706 | // a HeapNumber. |
| 1707 | if (op_ != Token::SHR) { |
| 1708 | __ bind(&non_smi_result); |
| 1709 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1710 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1711 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1712 | switch (mode_) { |
| 1713 | case OVERWRITE_LEFT: |
| 1714 | case OVERWRITE_RIGHT: |
| 1715 | // If the operand was an object, we skip the |
| 1716 | // allocation of a heap number. |
| 1717 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1718 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1719 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1720 | // Fall through! |
| 1721 | case NO_OVERWRITE: |
| 1722 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1723 | __ bind(&skip_allocation); |
| 1724 | break; |
| 1725 | default: UNREACHABLE(); |
| 1726 | } |
| 1727 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1728 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1729 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1730 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1731 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1732 | } else { |
| 1733 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1734 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1735 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1736 | } |
| 1737 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1738 | } |
| 1739 | |
| 1740 | __ bind(¬_floats); |
| 1741 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1742 | break; |
| 1743 | } |
| 1744 | default: UNREACHABLE(); break; |
| 1745 | } |
| 1746 | |
| 1747 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 1748 | // use the runtime system to get the correct result. |
| 1749 | __ bind(&call_runtime); |
| 1750 | |
| 1751 | switch (op_) { |
| 1752 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1753 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1754 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1755 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1756 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1757 | break; |
| 1758 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1759 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1760 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1761 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1762 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1763 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1764 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1765 | break; |
| 1766 | default: |
| 1767 | UNREACHABLE(); |
| 1768 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1769 | |
| 1770 | { |
| 1771 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1772 | __ push(edx); |
| 1773 | __ push(eax); |
| 1774 | GenerateCallRuntime(masm); |
| 1775 | } |
| 1776 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1780 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1781 | Label call_runtime; |
| 1782 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1783 | Counters* counters = masm->isolate()->counters(); |
| 1784 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1785 | |
| 1786 | switch (op_) { |
| 1787 | case Token::ADD: |
| 1788 | case Token::SUB: |
| 1789 | case Token::MUL: |
| 1790 | case Token::DIV: |
| 1791 | break; |
| 1792 | case Token::MOD: |
| 1793 | case Token::BIT_OR: |
| 1794 | case Token::BIT_AND: |
| 1795 | case Token::BIT_XOR: |
| 1796 | case Token::SAR: |
| 1797 | case Token::SHL: |
| 1798 | case Token::SHR: |
| 1799 | GenerateRegisterArgsPush(masm); |
| 1800 | break; |
| 1801 | default: |
| 1802 | UNREACHABLE(); |
| 1803 | } |
| 1804 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1805 | BinaryOpStub_GenerateSmiCode( |
| 1806 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1807 | |
| 1808 | // Floating point case. |
| 1809 | switch (op_) { |
| 1810 | case Token::ADD: |
| 1811 | case Token::SUB: |
| 1812 | case Token::MUL: |
| 1813 | case Token::DIV: { |
| 1814 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1815 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1816 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1817 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1818 | |
| 1819 | switch (op_) { |
| 1820 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1821 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1822 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1823 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1824 | default: UNREACHABLE(); |
| 1825 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1826 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1827 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1828 | __ ret(0); |
| 1829 | } else { // SSE2 not available, use FPU. |
| 1830 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1831 | FloatingPointHelper::LoadFloatOperands( |
| 1832 | masm, |
| 1833 | ecx, |
| 1834 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1835 | switch (op_) { |
| 1836 | case Token::ADD: __ faddp(1); break; |
| 1837 | case Token::SUB: __ fsubp(1); break; |
| 1838 | case Token::MUL: __ fmulp(1); break; |
| 1839 | case Token::DIV: __ fdivp(1); break; |
| 1840 | default: UNREACHABLE(); |
| 1841 | } |
| 1842 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1843 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1844 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1845 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1846 | __ ret(0); |
| 1847 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1848 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1849 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1850 | } |
| 1851 | __ bind(¬_floats); |
| 1852 | break; |
| 1853 | } |
| 1854 | case Token::MOD: { |
| 1855 | // For MOD we go directly to runtime in the non-smi case. |
| 1856 | break; |
| 1857 | } |
| 1858 | case Token::BIT_OR: |
| 1859 | case Token::BIT_AND: |
| 1860 | case Token::BIT_XOR: |
| 1861 | case Token::SAR: |
| 1862 | case Token::SHL: |
| 1863 | case Token::SHR: { |
| 1864 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1865 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1866 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1867 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1868 | BinaryOpIC::GENERIC, |
| 1869 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1870 | &call_runtime); |
| 1871 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1872 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1873 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1874 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1875 | case Token::SAR: __ sar_cl(eax); break; |
| 1876 | case Token::SHL: __ shl_cl(eax); break; |
| 1877 | case Token::SHR: __ shr_cl(eax); break; |
| 1878 | default: UNREACHABLE(); |
| 1879 | } |
| 1880 | if (op_ == Token::SHR) { |
| 1881 | // Check if result is non-negative and fits in a smi. |
| 1882 | __ test(eax, Immediate(0xc0000000)); |
| 1883 | __ j(not_zero, &call_runtime); |
| 1884 | } else { |
| 1885 | // Check if result fits in a smi. |
| 1886 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1887 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1888 | } |
| 1889 | // Tag smi result and return. |
| 1890 | __ SmiTag(eax); |
| 1891 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 1892 | |
| 1893 | // All ops except SHR return a signed int32 that we load in |
| 1894 | // a HeapNumber. |
| 1895 | if (op_ != Token::SHR) { |
| 1896 | __ bind(&non_smi_result); |
| 1897 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1898 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1899 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1900 | switch (mode_) { |
| 1901 | case OVERWRITE_LEFT: |
| 1902 | case OVERWRITE_RIGHT: |
| 1903 | // If the operand was an object, we skip the |
| 1904 | // allocation of a heap number. |
| 1905 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1906 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1907 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1908 | // Fall through! |
| 1909 | case NO_OVERWRITE: |
| 1910 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1911 | __ bind(&skip_allocation); |
| 1912 | break; |
| 1913 | default: UNREACHABLE(); |
| 1914 | } |
| 1915 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1916 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1917 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1918 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1919 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1920 | } else { |
| 1921 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1922 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1923 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1924 | } |
| 1925 | __ ret(2 * kPointerSize); |
| 1926 | } |
| 1927 | break; |
| 1928 | } |
| 1929 | default: UNREACHABLE(); break; |
| 1930 | } |
| 1931 | |
| 1932 | // If all else fails, use the runtime system to get the correct |
| 1933 | // result. |
| 1934 | __ bind(&call_runtime); |
| 1935 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1936 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1937 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1938 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1939 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1940 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1941 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1942 | break; |
| 1943 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1944 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1945 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1946 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1947 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1948 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1949 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1950 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1951 | break; |
| 1952 | default: |
| 1953 | UNREACHABLE(); |
| 1954 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1955 | |
| 1956 | { |
| 1957 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1958 | __ push(edx); |
| 1959 | __ push(eax); |
| 1960 | GenerateCallRuntime(masm); |
| 1961 | } |
| 1962 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1966 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1967 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1968 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1969 | |
| 1970 | // Registers containing left and right operands respectively. |
| 1971 | Register left = edx; |
| 1972 | Register right = eax; |
| 1973 | |
| 1974 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1975 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1976 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1977 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1978 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1979 | StringAddStub string_add_left_stub((StringAddFlags) |
| 1980 | (ERECT_FRAME | NO_STRING_CHECK_LEFT_IN_STUB)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1981 | GenerateRegisterArgsPush(masm); |
| 1982 | __ TailCallStub(&string_add_left_stub); |
| 1983 | |
| 1984 | // Left operand is not a string, test right. |
| 1985 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1986 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1987 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1988 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1989 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1990 | StringAddStub string_add_right_stub((StringAddFlags) |
| 1991 | (ERECT_FRAME | NO_STRING_CHECK_RIGHT_IN_STUB)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1992 | GenerateRegisterArgsPush(masm); |
| 1993 | __ TailCallStub(&string_add_right_stub); |
| 1994 | |
| 1995 | // Neither argument is a string. |
| 1996 | __ bind(&call_runtime); |
| 1997 | } |
| 1998 | |
| 1999 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2000 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2001 | Label* alloc_failure, |
| 2002 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2003 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2004 | switch (mode) { |
| 2005 | case OVERWRITE_LEFT: { |
| 2006 | // If the argument in edx is already an object, we skip the |
| 2007 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2008 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2009 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2010 | // for the possible runtime call. |
| 2011 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2012 | // Now edx can be overwritten losing one of the arguments as we are |
| 2013 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2014 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2015 | __ bind(&skip_allocation); |
| 2016 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2017 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2018 | break; |
| 2019 | } |
| 2020 | case OVERWRITE_RIGHT: |
| 2021 | // If the argument in eax is already an object, we skip the |
| 2022 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2023 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2024 | // Fall through! |
| 2025 | case NO_OVERWRITE: |
| 2026 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2027 | // for the possible runtime call. |
| 2028 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2029 | // Now eax can be overwritten losing one of the arguments as we are |
| 2030 | // now done and will not need it any more. |
| 2031 | __ mov(eax, ebx); |
| 2032 | __ bind(&skip_allocation); |
| 2033 | break; |
| 2034 | default: UNREACHABLE(); |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2039 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2040 | __ pop(ecx); |
| 2041 | __ push(edx); |
| 2042 | __ push(eax); |
| 2043 | __ push(ecx); |
| 2044 | } |
| 2045 | |
| 2046 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2047 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2048 | // TAGGED case: |
| 2049 | // Input: |
| 2050 | // esp[4]: tagged number input argument (should be number). |
| 2051 | // esp[0]: return address. |
| 2052 | // Output: |
| 2053 | // eax: tagged double result. |
| 2054 | // UNTAGGED case: |
| 2055 | // Input:: |
| 2056 | // esp[0]: return address. |
| 2057 | // xmm1: untagged double input argument |
| 2058 | // Output: |
| 2059 | // xmm1: untagged double result. |
| 2060 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2061 | Label runtime_call; |
| 2062 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2063 | Label skip_cache; |
| 2064 | const bool tagged = (argument_type_ == TAGGED); |
| 2065 | if (tagged) { |
| 2066 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2067 | Label input_not_smi; |
| 2068 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2069 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2070 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2071 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2072 | // Then load the low and high words of the double into ebx, edx. |
| 2073 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2074 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2075 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2076 | __ mov(Operand(esp, 0), eax); |
| 2077 | __ fild_s(Operand(esp, 0)); |
| 2078 | __ fst_d(Operand(esp, 0)); |
| 2079 | __ pop(edx); |
| 2080 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2081 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2082 | __ bind(&input_not_smi); |
| 2083 | // Check if input is a HeapNumber. |
| 2084 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2085 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2086 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2087 | __ j(not_equal, &runtime_call); |
| 2088 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2089 | // low and high words into ebx, edx. |
| 2090 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2091 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2092 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2093 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2094 | __ bind(&loaded); |
| 2095 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2096 | CpuFeatureScope scope(masm, SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2097 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2098 | CpuFeatureScope sse4_scope(masm, SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2099 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2100 | } else { |
| 2101 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2102 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2103 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2104 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2108 | // ebx = low 32 bits of double value |
| 2109 | // edx = high 32 bits of double value |
| 2110 | // Compute hash (the shifts are arithmetic): |
| 2111 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2112 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2113 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2114 | __ mov(eax, ecx); |
| 2115 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2116 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2117 | __ mov(eax, ecx); |
| 2118 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2119 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2120 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2121 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2122 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2123 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2124 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2125 | // ebx = low 32 bits of double value. |
| 2126 | // edx = high 32 bits of double value. |
| 2127 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2128 | ExternalReference cache_array = |
| 2129 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2130 | __ mov(eax, Immediate(cache_array)); |
| 2131 | int cache_array_index = |
| 2132 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2133 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2134 | // Eax points to the cache for the type type_. |
| 2135 | // 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] | 2136 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2137 | __ j(zero, &runtime_call_clear_stack); |
| 2138 | #ifdef DEBUG |
| 2139 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2140 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2141 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2142 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2143 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2144 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2145 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2146 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2147 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2148 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2149 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2150 | } |
| 2151 | #endif |
| 2152 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2153 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2154 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2155 | // 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] | 2156 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2157 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2158 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2159 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2160 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2161 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2162 | Counters* counters = masm->isolate()->counters(); |
| 2163 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2164 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2165 | if (tagged) { |
| 2166 | __ fstp(0); |
| 2167 | __ ret(kPointerSize); |
| 2168 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2169 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2170 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2171 | __ Ret(); |
| 2172 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2173 | |
| 2174 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2175 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2176 | // Update cache with new value. |
| 2177 | // We are short on registers, so use no_reg as scratch. |
| 2178 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2179 | if (tagged) { |
| 2180 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2181 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2182 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2183 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2184 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2185 | __ movdbl(Operand(esp, 0), xmm1); |
| 2186 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2187 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2188 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2189 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2190 | __ mov(Operand(ecx, 0), ebx); |
| 2191 | __ mov(Operand(ecx, kIntSize), edx); |
| 2192 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2193 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2194 | if (tagged) { |
| 2195 | __ ret(kPointerSize); |
| 2196 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2197 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2198 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2199 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2200 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2201 | // Skip cache and return answer directly, only in untagged case. |
| 2202 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2203 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2204 | __ movdbl(Operand(esp, 0), xmm1); |
| 2205 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2206 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2207 | __ fstp_d(Operand(esp, 0)); |
| 2208 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2209 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2210 | // We return the value in xmm1 without adding it to the cache, but |
| 2211 | // 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] | 2212 | { |
| 2213 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2214 | // Allocate an unused object bigger than a HeapNumber. |
| 2215 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2216 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2217 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2218 | __ Ret(); |
| 2219 | } |
| 2220 | |
| 2221 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2222 | if (tagged) { |
| 2223 | __ bind(&runtime_call_clear_stack); |
| 2224 | __ fstp(0); |
| 2225 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2226 | ExternalReference runtime = |
| 2227 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2228 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2229 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2230 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2231 | __ bind(&runtime_call_clear_stack); |
| 2232 | __ bind(&runtime_call); |
| 2233 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2234 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2235 | { |
| 2236 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2237 | __ push(eax); |
| 2238 | __ CallRuntime(RuntimeFunction(), 1); |
| 2239 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2240 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2241 | __ Ret(); |
| 2242 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2243 | } |
| 2244 | |
| 2245 | |
| 2246 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2247 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2248 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2249 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2250 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2251 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2252 | default: |
| 2253 | UNIMPLEMENTED(); |
| 2254 | return Runtime::kAbort; |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2259 | void TranscendentalCacheStub::GenerateOperation( |
| 2260 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2261 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2262 | // Input value is on FP stack, and also in ebx/edx. |
| 2263 | // Input value is possibly in xmm1. |
| 2264 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2265 | if (type == TranscendentalCache::SIN || |
| 2266 | type == TranscendentalCache::COS || |
| 2267 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2268 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2269 | // return NaN for infinities and NaN. They can share all code except |
| 2270 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2271 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2272 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2273 | // work. We must reduce it to the appropriate range. |
| 2274 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2275 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2276 | int supported_exponent_limit = |
| 2277 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2278 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2279 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2280 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2281 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2282 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2283 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2284 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2285 | __ fstp(0); |
| 2286 | // NaN is represented by 0x7ff8000000000000. |
| 2287 | __ push(Immediate(0x7ff80000)); |
| 2288 | __ push(Immediate(0)); |
| 2289 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2290 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2291 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2292 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2293 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2294 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2295 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2296 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2297 | __ fldpi(); |
| 2298 | __ fadd(0); |
| 2299 | __ fld(1); |
| 2300 | // FPU Stack: input, 2*pi, input. |
| 2301 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2302 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2303 | __ fwait(); |
| 2304 | __ fnstsw_ax(); |
| 2305 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2306 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2307 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2308 | __ fnclex(); |
| 2309 | __ bind(&no_exceptions); |
| 2310 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2311 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2312 | // Compute st(0) % st(1) |
| 2313 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2314 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2315 | __ bind(&partial_remainder_loop); |
| 2316 | __ fprem1(); |
| 2317 | __ fwait(); |
| 2318 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2319 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2320 | // If C2 is set, computation only has partial result. Loop to |
| 2321 | // continue computation. |
| 2322 | __ j(not_zero, &partial_remainder_loop); |
| 2323 | } |
| 2324 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2325 | __ fstp(2); |
| 2326 | __ fstp(0); |
| 2327 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2328 | |
| 2329 | // FPU Stack: input % 2*pi |
| 2330 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2331 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2332 | case TranscendentalCache::SIN: |
| 2333 | __ fsin(); |
| 2334 | break; |
| 2335 | case TranscendentalCache::COS: |
| 2336 | __ fcos(); |
| 2337 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2338 | case TranscendentalCache::TAN: |
| 2339 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2340 | // FP register stack. |
| 2341 | __ fptan(); |
| 2342 | __ fstp(0); // Pop FP register stack. |
| 2343 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2344 | default: |
| 2345 | UNREACHABLE(); |
| 2346 | } |
| 2347 | __ bind(&done); |
| 2348 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2349 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2350 | __ fldln2(); |
| 2351 | __ fxch(); |
| 2352 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2353 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2357 | // Input: edx, eax are the left and right objects of a bit op. |
| 2358 | // 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] | 2359 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2360 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2361 | MacroAssembler* masm, |
| 2362 | bool use_sse3, |
| 2363 | BinaryOpIC::TypeInfo left_type, |
| 2364 | BinaryOpIC::TypeInfo right_type, |
| 2365 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2366 | // Check float operands. |
| 2367 | Label arg1_is_object, check_undefined_arg1; |
| 2368 | Label arg2_is_object, check_undefined_arg2; |
| 2369 | Label load_arg2, done; |
| 2370 | |
| 2371 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2372 | if (left_type == BinaryOpIC::SMI) { |
| 2373 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2374 | } else { |
| 2375 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2376 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2377 | |
| 2378 | __ SmiUntag(edx); |
| 2379 | __ jmp(&load_arg2); |
| 2380 | |
| 2381 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2382 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2383 | Factory* factory = masm->isolate()->factory(); |
| 2384 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2385 | __ j(not_equal, conversion_failure); |
| 2386 | __ mov(edx, Immediate(0)); |
| 2387 | __ jmp(&load_arg2); |
| 2388 | |
| 2389 | __ bind(&arg1_is_object); |
| 2390 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2391 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2392 | __ j(not_equal, &check_undefined_arg1); |
| 2393 | |
| 2394 | // 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] | 2395 | if (left_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2396 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2397 | ConvertHeapNumberToInt32(masm, edx, conversion_failure); |
| 2398 | } else { |
| 2399 | IntegerConvert(masm, edx, use_sse3, conversion_failure); |
| 2400 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2401 | __ mov(edx, ecx); |
| 2402 | |
| 2403 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2404 | __ bind(&load_arg2); |
| 2405 | |
| 2406 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2407 | if (right_type == BinaryOpIC::SMI) { |
| 2408 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2409 | } else { |
| 2410 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2411 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2412 | |
| 2413 | __ SmiUntag(eax); |
| 2414 | __ mov(ecx, eax); |
| 2415 | __ jmp(&done); |
| 2416 | |
| 2417 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2418 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2419 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2420 | __ j(not_equal, conversion_failure); |
| 2421 | __ mov(ecx, Immediate(0)); |
| 2422 | __ jmp(&done); |
| 2423 | |
| 2424 | __ bind(&arg2_is_object); |
| 2425 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2426 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2427 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2428 | // 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] | 2429 | |
| 2430 | if (right_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2431 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2432 | ConvertHeapNumberToInt32(masm, eax, conversion_failure); |
| 2433 | } else { |
| 2434 | IntegerConvert(masm, eax, use_sse3, conversion_failure); |
| 2435 | } |
| 2436 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2437 | __ bind(&done); |
| 2438 | __ mov(eax, edx); |
| 2439 | } |
| 2440 | |
| 2441 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2442 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2443 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2444 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2445 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2446 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2447 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2448 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2449 | |
| 2450 | __ bind(&load_smi); |
| 2451 | __ SmiUntag(number); |
| 2452 | __ push(number); |
| 2453 | __ fild_s(Operand(esp, 0)); |
| 2454 | __ pop(number); |
| 2455 | |
| 2456 | __ bind(&done); |
| 2457 | } |
| 2458 | |
| 2459 | |
| 2460 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2461 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2462 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2463 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2464 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2465 | |
| 2466 | __ bind(&load_eax); |
| 2467 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2468 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2469 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2470 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2471 | |
| 2472 | __ bind(&load_smi_edx); |
| 2473 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2474 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2475 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2476 | __ jmp(&load_eax); |
| 2477 | |
| 2478 | __ bind(&load_smi_eax); |
| 2479 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2480 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2481 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2482 | |
| 2483 | __ bind(&done); |
| 2484 | } |
| 2485 | |
| 2486 | |
| 2487 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2488 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2489 | 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] | 2490 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2491 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2492 | Factory* factory = masm->isolate()->factory(); |
| 2493 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2494 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2495 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2496 | __ bind(&load_eax); |
| 2497 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2498 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2499 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2500 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2501 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2502 | __ bind(&load_smi_edx); |
| 2503 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2504 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2505 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2506 | __ jmp(&load_eax); |
| 2507 | __ bind(&load_smi_eax); |
| 2508 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2509 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2510 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2511 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2512 | __ bind(&load_float_eax); |
| 2513 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2514 | __ bind(&done); |
| 2515 | } |
| 2516 | |
| 2517 | |
| 2518 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2519 | Register scratch) { |
| 2520 | const Register left = edx; |
| 2521 | const Register right = eax; |
| 2522 | __ mov(scratch, left); |
| 2523 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2524 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2525 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2526 | |
| 2527 | __ mov(scratch, right); |
| 2528 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2529 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2533 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2534 | Label* non_int32, |
| 2535 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2536 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2537 | Register scratch, |
| 2538 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2539 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2540 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2541 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2542 | __ movmskps(scratch, xmm_scratch); |
| 2543 | // Two least significant bits should be both set. |
| 2544 | __ not_(scratch); |
| 2545 | __ test(scratch, Immediate(3)); |
| 2546 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2550 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2551 | Register scratch, |
| 2552 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2553 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2554 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2555 | __ mov(scratch, edx); |
| 2556 | } else { |
| 2557 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2558 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2559 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2560 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2561 | __ bind(&done_load_1); |
| 2562 | |
| 2563 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2564 | __ mov(scratch, eax); |
| 2565 | } else { |
| 2566 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2567 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2568 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2569 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2570 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2571 | |
| 2572 | __ bind(&load_smi_1); |
| 2573 | __ SmiUntag(scratch); |
| 2574 | __ push(scratch); |
| 2575 | __ fild_s(Operand(esp, 0)); |
| 2576 | __ pop(scratch); |
| 2577 | __ jmp(&done_load_1); |
| 2578 | |
| 2579 | __ bind(&load_smi_2); |
| 2580 | __ SmiUntag(scratch); |
| 2581 | __ push(scratch); |
| 2582 | __ fild_s(Operand(esp, 0)); |
| 2583 | __ pop(scratch); |
| 2584 | |
| 2585 | __ bind(&done); |
| 2586 | } |
| 2587 | |
| 2588 | |
| 2589 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2590 | Register scratch) { |
| 2591 | const Register left = edx; |
| 2592 | const Register right = eax; |
| 2593 | __ mov(scratch, left); |
| 2594 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2595 | __ SmiUntag(scratch); |
| 2596 | __ push(scratch); |
| 2597 | __ fild_s(Operand(esp, 0)); |
| 2598 | |
| 2599 | __ mov(scratch, right); |
| 2600 | __ SmiUntag(scratch); |
| 2601 | __ mov(Operand(esp, 0), scratch); |
| 2602 | __ fild_s(Operand(esp, 0)); |
| 2603 | __ pop(scratch); |
| 2604 | } |
| 2605 | |
| 2606 | |
| 2607 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2608 | Label* non_float, |
| 2609 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2610 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2611 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2612 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2613 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2614 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2615 | Factory* factory = masm->isolate()->factory(); |
| 2616 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2617 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2618 | |
| 2619 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2620 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2621 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2622 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2623 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2624 | |
| 2625 | // Fall-through: Both operands are numbers. |
| 2626 | __ bind(&done); |
| 2627 | } |
| 2628 | |
| 2629 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2630 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2631 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2632 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2633 | const Register exponent = eax; |
| 2634 | const Register base = edx; |
| 2635 | const Register scratch = ecx; |
| 2636 | const XMMRegister double_result = xmm3; |
| 2637 | const XMMRegister double_base = xmm2; |
| 2638 | const XMMRegister double_exponent = xmm1; |
| 2639 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2640 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2641 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2642 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2643 | // Save 1 in double_result - we need this several times later on. |
| 2644 | __ mov(scratch, Immediate(1)); |
| 2645 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2646 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2647 | if (exponent_type_ == ON_STACK) { |
| 2648 | Label base_is_smi, unpack_exponent; |
| 2649 | // The exponent and base are supplied as arguments on the stack. |
| 2650 | // This can only happen if the stub is called from non-optimized code. |
| 2651 | // Load input parameters from stack. |
| 2652 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 2653 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 2654 | |
| 2655 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2656 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 2657 | factory->heap_number_map()); |
| 2658 | __ j(not_equal, &call_runtime); |
| 2659 | |
| 2660 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2661 | __ jmp(&unpack_exponent, Label::kNear); |
| 2662 | |
| 2663 | __ bind(&base_is_smi); |
| 2664 | __ SmiUntag(base); |
| 2665 | __ cvtsi2sd(double_base, base); |
| 2666 | |
| 2667 | __ bind(&unpack_exponent); |
| 2668 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2669 | __ SmiUntag(exponent); |
| 2670 | __ jmp(&int_exponent); |
| 2671 | |
| 2672 | __ bind(&exponent_not_smi); |
| 2673 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2674 | factory->heap_number_map()); |
| 2675 | __ j(not_equal, &call_runtime); |
| 2676 | __ movdbl(double_exponent, |
| 2677 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2678 | } else if (exponent_type_ == TAGGED) { |
| 2679 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2680 | __ SmiUntag(exponent); |
| 2681 | __ jmp(&int_exponent); |
| 2682 | |
| 2683 | __ bind(&exponent_not_smi); |
| 2684 | __ movdbl(double_exponent, |
| 2685 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2686 | } |
| 2687 | |
| 2688 | if (exponent_type_ != INTEGER) { |
| 2689 | Label fast_power; |
| 2690 | // Detect integer exponents stored as double. |
| 2691 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 2692 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 2693 | __ cmp(exponent, Immediate(0x80000000u)); |
| 2694 | __ j(equal, &call_runtime); |
| 2695 | __ cvtsi2sd(double_scratch, exponent); |
| 2696 | // Already ruled out NaNs for exponent. |
| 2697 | __ ucomisd(double_exponent, double_scratch); |
| 2698 | __ j(equal, &int_exponent); |
| 2699 | |
| 2700 | if (exponent_type_ == ON_STACK) { |
| 2701 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 2702 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 2703 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 2704 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 2705 | // Test for 0.5. |
| 2706 | // Load double_scratch with 0.5. |
| 2707 | __ mov(scratch, Immediate(0x3F000000u)); |
| 2708 | __ movd(double_scratch, scratch); |
| 2709 | __ cvtss2sd(double_scratch, double_scratch); |
| 2710 | // Already ruled out NaNs for exponent. |
| 2711 | __ ucomisd(double_scratch, double_exponent); |
| 2712 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 2713 | |
| 2714 | // Calculates square root of base. Check for the special case of |
| 2715 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 2716 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2717 | // 9 bits set and the lowest 23 bits cleared. |
| 2718 | __ mov(scratch, 0xFF800000u); |
| 2719 | __ movd(double_scratch, scratch); |
| 2720 | __ cvtss2sd(double_scratch, double_scratch); |
| 2721 | __ ucomisd(double_base, double_scratch); |
| 2722 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2723 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2724 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 2725 | __ j(carry, &continue_sqrt, Label::kNear); |
| 2726 | |
| 2727 | // Set result to Infinity in the special case. |
| 2728 | __ xorps(double_result, double_result); |
| 2729 | __ subsd(double_result, double_scratch); |
| 2730 | __ jmp(&done); |
| 2731 | |
| 2732 | __ bind(&continue_sqrt); |
| 2733 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2734 | __ xorps(double_scratch, double_scratch); |
| 2735 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 2736 | __ sqrtsd(double_result, double_scratch); |
| 2737 | __ jmp(&done); |
| 2738 | |
| 2739 | // Test for -0.5. |
| 2740 | __ bind(¬_plus_half); |
| 2741 | // Load double_exponent with -0.5 by substracting 1. |
| 2742 | __ subsd(double_scratch, double_result); |
| 2743 | // Already ruled out NaNs for exponent. |
| 2744 | __ ucomisd(double_scratch, double_exponent); |
| 2745 | __ j(not_equal, &fast_power, Label::kNear); |
| 2746 | |
| 2747 | // Calculates reciprocal of square root of base. Check for the special |
| 2748 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 2749 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2750 | // 9 bits set and the lowest 23 bits cleared. |
| 2751 | __ mov(scratch, 0xFF800000u); |
| 2752 | __ movd(double_scratch, scratch); |
| 2753 | __ cvtss2sd(double_scratch, double_scratch); |
| 2754 | __ ucomisd(double_base, double_scratch); |
| 2755 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2756 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2757 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 2758 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 2759 | |
| 2760 | // Set result to 0 in the special case. |
| 2761 | __ xorps(double_result, double_result); |
| 2762 | __ jmp(&done); |
| 2763 | |
| 2764 | __ bind(&continue_rsqrt); |
| 2765 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2766 | __ xorps(double_exponent, double_exponent); |
| 2767 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 2768 | __ sqrtsd(double_exponent, double_exponent); |
| 2769 | __ divsd(double_result, double_exponent); |
| 2770 | __ jmp(&done); |
| 2771 | } |
| 2772 | |
| 2773 | // Using FPU instructions to calculate power. |
| 2774 | Label fast_power_failed; |
| 2775 | __ bind(&fast_power); |
| 2776 | __ fnclex(); // Clear flags to catch exceptions later. |
| 2777 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 2778 | __ sub(esp, Immediate(kDoubleSize)); |
| 2779 | __ movdbl(Operand(esp, 0), double_exponent); |
| 2780 | __ fld_d(Operand(esp, 0)); // E |
| 2781 | __ movdbl(Operand(esp, 0), double_base); |
| 2782 | __ fld_d(Operand(esp, 0)); // B, E |
| 2783 | |
| 2784 | // Exponent is in st(1) and base is in st(0) |
| 2785 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 2786 | // FYL2X calculates st(1) * log2(st(0)) |
| 2787 | __ fyl2x(); // X |
| 2788 | __ fld(0); // X, X |
| 2789 | __ frndint(); // rnd(X), X |
| 2790 | __ fsub(1); // rnd(X), X-rnd(X) |
| 2791 | __ fxch(1); // X - rnd(X), rnd(X) |
| 2792 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 2793 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 2794 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2795 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2796 | // FSCALE calculates st(0) * 2^st(1) |
| 2797 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2798 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2799 | // Bail out to runtime in case of exceptions in the status word. |
| 2800 | __ fnstsw_ax(); |
| 2801 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 2802 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 2803 | __ fstp_d(Operand(esp, 0)); |
| 2804 | __ movdbl(double_result, Operand(esp, 0)); |
| 2805 | __ add(esp, Immediate(kDoubleSize)); |
| 2806 | __ jmp(&done); |
| 2807 | |
| 2808 | __ bind(&fast_power_failed); |
| 2809 | __ fninit(); |
| 2810 | __ add(esp, Immediate(kDoubleSize)); |
| 2811 | __ jmp(&call_runtime); |
| 2812 | } |
| 2813 | |
| 2814 | // Calculate power with integer exponent. |
| 2815 | __ bind(&int_exponent); |
| 2816 | const XMMRegister double_scratch2 = double_exponent; |
| 2817 | __ mov(scratch, exponent); // Back up exponent. |
| 2818 | __ movsd(double_scratch, double_base); // Back up base. |
| 2819 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2820 | |
| 2821 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2822 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2823 | __ test(scratch, scratch); |
| 2824 | __ j(positive, &no_neg, Label::kNear); |
| 2825 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2826 | __ bind(&no_neg); |
| 2827 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2828 | __ j(zero, &while_false, Label::kNear); |
| 2829 | __ shr(scratch, 1); |
| 2830 | // Above condition means CF==0 && ZF==0. This means that the |
| 2831 | // bit that has been shifted out is 0 and the result is not 0. |
| 2832 | __ j(above, &while_true, Label::kNear); |
| 2833 | __ movsd(double_result, double_scratch); |
| 2834 | __ j(zero, &while_false, Label::kNear); |
| 2835 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2836 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2837 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2838 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2839 | __ j(above, &while_true, Label::kNear); |
| 2840 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2841 | __ j(not_zero, &while_true); |
| 2842 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2843 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2844 | // scratch has the original value of the exponent - if the exponent is |
| 2845 | // negative, return 1/result. |
| 2846 | __ test(exponent, exponent); |
| 2847 | __ j(positive, &done); |
| 2848 | __ divsd(double_scratch2, double_result); |
| 2849 | __ movsd(double_result, double_scratch2); |
| 2850 | // Test whether result is zero. Bail out to check for subnormal result. |
| 2851 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 2852 | __ xorps(double_scratch2, double_scratch2); |
| 2853 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 2854 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 2855 | // and may not have contained the exponent value in the first place when the |
| 2856 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 2857 | __ j(not_equal, &done); |
| 2858 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2859 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2860 | // Returning or bailing out. |
| 2861 | Counters* counters = masm->isolate()->counters(); |
| 2862 | if (exponent_type_ == ON_STACK) { |
| 2863 | // The arguments are still on the stack. |
| 2864 | __ bind(&call_runtime); |
| 2865 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2866 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2867 | // The stub is called from non-optimized code, which expects the result |
| 2868 | // as heap number in exponent. |
| 2869 | __ bind(&done); |
| 2870 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 2871 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 2872 | __ IncrementCounter(counters->math_pow(), 1); |
| 2873 | __ ret(2 * kPointerSize); |
| 2874 | } else { |
| 2875 | __ bind(&call_runtime); |
| 2876 | { |
| 2877 | AllowExternalCallThatCantCauseGC scope(masm); |
| 2878 | __ PrepareCallCFunction(4, scratch); |
| 2879 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 2880 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 2881 | __ CallCFunction( |
| 2882 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 2883 | } |
| 2884 | // Return value is in st(0) on ia32. |
| 2885 | // Store it into the (fixed) result register. |
| 2886 | __ sub(esp, Immediate(kDoubleSize)); |
| 2887 | __ fstp_d(Operand(esp, 0)); |
| 2888 | __ movdbl(double_result, Operand(esp, 0)); |
| 2889 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2890 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2891 | __ bind(&done); |
| 2892 | __ IncrementCounter(counters->math_pow(), 1); |
| 2893 | __ ret(0); |
| 2894 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2895 | } |
| 2896 | |
| 2897 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2898 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 2899 | // ----------- S t a t e ------------- |
| 2900 | // -- ecx : name |
| 2901 | // -- edx : receiver |
| 2902 | // -- esp[0] : return address |
| 2903 | // ----------------------------------- |
| 2904 | Label miss; |
| 2905 | |
| 2906 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2907 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2908 | __ j(not_equal, &miss); |
| 2909 | } |
| 2910 | |
| 2911 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 2912 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 2913 | StubCompiler::TailCallBuiltin( |
| 2914 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
| 2917 | |
| 2918 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 2919 | // ----------- S t a t e ------------- |
| 2920 | // -- ecx : name |
| 2921 | // -- edx : receiver |
| 2922 | // -- esp[0] : return address |
| 2923 | // ----------------------------------- |
| 2924 | Label miss; |
| 2925 | |
| 2926 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2927 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2928 | __ j(not_equal, &miss); |
| 2929 | } |
| 2930 | |
| 2931 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 2932 | support_wrapper_); |
| 2933 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 2934 | StubCompiler::TailCallBuiltin( |
| 2935 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2939 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 2940 | // ----------- S t a t e ------------- |
| 2941 | // -- eax : value |
| 2942 | // -- ecx : name |
| 2943 | // -- edx : receiver |
| 2944 | // -- esp[0] : return address |
| 2945 | // ----------------------------------- |
| 2946 | // |
| 2947 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 2948 | // (currently anything except for external arrays which means anything with |
| 2949 | // elements of FixedArray type). Value must be a number, but only smis are |
| 2950 | // accepted as the most common case. |
| 2951 | |
| 2952 | Label miss; |
| 2953 | |
| 2954 | Register receiver = edx; |
| 2955 | Register value = eax; |
| 2956 | Register scratch = ebx; |
| 2957 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2958 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2959 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2960 | __ j(not_equal, &miss); |
| 2961 | } |
| 2962 | |
| 2963 | // Check that the receiver isn't a smi. |
| 2964 | __ JumpIfSmi(receiver, &miss); |
| 2965 | |
| 2966 | // Check that the object is a JS array. |
| 2967 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 2968 | __ j(not_equal, &miss); |
| 2969 | |
| 2970 | // Check that elements are FixedArray. |
| 2971 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 2972 | // fast elements (including COW). |
| 2973 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 2974 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 2975 | __ j(not_equal, &miss); |
| 2976 | |
| 2977 | // Check that the array has fast properties, otherwise the length |
| 2978 | // property might have been redefined. |
| 2979 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 2980 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 2981 | Heap::kHashTableMapRootIndex); |
| 2982 | __ j(equal, &miss); |
| 2983 | |
| 2984 | // Check that value is a smi. |
| 2985 | __ JumpIfNotSmi(value, &miss); |
| 2986 | |
| 2987 | // Prepare tail call to StoreIC_ArrayLength. |
| 2988 | __ pop(scratch); |
| 2989 | __ push(receiver); |
| 2990 | __ push(value); |
| 2991 | __ push(scratch); // return address |
| 2992 | |
| 2993 | ExternalReference ref = |
| 2994 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 2995 | __ TailCallExternalReference(ref, 2, 1); |
| 2996 | |
| 2997 | __ bind(&miss); |
| 2998 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 2999 | StubCompiler::TailCallBuiltin( |
| 3000 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3004 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3005 | // The key is in edx and the parameter count is in eax. |
| 3006 | |
| 3007 | // The displacement is used for skipping the frame pointer on the |
| 3008 | // stack. It is the offset of the last parameter (if any) relative |
| 3009 | // to the frame pointer. |
| 3010 | static const int kDisplacement = 1 * kPointerSize; |
| 3011 | |
| 3012 | // Check that the key is a smi. |
| 3013 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3014 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3015 | |
| 3016 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3017 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3018 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3019 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3020 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3021 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3022 | |
| 3023 | // Check index against formal parameters count limit passed in |
| 3024 | // through register eax. Use unsigned comparison to get negative |
| 3025 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3026 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3027 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3028 | |
| 3029 | // Read the argument from the stack and return it. |
| 3030 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3031 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3032 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3033 | __ neg(edx); |
| 3034 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3035 | __ ret(0); |
| 3036 | |
| 3037 | // Arguments adaptor case: Check index against actual arguments |
| 3038 | // limit found in the arguments adaptor frame. Use unsigned |
| 3039 | // comparison to get negative check for free. |
| 3040 | __ bind(&adaptor); |
| 3041 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3042 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3043 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3044 | |
| 3045 | // Read the argument from the stack and return it. |
| 3046 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3047 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3048 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3049 | __ neg(edx); |
| 3050 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3051 | __ ret(0); |
| 3052 | |
| 3053 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3054 | // by calling the runtime system. |
| 3055 | __ bind(&slow); |
| 3056 | __ pop(ebx); // Return address. |
| 3057 | __ push(edx); |
| 3058 | __ push(ebx); |
| 3059 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3060 | } |
| 3061 | |
| 3062 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3063 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3064 | // esp[0] : return address |
| 3065 | // esp[4] : number of parameters |
| 3066 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3067 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3068 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3069 | // Check if the calling frame is an arguments adaptor frame. |
| 3070 | Label runtime; |
| 3071 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3072 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3073 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3074 | __ j(not_equal, &runtime, Label::kNear); |
| 3075 | |
| 3076 | // Patch the arguments.length and the parameters pointer. |
| 3077 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3078 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3079 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3080 | StandardFrameConstants::kCallerSPOffset)); |
| 3081 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3082 | |
| 3083 | __ bind(&runtime); |
| 3084 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3085 | } |
| 3086 | |
| 3087 | |
| 3088 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3089 | Isolate* isolate = masm->isolate(); |
| 3090 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3091 | // esp[0] : return address |
| 3092 | // esp[4] : number of parameters (tagged) |
| 3093 | // esp[8] : receiver displacement |
| 3094 | // esp[12] : function |
| 3095 | |
| 3096 | // ebx = parameter count (tagged) |
| 3097 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3098 | |
| 3099 | // Check if the calling frame is an arguments adaptor frame. |
| 3100 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3101 | // Generate* functions. |
| 3102 | Label runtime; |
| 3103 | Label adaptor_frame, try_allocate; |
| 3104 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3105 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3106 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3107 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3108 | |
| 3109 | // No adaptor, parameter count = argument count. |
| 3110 | __ mov(ecx, ebx); |
| 3111 | __ jmp(&try_allocate, Label::kNear); |
| 3112 | |
| 3113 | // We have an adaptor frame. Patch the parameters pointer. |
| 3114 | __ bind(&adaptor_frame); |
| 3115 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3116 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3117 | StandardFrameConstants::kCallerSPOffset)); |
| 3118 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3119 | |
| 3120 | // ebx = parameter count (tagged) |
| 3121 | // ecx = argument count (tagged) |
| 3122 | // esp[4] = parameter count (tagged) |
| 3123 | // esp[8] = address of receiver argument |
| 3124 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3125 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3126 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3127 | __ mov(ebx, ecx); |
| 3128 | |
| 3129 | __ bind(&try_allocate); |
| 3130 | |
| 3131 | // Save mapped parameter count. |
| 3132 | __ push(ebx); |
| 3133 | |
| 3134 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3135 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3136 | const int kParameterMapHeaderSize = |
| 3137 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3138 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3139 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3140 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3141 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3142 | __ bind(&no_parameter_map); |
| 3143 | |
| 3144 | // 2. Backing store. |
| 3145 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3146 | |
| 3147 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3148 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3149 | |
| 3150 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3151 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3152 | |
| 3153 | // eax = address of new object(s) (tagged) |
| 3154 | // ecx = argument count (tagged) |
| 3155 | // esp[0] = mapped parameter count (tagged) |
| 3156 | // esp[8] = parameter count (tagged) |
| 3157 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3158 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3159 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3160 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3161 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3162 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3163 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3164 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3165 | __ mov(edi, Operand(edi, |
| 3166 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3167 | __ jmp(©, Label::kNear); |
| 3168 | |
| 3169 | __ bind(&has_mapped_parameters); |
| 3170 | __ mov(edi, Operand(edi, |
| 3171 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3172 | __ bind(©); |
| 3173 | |
| 3174 | // eax = address of new object (tagged) |
| 3175 | // ebx = mapped parameter count (tagged) |
| 3176 | // ecx = argument count (tagged) |
| 3177 | // edi = address of boilerplate object (tagged) |
| 3178 | // esp[0] = mapped parameter count (tagged) |
| 3179 | // esp[8] = parameter count (tagged) |
| 3180 | // esp[12] = address of receiver argument |
| 3181 | // Copy the JS object part. |
| 3182 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3183 | __ mov(edx, FieldOperand(edi, i)); |
| 3184 | __ mov(FieldOperand(eax, i), edx); |
| 3185 | } |
| 3186 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3187 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3188 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3189 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3190 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3191 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3192 | edx); |
| 3193 | |
| 3194 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3195 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3196 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3197 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3198 | ecx); |
| 3199 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3200 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3201 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3202 | // backing store. |
| 3203 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3204 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3205 | |
| 3206 | // eax = address of new object (tagged) |
| 3207 | // ebx = mapped parameter count (tagged) |
| 3208 | // ecx = argument count (tagged) |
| 3209 | // edi = address of parameter map or backing store (tagged) |
| 3210 | // esp[0] = mapped parameter count (tagged) |
| 3211 | // esp[8] = parameter count (tagged) |
| 3212 | // esp[12] = address of receiver argument |
| 3213 | // Free a register. |
| 3214 | __ push(eax); |
| 3215 | |
| 3216 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3217 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3218 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3219 | __ j(zero, &skip_parameter_map); |
| 3220 | |
| 3221 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3222 | Immediate(isolate->factory()->non_strict_arguments_elements_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3223 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3224 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3225 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3226 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3227 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3228 | |
| 3229 | // Copy the parameter slots and the holes in the arguments. |
| 3230 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3231 | // where parameters are stored in reverse order, at |
| 3232 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3233 | // The mapped parameter thus need to get indices |
| 3234 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3235 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3236 | // We loop from right to left. |
| 3237 | Label parameters_loop, parameters_test; |
| 3238 | __ push(ecx); |
| 3239 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3240 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3241 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3242 | __ sub(ebx, eax); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3243 | __ mov(ecx, isolate->factory()->the_hole_value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3244 | __ mov(edx, edi); |
| 3245 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3246 | // eax = loop variable (tagged) |
| 3247 | // ebx = mapping index (tagged) |
| 3248 | // ecx = the hole value |
| 3249 | // edx = address of parameter map (tagged) |
| 3250 | // edi = address of backing store (tagged) |
| 3251 | // esp[0] = argument count (tagged) |
| 3252 | // esp[4] = address of new object (tagged) |
| 3253 | // esp[8] = mapped parameter count (tagged) |
| 3254 | // esp[16] = parameter count (tagged) |
| 3255 | // esp[20] = address of receiver argument |
| 3256 | __ jmp(¶meters_test, Label::kNear); |
| 3257 | |
| 3258 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3259 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3260 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3261 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3262 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3263 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3264 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3265 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3266 | __ pop(ecx); |
| 3267 | |
| 3268 | __ bind(&skip_parameter_map); |
| 3269 | |
| 3270 | // ecx = argument count (tagged) |
| 3271 | // edi = address of backing store (tagged) |
| 3272 | // esp[0] = address of new object (tagged) |
| 3273 | // esp[4] = mapped parameter count (tagged) |
| 3274 | // esp[12] = parameter count (tagged) |
| 3275 | // esp[16] = address of receiver argument |
| 3276 | // Copy arguments header and remaining slots (if there are any). |
| 3277 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3278 | Immediate(isolate->factory()->fixed_array_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3279 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3280 | |
| 3281 | Label arguments_loop, arguments_test; |
| 3282 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3283 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3284 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3285 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3286 | __ jmp(&arguments_test, Label::kNear); |
| 3287 | |
| 3288 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3289 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3290 | __ mov(eax, Operand(edx, 0)); |
| 3291 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3292 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3293 | |
| 3294 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3295 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3296 | __ j(less, &arguments_loop, Label::kNear); |
| 3297 | |
| 3298 | // Restore. |
| 3299 | __ pop(eax); // Address of arguments object. |
| 3300 | __ pop(ebx); // Parameter count. |
| 3301 | |
| 3302 | // Return and remove the on-stack parameters. |
| 3303 | __ ret(3 * kPointerSize); |
| 3304 | |
| 3305 | // Do the runtime call to allocate the arguments object. |
| 3306 | __ bind(&runtime); |
| 3307 | __ pop(eax); // Remove saved parameter count. |
| 3308 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3309 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3310 | } |
| 3311 | |
| 3312 | |
| 3313 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3314 | Isolate* isolate = masm->isolate(); |
| 3315 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3316 | // esp[0] : return address |
| 3317 | // esp[4] : number of parameters |
| 3318 | // esp[8] : receiver displacement |
| 3319 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3320 | |
| 3321 | // Check if the calling frame is an arguments adaptor frame. |
| 3322 | Label adaptor_frame, try_allocate, runtime; |
| 3323 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3324 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3325 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3326 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3327 | |
| 3328 | // Get the length from the frame. |
| 3329 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3330 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3331 | |
| 3332 | // Patch the arguments.length and the parameters pointer. |
| 3333 | __ bind(&adaptor_frame); |
| 3334 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3335 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3336 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3337 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3338 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3339 | |
| 3340 | // Try the new space allocation. Start out with computing the size of |
| 3341 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3342 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3343 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3344 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3345 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3346 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3347 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3348 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3349 | |
| 3350 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3351 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3352 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3353 | // Get the arguments boilerplate from the current native context. |
| 3354 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3355 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3356 | const int offset = |
| 3357 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3358 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3359 | |
| 3360 | // Copy the JS object part. |
| 3361 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3362 | __ mov(ebx, FieldOperand(edi, i)); |
| 3363 | __ mov(FieldOperand(eax, i), ebx); |
| 3364 | } |
| 3365 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3366 | // 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] | 3367 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3368 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3369 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3370 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3371 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3372 | |
| 3373 | // If there are no actual arguments, we're done. |
| 3374 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3375 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3376 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3377 | |
| 3378 | // Get the parameters pointer from the stack. |
| 3379 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3380 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3381 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3382 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3383 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3384 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3385 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3386 | Immediate(isolate->factory()->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3387 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3388 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3389 | // Untag the length for the loop below. |
| 3390 | __ SmiUntag(ecx); |
| 3391 | |
| 3392 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3393 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3394 | __ bind(&loop); |
| 3395 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3396 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3397 | __ add(edi, Immediate(kPointerSize)); |
| 3398 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3399 | __ dec(ecx); |
| 3400 | __ j(not_zero, &loop); |
| 3401 | |
| 3402 | // Return and remove the on-stack parameters. |
| 3403 | __ bind(&done); |
| 3404 | __ ret(3 * kPointerSize); |
| 3405 | |
| 3406 | // Do the runtime call to allocate the arguments object. |
| 3407 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3408 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | |
| 3412 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3413 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3414 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3415 | // at compilation. |
| 3416 | #ifdef V8_INTERPRETED_REGEXP |
| 3417 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3418 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3419 | |
| 3420 | // Stack frame on entry. |
| 3421 | // esp[0]: return address |
| 3422 | // esp[4]: last_match_info (expected JSArray) |
| 3423 | // esp[8]: previous index |
| 3424 | // esp[12]: subject string |
| 3425 | // esp[16]: JSRegExp object |
| 3426 | |
| 3427 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3428 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3429 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3430 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3431 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3432 | Label runtime; |
| 3433 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3434 | |
| 3435 | // Ensure that a RegExp stack is allocated. |
| 3436 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3437 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3438 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3439 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3440 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3441 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3442 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3443 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3444 | |
| 3445 | // Check that the first argument is a JSRegExp object. |
| 3446 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3447 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3448 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3449 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3450 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3451 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3452 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3453 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3454 | if (FLAG_debug_code) { |
| 3455 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3456 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3457 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3458 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3459 | } |
| 3460 | |
| 3461 | // ecx: RegExp data (FixedArray) |
| 3462 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3463 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3464 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3465 | __ j(not_equal, &runtime); |
| 3466 | |
| 3467 | // ecx: RegExp data (FixedArray) |
| 3468 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3469 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3470 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3471 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3472 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3473 | STATIC_ASSERT(kSmiTag == 0); |
| 3474 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3475 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3476 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3477 | __ j(above, &runtime); |
| 3478 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3479 | // Reset offset for possibly sliced string. |
| 3480 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3481 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3482 | __ JumpIfSmi(eax, &runtime); |
| 3483 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3484 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3485 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3486 | |
| 3487 | // eax: subject string |
| 3488 | // edx: subject string |
| 3489 | // ebx: subject string instance type |
| 3490 | // ecx: RegExp data (FixedArray) |
| 3491 | // Handle subject string according to its encoding and representation: |
| 3492 | // (1) Sequential two byte? If yes, go to (9). |
| 3493 | // (2) Sequential one byte? If yes, go to (6). |
| 3494 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3495 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3496 | // Otherwise bailout. |
| 3497 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3498 | // (5b) Is subject external? If yes, go to (8). |
| 3499 | // (6) One byte sequential. Load regexp code for one byte. |
| 3500 | // (E) Carry on. |
| 3501 | /// [...] |
| 3502 | |
| 3503 | // Deferred code at the end of the stub: |
| 3504 | // (7) Not a long external string? If yes, go to (10). |
| 3505 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3506 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3507 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3508 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3509 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3510 | |
| 3511 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3512 | external_string /* 8 */, check_underlying /* 5a */, |
| 3513 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3514 | not_long_external /* 10 */; |
| 3515 | |
| 3516 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3517 | __ and_(ebx, kIsNotStringMask | |
| 3518 | kStringRepresentationMask | |
| 3519 | kStringEncodingMask | |
| 3520 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3521 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3522 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3523 | |
| 3524 | // (2) Sequential one byte? If yes, go to (6). |
| 3525 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3526 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3527 | kStringRepresentationMask | |
| 3528 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3529 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3530 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3531 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3532 | // We check whether the subject string is a cons, since sequential strings |
| 3533 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3534 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3535 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3536 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3537 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3538 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3539 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3540 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3541 | // (4) Cons string. Check that it's flat. |
| 3542 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3543 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3544 | __ j(not_equal, &runtime); |
| 3545 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3546 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3547 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3548 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3549 | |
| 3550 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3551 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3552 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3553 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3554 | // (5b) Is subject external? If yes, go to (8). |
| 3555 | __ test_b(ebx, kStringRepresentationMask); |
| 3556 | // The underlying external string is never a short external string. |
| 3557 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3558 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3559 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3560 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3561 | // eax: sequential subject string (or look-alike, external string) |
| 3562 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3563 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3564 | // (6) One byte sequential. Load regexp code for one byte. |
| 3565 | __ bind(&seq_one_byte_string); |
| 3566 | // Load previous index and check range before edx is overwritten. We have |
| 3567 | // to use edx instead of eax here because it might have been only made to |
| 3568 | // look like a sequential string when it actually is an external string. |
| 3569 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3570 | __ JumpIfNotSmi(ebx, &runtime); |
| 3571 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3572 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3573 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3574 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3575 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3576 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3577 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3578 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3579 | // Check that the irregexp code has been generated for the actual string |
| 3580 | // 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] | 3581 | // a smi (code flushing support). |
| 3582 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3583 | |
| 3584 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3585 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3586 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3587 | // 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] | 3588 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3589 | Counters* counters = masm->isolate()->counters(); |
| 3590 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3591 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3592 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3593 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3594 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3595 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3596 | // Argument 9: Pass current isolate address. |
| 3597 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3598 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3599 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3600 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3601 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3602 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3603 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3604 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3605 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3606 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3607 | |
| 3608 | // Argument 6: Set the number of capture registers to zero to force global |
| 3609 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3610 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3611 | |
| 3612 | // Argument 5: static offsets vector buffer. |
| 3613 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3614 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3615 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3616 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3617 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3618 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3619 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3620 | |
| 3621 | // Argument 1: Original subject string. |
| 3622 | // The original subject is in the previous stack frame. Therefore we have to |
| 3623 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3624 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3625 | // and thereby moves up esp by one kPointerSize.) |
| 3626 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3627 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3628 | |
| 3629 | // esi: original subject string |
| 3630 | // eax: underlying subject string |
| 3631 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3632 | // 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] | 3633 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3634 | // Argument 4: End of string data |
| 3635 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3636 | // Prepare start and end index of the input. |
| 3637 | // Load the length from the original sliced string if that is the case. |
| 3638 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3639 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3640 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3641 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3642 | |
| 3643 | // ebx: start index of the input string |
| 3644 | // esi: end index of the input string |
| 3645 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3646 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3647 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3648 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3649 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3650 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3651 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3652 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3653 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3654 | |
| 3655 | __ bind(&setup_two_byte); |
| 3656 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3657 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3658 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3659 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3660 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3661 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3662 | |
| 3663 | __ bind(&setup_rest); |
| 3664 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3665 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3666 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3667 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3668 | |
| 3669 | // Drop arguments and come back to JS mode. |
| 3670 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3671 | |
| 3672 | // Check the result. |
| 3673 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3674 | __ cmp(eax, 1); |
| 3675 | // We expect exactly one result since we force the called regexp to behave |
| 3676 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3677 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3678 | Label failure; |
| 3679 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3680 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3681 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3682 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3683 | __ j(not_equal, &runtime); |
| 3684 | // Result must now be exception. If there is no pending exception already a |
| 3685 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3686 | // haven't created the exception yet. Handle that in the runtime system. |
| 3687 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3688 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3689 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3690 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3691 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3692 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3693 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3694 | // For exception, throw the exception again. |
| 3695 | |
| 3696 | // Clear the pending exception variable. |
| 3697 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3698 | |
| 3699 | // Special handling of termination exceptions which are uncatchable |
| 3700 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3701 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3702 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3703 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3704 | |
| 3705 | // Handle normal exception by following handler chain. |
| 3706 | __ Throw(eax); |
| 3707 | |
| 3708 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3709 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3710 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3711 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3712 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3713 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3714 | __ ret(4 * kPointerSize); |
| 3715 | |
| 3716 | // Load RegExp data. |
| 3717 | __ bind(&success); |
| 3718 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3719 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3720 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3721 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3722 | STATIC_ASSERT(kSmiTag == 0); |
| 3723 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3724 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3725 | |
| 3726 | // edx: Number of capture registers |
| 3727 | // 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] | 3728 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3729 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3730 | __ JumpIfSmi(eax, &runtime); |
| 3731 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3732 | __ j(not_equal, &runtime); |
| 3733 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3734 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3735 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 3736 | __ cmp(eax, factory->fixed_array_map()); |
| 3737 | __ j(not_equal, &runtime); |
| 3738 | // Check that the last match info has space for the capture registers and the |
| 3739 | // additional information. |
| 3740 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3741 | __ SmiUntag(eax); |
| 3742 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3743 | __ cmp(edx, eax); |
| 3744 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3745 | |
| 3746 | // ebx: last_match_info backing store (FixedArray) |
| 3747 | // edx: number of capture registers |
| 3748 | // Store the capture count. |
| 3749 | __ SmiTag(edx); // Number of capture registers to smi. |
| 3750 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 3751 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 3752 | // Store last subject and last input. |
| 3753 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3754 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3755 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3756 | __ RecordWriteField(ebx, |
| 3757 | RegExpImpl::kLastSubjectOffset, |
| 3758 | eax, |
| 3759 | edi, |
| 3760 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3761 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3762 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3763 | __ RecordWriteField(ebx, |
| 3764 | RegExpImpl::kLastInputOffset, |
| 3765 | eax, |
| 3766 | edi, |
| 3767 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3768 | |
| 3769 | // Get the static offsets vector filled by the native regexp code. |
| 3770 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3771 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3772 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 3773 | |
| 3774 | // ebx: last_match_info backing store (FixedArray) |
| 3775 | // ecx: offsets vector |
| 3776 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3777 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3778 | // Capture register counter starts from number of capture registers and |
| 3779 | // counts down until wraping after zero. |
| 3780 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3781 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3782 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3783 | // Read the value from the static offsets vector buffer. |
| 3784 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 3785 | __ SmiTag(edi); |
| 3786 | // Store the smi value in the last match info. |
| 3787 | __ mov(FieldOperand(ebx, |
| 3788 | edx, |
| 3789 | times_pointer_size, |
| 3790 | RegExpImpl::kFirstCaptureOffset), |
| 3791 | edi); |
| 3792 | __ jmp(&next_capture); |
| 3793 | __ bind(&done); |
| 3794 | |
| 3795 | // Return last match info. |
| 3796 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 3797 | __ ret(4 * kPointerSize); |
| 3798 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3799 | // Do the runtime call to execute the regexp. |
| 3800 | __ bind(&runtime); |
| 3801 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3802 | |
| 3803 | // Deferred code for string handling. |
| 3804 | // (7) Not a long external string? If yes, go to (10). |
| 3805 | __ bind(¬_seq_nor_cons); |
| 3806 | // Compare flags are still set from (3). |
| 3807 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 3808 | |
| 3809 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3810 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3811 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3812 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3813 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3814 | if (FLAG_debug_code) { |
| 3815 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 3816 | // Sequential strings have already been ruled out. |
| 3817 | __ test_b(ebx, kIsIndirectStringMask); |
| 3818 | __ Assert(zero, "external string expected, but not found"); |
| 3819 | } |
| 3820 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 3821 | // 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] | 3822 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3823 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3824 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3825 | // (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] | 3826 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3827 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3828 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3829 | // eax: sequential subject string (or look-alike, external string) |
| 3830 | // edx: original subject string |
| 3831 | // ecx: RegExp data (FixedArray) |
| 3832 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3833 | __ bind(&seq_two_byte_string); |
| 3834 | // Load previous index and check range before edx is overwritten. We have |
| 3835 | // to use edx instead of eax here because it might have been only made to |
| 3836 | // look like a sequential string when it actually is an external string. |
| 3837 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3838 | __ JumpIfNotSmi(ebx, &runtime); |
| 3839 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3840 | __ j(above_equal, &runtime); |
| 3841 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 3842 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 3843 | __ jmp(&check_code); // Go to (E). |
| 3844 | |
| 3845 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 3846 | __ bind(¬_long_external); |
| 3847 | // Catch non-string subject or short external string. |
| 3848 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3849 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 3850 | __ j(not_zero, &runtime); |
| 3851 | |
| 3852 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3853 | // Load offset into edi and replace subject string with parent. |
| 3854 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3855 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3856 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3857 | #endif // V8_INTERPRETED_REGEXP |
| 3858 | } |
| 3859 | |
| 3860 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3861 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 3862 | const int kMaxInlineLength = 100; |
| 3863 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3864 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3865 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3866 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3867 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3868 | __ j(above, &slowcase); |
| 3869 | // Smi-tagging is equivalent to multiplying by 2. |
| 3870 | STATIC_ASSERT(kSmiTag == 0); |
| 3871 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3872 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 3873 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 3874 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3875 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 3876 | times_pointer_size, |
| 3877 | ebx, // In: Number of elements as a smi |
| 3878 | REGISTER_VALUE_IS_SMI, |
| 3879 | eax, // Out: Start of allocation (tagged). |
| 3880 | ecx, // Out: End of allocation. |
| 3881 | edx, // Scratch register |
| 3882 | &slowcase, |
| 3883 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3884 | // eax: Start of allocated area, object-tagged. |
| 3885 | |
| 3886 | // Set JSArray map to global.regexp_result_map(). |
| 3887 | // Set empty properties FixedArray. |
| 3888 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 3889 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3890 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3891 | Factory* factory = masm->isolate()->factory(); |
| 3892 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3893 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3894 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3895 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 3896 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 3897 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 3898 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 3899 | |
| 3900 | // Set input, index and length fields from arguments. |
| 3901 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 3902 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 3903 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 3904 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 3905 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 3906 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 3907 | |
| 3908 | // Fill out the elements FixedArray. |
| 3909 | // eax: JSArray. |
| 3910 | // ebx: FixedArray. |
| 3911 | // ecx: Number of elements in array, as smi. |
| 3912 | |
| 3913 | // Set map. |
| 3914 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3915 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3916 | // Set length. |
| 3917 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3918 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3919 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3920 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3921 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3922 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3923 | // eax: JSArray. |
| 3924 | // ecx: Number of elements to fill. |
| 3925 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3926 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3927 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3928 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3929 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3930 | __ 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] | 3931 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3932 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 3933 | __ jmp(&loop); |
| 3934 | |
| 3935 | __ bind(&done); |
| 3936 | __ ret(3 * kPointerSize); |
| 3937 | |
| 3938 | __ bind(&slowcase); |
| 3939 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 3940 | } |
| 3941 | |
| 3942 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3943 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 3944 | Register object, |
| 3945 | Register result, |
| 3946 | Register scratch1, |
| 3947 | Register scratch2, |
| 3948 | bool object_is_smi, |
| 3949 | Label* not_found) { |
| 3950 | // Use of registers. Register result is used as a temporary. |
| 3951 | Register number_string_cache = result; |
| 3952 | Register mask = scratch1; |
| 3953 | Register scratch = scratch2; |
| 3954 | |
| 3955 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3956 | ExternalReference roots_array_start = |
| 3957 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3958 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 3959 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3960 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3961 | // Make the hash mask from the length of the number string cache. It |
| 3962 | // contains two elements (number and string) for each cache entry. |
| 3963 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 3964 | __ 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] | 3965 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3966 | |
| 3967 | // Calculate the entry in the number string cache. The hash value in the |
| 3968 | // number string cache for smis is just the smi value, and the hash for |
| 3969 | // doubles is the xor of the upper and lower words. See |
| 3970 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3971 | Label smi_hash_calculated; |
| 3972 | Label load_result_from_cache; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3973 | if (object_is_smi) { |
| 3974 | __ mov(scratch, object); |
| 3975 | __ SmiUntag(scratch); |
| 3976 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3977 | Label not_smi; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3978 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3979 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3980 | __ mov(scratch, object); |
| 3981 | __ SmiUntag(scratch); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3982 | __ jmp(&smi_hash_calculated, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3983 | __ bind(¬_smi); |
| 3984 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3985 | masm->isolate()->factory()->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3986 | __ j(not_equal, not_found); |
| 3987 | STATIC_ASSERT(8 == kDoubleSize); |
| 3988 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 3989 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 3990 | // 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] | 3991 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3992 | Register index = scratch; |
| 3993 | Register probe = mask; |
| 3994 | __ mov(probe, |
| 3995 | FieldOperand(number_string_cache, |
| 3996 | index, |
| 3997 | times_twice_pointer_size, |
| 3998 | FixedArray::kHeaderSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3999 | __ JumpIfSmi(probe, not_found); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4000 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4001 | CpuFeatureScope fscope(masm, SSE2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4002 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4003 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4004 | __ ucomisd(xmm0, xmm1); |
| 4005 | } else { |
| 4006 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4007 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4008 | __ FCmp(); |
| 4009 | } |
| 4010 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4011 | __ 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] | 4012 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4013 | } |
| 4014 | |
| 4015 | __ bind(&smi_hash_calculated); |
| 4016 | // 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] | 4017 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4018 | Register index = scratch; |
| 4019 | // Check if the entry is the smi we are looking for. |
| 4020 | __ cmp(object, |
| 4021 | FieldOperand(number_string_cache, |
| 4022 | index, |
| 4023 | times_twice_pointer_size, |
| 4024 | FixedArray::kHeaderSize)); |
| 4025 | __ j(not_equal, not_found); |
| 4026 | |
| 4027 | // Get the result from the cache. |
| 4028 | __ bind(&load_result_from_cache); |
| 4029 | __ mov(result, |
| 4030 | FieldOperand(number_string_cache, |
| 4031 | index, |
| 4032 | times_twice_pointer_size, |
| 4033 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4034 | Counters* counters = masm->isolate()->counters(); |
| 4035 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4036 | } |
| 4037 | |
| 4038 | |
| 4039 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4040 | Label runtime; |
| 4041 | |
| 4042 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4043 | |
| 4044 | // Generate code to lookup number in the number string cache. |
| 4045 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, false, &runtime); |
| 4046 | __ ret(1 * kPointerSize); |
| 4047 | |
| 4048 | __ bind(&runtime); |
| 4049 | // Handle number to string in the runtime system if not found in the cache. |
| 4050 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4051 | } |
| 4052 | |
| 4053 | |
| 4054 | static int NegativeComparisonResult(Condition cc) { |
| 4055 | ASSERT(cc != equal); |
| 4056 | ASSERT((cc == less) || (cc == less_equal) |
| 4057 | || (cc == greater) || (cc == greater_equal)); |
| 4058 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4059 | } |
| 4060 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4061 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4062 | static void CheckInputType(MacroAssembler* masm, |
| 4063 | Register input, |
| 4064 | CompareIC::State expected, |
| 4065 | Label* fail) { |
| 4066 | Label ok; |
| 4067 | if (expected == CompareIC::SMI) { |
| 4068 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4069 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4070 | __ JumpIfSmi(input, &ok); |
| 4071 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4072 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4073 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4074 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4075 | // 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] | 4076 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4077 | __ bind(&ok); |
| 4078 | } |
| 4079 | |
| 4080 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4081 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 4082 | Label* label, |
| 4083 | Register object, |
| 4084 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4085 | __ JumpIfSmi(object, label); |
| 4086 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4087 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4088 | __ and_(scratch, kIsInternalizedMask | kIsNotStringMask); |
| 4089 | __ cmp(scratch, kInternalizedTag | kStringTag); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4090 | __ j(not_equal, label); |
| 4091 | } |
| 4092 | |
| 4093 | |
| 4094 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4095 | Label check_unequal_objects; |
| 4096 | Condition cc = GetCondition(); |
| 4097 | |
| 4098 | Label miss; |
| 4099 | CheckInputType(masm, edx, left_, &miss); |
| 4100 | CheckInputType(masm, eax, right_, &miss); |
| 4101 | |
| 4102 | // Compare two smis. |
| 4103 | Label non_smi, smi_done; |
| 4104 | __ mov(ecx, edx); |
| 4105 | __ or_(ecx, eax); |
| 4106 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4107 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4108 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4109 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4110 | __ bind(&smi_done); |
| 4111 | __ mov(eax, edx); |
| 4112 | __ ret(0); |
| 4113 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4114 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4115 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4116 | // it is certain that at least one operand isn't a smi. |
| 4117 | |
| 4118 | // Identical objects can be compared fast, but there are some tricky cases |
| 4119 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4120 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4121 | { |
| 4122 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4123 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4124 | __ j(not_equal, ¬_identical); |
| 4125 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4126 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4127 | // Check for undefined. undefined OP undefined is false even though |
| 4128 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4129 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4130 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4131 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4132 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4133 | __ ret(0); |
| 4134 | __ bind(&check_for_nan); |
| 4135 | } |
| 4136 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4137 | // Test for NaN. Compare heap numbers in a general way, |
| 4138 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4139 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4140 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4141 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4142 | if (cc != equal) { |
| 4143 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4144 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4145 | __ j(above_equal, ¬_identical); |
| 4146 | } |
| 4147 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4148 | __ ret(0); |
| 4149 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4150 | |
| 4151 | __ bind(¬_identical); |
| 4152 | } |
| 4153 | |
| 4154 | // Strict equality can quickly decide whether objects are equal. |
| 4155 | // 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] | 4156 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4157 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4158 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4159 | // If we're doing a strict equality comparison, we don't have to do |
| 4160 | // type conversion, so we generate code to do fast comparison for objects |
| 4161 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4162 | // slow-case code. |
| 4163 | // If either is a Smi (we know that not both are), then they can only |
| 4164 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4165 | STATIC_ASSERT(kSmiTag == 0); |
| 4166 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4167 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4168 | __ and_(ecx, eax); |
| 4169 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4170 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4171 | // One operand is a smi. |
| 4172 | |
| 4173 | // Check whether the non-smi is a heap number. |
| 4174 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4175 | // 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] | 4176 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4177 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4178 | __ xor_(ebx, eax); |
| 4179 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4180 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4181 | // if eax was smi, ebx is now edx, else eax. |
| 4182 | |
| 4183 | // Check if the non-smi operand is a heap number. |
| 4184 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4185 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4186 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4187 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4188 | // Return non-equal (ebx is not zero) |
| 4189 | __ mov(eax, ebx); |
| 4190 | __ ret(0); |
| 4191 | |
| 4192 | __ bind(¬_smis); |
| 4193 | // If either operand is a JSObject or an oddball value, then they are not |
| 4194 | // equal since their pointers are different |
| 4195 | // There is no test for undetectability in strict equality. |
| 4196 | |
| 4197 | // Get the type of the first operand. |
| 4198 | // 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] | 4199 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4200 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4201 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4202 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4203 | |
| 4204 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4205 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4206 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4207 | __ bind(&return_not_equal); |
| 4208 | __ ret(0); |
| 4209 | |
| 4210 | __ bind(&first_non_object); |
| 4211 | // Check for oddballs: true, false, null, undefined. |
| 4212 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4213 | __ j(equal, &return_not_equal); |
| 4214 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4215 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4216 | __ j(above_equal, &return_not_equal); |
| 4217 | |
| 4218 | // Check for oddballs: true, false, null, undefined. |
| 4219 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4220 | __ j(equal, &return_not_equal); |
| 4221 | |
| 4222 | // Fall through to the general case. |
| 4223 | __ bind(&slow); |
| 4224 | } |
| 4225 | |
| 4226 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4227 | Label non_number_comparison; |
| 4228 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4229 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4230 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4231 | CpuFeatureScope use_sse2(masm, SSE2); |
| 4232 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4233 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4234 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4235 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4236 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4237 | // Don't base result on EFLAGS when a NaN is involved. |
| 4238 | __ j(parity_even, &unordered, Label::kNear); |
| 4239 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4240 | __ mov(eax, 0); // equal |
| 4241 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4242 | __ cmov(above, eax, ecx); |
| 4243 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4244 | __ cmov(below, eax, ecx); |
| 4245 | __ ret(0); |
| 4246 | } else { |
| 4247 | FloatingPointHelper::CheckFloatOperands( |
| 4248 | masm, &non_number_comparison, ebx); |
| 4249 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4250 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4251 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4252 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4253 | // Don't base result on EFLAGS when a NaN is involved. |
| 4254 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4255 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4256 | Label below_label, above_label; |
| 4257 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4258 | __ j(below, &below_label, Label::kNear); |
| 4259 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4260 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4261 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4262 | __ ret(0); |
| 4263 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4264 | __ bind(&below_label); |
| 4265 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4266 | __ ret(0); |
| 4267 | |
| 4268 | __ bind(&above_label); |
| 4269 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4270 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4271 | } |
| 4272 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4273 | // If one of the numbers was NaN, then the result is always false. |
| 4274 | // The cc is never not-equal. |
| 4275 | __ bind(&unordered); |
| 4276 | ASSERT(cc != not_equal); |
| 4277 | if (cc == less || cc == less_equal) { |
| 4278 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4279 | } else { |
| 4280 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4281 | } |
| 4282 | __ ret(0); |
| 4283 | |
| 4284 | // The number comparison code did not provide a valid result. |
| 4285 | __ bind(&non_number_comparison); |
| 4286 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4287 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4288 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4289 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4290 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 4291 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4292 | |
| 4293 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4294 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4295 | // non-zero value, which indicates not equal, so just return. |
| 4296 | __ ret(0); |
| 4297 | } |
| 4298 | |
| 4299 | __ bind(&check_for_strings); |
| 4300 | |
| 4301 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4302 | &check_unequal_objects); |
| 4303 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4304 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4305 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4306 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4307 | edx, |
| 4308 | eax, |
| 4309 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4310 | ebx); |
| 4311 | } else { |
| 4312 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4313 | edx, |
| 4314 | eax, |
| 4315 | ecx, |
| 4316 | ebx, |
| 4317 | edi); |
| 4318 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4319 | #ifdef DEBUG |
| 4320 | __ Abort("Unexpected fall-through from string comparison"); |
| 4321 | #endif |
| 4322 | |
| 4323 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4324 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4325 | // Non-strict equality. Objects are unequal if |
| 4326 | // they are both JSObjects and not undetectable, |
| 4327 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4328 | Label not_both_objects; |
| 4329 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4330 | // At most one is a smi, so we can test for smi by adding the two. |
| 4331 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4332 | // a heap object has the low bit clear. |
| 4333 | STATIC_ASSERT(kSmiTag == 0); |
| 4334 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4335 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4336 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4337 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4338 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4339 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4340 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4341 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4342 | // We do not bail out after this point. Both are JSObjects, and |
| 4343 | // they are equal if and only if both are undetectable. |
| 4344 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4345 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4346 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4347 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4348 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4349 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4350 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4351 | // The objects are both undetectable, so they both compare as the value |
| 4352 | // undefined, and are equal. |
| 4353 | __ Set(eax, Immediate(EQUAL)); |
| 4354 | __ bind(&return_unequal); |
| 4355 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4356 | // or return equal if we fell through to here. |
| 4357 | __ ret(0); // rax, rdx were pushed |
| 4358 | __ bind(¬_both_objects); |
| 4359 | } |
| 4360 | |
| 4361 | // Push arguments below the return address. |
| 4362 | __ pop(ecx); |
| 4363 | __ push(edx); |
| 4364 | __ push(eax); |
| 4365 | |
| 4366 | // Figure out which native to call and setup the arguments. |
| 4367 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4368 | if (cc == equal) { |
| 4369 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4370 | } else { |
| 4371 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4372 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4373 | } |
| 4374 | |
| 4375 | // Restore return address on the stack. |
| 4376 | __ push(ecx); |
| 4377 | |
| 4378 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4379 | // tagged as a small integer. |
| 4380 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4381 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4382 | __ bind(&miss); |
| 4383 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4384 | } |
| 4385 | |
| 4386 | |
| 4387 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4388 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4389 | } |
| 4390 | |
| 4391 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4392 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4393 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4394 | } |
| 4395 | |
| 4396 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4397 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4398 | // Cache the called function in a global property cell. Cache states |
| 4399 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4400 | // megamorphic. |
| 4401 | // ebx : cache cell for call target |
| 4402 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4403 | Isolate* isolate = masm->isolate(); |
| 4404 | Label initialize, done, miss, megamorphic, not_array_function; |
| 4405 | |
| 4406 | // Load the cache state into ecx. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4407 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4408 | |
| 4409 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4410 | // function without changing the state. |
| 4411 | __ cmp(ecx, edi); |
| 4412 | __ j(equal, &done); |
| 4413 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4414 | __ j(equal, &done); |
| 4415 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 4416 | // If we came here, we need to see if we are the array function. |
| 4417 | // If we didn't have a matching function, and we didn't find the megamorph |
| 4418 | // sentinel, then we have in the cell either some other function or an |
| 4419 | // AllocationSite. Do a map check on the object in ecx. |
| 4420 | Handle<Map> allocation_site_map( |
| 4421 | masm->isolate()->heap()->allocation_site_map(), |
| 4422 | masm->isolate()); |
| 4423 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 4424 | __ j(not_equal, &miss); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4425 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4426 | // Load the global or builtins object from the current context |
| 4427 | __ LoadGlobalContext(ecx); |
| 4428 | // Make sure the function is the Array() function |
| 4429 | __ cmp(edi, Operand(ecx, |
| 4430 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4431 | __ j(not_equal, &megamorphic); |
| 4432 | __ jmp(&done); |
| 4433 | |
| 4434 | __ bind(&miss); |
| 4435 | |
| 4436 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4437 | // megamorphic. |
| 4438 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4439 | __ j(equal, &initialize); |
| 4440 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4441 | // write-barrier is needed. |
| 4442 | __ bind(&megamorphic); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4443 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4444 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4445 | __ jmp(&done, Label::kNear); |
| 4446 | |
| 4447 | // An uninitialized cache is patched with the function or sentinel to |
| 4448 | // indicate the ElementsKind if function is the Array constructor. |
| 4449 | __ bind(&initialize); |
| 4450 | __ LoadGlobalContext(ecx); |
| 4451 | // Make sure the function is the Array() function |
| 4452 | __ cmp(edi, Operand(ecx, |
| 4453 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4454 | __ j(not_equal, ¬_array_function); |
| 4455 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 4456 | // The target function is the Array constructor, |
| 4457 | // Create an AllocationSite if we don't already have it, store it in the cell |
| 4458 | { |
| 4459 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4460 | |
| 4461 | __ push(eax); |
| 4462 | __ push(edi); |
| 4463 | __ push(ebx); |
| 4464 | |
| 4465 | CreateAllocationSiteStub create_stub; |
| 4466 | __ CallStub(&create_stub); |
| 4467 | |
| 4468 | __ pop(ebx); |
| 4469 | __ pop(edi); |
| 4470 | __ pop(eax); |
| 4471 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4472 | __ jmp(&done); |
| 4473 | |
| 4474 | __ bind(¬_array_function); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4475 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4476 | // No need for a write barrier here - cells are rescanned. |
| 4477 | |
| 4478 | __ bind(&done); |
| 4479 | } |
| 4480 | |
| 4481 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4482 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4483 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4484 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4485 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4486 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4487 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4488 | // The receiver might implicitly be the global object. This is |
| 4489 | // indicated by passing the hole as the receiver to the call |
| 4490 | // function stub. |
| 4491 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4492 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4493 | // Get the receiver from the stack. |
| 4494 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4495 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4496 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4497 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4498 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4499 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4500 | __ mov(ecx, GlobalObjectOperand()); |
| 4501 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4502 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4503 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4504 | } |
| 4505 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4506 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4507 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4508 | // Goto slow case if we do not have a function. |
| 4509 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4510 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4511 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4512 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4513 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4514 | } |
| 4515 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4516 | // Fast-case: Just invoke the function. |
| 4517 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4518 | |
| 4519 | if (ReceiverMightBeImplicit()) { |
| 4520 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4521 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4522 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4523 | __ InvokeFunction(edi, |
| 4524 | actual, |
| 4525 | JUMP_FUNCTION, |
| 4526 | NullCallWrapper(), |
| 4527 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4528 | __ bind(&call_as_function); |
| 4529 | } |
| 4530 | __ InvokeFunction(edi, |
| 4531 | actual, |
| 4532 | JUMP_FUNCTION, |
| 4533 | NullCallWrapper(), |
| 4534 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4535 | |
| 4536 | // Slow-case: Non-function called. |
| 4537 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4538 | if (RecordCallTarget()) { |
| 4539 | // 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] | 4540 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4541 | // object (undefined) so no write barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4542 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4543 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4544 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4545 | // Check for function proxy. |
| 4546 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4547 | __ j(not_equal, &non_function); |
| 4548 | __ pop(ecx); |
| 4549 | __ push(edi); // put proxy as additional argument under return address |
| 4550 | __ push(ecx); |
| 4551 | __ Set(eax, Immediate(argc_ + 1)); |
| 4552 | __ Set(ebx, Immediate(0)); |
| 4553 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4554 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4555 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4556 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4557 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4558 | } |
| 4559 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4560 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4561 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4562 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4563 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4564 | __ Set(eax, Immediate(argc_)); |
| 4565 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4566 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4567 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4568 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4569 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4570 | } |
| 4571 | |
| 4572 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4573 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4574 | // eax : number of arguments |
| 4575 | // ebx : cache cell for call target |
| 4576 | // edi : constructor function |
| 4577 | Label slow, non_function_call; |
| 4578 | |
| 4579 | // Check that function is not a smi. |
| 4580 | __ JumpIfSmi(edi, &non_function_call); |
| 4581 | // Check that function is a JSFunction. |
| 4582 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4583 | __ j(not_equal, &slow); |
| 4584 | |
| 4585 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4586 | GenerateRecordCallTarget(masm); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4587 | } |
| 4588 | |
| 4589 | // Jump to the function-specific construct stub. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4590 | Register jmp_reg = ecx; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4591 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4592 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 4593 | SharedFunctionInfo::kConstructStubOffset)); |
| 4594 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 4595 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4596 | |
| 4597 | // edi: called object |
| 4598 | // eax: number of arguments |
| 4599 | // ecx: object map |
| 4600 | Label do_call; |
| 4601 | __ bind(&slow); |
| 4602 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4603 | __ j(not_equal, &non_function_call); |
| 4604 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4605 | __ jmp(&do_call); |
| 4606 | |
| 4607 | __ bind(&non_function_call); |
| 4608 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4609 | __ bind(&do_call); |
| 4610 | // Set expected number of arguments to zero (not changing eax). |
| 4611 | __ Set(ebx, Immediate(0)); |
| 4612 | Handle<Code> arguments_adaptor = |
| 4613 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4614 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4615 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4616 | } |
| 4617 | |
| 4618 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4619 | bool CEntryStub::NeedsImmovableCode() { |
| 4620 | return false; |
| 4621 | } |
| 4622 | |
| 4623 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4624 | bool CEntryStub::IsPregenerated() { |
| 4625 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4626 | result_size_ == 1; |
| 4627 | } |
| 4628 | |
| 4629 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4630 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4631 | CEntryStub::GenerateAheadOfTime(isolate); |
| 4632 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4633 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4634 | // 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] | 4635 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4636 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 4637 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4638 | } |
| 4639 | |
| 4640 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4641 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4642 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4643 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4644 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4645 | // which would lead to code stub initialization state being messed up. |
| 4646 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4647 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 4648 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4649 | } |
| 4650 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4651 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4652 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4656 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4657 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4658 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4659 | code->set_is_pregenerated(true); |
| 4660 | } |
| 4661 | |
| 4662 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4663 | static void JumpIfOOM(MacroAssembler* masm, |
| 4664 | Register value, |
| 4665 | Register scratch, |
| 4666 | Label* oom_label) { |
| 4667 | __ mov(scratch, value); |
| 4668 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 4669 | STATIC_ASSERT(kFailureTag == 3); |
| 4670 | __ and_(scratch, 0xf); |
| 4671 | __ cmp(scratch, 0xf); |
| 4672 | __ j(equal, oom_label); |
| 4673 | } |
| 4674 | |
| 4675 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4676 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4677 | Label* throw_normal_exception, |
| 4678 | Label* throw_termination_exception, |
| 4679 | Label* throw_out_of_memory_exception, |
| 4680 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4681 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4682 | // eax: result parameter for PerformGC, if any |
| 4683 | // ebx: pointer to C function (C callee-saved) |
| 4684 | // ebp: frame pointer (restored after C call) |
| 4685 | // esp: stack pointer (restored after C call) |
| 4686 | // edi: number of arguments including receiver (C callee-saved) |
| 4687 | // esi: pointer to the first argument (C callee-saved) |
| 4688 | |
| 4689 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4690 | |
| 4691 | // Check stack alignment. |
| 4692 | if (FLAG_debug_code) { |
| 4693 | __ CheckStackAlignment(); |
| 4694 | } |
| 4695 | |
| 4696 | if (do_gc) { |
| 4697 | // Pass failure code returned from last attempt as first argument to |
| 4698 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4699 | // stack alignment is known to be correct. This function takes one argument |
| 4700 | // which is passed on the stack, and we know that the stack has been |
| 4701 | // prepared to pass at least one argument. |
| 4702 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4703 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4704 | } |
| 4705 | |
| 4706 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4707 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4708 | if (always_allocate_scope) { |
| 4709 | __ inc(Operand::StaticVariable(scope_depth)); |
| 4710 | } |
| 4711 | |
| 4712 | // Call C function. |
| 4713 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 4714 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4715 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4716 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4717 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4718 | // Result is in eax or edx:eax - do not destroy these registers! |
| 4719 | |
| 4720 | if (always_allocate_scope) { |
| 4721 | __ dec(Operand::StaticVariable(scope_depth)); |
| 4722 | } |
| 4723 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4724 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 4725 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4726 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4727 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4728 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4729 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4730 | __ int3(); |
| 4731 | __ bind(&okay); |
| 4732 | } |
| 4733 | |
| 4734 | // Check for failure result. |
| 4735 | Label failure_returned; |
| 4736 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4737 | __ lea(ecx, Operand(eax, 1)); |
| 4738 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 4739 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4740 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4741 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4742 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4743 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4744 | |
| 4745 | // Check that there is no pending exception, otherwise we |
| 4746 | // should have returned some failure value. |
| 4747 | if (FLAG_debug_code) { |
| 4748 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4749 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4750 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4751 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 4752 | // 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] | 4753 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4754 | __ int3(); |
| 4755 | __ bind(&okay); |
| 4756 | __ pop(edx); |
| 4757 | } |
| 4758 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4759 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4760 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4761 | __ ret(0); |
| 4762 | |
| 4763 | // Handling of failure. |
| 4764 | __ bind(&failure_returned); |
| 4765 | |
| 4766 | Label retry; |
| 4767 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 4768 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4769 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4770 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4771 | |
| 4772 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4773 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4774 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4775 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4776 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4777 | |
| 4778 | // See if we just retrieved an OOM exception. |
| 4779 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 4780 | |
| 4781 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4782 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4783 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 4784 | |
| 4785 | // Special handling of termination exceptions which are uncatchable |
| 4786 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4787 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4788 | __ j(equal, throw_termination_exception); |
| 4789 | |
| 4790 | // Handle normal exception. |
| 4791 | __ jmp(throw_normal_exception); |
| 4792 | |
| 4793 | // Retry. |
| 4794 | __ bind(&retry); |
| 4795 | } |
| 4796 | |
| 4797 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4798 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4799 | // eax: number of arguments including receiver |
| 4800 | // ebx: pointer to C function (C callee-saved) |
| 4801 | // ebp: frame pointer (restored after C call) |
| 4802 | // esp: stack pointer (restored after C call) |
| 4803 | // esi: current context (C callee-saved) |
| 4804 | // edi: JS function of the caller (C callee-saved) |
| 4805 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4806 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 4807 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4808 | // NOTE: Invocations of builtins may return failure objects instead |
| 4809 | // of a proper result. The builtin entry handles this by performing |
| 4810 | // a garbage collection and retrying the builtin (twice). |
| 4811 | |
| 4812 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4813 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4814 | |
| 4815 | // eax: result parameter for PerformGC, if any (setup below) |
| 4816 | // ebx: pointer to builtin function (C callee-saved) |
| 4817 | // ebp: frame pointer (restored after C call) |
| 4818 | // esp: stack pointer (restored after C call) |
| 4819 | // edi: number of arguments including receiver (C callee-saved) |
| 4820 | // esi: argv pointer (C callee-saved) |
| 4821 | |
| 4822 | Label throw_normal_exception; |
| 4823 | Label throw_termination_exception; |
| 4824 | Label throw_out_of_memory_exception; |
| 4825 | |
| 4826 | // Call into the runtime system. |
| 4827 | GenerateCore(masm, |
| 4828 | &throw_normal_exception, |
| 4829 | &throw_termination_exception, |
| 4830 | &throw_out_of_memory_exception, |
| 4831 | false, |
| 4832 | false); |
| 4833 | |
| 4834 | // Do space-specific GC and retry runtime call. |
| 4835 | GenerateCore(masm, |
| 4836 | &throw_normal_exception, |
| 4837 | &throw_termination_exception, |
| 4838 | &throw_out_of_memory_exception, |
| 4839 | true, |
| 4840 | false); |
| 4841 | |
| 4842 | // Do full GC and retry runtime call one final time. |
| 4843 | Failure* failure = Failure::InternalError(); |
| 4844 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 4845 | GenerateCore(masm, |
| 4846 | &throw_normal_exception, |
| 4847 | &throw_termination_exception, |
| 4848 | &throw_out_of_memory_exception, |
| 4849 | true, |
| 4850 | true); |
| 4851 | |
| 4852 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4853 | // Set external caught exception to false. |
| 4854 | Isolate* isolate = masm->isolate(); |
| 4855 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 4856 | isolate); |
| 4857 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 4858 | |
| 4859 | // Set pending exception and eax to out of memory exception. |
| 4860 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 4861 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4862 | Label already_have_failure; |
| 4863 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 4864 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 4865 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4866 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4867 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4868 | |
| 4869 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4870 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4871 | |
| 4872 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4873 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4874 | } |
| 4875 | |
| 4876 | |
| 4877 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4878 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4879 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4880 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4881 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 4882 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4883 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4884 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4885 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4886 | |
| 4887 | // Push marker in two places. |
| 4888 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4889 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 4890 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 4891 | // Save callee-saved registers (C calling conventions). |
| 4892 | __ push(edi); |
| 4893 | __ push(esi); |
| 4894 | __ push(ebx); |
| 4895 | |
| 4896 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4897 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4898 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 4899 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4900 | // 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] | 4901 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4902 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4903 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4904 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4905 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4906 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 4907 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4908 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4909 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4910 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4911 | // Jump to a faked try block that does the invoke, with a faked catch |
| 4912 | // block that sets the pending exception. |
| 4913 | __ jmp(&invoke); |
| 4914 | __ bind(&handler_entry); |
| 4915 | handler_offset_ = handler_entry.pos(); |
| 4916 | // Caught exception: Store result (exception) in the pending exception |
| 4917 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4918 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4919 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4920 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4921 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 4922 | __ jmp(&exit); |
| 4923 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4924 | // Invoke: Link this frame into the handler chain. There's only one |
| 4925 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4926 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4927 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4928 | |
| 4929 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4930 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4931 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4932 | |
| 4933 | // Fake a receiver (NULL). |
| 4934 | __ push(Immediate(0)); // receiver |
| 4935 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4936 | // Invoke the function by calling through JS entry trampoline builtin and |
| 4937 | // pop the faked function when we return. Notice that we cannot store a |
| 4938 | // reference to the trampoline code directly in this stub, because the |
| 4939 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4940 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4941 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 4942 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4943 | __ mov(edx, Immediate(construct_entry)); |
| 4944 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4945 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4946 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4947 | __ mov(edx, Immediate(entry)); |
| 4948 | } |
| 4949 | __ mov(edx, Operand(edx, 0)); // deref address |
| 4950 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4951 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4952 | |
| 4953 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4954 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4955 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4956 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4957 | // Check if the current stack frame is marked as the outermost JS frame. |
| 4958 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4959 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4960 | __ j(not_equal, ¬_outermost_js_2); |
| 4961 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 4962 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4963 | |
| 4964 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4965 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4966 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4967 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4968 | |
| 4969 | // Restore callee-saved registers (C calling conventions). |
| 4970 | __ pop(ebx); |
| 4971 | __ pop(esi); |
| 4972 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4973 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4974 | |
| 4975 | // Restore frame pointer and return. |
| 4976 | __ pop(ebp); |
| 4977 | __ ret(0); |
| 4978 | } |
| 4979 | |
| 4980 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4981 | // Generate stub code for instanceof. |
| 4982 | // This code can patch a call site inlined cache of the instance of check, |
| 4983 | // which looks like this. |
| 4984 | // |
| 4985 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 4986 | // 75 0a jne <some near label> |
| 4987 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 4988 | // |
| 4989 | // If call site patching is requested the stack will have the delta from the |
| 4990 | // return address to the cmp instruction just below the return address. This |
| 4991 | // also means that call site patching can only take place with arguments in |
| 4992 | // registers. TOS looks like this when call site patching is requested |
| 4993 | // |
| 4994 | // esp[0] : return address |
| 4995 | // esp[4] : delta from return address to cmp instruction |
| 4996 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4997 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4998 | // Call site inlining and patching implies arguments in registers. |
| 4999 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5000 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5001 | // Fixed register usage throughout the stub. |
| 5002 | Register object = eax; // Object (lhs). |
| 5003 | Register map = ebx; // Map of the object. |
| 5004 | Register function = edx; // Function (rhs). |
| 5005 | Register prototype = edi; // Prototype of the function. |
| 5006 | Register scratch = ecx; |
| 5007 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5008 | // Constants describing the call site code to patch. |
| 5009 | static const int kDeltaToCmpImmediate = 2; |
| 5010 | static const int kDeltaToMov = 8; |
| 5011 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5012 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5013 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5014 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5015 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5016 | ExternalReference roots_array_start = |
| 5017 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5018 | |
| 5019 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5020 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5021 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5022 | // Get the object and function - they are always both needed. |
| 5023 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5024 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5025 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5026 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5027 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5028 | |
| 5029 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5030 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5031 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5032 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5033 | // If there is a call site cache don't look in the global cache, but do the |
| 5034 | // real lookup and update the call site cache. |
| 5035 | if (!HasCallSiteInlineCheck()) { |
| 5036 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5037 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5038 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5039 | __ cmp(function, Operand::StaticArray(scratch, |
| 5040 | times_pointer_size, |
| 5041 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5042 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5043 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5044 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5045 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5046 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5047 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5048 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5049 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5050 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5051 | __ bind(&miss); |
| 5052 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5053 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5054 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5055 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5056 | |
| 5057 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5058 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5059 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5060 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5061 | // Update the global instanceof or call site inlined cache with the current |
| 5062 | // map and function. The cached answer will be set when it is known below. |
| 5063 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5064 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5065 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5066 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5067 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5068 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5069 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5070 | } else { |
| 5071 | // The constants for the code patching are based on no push instructions |
| 5072 | // at the call site. |
| 5073 | ASSERT(HasArgsInRegisters()); |
| 5074 | // Get return address and delta to inlined map check. |
| 5075 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5076 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5077 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5078 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5079 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5080 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5081 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5082 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5083 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5084 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5085 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5086 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5087 | // Loop through the prototype chain of the object looking for the function |
| 5088 | // prototype. |
| 5089 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5090 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5091 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5092 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5093 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5094 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5095 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5096 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5097 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5098 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5099 | __ jmp(&loop); |
| 5100 | |
| 5101 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5102 | if (!HasCallSiteInlineCheck()) { |
| 5103 | __ Set(eax, Immediate(0)); |
| 5104 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5105 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5106 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5107 | } else { |
| 5108 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5109 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5110 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5111 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5112 | if (FLAG_debug_code) { |
| 5113 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5114 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5115 | } |
| 5116 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5117 | if (!ReturnTrueFalseObject()) { |
| 5118 | __ Set(eax, Immediate(0)); |
| 5119 | } |
| 5120 | } |
| 5121 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5122 | |
| 5123 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5124 | if (!HasCallSiteInlineCheck()) { |
| 5125 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5126 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5127 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5128 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5129 | } else { |
| 5130 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5131 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5132 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5133 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5134 | if (FLAG_debug_code) { |
| 5135 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5136 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5137 | } |
| 5138 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5139 | if (!ReturnTrueFalseObject()) { |
| 5140 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5141 | } |
| 5142 | } |
| 5143 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5144 | |
| 5145 | Label object_not_null, object_not_null_or_smi; |
| 5146 | __ bind(¬_js_object); |
| 5147 | // Before null, smi and string value checks, check that the rhs is a function |
| 5148 | // 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] | 5149 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5150 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5151 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5152 | |
| 5153 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5154 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5155 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5156 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5157 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5158 | |
| 5159 | __ bind(&object_not_null); |
| 5160 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5161 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5162 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5163 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5164 | |
| 5165 | __ bind(&object_not_null_or_smi); |
| 5166 | // String values is not instance of anything. |
| 5167 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5168 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5169 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5170 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5171 | |
| 5172 | // Slow-case: Go through the JavaScript implementation. |
| 5173 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5174 | if (!ReturnTrueFalseObject()) { |
| 5175 | // Tail call the builtin which returns 0 or 1. |
| 5176 | if (HasArgsInRegisters()) { |
| 5177 | // Push arguments below return address. |
| 5178 | __ pop(scratch); |
| 5179 | __ push(object); |
| 5180 | __ push(function); |
| 5181 | __ push(scratch); |
| 5182 | } |
| 5183 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5184 | } else { |
| 5185 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5186 | { |
| 5187 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5188 | __ push(object); |
| 5189 | __ push(function); |
| 5190 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5191 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5192 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5193 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5194 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5195 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5196 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5197 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5198 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5199 | __ bind(&done); |
| 5200 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5201 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5205 | Register InstanceofStub::left() { return eax; } |
| 5206 | |
| 5207 | |
| 5208 | Register InstanceofStub::right() { return edx; } |
| 5209 | |
| 5210 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5211 | // ------------------------------------------------------------------------- |
| 5212 | // StringCharCodeAtGenerator |
| 5213 | |
| 5214 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5215 | // If the receiver is a smi trigger the non-string case. |
| 5216 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5217 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5218 | |
| 5219 | // Fetch the instance type of the receiver into result register. |
| 5220 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5221 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5222 | // If the receiver is not a string trigger the non-string case. |
| 5223 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5224 | __ j(not_zero, receiver_not_string_); |
| 5225 | |
| 5226 | // If the index is non-smi trigger the non-smi case. |
| 5227 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5228 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5229 | __ bind(&got_smi_index_); |
| 5230 | |
| 5231 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5232 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5233 | __ j(above_equal, index_out_of_range_); |
| 5234 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5235 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5236 | |
| 5237 | Factory* factory = masm->isolate()->factory(); |
| 5238 | StringCharLoadGenerator::Generate( |
| 5239 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5240 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5241 | __ SmiTag(result_); |
| 5242 | __ bind(&exit_); |
| 5243 | } |
| 5244 | |
| 5245 | |
| 5246 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5247 | MacroAssembler* masm, |
| 5248 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5249 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5250 | |
| 5251 | // Index is not a smi. |
| 5252 | __ bind(&index_not_smi_); |
| 5253 | // 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] | 5254 | __ CheckMap(index_, |
| 5255 | masm->isolate()->factory()->heap_number_map(), |
| 5256 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5257 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5258 | call_helper.BeforeCall(masm); |
| 5259 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5260 | __ push(index_); // Consumed by runtime conversion function. |
| 5261 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5262 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5263 | } else { |
| 5264 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5265 | // NumberToSmi discards numbers that are not exact integers. |
| 5266 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5267 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5268 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5269 | // Save the conversion result before the pop instructions below |
| 5270 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5271 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5272 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5273 | __ pop(object_); |
| 5274 | // Reload the instance type. |
| 5275 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5276 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5277 | call_helper.AfterCall(masm); |
| 5278 | // If index is still not a smi, it must be out of range. |
| 5279 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5280 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5281 | // Otherwise, return to the fast path. |
| 5282 | __ jmp(&got_smi_index_); |
| 5283 | |
| 5284 | // Call runtime. We get here when the receiver is a string and the |
| 5285 | // index is a number, but the code of getting the actual character |
| 5286 | // is too complex (e.g., when the string needs to be flattened). |
| 5287 | __ bind(&call_runtime_); |
| 5288 | call_helper.BeforeCall(masm); |
| 5289 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5290 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5291 | __ push(index_); |
| 5292 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5293 | if (!result_.is(eax)) { |
| 5294 | __ mov(result_, eax); |
| 5295 | } |
| 5296 | call_helper.AfterCall(masm); |
| 5297 | __ jmp(&exit_); |
| 5298 | |
| 5299 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5300 | } |
| 5301 | |
| 5302 | |
| 5303 | // ------------------------------------------------------------------------- |
| 5304 | // StringCharFromCodeGenerator |
| 5305 | |
| 5306 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5307 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5308 | STATIC_ASSERT(kSmiTag == 0); |
| 5309 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5310 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5311 | __ test(code_, |
| 5312 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5313 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5314 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5315 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5316 | Factory* factory = masm->isolate()->factory(); |
| 5317 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5318 | STATIC_ASSERT(kSmiTag == 0); |
| 5319 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5320 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5321 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5322 | __ mov(result_, FieldOperand(result_, |
| 5323 | code_, times_half_pointer_size, |
| 5324 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5325 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5326 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5327 | __ bind(&exit_); |
| 5328 | } |
| 5329 | |
| 5330 | |
| 5331 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5332 | MacroAssembler* masm, |
| 5333 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5334 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5335 | |
| 5336 | __ bind(&slow_case_); |
| 5337 | call_helper.BeforeCall(masm); |
| 5338 | __ push(code_); |
| 5339 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5340 | if (!result_.is(eax)) { |
| 5341 | __ mov(result_, eax); |
| 5342 | } |
| 5343 | call_helper.AfterCall(masm); |
| 5344 | __ jmp(&exit_); |
| 5345 | |
| 5346 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5347 | } |
| 5348 | |
| 5349 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5350 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5351 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5352 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5353 | |
| 5354 | // Load the two arguments. |
| 5355 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5356 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5357 | |
| 5358 | // 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] | 5359 | if ((flags_ & NO_STRING_ADD_FLAGS) != 0) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5360 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5361 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5362 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5363 | |
| 5364 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5365 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5366 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5367 | __ j(above_equal, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5368 | } else { |
| 5369 | // Here at least one of the arguments is definitely a string. |
| 5370 | // We convert the one that is not known to be a string. |
| 5371 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5372 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5373 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5374 | &call_builtin); |
| 5375 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5376 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5377 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5378 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5379 | &call_builtin); |
| 5380 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5381 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | // Both arguments are strings. |
| 5385 | // eax: first string |
| 5386 | // edx: second string |
| 5387 | // 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] | 5388 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5389 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5390 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5391 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5392 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5393 | // 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] | 5394 | Counters* counters = masm->isolate()->counters(); |
| 5395 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5396 | __ ret(2 * kPointerSize); |
| 5397 | __ bind(&second_not_zero_length); |
| 5398 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5399 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5400 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5401 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5402 | // First string is empty, result is second string which is in edx. |
| 5403 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5404 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5405 | __ ret(2 * kPointerSize); |
| 5406 | |
| 5407 | // Both strings are non-empty. |
| 5408 | // eax: first string |
| 5409 | // ebx: length of first string as a smi |
| 5410 | // ecx: length of second string as a smi |
| 5411 | // edx: second string |
| 5412 | // Look at the length of the result of adding the two strings. |
| 5413 | Label string_add_flat_result, longer_than_two; |
| 5414 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5415 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5416 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5417 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5418 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5419 | // Use the string table when adding two one character strings, as it |
| 5420 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5421 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5422 | __ j(not_equal, &longer_than_two); |
| 5423 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5424 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5425 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5426 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5427 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5428 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5429 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5430 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5431 | // 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] | 5432 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5433 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5434 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5435 | masm, ebx, ecx, eax, edx, edi, |
| 5436 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5437 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5438 | __ ret(2 * kPointerSize); |
| 5439 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5440 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5441 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5442 | // Reload the arguments. |
| 5443 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5444 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5445 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5446 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5447 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5448 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5449 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5450 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5451 | // Pack both characters in ebx. |
| 5452 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5453 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5454 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5455 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5456 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5457 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5458 | |
| 5459 | __ bind(&longer_than_two); |
| 5460 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5461 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5462 | __ j(below, &string_add_flat_result); |
| 5463 | |
| 5464 | // 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] | 5465 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5466 | Label non_ascii, allocated, ascii_data; |
| 5467 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5468 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5469 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5470 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5471 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5472 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5473 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5474 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5475 | __ j(zero, &non_ascii); |
| 5476 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5477 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5478 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5479 | __ bind(&allocated); |
| 5480 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5481 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5482 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5483 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5484 | Immediate(String::kEmptyHashField)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5485 | |
| 5486 | Label skip_write_barrier, after_writing; |
| 5487 | ExternalReference high_promotion_mode = ExternalReference:: |
| 5488 | new_space_high_promotion_mode_active_address(masm->isolate()); |
| 5489 | __ test(Operand::StaticVariable(high_promotion_mode), Immediate(1)); |
| 5490 | __ j(zero, &skip_write_barrier); |
| 5491 | |
| 5492 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5493 | __ RecordWriteField(ecx, |
| 5494 | ConsString::kFirstOffset, |
| 5495 | eax, |
| 5496 | ebx, |
| 5497 | kDontSaveFPRegs); |
| 5498 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5499 | __ RecordWriteField(ecx, |
| 5500 | ConsString::kSecondOffset, |
| 5501 | edx, |
| 5502 | ebx, |
| 5503 | kDontSaveFPRegs); |
| 5504 | __ jmp(&after_writing); |
| 5505 | |
| 5506 | __ bind(&skip_write_barrier); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5507 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5508 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5509 | |
| 5510 | __ bind(&after_writing); |
| 5511 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5512 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5513 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5514 | __ ret(2 * kPointerSize); |
| 5515 | __ bind(&non_ascii); |
| 5516 | // 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] | 5517 | // to contain only one byte characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5518 | // ecx: first instance type AND second instance type. |
| 5519 | // edi: second instance type. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5520 | __ test(ecx, Immediate(kOneByteDataHintMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5521 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5522 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5523 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5524 | __ xor_(edi, ecx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5525 | STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0); |
| 5526 | __ and_(edi, kOneByteStringTag | kOneByteDataHintTag); |
| 5527 | __ cmp(edi, kOneByteStringTag | kOneByteDataHintTag); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5528 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5529 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5530 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5531 | __ jmp(&allocated); |
| 5532 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5533 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5534 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5535 | // Handle creating a flat result from either external or sequential strings. |
| 5536 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5537 | // eax: first string |
| 5538 | // ebx: length of resulting flat string as a smi |
| 5539 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5540 | Label first_prepared, second_prepared; |
| 5541 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5542 | __ bind(&string_add_flat_result); |
| 5543 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5544 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5545 | // ecx: instance type of first string |
| 5546 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5547 | __ test_b(ecx, kStringRepresentationMask); |
| 5548 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5549 | // Rule out short external string and load string resource. |
| 5550 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5551 | __ test_b(ecx, kShortExternalStringMask); |
| 5552 | __ j(not_zero, &call_runtime); |
| 5553 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5554 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5555 | __ jmp(&first_prepared, Label::kNear); |
| 5556 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5557 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5558 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5559 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5560 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5561 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5562 | // Check whether both strings have same encoding. |
| 5563 | // edi: instance type of second string |
| 5564 | __ xor_(ecx, edi); |
| 5565 | __ test_b(ecx, kStringEncodingMask); |
| 5566 | __ j(not_zero, &call_runtime); |
| 5567 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5568 | __ test_b(edi, kStringRepresentationMask); |
| 5569 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5570 | // Rule out short external string and load string resource. |
| 5571 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5572 | __ test_b(edi, kShortExternalStringMask); |
| 5573 | __ j(not_zero, &call_runtime); |
| 5574 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5575 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5576 | __ jmp(&second_prepared, Label::kNear); |
| 5577 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5578 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5579 | __ bind(&second_prepared); |
| 5580 | |
| 5581 | // Push the addresses of both strings' first characters onto the stack. |
| 5582 | __ push(edx); |
| 5583 | __ push(eax); |
| 5584 | |
| 5585 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5586 | // edi: instance type of second string |
| 5587 | // First string and second string have the same encoding. |
| 5588 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5589 | __ test_b(edi, kStringEncodingMask); |
| 5590 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5591 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5592 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5593 | // ebx: length of resulting flat string as a smi |
| 5594 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5595 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5596 | // eax: result string |
| 5597 | __ mov(ecx, eax); |
| 5598 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5599 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5600 | // Load first argument's length and first character location. Account for |
| 5601 | // values currently on the stack when fetching arguments from it. |
| 5602 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5603 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5604 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5605 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5606 | // eax: result string |
| 5607 | // ecx: first character of result |
| 5608 | // edx: first char of first argument |
| 5609 | // edi: length of first argument |
| 5610 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5611 | // Load second argument's length and first character location. Account for |
| 5612 | // values currently on the stack when fetching arguments from it. |
| 5613 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5614 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5615 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5616 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5617 | // eax: result string |
| 5618 | // ecx: next character of result |
| 5619 | // edx: first char of second argument |
| 5620 | // edi: length of second argument |
| 5621 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5622 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5623 | __ ret(2 * kPointerSize); |
| 5624 | |
| 5625 | // Handle creating a flat two byte result. |
| 5626 | // eax: first string - known to be two byte |
| 5627 | // ebx: length of resulting flat string as a smi |
| 5628 | // edx: second string |
| 5629 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5630 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5631 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5632 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5633 | // eax: result string |
| 5634 | __ mov(ecx, eax); |
| 5635 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5636 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5637 | // Load second argument's length and first character location. Account for |
| 5638 | // values currently on the stack when fetching arguments from it. |
| 5639 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5640 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5641 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5642 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5643 | // eax: result string |
| 5644 | // ecx: first character of result |
| 5645 | // edx: first char of first argument |
| 5646 | // edi: length of first argument |
| 5647 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5648 | // Load second argument's length and first character location. Account for |
| 5649 | // values currently on the stack when fetching arguments from it. |
| 5650 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5651 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5652 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5653 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5654 | // eax: result string |
| 5655 | // ecx: next character of result |
| 5656 | // edx: first char of second argument |
| 5657 | // edi: length of second argument |
| 5658 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5659 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5660 | __ ret(2 * kPointerSize); |
| 5661 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5662 | // Recover stack pointer before jumping to runtime. |
| 5663 | __ bind(&call_runtime_drop_two); |
| 5664 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5665 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5666 | __ bind(&call_runtime); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5667 | if ((flags_ & ERECT_FRAME) != 0) { |
| 5668 | GenerateRegisterArgsPop(masm, ecx); |
| 5669 | // Build a frame |
| 5670 | { |
| 5671 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5672 | GenerateRegisterArgsPush(masm); |
| 5673 | __ CallRuntime(Runtime::kStringAdd, 2); |
| 5674 | } |
| 5675 | __ ret(0); |
| 5676 | } else { |
| 5677 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
| 5678 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5679 | |
| 5680 | if (call_builtin.is_linked()) { |
| 5681 | __ bind(&call_builtin); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5682 | if ((flags_ & ERECT_FRAME) != 0) { |
| 5683 | GenerateRegisterArgsPop(masm, ecx); |
| 5684 | // Build a frame |
| 5685 | { |
| 5686 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5687 | GenerateRegisterArgsPush(masm); |
| 5688 | __ InvokeBuiltin(builtin_id, CALL_FUNCTION); |
| 5689 | } |
| 5690 | __ ret(0); |
| 5691 | } else { |
| 5692 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5693 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5694 | } |
| 5695 | } |
| 5696 | |
| 5697 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5698 | void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
| 5699 | __ push(eax); |
| 5700 | __ push(edx); |
| 5701 | } |
| 5702 | |
| 5703 | |
| 5704 | void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm, |
| 5705 | Register temp) { |
| 5706 | __ pop(temp); |
| 5707 | __ pop(edx); |
| 5708 | __ pop(eax); |
| 5709 | __ push(temp); |
| 5710 | } |
| 5711 | |
| 5712 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5713 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5714 | int stack_offset, |
| 5715 | Register arg, |
| 5716 | Register scratch1, |
| 5717 | Register scratch2, |
| 5718 | Register scratch3, |
| 5719 | Label* slow) { |
| 5720 | // First check if the argument is already a string. |
| 5721 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5722 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5723 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5724 | __ j(below, &done); |
| 5725 | |
| 5726 | // Check the number to string cache. |
| 5727 | Label not_cached; |
| 5728 | __ bind(¬_string); |
| 5729 | // Puts the cached result into scratch1. |
| 5730 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 5731 | arg, |
| 5732 | scratch1, |
| 5733 | scratch2, |
| 5734 | scratch3, |
| 5735 | false, |
| 5736 | ¬_cached); |
| 5737 | __ mov(arg, scratch1); |
| 5738 | __ mov(Operand(esp, stack_offset), arg); |
| 5739 | __ jmp(&done); |
| 5740 | |
| 5741 | // Check if the argument is a safe string wrapper. |
| 5742 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5743 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5744 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 5745 | __ j(not_equal, slow); |
| 5746 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 5747 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 5748 | __ j(zero, slow); |
| 5749 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 5750 | __ mov(Operand(esp, stack_offset), arg); |
| 5751 | |
| 5752 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5753 | } |
| 5754 | |
| 5755 | |
| 5756 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5757 | Register dest, |
| 5758 | Register src, |
| 5759 | Register count, |
| 5760 | Register scratch, |
| 5761 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5762 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5763 | __ bind(&loop); |
| 5764 | // This loop just copies one character at a time, as it is only used for very |
| 5765 | // short strings. |
| 5766 | if (ascii) { |
| 5767 | __ mov_b(scratch, Operand(src, 0)); |
| 5768 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5769 | __ add(src, Immediate(1)); |
| 5770 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5771 | } else { |
| 5772 | __ mov_w(scratch, Operand(src, 0)); |
| 5773 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5774 | __ add(src, Immediate(2)); |
| 5775 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5776 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5777 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5778 | __ j(not_zero, &loop); |
| 5779 | } |
| 5780 | |
| 5781 | |
| 5782 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 5783 | Register dest, |
| 5784 | Register src, |
| 5785 | Register count, |
| 5786 | Register scratch, |
| 5787 | bool ascii) { |
| 5788 | // Copy characters using rep movs of doublewords. |
| 5789 | // The destination is aligned on a 4 byte boundary because we are |
| 5790 | // copying to the beginning of a newly allocated string. |
| 5791 | ASSERT(dest.is(edi)); // rep movs destination |
| 5792 | ASSERT(src.is(esi)); // rep movs source |
| 5793 | ASSERT(count.is(ecx)); // rep movs count |
| 5794 | ASSERT(!scratch.is(dest)); |
| 5795 | ASSERT(!scratch.is(src)); |
| 5796 | ASSERT(!scratch.is(count)); |
| 5797 | |
| 5798 | // Nothing to do for zero characters. |
| 5799 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5800 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5801 | __ j(zero, &done); |
| 5802 | |
| 5803 | // Make count the number of bytes to copy. |
| 5804 | if (!ascii) { |
| 5805 | __ shl(count, 1); |
| 5806 | } |
| 5807 | |
| 5808 | // 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] | 5809 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5810 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5811 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5812 | |
| 5813 | // Copy from edi to esi using rep movs instruction. |
| 5814 | __ mov(scratch, count); |
| 5815 | __ sar(count, 2); // Number of doublewords to copy. |
| 5816 | __ cld(); |
| 5817 | __ rep_movs(); |
| 5818 | |
| 5819 | // Find number of bytes left. |
| 5820 | __ mov(count, scratch); |
| 5821 | __ and_(count, 3); |
| 5822 | |
| 5823 | // Check if there are more bytes to copy. |
| 5824 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5825 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5826 | __ j(zero, &done); |
| 5827 | |
| 5828 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5829 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5830 | __ bind(&loop); |
| 5831 | __ mov_b(scratch, Operand(src, 0)); |
| 5832 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5833 | __ add(src, Immediate(1)); |
| 5834 | __ add(dest, Immediate(1)); |
| 5835 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5836 | __ j(not_zero, &loop); |
| 5837 | |
| 5838 | __ bind(&done); |
| 5839 | } |
| 5840 | |
| 5841 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5842 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5843 | Register c1, |
| 5844 | Register c2, |
| 5845 | Register scratch1, |
| 5846 | Register scratch2, |
| 5847 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5848 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5849 | Label* not_found) { |
| 5850 | // Register scratch3 is the general scratch register in this function. |
| 5851 | Register scratch = scratch3; |
| 5852 | |
| 5853 | // 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] | 5854 | // 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] | 5855 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5856 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5857 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5858 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5859 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5860 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5861 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5862 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5863 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5864 | |
| 5865 | __ bind(¬_array_index); |
| 5866 | // Calculate the two character string hash. |
| 5867 | Register hash = scratch1; |
| 5868 | GenerateHashInit(masm, hash, c1, scratch); |
| 5869 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 5870 | GenerateHashGetHash(masm, hash, scratch); |
| 5871 | |
| 5872 | // Collect the two characters in a register. |
| 5873 | Register chars = c1; |
| 5874 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5875 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5876 | |
| 5877 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5878 | // hash: hash of two character string. |
| 5879 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5880 | // Load the string table. |
| 5881 | Register string_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5882 | ExternalReference roots_array_start = |
| 5883 | ExternalReference::roots_array_start(masm->isolate()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5884 | __ mov(scratch, Immediate(Heap::kStringTableRootIndex)); |
| 5885 | __ mov(string_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5886 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5887 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5888 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5889 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5890 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5891 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5892 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5893 | |
| 5894 | // Registers |
| 5895 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5896 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5897 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5898 | // mask: capacity mask |
| 5899 | // scratch: - |
| 5900 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5901 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5902 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5903 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5904 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5905 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5906 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5907 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5908 | __ mov(scratch, hash); |
| 5909 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5910 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5911 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5912 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5913 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5914 | // Load the entry from the string table. |
| 5915 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5916 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5917 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5918 | scratch, |
| 5919 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5920 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5921 | |
| 5922 | // 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] | 5923 | Factory* factory = masm->isolate()->factory(); |
| 5924 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5925 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5926 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5927 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5928 | |
| 5929 | // If length is not 2 the string is not a candidate. |
| 5930 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 5931 | Immediate(Smi::FromInt(2))); |
| 5932 | __ j(not_equal, &next_probe[i]); |
| 5933 | |
| 5934 | // As we are out of registers save the mask on the stack and use that |
| 5935 | // register as a temporary. |
| 5936 | __ push(mask); |
| 5937 | Register temp = mask; |
| 5938 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5939 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5940 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 5941 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 5942 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 5943 | temp, temp, &next_probe_pop_mask[i]); |
| 5944 | |
| 5945 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5946 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5947 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5948 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5949 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5950 | __ bind(&next_probe_pop_mask[i]); |
| 5951 | __ pop(mask); |
| 5952 | __ bind(&next_probe[i]); |
| 5953 | } |
| 5954 | |
| 5955 | // No matching 2 character string found by probing. |
| 5956 | __ jmp(not_found); |
| 5957 | |
| 5958 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5959 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5960 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5961 | __ pop(mask); // Pop saved mask from the stack. |
| 5962 | if (!result.is(eax)) { |
| 5963 | __ mov(eax, result); |
| 5964 | } |
| 5965 | } |
| 5966 | |
| 5967 | |
| 5968 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 5969 | Register hash, |
| 5970 | Register character, |
| 5971 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5972 | // hash = (seed + character) + ((seed + character) << 10); |
| 5973 | if (Serializer::enabled()) { |
| 5974 | ExternalReference roots_array_start = |
| 5975 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5976 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5977 | __ mov(scratch, Operand::StaticArray(scratch, |
| 5978 | times_pointer_size, |
| 5979 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5980 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5981 | __ add(scratch, character); |
| 5982 | __ mov(hash, scratch); |
| 5983 | __ shl(scratch, 10); |
| 5984 | __ add(hash, scratch); |
| 5985 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5986 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5987 | __ lea(scratch, Operand(character, seed)); |
| 5988 | __ shl(scratch, 10); |
| 5989 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 5990 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5991 | // hash ^= hash >> 6; |
| 5992 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5993 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5994 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5995 | } |
| 5996 | |
| 5997 | |
| 5998 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 5999 | Register hash, |
| 6000 | Register character, |
| 6001 | Register scratch) { |
| 6002 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6003 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6004 | // hash += hash << 10; |
| 6005 | __ mov(scratch, hash); |
| 6006 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6007 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6008 | // hash ^= hash >> 6; |
| 6009 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6010 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6011 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6012 | } |
| 6013 | |
| 6014 | |
| 6015 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6016 | Register hash, |
| 6017 | Register scratch) { |
| 6018 | // hash += hash << 3; |
| 6019 | __ mov(scratch, hash); |
| 6020 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6021 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6022 | // hash ^= hash >> 11; |
| 6023 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6024 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6025 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6026 | // hash += hash << 15; |
| 6027 | __ mov(scratch, hash); |
| 6028 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6029 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6030 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6031 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6032 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6033 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6034 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6035 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6036 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6037 | __ bind(&hash_not_zero); |
| 6038 | } |
| 6039 | |
| 6040 | |
| 6041 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6042 | Label runtime; |
| 6043 | |
| 6044 | // Stack frame on entry. |
| 6045 | // esp[0]: return address |
| 6046 | // esp[4]: to |
| 6047 | // esp[8]: from |
| 6048 | // esp[12]: string |
| 6049 | |
| 6050 | // Make sure first argument is a string. |
| 6051 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6052 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6053 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6054 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6055 | __ j(NegateCondition(is_string), &runtime); |
| 6056 | |
| 6057 | // eax: string |
| 6058 | // ebx: instance type |
| 6059 | |
| 6060 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6061 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6062 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6063 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6064 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6065 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6066 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6067 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6068 | // Shorter than original string's length: an actual substring. |
| 6069 | __ j(below, ¬_original_string, Label::kNear); |
| 6070 | // Longer than original string's length or negative: unsafe arguments. |
| 6071 | __ j(above, &runtime); |
| 6072 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6073 | Counters* counters = masm->isolate()->counters(); |
| 6074 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6075 | __ ret(3 * kPointerSize); |
| 6076 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6077 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6078 | Label single_char; |
| 6079 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 6080 | __ j(equal, &single_char); |
| 6081 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6082 | // eax: string |
| 6083 | // ebx: instance type |
| 6084 | // ecx: sub string length (smi) |
| 6085 | // edx: from index (smi) |
| 6086 | // Deal with different string types: update the index if necessary |
| 6087 | // and put the underlying string into edi. |
| 6088 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6089 | // If the string is not indirect, it can only be sequential or external. |
| 6090 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6091 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6092 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6093 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6094 | |
| 6095 | Factory* factory = masm->isolate()->factory(); |
| 6096 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6097 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6098 | // Cons string. Check whether it is flat, then fetch first part. |
| 6099 | // Flat cons strings have an empty second part. |
| 6100 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6101 | factory->empty_string()); |
| 6102 | __ j(not_equal, &runtime); |
| 6103 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6104 | // Update instance type. |
| 6105 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6106 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6107 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6108 | |
| 6109 | __ bind(&sliced_string); |
| 6110 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6111 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6112 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6113 | // Update instance type. |
| 6114 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6115 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6116 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6117 | |
| 6118 | __ bind(&seq_or_external_string); |
| 6119 | // Sequential or external string. Just move string to the expected register. |
| 6120 | __ mov(edi, eax); |
| 6121 | |
| 6122 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6123 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6124 | if (FLAG_string_slices) { |
| 6125 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6126 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6127 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6128 | // edx: adjusted start index (smi) |
| 6129 | // ecx: length (smi) |
| 6130 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6131 | // Short slice. Copy instead of slicing. |
| 6132 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6133 | // Allocate new sliced string. At this point we do not reload the instance |
| 6134 | // type including the string encoding because we simply rely on the info |
| 6135 | // provided by the original string. It does not matter if the original |
| 6136 | // string's encoding is wrong because we always have to recheck encoding of |
| 6137 | // the newly created string's parent anyways due to externalized strings. |
| 6138 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6139 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6140 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6141 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6142 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6143 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6144 | __ jmp(&set_slice_header, Label::kNear); |
| 6145 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6146 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6147 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6148 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6149 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6150 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6151 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6152 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6153 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6154 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6155 | |
| 6156 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6157 | } |
| 6158 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6159 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6160 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6161 | // edx: adjusted start index (smi) |
| 6162 | // ecx: length (smi) |
| 6163 | // The subject string can only be external or sequential string of either |
| 6164 | // encoding at this point. |
| 6165 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6166 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6167 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6168 | __ test_b(ebx, kExternalStringTag); |
| 6169 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6170 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6171 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6172 | // Rule out short external strings. |
| 6173 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6174 | __ test_b(ebx, kShortExternalStringMask); |
| 6175 | __ j(not_zero, &runtime); |
| 6176 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6177 | // 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] | 6178 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6179 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6180 | |
| 6181 | __ bind(&sequential_string); |
| 6182 | // Stash away (adjusted) index and (underlying) string. |
| 6183 | __ push(edx); |
| 6184 | __ push(edi); |
| 6185 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6186 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6187 | __ test_b(ebx, kStringEncodingMask); |
| 6188 | __ j(zero, &two_byte_sequential); |
| 6189 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6190 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6191 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6192 | |
| 6193 | // eax: result string |
| 6194 | // ecx: result string length |
| 6195 | __ mov(edx, esi); // esi used by following code. |
| 6196 | // Locate first character of result. |
| 6197 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6198 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6199 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6200 | __ pop(esi); |
| 6201 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6202 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6203 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6204 | |
| 6205 | // eax: result string |
| 6206 | // ecx: result length |
| 6207 | // edx: original value of esi |
| 6208 | // edi: first character of result |
| 6209 | // esi: character of sub string start |
| 6210 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6211 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6212 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6213 | __ ret(3 * kPointerSize); |
| 6214 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6215 | __ bind(&two_byte_sequential); |
| 6216 | // Sequential two-byte string. Allocate the result. |
| 6217 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6218 | |
| 6219 | // eax: result string |
| 6220 | // ecx: result string length |
| 6221 | __ mov(edx, esi); // esi used by following code. |
| 6222 | // Locate first character of result. |
| 6223 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6224 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6225 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6226 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6227 | __ pop(esi); |
| 6228 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6229 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6230 | // byte character. |
| 6231 | STATIC_ASSERT(kSmiTag == 0); |
| 6232 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6233 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6234 | |
| 6235 | // eax: result string |
| 6236 | // ecx: result length |
| 6237 | // edx: original value of esi |
| 6238 | // edi: first character of result |
| 6239 | // esi: character of sub string start |
| 6240 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6241 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6242 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6243 | __ ret(3 * kPointerSize); |
| 6244 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6245 | // Drop pushed values on the stack before tail call. |
| 6246 | __ bind(&runtime_drop_two); |
| 6247 | __ Drop(2); |
| 6248 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6249 | // Just jump to runtime to create the sub string. |
| 6250 | __ bind(&runtime); |
| 6251 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6252 | |
| 6253 | __ bind(&single_char); |
| 6254 | // eax: string |
| 6255 | // ebx: instance type |
| 6256 | // ecx: sub string length (smi) |
| 6257 | // edx: from index (smi) |
| 6258 | StringCharAtGenerator generator( |
| 6259 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6260 | generator.GenerateFast(masm); |
| 6261 | __ ret(3 * kPointerSize); |
| 6262 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6263 | } |
| 6264 | |
| 6265 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6266 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6267 | Register left, |
| 6268 | Register right, |
| 6269 | Register scratch1, |
| 6270 | Register scratch2) { |
| 6271 | Register length = scratch1; |
| 6272 | |
| 6273 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6274 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6275 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6276 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6277 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6278 | __ bind(&strings_not_equal); |
| 6279 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6280 | __ ret(0); |
| 6281 | |
| 6282 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6283 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6284 | __ bind(&check_zero_length); |
| 6285 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6286 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6287 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6288 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6289 | __ ret(0); |
| 6290 | |
| 6291 | // Compare characters. |
| 6292 | __ bind(&compare_chars); |
| 6293 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6294 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6295 | |
| 6296 | // Characters are equal. |
| 6297 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6298 | __ ret(0); |
| 6299 | } |
| 6300 | |
| 6301 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6302 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6303 | Register left, |
| 6304 | Register right, |
| 6305 | Register scratch1, |
| 6306 | Register scratch2, |
| 6307 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6308 | Counters* counters = masm->isolate()->counters(); |
| 6309 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6310 | |
| 6311 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6312 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6313 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6314 | __ mov(scratch3, scratch1); |
| 6315 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6316 | |
| 6317 | Register length_delta = scratch3; |
| 6318 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6319 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6320 | // 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] | 6321 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6322 | __ bind(&left_shorter); |
| 6323 | |
| 6324 | Register min_length = scratch1; |
| 6325 | |
| 6326 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6327 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6328 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6329 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6330 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6331 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6332 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6333 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6334 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6335 | |
| 6336 | // Compare lengths - strings up to min-length are equal. |
| 6337 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6338 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6339 | Label length_not_equal; |
| 6340 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6341 | |
| 6342 | // Result is EQUAL. |
| 6343 | STATIC_ASSERT(EQUAL == 0); |
| 6344 | STATIC_ASSERT(kSmiTag == 0); |
| 6345 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6346 | __ ret(0); |
| 6347 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6348 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6349 | Label result_less; |
| 6350 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6351 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6352 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6353 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6354 | __ j(above, &result_greater, Label::kNear); |
| 6355 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6356 | |
| 6357 | // Result is LESS. |
| 6358 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6359 | __ ret(0); |
| 6360 | |
| 6361 | // Result is GREATER. |
| 6362 | __ bind(&result_greater); |
| 6363 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6364 | __ ret(0); |
| 6365 | } |
| 6366 | |
| 6367 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6368 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6369 | MacroAssembler* masm, |
| 6370 | Register left, |
| 6371 | Register right, |
| 6372 | Register length, |
| 6373 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6374 | Label* chars_not_equal, |
| 6375 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6376 | // Change index to run from -length to -1 by adding length to string |
| 6377 | // start. This means that loop ends when index reaches zero, which |
| 6378 | // doesn't need an additional compare. |
| 6379 | __ SmiUntag(length); |
| 6380 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6381 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6382 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6383 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6384 | __ neg(length); |
| 6385 | Register index = length; // index = -length; |
| 6386 | |
| 6387 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6388 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6389 | __ bind(&loop); |
| 6390 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6391 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6392 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6393 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6394 | __ j(not_zero, &loop); |
| 6395 | } |
| 6396 | |
| 6397 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6398 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6399 | Label runtime; |
| 6400 | |
| 6401 | // Stack frame on entry. |
| 6402 | // esp[0]: return address |
| 6403 | // esp[4]: right string |
| 6404 | // esp[8]: left string |
| 6405 | |
| 6406 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6407 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6408 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6409 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6410 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6411 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6412 | STATIC_ASSERT(EQUAL == 0); |
| 6413 | STATIC_ASSERT(kSmiTag == 0); |
| 6414 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6415 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6416 | __ ret(2 * kPointerSize); |
| 6417 | |
| 6418 | __ bind(¬_same); |
| 6419 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6420 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6421 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6422 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6423 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6424 | // Drop arguments from the stack. |
| 6425 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6426 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6427 | __ push(ecx); |
| 6428 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6429 | |
| 6430 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6431 | // tagged as a small integer. |
| 6432 | __ bind(&runtime); |
| 6433 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6434 | } |
| 6435 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6436 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6437 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6438 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6439 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6440 | __ mov(ecx, edx); |
| 6441 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6442 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6443 | |
| 6444 | if (GetCondition() == equal) { |
| 6445 | // 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] | 6446 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6447 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6448 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6449 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6450 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6451 | // Correct sign of result in case of overflow. |
| 6452 | __ not_(edx); |
| 6453 | __ bind(&done); |
| 6454 | __ mov(eax, edx); |
| 6455 | } |
| 6456 | __ ret(0); |
| 6457 | |
| 6458 | __ bind(&miss); |
| 6459 | GenerateMiss(masm); |
| 6460 | } |
| 6461 | |
| 6462 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6463 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6464 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6465 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6466 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6467 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6468 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6469 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6470 | if (left_ == CompareIC::SMI) { |
| 6471 | __ JumpIfNotSmi(edx, &miss); |
| 6472 | } |
| 6473 | if (right_ == CompareIC::SMI) { |
| 6474 | __ JumpIfNotSmi(eax, &miss); |
| 6475 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6476 | |
| 6477 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6478 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6479 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6480 | CpuFeatureScope scope1(masm, SSE2); |
| 6481 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6482 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6483 | // Load left and right operand. |
| 6484 | Label done, left, left_smi, right_smi; |
| 6485 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6486 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6487 | masm->isolate()->factory()->heap_number_map()); |
| 6488 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6489 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6490 | __ jmp(&left, Label::kNear); |
| 6491 | __ bind(&right_smi); |
| 6492 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6493 | __ SmiUntag(ecx); |
| 6494 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6495 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6496 | __ bind(&left); |
| 6497 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6498 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6499 | masm->isolate()->factory()->heap_number_map()); |
| 6500 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6501 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6502 | __ jmp(&done); |
| 6503 | __ bind(&left_smi); |
| 6504 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6505 | __ SmiUntag(ecx); |
| 6506 | __ cvtsi2sd(xmm0, ecx); |
| 6507 | |
| 6508 | __ bind(&done); |
| 6509 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6510 | __ ucomisd(xmm0, xmm1); |
| 6511 | |
| 6512 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6513 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6514 | |
| 6515 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6516 | // Performing mov, because xor would destroy the flag register. |
| 6517 | __ mov(eax, 0); // equal |
| 6518 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6519 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6520 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6521 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6522 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6523 | } else { |
| 6524 | __ mov(ecx, edx); |
| 6525 | __ and_(ecx, eax); |
| 6526 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6527 | |
| 6528 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6529 | masm->isolate()->factory()->heap_number_map()); |
| 6530 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6531 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6532 | masm->isolate()->factory()->heap_number_map()); |
| 6533 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6534 | } |
| 6535 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6536 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6537 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6538 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6539 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6540 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6541 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6542 | __ bind(&maybe_undefined1); |
| 6543 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6544 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6545 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6546 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6547 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6548 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6549 | __ jmp(&unordered); |
| 6550 | } |
| 6551 | |
| 6552 | __ bind(&maybe_undefined2); |
| 6553 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6554 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6555 | __ j(equal, &unordered); |
| 6556 | } |
| 6557 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6558 | __ bind(&miss); |
| 6559 | GenerateMiss(masm); |
| 6560 | } |
| 6561 | |
| 6562 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6563 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 6564 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6565 | ASSERT(GetCondition() == equal); |
| 6566 | |
| 6567 | // Registers containing left and right operands respectively. |
| 6568 | Register left = edx; |
| 6569 | Register right = eax; |
| 6570 | Register tmp1 = ecx; |
| 6571 | Register tmp2 = ebx; |
| 6572 | |
| 6573 | // Check that both operands are heap objects. |
| 6574 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6575 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6576 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6577 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6578 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6579 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6580 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6581 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6582 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6583 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6584 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6585 | STATIC_ASSERT(kInternalizedTag != 0); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6586 | __ and_(tmp1, Immediate(kIsNotStringMask | kIsInternalizedMask)); |
| 6587 | __ cmpb(tmp1, kInternalizedTag | kStringTag); |
| 6588 | __ j(not_equal, &miss, Label::kNear); |
| 6589 | |
| 6590 | __ and_(tmp2, Immediate(kIsNotStringMask | kIsInternalizedMask)); |
| 6591 | __ cmpb(tmp2, kInternalizedTag | kStringTag); |
| 6592 | __ j(not_equal, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6593 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6594 | // Internalized strings are compared by identity. |
| 6595 | Label done; |
| 6596 | __ cmp(left, right); |
| 6597 | // Make sure eax is non-zero. At this point input operands are |
| 6598 | // guaranteed to be non-zero. |
| 6599 | ASSERT(right.is(eax)); |
| 6600 | __ j(not_equal, &done, Label::kNear); |
| 6601 | STATIC_ASSERT(EQUAL == 0); |
| 6602 | STATIC_ASSERT(kSmiTag == 0); |
| 6603 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6604 | __ bind(&done); |
| 6605 | __ ret(0); |
| 6606 | |
| 6607 | __ bind(&miss); |
| 6608 | GenerateMiss(masm); |
| 6609 | } |
| 6610 | |
| 6611 | |
| 6612 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 6613 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 6614 | ASSERT(GetCondition() == equal); |
| 6615 | |
| 6616 | // Registers containing left and right operands respectively. |
| 6617 | Register left = edx; |
| 6618 | Register right = eax; |
| 6619 | Register tmp1 = ecx; |
| 6620 | Register tmp2 = ebx; |
| 6621 | |
| 6622 | // Check that both operands are heap objects. |
| 6623 | Label miss; |
| 6624 | __ mov(tmp1, left); |
| 6625 | STATIC_ASSERT(kSmiTag == 0); |
| 6626 | __ and_(tmp1, right); |
| 6627 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 6628 | |
| 6629 | // Check that both operands are unique names. This leaves the instance |
| 6630 | // types loaded in tmp1 and tmp2. |
| 6631 | STATIC_ASSERT(kInternalizedTag != 0); |
| 6632 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6633 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6634 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6635 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6636 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6637 | __ JumpIfNotUniqueName(tmp1, &miss, Label::kNear); |
| 6638 | __ JumpIfNotUniqueName(tmp2, &miss, Label::kNear); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6639 | |
| 6640 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6641 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6642 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6643 | // Make sure eax is non-zero. At this point input operands are |
| 6644 | // guaranteed to be non-zero. |
| 6645 | ASSERT(right.is(eax)); |
| 6646 | __ j(not_equal, &done, Label::kNear); |
| 6647 | STATIC_ASSERT(EQUAL == 0); |
| 6648 | STATIC_ASSERT(kSmiTag == 0); |
| 6649 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6650 | __ bind(&done); |
| 6651 | __ ret(0); |
| 6652 | |
| 6653 | __ bind(&miss); |
| 6654 | GenerateMiss(masm); |
| 6655 | } |
| 6656 | |
| 6657 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6658 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6659 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6660 | Label miss; |
| 6661 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6662 | bool equality = Token::IsEqualityOp(op_); |
| 6663 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6664 | // Registers containing left and right operands respectively. |
| 6665 | Register left = edx; |
| 6666 | Register right = eax; |
| 6667 | Register tmp1 = ecx; |
| 6668 | Register tmp2 = ebx; |
| 6669 | Register tmp3 = edi; |
| 6670 | |
| 6671 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6672 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6673 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6674 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6675 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6676 | |
| 6677 | // Check that both operands are strings. This leaves the instance |
| 6678 | // types loaded in tmp1 and tmp2. |
| 6679 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6680 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6681 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6682 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6683 | __ mov(tmp3, tmp1); |
| 6684 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6685 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6686 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6687 | __ j(not_zero, &miss); |
| 6688 | |
| 6689 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6690 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6691 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6692 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6693 | STATIC_ASSERT(EQUAL == 0); |
| 6694 | STATIC_ASSERT(kSmiTag == 0); |
| 6695 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6696 | __ ret(0); |
| 6697 | |
| 6698 | // Handle not identical strings. |
| 6699 | __ bind(¬_same); |
| 6700 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6701 | // 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] | 6702 | // because we already know they are not identical. But in the case of |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6703 | // non-equality compare, we still need to determine the order. We |
| 6704 | // also know they are both strings. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6705 | if (equality) { |
| 6706 | Label do_compare; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6707 | STATIC_ASSERT(kInternalizedTag != 0); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6708 | __ and_(tmp1, tmp2); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6709 | __ test(tmp1, Immediate(kIsInternalizedMask)); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6710 | __ j(zero, &do_compare, Label::kNear); |
| 6711 | // Make sure eax is non-zero. At this point input operands are |
| 6712 | // guaranteed to be non-zero. |
| 6713 | ASSERT(right.is(eax)); |
| 6714 | __ ret(0); |
| 6715 | __ bind(&do_compare); |
| 6716 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6717 | |
| 6718 | // Check that both strings are sequential ASCII. |
| 6719 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6720 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6721 | |
| 6722 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6723 | if (equality) { |
| 6724 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6725 | masm, left, right, tmp1, tmp2); |
| 6726 | } else { |
| 6727 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6728 | masm, left, right, tmp1, tmp2, tmp3); |
| 6729 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6730 | |
| 6731 | // Handle more complex cases in runtime. |
| 6732 | __ bind(&runtime); |
| 6733 | __ pop(tmp1); // Return address. |
| 6734 | __ push(left); |
| 6735 | __ push(right); |
| 6736 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6737 | if (equality) { |
| 6738 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6739 | } else { |
| 6740 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6741 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6742 | |
| 6743 | __ bind(&miss); |
| 6744 | GenerateMiss(masm); |
| 6745 | } |
| 6746 | |
| 6747 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6748 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6749 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6750 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6751 | __ mov(ecx, edx); |
| 6752 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6753 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6754 | |
| 6755 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6756 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6757 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6758 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6759 | |
| 6760 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6761 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6762 | __ ret(0); |
| 6763 | |
| 6764 | __ bind(&miss); |
| 6765 | GenerateMiss(masm); |
| 6766 | } |
| 6767 | |
| 6768 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6769 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6770 | Label miss; |
| 6771 | __ mov(ecx, edx); |
| 6772 | __ and_(ecx, eax); |
| 6773 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6774 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6775 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 6776 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 6777 | __ cmp(ecx, known_map_); |
| 6778 | __ j(not_equal, &miss, Label::kNear); |
| 6779 | __ cmp(ebx, known_map_); |
| 6780 | __ j(not_equal, &miss, Label::kNear); |
| 6781 | |
| 6782 | __ sub(eax, edx); |
| 6783 | __ ret(0); |
| 6784 | |
| 6785 | __ bind(&miss); |
| 6786 | GenerateMiss(masm); |
| 6787 | } |
| 6788 | |
| 6789 | |
| 6790 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6791 | { |
| 6792 | // Call the runtime system in a fresh internal frame. |
| 6793 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 6794 | masm->isolate()); |
| 6795 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6796 | __ push(edx); // Preserve edx and eax. |
| 6797 | __ push(eax); |
| 6798 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6799 | __ push(eax); |
| 6800 | __ push(Immediate(Smi::FromInt(op_))); |
| 6801 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6802 | // Compute the entry point of the rewritten stub. |
| 6803 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 6804 | __ pop(eax); |
| 6805 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6806 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6807 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6808 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6809 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6810 | } |
| 6811 | |
| 6812 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6813 | // Helper function used to check that the dictionary doesn't contain |
| 6814 | // the property. This function may return false negatives, so miss_label |
| 6815 | // must always call a backup property check that is complete. |
| 6816 | // 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] | 6817 | // Name must be a unique name and receiver must be a heap object. |
| 6818 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6819 | Label* miss, |
| 6820 | Label* done, |
| 6821 | Register properties, |
| 6822 | Handle<Name> name, |
| 6823 | Register r0) { |
| 6824 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6825 | |
| 6826 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6827 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6828 | // undefined value), it guarantees the hash table doesn't contain the |
| 6829 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6830 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6831 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6832 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6833 | Register index = r0; |
| 6834 | // Capacity is smi 2^n. |
| 6835 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 6836 | __ dec(index); |
| 6837 | __ and_(index, |
| 6838 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6839 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6840 | |
| 6841 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6842 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6843 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6844 | Register entity_name = r0; |
| 6845 | // Having undefined at this place means the name is not contained. |
| 6846 | ASSERT_EQ(kSmiTagSize, 1); |
| 6847 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 6848 | kElementsStartOffset - kHeapObjectTag)); |
| 6849 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 6850 | __ j(equal, done); |
| 6851 | |
| 6852 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6853 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6854 | __ j(equal, miss); |
| 6855 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6856 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6857 | // Check for the hole and skip. |
| 6858 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6859 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6860 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6861 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6862 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6863 | __ JumpIfNotUniqueName(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6864 | miss); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6865 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6866 | } |
| 6867 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6868 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6869 | __ push(Immediate(Handle<Object>(name))); |
| 6870 | __ push(Immediate(name->Hash())); |
| 6871 | __ CallStub(&stub); |
| 6872 | __ test(r0, r0); |
| 6873 | __ j(not_zero, miss); |
| 6874 | __ jmp(done); |
| 6875 | } |
| 6876 | |
| 6877 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6878 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6879 | // |done| label if a property with the given name is found leaving the |
| 6880 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 6881 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6882 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6883 | Label* miss, |
| 6884 | Label* done, |
| 6885 | Register elements, |
| 6886 | Register name, |
| 6887 | Register r0, |
| 6888 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6889 | ASSERT(!elements.is(r0)); |
| 6890 | ASSERT(!elements.is(r1)); |
| 6891 | ASSERT(!name.is(r0)); |
| 6892 | ASSERT(!name.is(r1)); |
| 6893 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6894 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6895 | |
| 6896 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 6897 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 6898 | __ dec(r1); |
| 6899 | |
| 6900 | // Generate an unrolled loop that performs a few probes before |
| 6901 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6902 | // cover ~93% of loads from dictionaries. |
| 6903 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6904 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6905 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 6906 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6907 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6908 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6909 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6910 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6911 | |
| 6912 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6913 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6914 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 6915 | |
| 6916 | // Check if the key is identical to the name. |
| 6917 | __ cmp(name, Operand(elements, |
| 6918 | r0, |
| 6919 | times_4, |
| 6920 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6921 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6922 | } |
| 6923 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6924 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6925 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6926 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 6927 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6928 | __ push(r0); |
| 6929 | __ CallStub(&stub); |
| 6930 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6931 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6932 | __ j(zero, miss); |
| 6933 | __ jmp(done); |
| 6934 | } |
| 6935 | |
| 6936 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6937 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6938 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 6939 | // 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] | 6940 | // Stack frame on entry: |
| 6941 | // esp[0 * kPointerSize]: return address. |
| 6942 | // esp[1 * kPointerSize]: key's hash. |
| 6943 | // esp[2 * kPointerSize]: key. |
| 6944 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6945 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6946 | // result_: used as scratch. |
| 6947 | // index_: will hold an index of entry if lookup is successful. |
| 6948 | // might alias with result_. |
| 6949 | // Returns: |
| 6950 | // result_ is zero if lookup failed, non zero otherwise. |
| 6951 | |
| 6952 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 6953 | |
| 6954 | Register scratch = result_; |
| 6955 | |
| 6956 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 6957 | __ dec(scratch); |
| 6958 | __ SmiUntag(scratch); |
| 6959 | __ push(scratch); |
| 6960 | |
| 6961 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6962 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6963 | // undefined value), it guarantees the hash table doesn't contain the |
| 6964 | // property. It's true even if some slots represent deleted properties |
| 6965 | // (their names are the null value). |
| 6966 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 6967 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6968 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 6969 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6970 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6971 | } |
| 6972 | __ and_(scratch, Operand(esp, 0)); |
| 6973 | |
| 6974 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6975 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6976 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 6977 | |
| 6978 | // Having undefined at this place means the name is not contained. |
| 6979 | ASSERT_EQ(kSmiTagSize, 1); |
| 6980 | __ mov(scratch, Operand(dictionary_, |
| 6981 | index_, |
| 6982 | times_pointer_size, |
| 6983 | kElementsStartOffset - kHeapObjectTag)); |
| 6984 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 6985 | __ j(equal, ¬_in_dictionary); |
| 6986 | |
| 6987 | // Stop if found the property. |
| 6988 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 6989 | __ j(equal, &in_dictionary); |
| 6990 | |
| 6991 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6992 | // 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] | 6993 | // 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] | 6994 | // key we are looking for. |
| 6995 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6996 | // Check if the entry name is not a unique name. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6997 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6998 | __ JumpIfNotUniqueName(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 6999 | &maybe_in_dictionary); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7000 | } |
| 7001 | } |
| 7002 | |
| 7003 | __ bind(&maybe_in_dictionary); |
| 7004 | // If we are doing negative lookup then probing failure should be |
| 7005 | // treated as a lookup success. For positive lookup probing failure |
| 7006 | // should be treated as lookup failure. |
| 7007 | if (mode_ == POSITIVE_LOOKUP) { |
| 7008 | __ mov(result_, Immediate(0)); |
| 7009 | __ Drop(1); |
| 7010 | __ ret(2 * kPointerSize); |
| 7011 | } |
| 7012 | |
| 7013 | __ bind(&in_dictionary); |
| 7014 | __ mov(result_, Immediate(1)); |
| 7015 | __ Drop(1); |
| 7016 | __ ret(2 * kPointerSize); |
| 7017 | |
| 7018 | __ bind(¬_in_dictionary); |
| 7019 | __ mov(result_, Immediate(0)); |
| 7020 | __ Drop(1); |
| 7021 | __ ret(2 * kPointerSize); |
| 7022 | } |
| 7023 | |
| 7024 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7025 | struct AheadOfTimeWriteBarrierStubList { |
| 7026 | Register object, value, address; |
| 7027 | RememberedSetAction action; |
| 7028 | }; |
| 7029 | |
| 7030 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7031 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7032 | |
| 7033 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7034 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7035 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7036 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7037 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7038 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7039 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7040 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7041 | // Used in StoreStubCompiler::CompileStoreField and |
| 7042 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7043 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7044 | // GenerateStoreField calls the stub with two different permutations of |
| 7045 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7046 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7047 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7048 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7049 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7050 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7051 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7052 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7053 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7054 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7055 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7056 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7057 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7058 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7059 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7060 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7061 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7062 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7063 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7064 | // FastNewClosureStub and StringAddStub::Generate |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7065 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7066 | // StringAddStub::Generate |
| 7067 | { REG(ecx), REG(eax), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7068 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7069 | { 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] | 7070 | }; |
| 7071 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7072 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7073 | |
| 7074 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7075 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7076 | !entry->object.is(no_reg); |
| 7077 | entry++) { |
| 7078 | if (object_.is(entry->object) && |
| 7079 | value_.is(entry->value) && |
| 7080 | address_.is(entry->address) && |
| 7081 | remembered_set_action_ == entry->action && |
| 7082 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7083 | return true; |
| 7084 | } |
| 7085 | } |
| 7086 | return false; |
| 7087 | } |
| 7088 | |
| 7089 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7090 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 7091 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7092 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
| 7093 | stub.GetCode(isolate)->set_is_pregenerated(true); |
| 7094 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7095 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7096 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7097 | } |
| 7098 | } |
| 7099 | |
| 7100 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7101 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7102 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7103 | !entry->object.is(no_reg); |
| 7104 | entry++) { |
| 7105 | RecordWriteStub stub(entry->object, |
| 7106 | entry->value, |
| 7107 | entry->address, |
| 7108 | entry->action, |
| 7109 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7110 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7111 | } |
| 7112 | } |
| 7113 | |
| 7114 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7115 | bool CodeStub::CanUseFPRegisters() { |
| 7116 | return CpuFeatures::IsSupported(SSE2); |
| 7117 | } |
| 7118 | |
| 7119 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7120 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7121 | // the value has just been written into the object, now this stub makes sure |
| 7122 | // we keep the GC informed. The word in the object where the value has been |
| 7123 | // written is in the address register. |
| 7124 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7125 | Label skip_to_incremental_noncompacting; |
| 7126 | Label skip_to_incremental_compacting; |
| 7127 | |
| 7128 | // The first two instructions are generated with labels so as to get the |
| 7129 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7130 | // forth between a compare instructions (a nop in this position) and the |
| 7131 | // real branch when we start and stop incremental heap marking. |
| 7132 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7133 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7134 | |
| 7135 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7136 | __ RememberedSetHelper(object_, |
| 7137 | address_, |
| 7138 | value_, |
| 7139 | save_fp_regs_mode_, |
| 7140 | MacroAssembler::kReturnAtEnd); |
| 7141 | } else { |
| 7142 | __ ret(0); |
| 7143 | } |
| 7144 | |
| 7145 | __ bind(&skip_to_incremental_noncompacting); |
| 7146 | GenerateIncremental(masm, INCREMENTAL); |
| 7147 | |
| 7148 | __ bind(&skip_to_incremental_compacting); |
| 7149 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7150 | |
| 7151 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7152 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7153 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7154 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7155 | } |
| 7156 | |
| 7157 | |
| 7158 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7159 | regs_.Save(masm); |
| 7160 | |
| 7161 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7162 | Label dont_need_remembered_set; |
| 7163 | |
| 7164 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7165 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7166 | regs_.scratch0(), |
| 7167 | &dont_need_remembered_set); |
| 7168 | |
| 7169 | __ CheckPageFlag(regs_.object(), |
| 7170 | regs_.scratch0(), |
| 7171 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7172 | not_zero, |
| 7173 | &dont_need_remembered_set); |
| 7174 | |
| 7175 | // First notify the incremental marker if necessary, then update the |
| 7176 | // remembered set. |
| 7177 | CheckNeedsToInformIncrementalMarker( |
| 7178 | masm, |
| 7179 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7180 | mode); |
| 7181 | InformIncrementalMarker(masm, mode); |
| 7182 | regs_.Restore(masm); |
| 7183 | __ RememberedSetHelper(object_, |
| 7184 | address_, |
| 7185 | value_, |
| 7186 | save_fp_regs_mode_, |
| 7187 | MacroAssembler::kReturnAtEnd); |
| 7188 | |
| 7189 | __ bind(&dont_need_remembered_set); |
| 7190 | } |
| 7191 | |
| 7192 | CheckNeedsToInformIncrementalMarker( |
| 7193 | masm, |
| 7194 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7195 | mode); |
| 7196 | InformIncrementalMarker(masm, mode); |
| 7197 | regs_.Restore(masm); |
| 7198 | __ ret(0); |
| 7199 | } |
| 7200 | |
| 7201 | |
| 7202 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7203 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7204 | int argument_count = 3; |
| 7205 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7206 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7207 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7208 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 7209 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7210 | |
| 7211 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7212 | if (mode == INCREMENTAL_COMPACTION) { |
| 7213 | __ CallCFunction( |
| 7214 | ExternalReference::incremental_evacuation_record_write_function( |
| 7215 | masm->isolate()), |
| 7216 | argument_count); |
| 7217 | } else { |
| 7218 | ASSERT(mode == INCREMENTAL); |
| 7219 | __ CallCFunction( |
| 7220 | ExternalReference::incremental_marking_record_write_function( |
| 7221 | masm->isolate()), |
| 7222 | argument_count); |
| 7223 | } |
| 7224 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7225 | } |
| 7226 | |
| 7227 | |
| 7228 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7229 | MacroAssembler* masm, |
| 7230 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7231 | Mode mode) { |
| 7232 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7233 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7234 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7235 | __ and_(regs_.scratch0(), regs_.object()); |
| 7236 | __ mov(regs_.scratch1(), |
| 7237 | Operand(regs_.scratch0(), |
| 7238 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7239 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7240 | __ mov(Operand(regs_.scratch0(), |
| 7241 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7242 | regs_.scratch1()); |
| 7243 | __ j(negative, &need_incremental); |
| 7244 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7245 | // Let's look at the color of the object: If it is not black we don't have |
| 7246 | // to inform the incremental marker. |
| 7247 | __ JumpIfBlack(regs_.object(), |
| 7248 | regs_.scratch0(), |
| 7249 | regs_.scratch1(), |
| 7250 | &object_is_black, |
| 7251 | Label::kNear); |
| 7252 | |
| 7253 | regs_.Restore(masm); |
| 7254 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7255 | __ RememberedSetHelper(object_, |
| 7256 | address_, |
| 7257 | value_, |
| 7258 | save_fp_regs_mode_, |
| 7259 | MacroAssembler::kReturnAtEnd); |
| 7260 | } else { |
| 7261 | __ ret(0); |
| 7262 | } |
| 7263 | |
| 7264 | __ bind(&object_is_black); |
| 7265 | |
| 7266 | // Get the value from the slot. |
| 7267 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7268 | |
| 7269 | if (mode == INCREMENTAL_COMPACTION) { |
| 7270 | Label ensure_not_white; |
| 7271 | |
| 7272 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7273 | regs_.scratch1(), // Scratch. |
| 7274 | MemoryChunk::kEvacuationCandidateMask, |
| 7275 | zero, |
| 7276 | &ensure_not_white, |
| 7277 | Label::kNear); |
| 7278 | |
| 7279 | __ CheckPageFlag(regs_.object(), |
| 7280 | regs_.scratch1(), // Scratch. |
| 7281 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7282 | not_zero, |
| 7283 | &ensure_not_white, |
| 7284 | Label::kNear); |
| 7285 | |
| 7286 | __ jmp(&need_incremental); |
| 7287 | |
| 7288 | __ bind(&ensure_not_white); |
| 7289 | } |
| 7290 | |
| 7291 | // We need an extra register for this, so we push the object register |
| 7292 | // temporarily. |
| 7293 | __ push(regs_.object()); |
| 7294 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7295 | regs_.scratch1(), // Scratch. |
| 7296 | regs_.object(), // Scratch. |
| 7297 | &need_incremental_pop_object, |
| 7298 | Label::kNear); |
| 7299 | __ pop(regs_.object()); |
| 7300 | |
| 7301 | regs_.Restore(masm); |
| 7302 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7303 | __ RememberedSetHelper(object_, |
| 7304 | address_, |
| 7305 | value_, |
| 7306 | save_fp_regs_mode_, |
| 7307 | MacroAssembler::kReturnAtEnd); |
| 7308 | } else { |
| 7309 | __ ret(0); |
| 7310 | } |
| 7311 | |
| 7312 | __ bind(&need_incremental_pop_object); |
| 7313 | __ pop(regs_.object()); |
| 7314 | |
| 7315 | __ bind(&need_incremental); |
| 7316 | |
| 7317 | // Fall through when we need to inform the incremental marker. |
| 7318 | } |
| 7319 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7320 | |
| 7321 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7322 | // ----------- S t a t e ------------- |
| 7323 | // -- eax : element value to store |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7324 | // -- ecx : element index as smi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7325 | // -- esp[0] : return address |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7326 | // -- esp[4] : array literal index in function |
| 7327 | // -- esp[8] : array literal |
| 7328 | // clobbers ebx, edx, edi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7329 | // ----------------------------------- |
| 7330 | |
| 7331 | Label element_done; |
| 7332 | Label double_elements; |
| 7333 | Label smi_element; |
| 7334 | Label slow_elements; |
| 7335 | Label slow_elements_from_double; |
| 7336 | Label fast_elements; |
| 7337 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7338 | // Get array literal index, array literal and its map. |
| 7339 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 7340 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 7341 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 7342 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7343 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7344 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7345 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7346 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7347 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7348 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7349 | // Store into the array literal requires a elements transition. Call into |
| 7350 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7351 | |
| 7352 | __ bind(&slow_elements); |
| 7353 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7354 | // call. |
| 7355 | __ push(ebx); |
| 7356 | __ push(ecx); |
| 7357 | __ push(eax); |
| 7358 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7359 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7360 | __ push(edx); |
| 7361 | __ push(edi); // Return return address so that tail call returns to right |
| 7362 | // place. |
| 7363 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7364 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7365 | __ bind(&slow_elements_from_double); |
| 7366 | __ pop(edx); |
| 7367 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7368 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7369 | // 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] | 7370 | __ bind(&fast_elements); |
| 7371 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7372 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7373 | FixedArrayBase::kHeaderSize)); |
| 7374 | __ mov(Operand(ecx, 0), eax); |
| 7375 | // Update the write barrier for the array store. |
| 7376 | __ RecordWrite(ebx, ecx, eax, |
| 7377 | kDontSaveFPRegs, |
| 7378 | EMIT_REMEMBERED_SET, |
| 7379 | OMIT_SMI_CHECK); |
| 7380 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7381 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7382 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7383 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7384 | __ bind(&smi_element); |
| 7385 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7386 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7387 | FixedArrayBase::kHeaderSize), eax); |
| 7388 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7389 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7390 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7391 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7392 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7393 | __ push(edx); |
| 7394 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7395 | __ StoreNumberToDoubleElements(eax, |
| 7396 | edx, |
| 7397 | ecx, |
| 7398 | edi, |
| 7399 | xmm0, |
| 7400 | &slow_elements_from_double, |
| 7401 | false); |
| 7402 | __ pop(edx); |
| 7403 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7404 | } |
| 7405 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7406 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7407 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7408 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7409 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7410 | int parameter_count_offset = |
| 7411 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7412 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7413 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7414 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7415 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 7416 | ? kPointerSize |
| 7417 | : 0; |
| 7418 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7419 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7420 | } |
| 7421 | |
| 7422 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7423 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7424 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 7425 | // It's always safe to call the entry hook stub, as the hook itself |
| 7426 | // is not allowed to call back to V8. |
| 7427 | AllowStubCallsScope allow_stub_calls(masm, true); |
| 7428 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7429 | ProfileEntryHookStub stub; |
| 7430 | masm->CallStub(&stub); |
| 7431 | } |
| 7432 | } |
| 7433 | |
| 7434 | |
| 7435 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7436 | // Save volatile registers. |
| 7437 | const int kNumSavedRegisters = 3; |
| 7438 | __ push(eax); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7439 | __ push(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7440 | __ push(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7441 | |
| 7442 | // Calculate and push the original stack pointer. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7443 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7444 | __ push(eax); |
| 7445 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7446 | // Retrieve our return address and use it to calculate the calling |
| 7447 | // function's address. |
| 7448 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7449 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7450 | __ push(eax); |
| 7451 | |
| 7452 | // Call the entry hook. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7453 | ASSERT(masm->isolate()->function_entry_hook() != NULL); |
| 7454 | __ call(FUNCTION_ADDR(masm->isolate()->function_entry_hook()), |
| 7455 | RelocInfo::RUNTIME_ENTRY); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7456 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7457 | |
| 7458 | // Restore ecx. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7459 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7460 | __ pop(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7461 | __ pop(eax); |
| 7462 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7463 | __ ret(0); |
| 7464 | } |
| 7465 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7466 | |
| 7467 | template<class T> |
| 7468 | static void CreateArrayDispatch(MacroAssembler* masm) { |
| 7469 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7470 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7471 | for (int i = 0; i <= last_index; ++i) { |
| 7472 | Label next; |
| 7473 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7474 | __ cmp(edx, kind); |
| 7475 | __ j(not_equal, &next); |
| 7476 | T stub(kind); |
| 7477 | __ TailCallStub(&stub); |
| 7478 | __ bind(&next); |
| 7479 | } |
| 7480 | |
| 7481 | // If we reached this point there is a problem. |
| 7482 | __ Abort("Unexpected ElementsKind in array constructor"); |
| 7483 | } |
| 7484 | |
| 7485 | |
| 7486 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm) { |
| 7487 | // ebx - type info cell |
| 7488 | // edx - kind |
| 7489 | // eax - number of arguments |
| 7490 | // edi - constructor? |
| 7491 | // esp[0] - return address |
| 7492 | // esp[4] - last argument |
| 7493 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 7494 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 7495 | ASSERT(FAST_ELEMENTS == 2); |
| 7496 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 7497 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 7498 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 7499 | |
| 7500 | Handle<Object> undefined_sentinel( |
| 7501 | masm->isolate()->heap()->undefined_value(), |
| 7502 | masm->isolate()); |
| 7503 | |
| 7504 | // is the low bit set? If so, we are holey and that is good. |
| 7505 | __ test_b(edx, 1); |
| 7506 | Label normal_sequence; |
| 7507 | __ j(not_zero, &normal_sequence); |
| 7508 | |
| 7509 | // look at the first argument |
| 7510 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7511 | __ test(ecx, ecx); |
| 7512 | __ j(zero, &normal_sequence); |
| 7513 | |
| 7514 | // We are going to create a holey array, but our kind is non-holey. |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 7515 | // Fix kind and retry (only if we have an allocation site in the cell). |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7516 | __ inc(edx); |
| 7517 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7518 | __ j(equal, &normal_sequence); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 7519 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
| 7520 | Handle<Map> allocation_site_map( |
| 7521 | masm->isolate()->heap()->allocation_site_map(), |
| 7522 | masm->isolate()); |
| 7523 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 7524 | __ j(not_equal, &normal_sequence); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7525 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7526 | // Save the resulting elements kind in type info |
| 7527 | __ SmiTag(edx); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 7528 | __ mov(FieldOperand(ecx, AllocationSite::kTransitionInfoOffset), edx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7529 | __ SmiUntag(edx); |
| 7530 | |
| 7531 | __ bind(&normal_sequence); |
| 7532 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7533 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7534 | for (int i = 0; i <= last_index; ++i) { |
| 7535 | Label next; |
| 7536 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7537 | __ cmp(edx, kind); |
| 7538 | __ j(not_equal, &next); |
| 7539 | ArraySingleArgumentConstructorStub stub(kind); |
| 7540 | __ TailCallStub(&stub); |
| 7541 | __ bind(&next); |
| 7542 | } |
| 7543 | |
| 7544 | // If we reached this point there is a problem. |
| 7545 | __ Abort("Unexpected ElementsKind in array constructor"); |
| 7546 | } |
| 7547 | |
| 7548 | |
| 7549 | template<class T> |
| 7550 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 7551 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 7552 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7553 | for (int i = 0; i <= to_index; ++i) { |
| 7554 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7555 | T stub(kind); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7556 | stub.GetCode(isolate)->set_is_pregenerated(true); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 7557 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7558 | T stub1(kind, CONTEXT_CHECK_REQUIRED, DISABLE_ALLOCATION_SITES); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7559 | stub1.GetCode(isolate)->set_is_pregenerated(true); |
| 7560 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7561 | } |
| 7562 | } |
| 7563 | |
| 7564 | |
| 7565 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 7566 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 7567 | isolate); |
| 7568 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 7569 | isolate); |
| 7570 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 7571 | isolate); |
| 7572 | } |
| 7573 | |
| 7574 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7575 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 7576 | Isolate* isolate) { |
| 7577 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 7578 | for (int i = 0; i < 2; i++) { |
| 7579 | // For internal arrays we only need a few things |
| 7580 | InternalArrayNoArgumentConstructorStub stubh1(kinds[i]); |
| 7581 | stubh1.GetCode(isolate)->set_is_pregenerated(true); |
| 7582 | InternalArraySingleArgumentConstructorStub stubh2(kinds[i]); |
| 7583 | stubh2.GetCode(isolate)->set_is_pregenerated(true); |
| 7584 | InternalArrayNArgumentsConstructorStub stubh3(kinds[i]); |
| 7585 | stubh3.GetCode(isolate)->set_is_pregenerated(true); |
| 7586 | } |
| 7587 | } |
| 7588 | |
| 7589 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7590 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7591 | // ----------- S t a t e ------------- |
| 7592 | // -- eax : argc (only if argument_count_ == ANY) |
| 7593 | // -- ebx : type info cell |
| 7594 | // -- edi : constructor |
| 7595 | // -- esp[0] : return address |
| 7596 | // -- esp[4] : last argument |
| 7597 | // ----------------------------------- |
| 7598 | Handle<Object> undefined_sentinel( |
| 7599 | masm->isolate()->heap()->undefined_value(), |
| 7600 | masm->isolate()); |
| 7601 | |
| 7602 | if (FLAG_debug_code) { |
| 7603 | // The array construct code is only set for the global and natives |
| 7604 | // builtin Array functions which always have maps. |
| 7605 | |
| 7606 | // Initial map for the builtin Array function should be a map. |
| 7607 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7608 | // Will both indicate a NULL and a Smi. |
| 7609 | __ test(ecx, Immediate(kSmiTagMask)); |
| 7610 | __ Assert(not_zero, "Unexpected initial map for Array function"); |
| 7611 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 7612 | __ Assert(equal, "Unexpected initial map for Array function"); |
| 7613 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7614 | // We should either have undefined in ebx or a valid cell |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7615 | Label okay_here; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7616 | Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7617 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7618 | __ j(equal, &okay_here); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7619 | __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7620 | __ Assert(equal, "Expected property cell in register ebx"); |
| 7621 | __ bind(&okay_here); |
| 7622 | } |
| 7623 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7624 | Label no_info, switch_ready; |
| 7625 | // Get the elements kind and case on that. |
| 7626 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7627 | __ j(equal, &no_info); |
| 7628 | __ mov(edx, FieldOperand(ebx, Cell::kValueOffset)); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame^] | 7629 | |
| 7630 | // The type cell may have undefined in its value. |
| 7631 | __ cmp(edx, Immediate(undefined_sentinel)); |
| 7632 | __ j(equal, &no_info); |
| 7633 | |
| 7634 | // The type cell has either an AllocationSite or a JSFunction |
| 7635 | __ cmp(FieldOperand(edx, 0), Immediate(Handle<Map>( |
| 7636 | masm->isolate()->heap()->allocation_site_map()))); |
| 7637 | __ j(not_equal, &no_info); |
| 7638 | |
| 7639 | __ mov(edx, FieldOperand(edx, AllocationSite::kTransitionInfoOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7640 | __ SmiUntag(edx); |
| 7641 | __ jmp(&switch_ready); |
| 7642 | __ bind(&no_info); |
| 7643 | __ mov(edx, Immediate(GetInitialFastElementsKind())); |
| 7644 | __ bind(&switch_ready); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7645 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7646 | if (argument_count_ == ANY) { |
| 7647 | Label not_zero_case, not_one_case; |
| 7648 | __ test(eax, eax); |
| 7649 | __ j(not_zero, ¬_zero_case); |
| 7650 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7651 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7652 | __ bind(¬_zero_case); |
| 7653 | __ cmp(eax, 1); |
| 7654 | __ j(greater, ¬_one_case); |
| 7655 | CreateArrayDispatchOneArgument(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7656 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7657 | __ bind(¬_one_case); |
| 7658 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
| 7659 | } else if (argument_count_ == NONE) { |
| 7660 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
| 7661 | } else if (argument_count_ == ONE) { |
| 7662 | CreateArrayDispatchOneArgument(masm); |
| 7663 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 7664 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7665 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7666 | UNREACHABLE(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7667 | } |
| 7668 | } |
| 7669 | |
| 7670 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7671 | void InternalArrayConstructorStub::GenerateCase( |
| 7672 | MacroAssembler* masm, ElementsKind kind) { |
| 7673 | Label not_zero_case, not_one_case; |
| 7674 | Label normal_sequence; |
| 7675 | |
| 7676 | __ test(eax, eax); |
| 7677 | __ j(not_zero, ¬_zero_case); |
| 7678 | InternalArrayNoArgumentConstructorStub stub0(kind); |
| 7679 | __ TailCallStub(&stub0); |
| 7680 | |
| 7681 | __ bind(¬_zero_case); |
| 7682 | __ cmp(eax, 1); |
| 7683 | __ j(greater, ¬_one_case); |
| 7684 | |
| 7685 | if (IsFastPackedElementsKind(kind)) { |
| 7686 | // We might need to create a holey array |
| 7687 | // look at the first argument |
| 7688 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7689 | __ test(ecx, ecx); |
| 7690 | __ j(zero, &normal_sequence); |
| 7691 | |
| 7692 | InternalArraySingleArgumentConstructorStub |
| 7693 | stub1_holey(GetHoleyElementsKind(kind)); |
| 7694 | __ TailCallStub(&stub1_holey); |
| 7695 | } |
| 7696 | |
| 7697 | __ bind(&normal_sequence); |
| 7698 | InternalArraySingleArgumentConstructorStub stub1(kind); |
| 7699 | __ TailCallStub(&stub1); |
| 7700 | |
| 7701 | __ bind(¬_one_case); |
| 7702 | InternalArrayNArgumentsConstructorStub stubN(kind); |
| 7703 | __ TailCallStub(&stubN); |
| 7704 | } |
| 7705 | |
| 7706 | |
| 7707 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7708 | // ----------- S t a t e ------------- |
| 7709 | // -- eax : argc |
| 7710 | // -- ebx : type info cell |
| 7711 | // -- edi : constructor |
| 7712 | // -- esp[0] : return address |
| 7713 | // -- esp[4] : last argument |
| 7714 | // ----------------------------------- |
| 7715 | |
| 7716 | if (FLAG_debug_code) { |
| 7717 | // The array construct code is only set for the global and natives |
| 7718 | // builtin Array functions which always have maps. |
| 7719 | |
| 7720 | // Initial map for the builtin Array function should be a map. |
| 7721 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7722 | // Will both indicate a NULL and a Smi. |
| 7723 | __ test(ecx, Immediate(kSmiTagMask)); |
| 7724 | __ Assert(not_zero, "Unexpected initial map for Array function"); |
| 7725 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 7726 | __ Assert(equal, "Unexpected initial map for Array function"); |
| 7727 | } |
| 7728 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7729 | // Figure out the right elements kind |
| 7730 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7731 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7732 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 7733 | // but the following masking takes care of that anyway. |
| 7734 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 7735 | // Retrieve elements_kind from bit field 2. |
| 7736 | __ and_(ecx, Map::kElementsKindMask); |
| 7737 | __ shr(ecx, Map::kElementsKindShift); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7738 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7739 | if (FLAG_debug_code) { |
| 7740 | Label done; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7741 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7742 | __ j(equal, &done); |
| 7743 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 7744 | __ Assert(equal, |
| 7745 | "Invalid ElementsKind for InternalArray or InternalPackedArray"); |
| 7746 | __ bind(&done); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7747 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7748 | |
| 7749 | Label fast_elements_case; |
| 7750 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 7751 | __ j(equal, &fast_elements_case); |
| 7752 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 7753 | |
| 7754 | __ bind(&fast_elements_case); |
| 7755 | GenerateCase(masm, FAST_ELEMENTS); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7756 | } |
| 7757 | |
| 7758 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7759 | #undef __ |
| 7760 | |
| 7761 | } } // namespace v8::internal |
| 7762 | |
| 7763 | #endif // V8_TARGET_ARCH_IA32 |