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 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 46 | void FastNewClosureStub::InitializeInterfaceDescriptor( |
| 47 | Isolate* isolate, |
| 48 | CodeStubInterfaceDescriptor* descriptor) { |
| 49 | static Register registers[] = { ebx }; |
| 50 | descriptor->register_param_count_ = 1; |
| 51 | descriptor->register_params_ = registers; |
| 52 | descriptor->deoptimization_handler_ = |
| 53 | Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry; |
| 54 | } |
| 55 | |
| 56 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 57 | void ToNumberStub::InitializeInterfaceDescriptor( |
| 58 | Isolate* isolate, |
| 59 | CodeStubInterfaceDescriptor* descriptor) { |
| 60 | static Register registers[] = { eax }; |
| 61 | descriptor->register_param_count_ = 1; |
| 62 | descriptor->register_params_ = registers; |
| 63 | descriptor->deoptimization_handler_ = NULL; |
| 64 | } |
| 65 | |
| 66 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 67 | void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( |
| 68 | Isolate* isolate, |
| 69 | CodeStubInterfaceDescriptor* descriptor) { |
| 70 | static Register registers[] = { eax, ebx, ecx }; |
| 71 | descriptor->register_param_count_ = 3; |
| 72 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 73 | descriptor->deoptimization_handler_ = |
| 74 | Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; |
| 75 | } |
| 76 | |
| 77 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 78 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 79 | Isolate* isolate, |
| 80 | CodeStubInterfaceDescriptor* descriptor) { |
| 81 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 82 | descriptor->register_param_count_ = 4; |
| 83 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 84 | descriptor->deoptimization_handler_ = |
| 85 | Runtime::FunctionForId(Runtime::kCreateObjectLiteralShallow)->entry; |
| 86 | } |
| 87 | |
| 88 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 89 | void CreateAllocationSiteStub::InitializeInterfaceDescriptor( |
| 90 | Isolate* isolate, |
| 91 | CodeStubInterfaceDescriptor* descriptor) { |
| 92 | static Register registers[] = { ebx }; |
| 93 | descriptor->register_param_count_ = 1; |
| 94 | descriptor->register_params_ = registers; |
| 95 | descriptor->deoptimization_handler_ = NULL; |
| 96 | } |
| 97 | |
| 98 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 99 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 100 | Isolate* isolate, |
| 101 | CodeStubInterfaceDescriptor* descriptor) { |
| 102 | static Register registers[] = { edx, ecx }; |
| 103 | descriptor->register_param_count_ = 2; |
| 104 | descriptor->register_params_ = registers; |
| 105 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 106 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 110 | void LoadFieldStub::InitializeInterfaceDescriptor( |
| 111 | Isolate* isolate, |
| 112 | CodeStubInterfaceDescriptor* descriptor) { |
| 113 | static Register registers[] = { edx }; |
| 114 | descriptor->register_param_count_ = 1; |
| 115 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 116 | descriptor->deoptimization_handler_ = NULL; |
| 117 | } |
| 118 | |
| 119 | |
| 120 | void KeyedLoadFieldStub::InitializeInterfaceDescriptor( |
| 121 | Isolate* isolate, |
| 122 | CodeStubInterfaceDescriptor* descriptor) { |
| 123 | static Register registers[] = { edx }; |
| 124 | descriptor->register_param_count_ = 1; |
| 125 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 126 | descriptor->deoptimization_handler_ = NULL; |
| 127 | } |
| 128 | |
| 129 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 130 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 131 | Isolate* isolate, |
| 132 | CodeStubInterfaceDescriptor* descriptor) { |
| 133 | static Register registers[] = { edx, ecx, eax }; |
| 134 | descriptor->register_param_count_ = 3; |
| 135 | descriptor->register_params_ = registers; |
| 136 | descriptor->deoptimization_handler_ = |
| 137 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 138 | } |
| 139 | |
| 140 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 141 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 142 | Isolate* isolate, |
| 143 | CodeStubInterfaceDescriptor* descriptor) { |
| 144 | static Register registers[] = { eax, ebx }; |
| 145 | descriptor->register_param_count_ = 2; |
| 146 | descriptor->register_params_ = registers; |
| 147 | descriptor->deoptimization_handler_ = |
| 148 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 149 | } |
| 150 | |
| 151 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 152 | static void InitializeArrayConstructorDescriptor( |
| 153 | Isolate* isolate, |
| 154 | CodeStubInterfaceDescriptor* descriptor, |
| 155 | int constant_stack_parameter_count) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 156 | // register state |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 157 | // eax -- number of arguments |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 158 | // edi -- function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 159 | // ebx -- type info cell with elements kind |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 160 | static Register registers[] = { edi, ebx }; |
| 161 | descriptor->register_param_count_ = 2; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 162 | |
| 163 | if (constant_stack_parameter_count != 0) { |
| 164 | // stack param count needs (constructor pointer, and single argument) |
| 165 | descriptor->stack_parameter_count_ = &eax; |
| 166 | } |
| 167 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 168 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 169 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 170 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 171 | Runtime::FunctionForId(Runtime::kArrayConstructor)->entry; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 175 | static void InitializeInternalArrayConstructorDescriptor( |
| 176 | Isolate* isolate, |
| 177 | CodeStubInterfaceDescriptor* descriptor, |
| 178 | int constant_stack_parameter_count) { |
| 179 | // register state |
| 180 | // eax -- number of arguments |
| 181 | // edi -- constructor function |
| 182 | static Register registers[] = { edi }; |
| 183 | descriptor->register_param_count_ = 1; |
| 184 | |
| 185 | if (constant_stack_parameter_count != 0) { |
| 186 | // stack param count needs (constructor pointer, and single argument) |
| 187 | descriptor->stack_parameter_count_ = &eax; |
| 188 | } |
| 189 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
| 190 | descriptor->register_params_ = registers; |
| 191 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
| 192 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 193 | Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 197 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 198 | Isolate* isolate, |
| 199 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 200 | InitializeArrayConstructorDescriptor(isolate, descriptor, 0); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | |
| 204 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 205 | Isolate* isolate, |
| 206 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 207 | InitializeArrayConstructorDescriptor(isolate, descriptor, 1); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | |
| 211 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 212 | Isolate* isolate, |
| 213 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 214 | InitializeArrayConstructorDescriptor(isolate, descriptor, -1); |
| 215 | } |
| 216 | |
| 217 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 218 | void InternalArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 219 | Isolate* isolate, |
| 220 | CodeStubInterfaceDescriptor* descriptor) { |
| 221 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 0); |
| 222 | } |
| 223 | |
| 224 | |
| 225 | void InternalArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 226 | Isolate* isolate, |
| 227 | CodeStubInterfaceDescriptor* descriptor) { |
| 228 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 1); |
| 229 | } |
| 230 | |
| 231 | |
| 232 | void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 233 | Isolate* isolate, |
| 234 | CodeStubInterfaceDescriptor* descriptor) { |
| 235 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, -1); |
| 236 | } |
| 237 | |
| 238 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 239 | void CompareNilICStub::InitializeInterfaceDescriptor( |
| 240 | Isolate* isolate, |
| 241 | CodeStubInterfaceDescriptor* descriptor) { |
| 242 | static Register registers[] = { eax }; |
| 243 | descriptor->register_param_count_ = 1; |
| 244 | descriptor->register_params_ = registers; |
| 245 | descriptor->deoptimization_handler_ = |
| 246 | FUNCTION_ADDR(CompareNilIC_Miss); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 247 | descriptor->SetMissHandler( |
| 248 | ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 249 | } |
| 250 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 251 | void ToBooleanStub::InitializeInterfaceDescriptor( |
| 252 | Isolate* isolate, |
| 253 | CodeStubInterfaceDescriptor* descriptor) { |
| 254 | static Register registers[] = { eax }; |
| 255 | descriptor->register_param_count_ = 1; |
| 256 | descriptor->register_params_ = registers; |
| 257 | descriptor->deoptimization_handler_ = |
| 258 | FUNCTION_ADDR(ToBooleanIC_Miss); |
| 259 | descriptor->SetMissHandler( |
| 260 | ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate)); |
| 261 | } |
| 262 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 263 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 264 | void StoreGlobalStub::InitializeInterfaceDescriptor( |
| 265 | Isolate* isolate, |
| 266 | CodeStubInterfaceDescriptor* descriptor) { |
| 267 | static Register registers[] = { edx, ecx, eax }; |
| 268 | descriptor->register_param_count_ = 3; |
| 269 | descriptor->register_params_ = registers; |
| 270 | descriptor->deoptimization_handler_ = |
| 271 | FUNCTION_ADDR(StoreIC_MissFromStubFailure); |
| 272 | } |
| 273 | |
| 274 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 275 | void ElementsTransitionAndStoreStub::InitializeInterfaceDescriptor( |
| 276 | Isolate* isolate, |
| 277 | CodeStubInterfaceDescriptor* descriptor) { |
| 278 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 279 | descriptor->register_param_count_ = 4; |
| 280 | descriptor->register_params_ = registers; |
| 281 | descriptor->deoptimization_handler_ = |
| 282 | FUNCTION_ADDR(ElementsTransitionAndStoreIC_Miss); |
| 283 | } |
| 284 | |
| 285 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 286 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 287 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 288 | |
| 289 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
| 290 | // Update the static counter each time a new code stub is generated. |
| 291 | Isolate* isolate = masm->isolate(); |
| 292 | isolate->counters()->code_stubs()->Increment(); |
| 293 | |
| 294 | CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
| 295 | int param_count = descriptor->register_param_count_; |
| 296 | { |
| 297 | // Call the runtime system in a fresh internal frame. |
| 298 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 299 | ASSERT(descriptor->register_param_count_ == 0 || |
| 300 | eax.is(descriptor->register_params_[param_count - 1])); |
| 301 | // Push arguments |
| 302 | for (int i = 0; i < param_count; ++i) { |
| 303 | __ push(descriptor->register_params_[i]); |
| 304 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 305 | ExternalReference miss = descriptor->miss_handler(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 306 | __ CallExternalReference(miss, descriptor->register_param_count_); |
| 307 | } |
| 308 | |
| 309 | __ ret(0); |
| 310 | } |
| 311 | |
| 312 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 313 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 314 | // Try to allocate the context in new space. |
| 315 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 316 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 317 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 318 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 319 | |
| 320 | // Get the function from the stack. |
| 321 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 322 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 323 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 324 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 325 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 326 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 327 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 328 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 329 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 330 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 331 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 332 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 333 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 334 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 335 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 336 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 337 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 338 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 339 | |
| 340 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 341 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 342 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 343 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 344 | } |
| 345 | |
| 346 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 347 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 348 | __ ret(1 * kPointerSize); |
| 349 | |
| 350 | // Need to collect. Call into runtime system. |
| 351 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 352 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 356 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 357 | // Stack layout on entry: |
| 358 | // |
| 359 | // [esp + (1 * kPointerSize)]: function |
| 360 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 361 | |
| 362 | // Try to allocate the context in new space. |
| 363 | Label gc; |
| 364 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 365 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 366 | |
| 367 | // Get the function or sentinel from the stack. |
| 368 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 369 | |
| 370 | // Get the serialized scope info from the stack. |
| 371 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 372 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 373 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 374 | Factory* factory = masm->isolate()->factory(); |
| 375 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 376 | factory->block_context_map()); |
| 377 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 378 | Immediate(Smi::FromInt(length))); |
| 379 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 380 | // 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] | 381 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 382 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 383 | // we still have to look up. |
| 384 | Label after_sentinel; |
| 385 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 386 | if (FLAG_debug_code) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 387 | __ cmp(ecx, 0); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 388 | __ Assert(equal, kExpected0AsASmiSentinel); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 389 | } |
| 390 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 391 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 392 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 393 | __ bind(&after_sentinel); |
| 394 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 395 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 396 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 397 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 398 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 399 | |
| 400 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 401 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 402 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 403 | |
| 404 | // Initialize the rest of the slots to the hole value. |
| 405 | if (slots_ == 1) { |
| 406 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 407 | factory->the_hole_value()); |
| 408 | } else { |
| 409 | __ mov(ebx, factory->the_hole_value()); |
| 410 | for (int i = 0; i < slots_; i++) { |
| 411 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | // Return and remove the on-stack parameters. |
| 416 | __ mov(esi, eax); |
| 417 | __ ret(2 * kPointerSize); |
| 418 | |
| 419 | // Need to collect. Call into runtime system. |
| 420 | __ bind(&gc); |
| 421 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 422 | } |
| 423 | |
| 424 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 425 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 426 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 427 | // store the registers in any particular way, but we do have to store and |
| 428 | // restore them. |
| 429 | __ pushad(); |
| 430 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 431 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 432 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 433 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 434 | XMMRegister reg = XMMRegister::from_code(i); |
| 435 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 436 | } |
| 437 | } |
| 438 | const int argument_count = 1; |
| 439 | |
| 440 | AllowExternalCallThatCantCauseGC scope(masm); |
| 441 | __ PrepareCallCFunction(argument_count, ecx); |
| 442 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 443 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 444 | __ CallCFunction( |
| 445 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 446 | argument_count); |
| 447 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 448 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 449 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 450 | XMMRegister reg = XMMRegister::from_code(i); |
| 451 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 452 | } |
| 453 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 454 | } |
| 455 | __ popad(); |
| 456 | __ ret(0); |
| 457 | } |
| 458 | |
| 459 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 460 | class FloatingPointHelper : public AllStatic { |
| 461 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 462 | enum ArgLocation { |
| 463 | ARGS_ON_STACK, |
| 464 | ARGS_IN_REGISTERS |
| 465 | }; |
| 466 | |
| 467 | // Code pattern for loading a floating point value. Input value must |
| 468 | // be either a smi or a heap number object (fp value). Requirements: |
| 469 | // operand in register number. Returns operand as floating point number |
| 470 | // on FPU stack. |
| 471 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 472 | |
| 473 | // Code pattern for loading floating point values. Input values must |
| 474 | // be either smi or heap number objects (fp values). Requirements: |
| 475 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 476 | // Returns operands as floating point numbers on FPU stack. |
| 477 | static void LoadFloatOperands(MacroAssembler* masm, |
| 478 | Register scratch, |
| 479 | ArgLocation arg_location = ARGS_ON_STACK); |
| 480 | |
| 481 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 482 | // Expects operands in edx, eax. |
| 483 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 484 | |
| 485 | // Test if operands are smi or number objects (fp). Requirements: |
| 486 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 487 | // operands, jumps to the non_float label otherwise. |
| 488 | static void CheckFloatOperands(MacroAssembler* masm, |
| 489 | Label* non_float, |
| 490 | Register scratch); |
| 491 | |
| 492 | // Takes the operands in edx and eax and loads them as integers in eax |
| 493 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 494 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 495 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 496 | BinaryOpIC::TypeInfo left_type, |
| 497 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 498 | Label* operand_conversion_failure); |
| 499 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 500 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 501 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 502 | // either operand is not a number. Operands are in edx and eax. |
| 503 | // Leaves operands unchanged. |
| 504 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 505 | |
| 506 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 507 | // Expects operands in edx, eax. |
| 508 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 509 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 510 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 511 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 512 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 513 | Label* non_int32, |
| 514 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 515 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 516 | Register scratch, |
| 517 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 518 | }; |
| 519 | |
| 520 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 521 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 522 | Register input_reg = this->source(); |
| 523 | Register final_result_reg = this->destination(); |
| 524 | ASSERT(is_truncating()); |
| 525 | |
| 526 | Label check_negative, process_64_bits, done, done_no_stash; |
| 527 | |
| 528 | int double_offset = offset(); |
| 529 | |
| 530 | // Account for return address and saved regs if input is esp. |
| 531 | if (input_reg.is(esp)) double_offset += 3 * kPointerSize; |
| 532 | |
| 533 | MemOperand mantissa_operand(MemOperand(input_reg, double_offset)); |
| 534 | MemOperand exponent_operand(MemOperand(input_reg, |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 535 | double_offset + kDoubleSize / 2)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 536 | |
| 537 | Register scratch1; |
| 538 | { |
| 539 | Register scratch_candidates[3] = { ebx, edx, edi }; |
| 540 | for (int i = 0; i < 3; i++) { |
| 541 | scratch1 = scratch_candidates[i]; |
| 542 | if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break; |
| 543 | } |
| 544 | } |
| 545 | // Since we must use ecx for shifts below, use some other register (eax) |
| 546 | // to calculate the result if ecx is the requested return register. |
| 547 | Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg; |
| 548 | // Save ecx if it isn't the return register and therefore volatile, or if it |
| 549 | // is the return register, then save the temp register we use in its stead for |
| 550 | // the result. |
| 551 | Register save_reg = final_result_reg.is(ecx) ? eax : ecx; |
| 552 | __ push(scratch1); |
| 553 | __ push(save_reg); |
| 554 | |
| 555 | bool stash_exponent_copy = !input_reg.is(esp); |
| 556 | __ mov(scratch1, mantissa_operand); |
| 557 | if (CpuFeatures::IsSupported(SSE3)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 558 | CpuFeatureScope scope(masm, SSE3); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 559 | // Load x87 register with heap number. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 560 | __ fld_d(mantissa_operand); |
| 561 | } |
| 562 | __ mov(ecx, exponent_operand); |
| 563 | if (stash_exponent_copy) __ push(ecx); |
| 564 | |
| 565 | __ and_(ecx, HeapNumber::kExponentMask); |
| 566 | __ shr(ecx, HeapNumber::kExponentShift); |
| 567 | __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias)); |
| 568 | __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits)); |
| 569 | __ j(below, &process_64_bits); |
| 570 | |
| 571 | // Result is entirely in lower 32-bits of mantissa |
| 572 | int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize; |
| 573 | if (CpuFeatures::IsSupported(SSE3)) { |
| 574 | __ fstp(0); |
| 575 | } |
| 576 | __ sub(ecx, Immediate(delta)); |
| 577 | __ xor_(result_reg, result_reg); |
| 578 | __ cmp(ecx, Immediate(31)); |
| 579 | __ j(above, &done); |
| 580 | __ shl_cl(scratch1); |
| 581 | __ jmp(&check_negative); |
| 582 | |
| 583 | __ bind(&process_64_bits); |
| 584 | if (CpuFeatures::IsSupported(SSE3)) { |
| 585 | CpuFeatureScope scope(masm, SSE3); |
| 586 | if (stash_exponent_copy) { |
| 587 | // Already a copy of the exponent on the stack, overwrite it. |
| 588 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 589 | __ sub(esp, Immediate(kDoubleSize / 2)); |
| 590 | } else { |
| 591 | // Reserve space for 64 bit answer. |
| 592 | __ sub(esp, Immediate(kDoubleSize)); // Nolint. |
| 593 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 594 | // Do conversion, which cannot fail because we checked the exponent. |
| 595 | __ fisttp_d(Operand(esp, 0)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 596 | __ mov(result_reg, Operand(esp, 0)); // Load low word of answer as result |
| 597 | __ add(esp, Immediate(kDoubleSize)); |
| 598 | __ jmp(&done_no_stash); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 599 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 600 | // Result must be extracted from shifted 32-bit mantissa |
| 601 | __ sub(ecx, Immediate(delta)); |
| 602 | __ neg(ecx); |
| 603 | if (stash_exponent_copy) { |
| 604 | __ mov(result_reg, MemOperand(esp, 0)); |
| 605 | } else { |
| 606 | __ mov(result_reg, exponent_operand); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 607 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 608 | __ and_(result_reg, |
| 609 | Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32))); |
| 610 | __ add(result_reg, |
| 611 | Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32))); |
| 612 | __ shrd(result_reg, scratch1); |
| 613 | __ shr_cl(result_reg); |
| 614 | __ test(ecx, Immediate(32)); |
| 615 | if (CpuFeatures::IsSupported(CMOV)) { |
| 616 | CpuFeatureScope use_cmov(masm, CMOV); |
| 617 | __ cmov(not_equal, scratch1, result_reg); |
| 618 | } else { |
| 619 | Label skip_mov; |
| 620 | __ j(equal, &skip_mov, Label::kNear); |
| 621 | __ mov(scratch1, result_reg); |
| 622 | __ bind(&skip_mov); |
| 623 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 624 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 625 | |
| 626 | // If the double was negative, negate the integer result. |
| 627 | __ bind(&check_negative); |
| 628 | __ mov(result_reg, scratch1); |
| 629 | __ neg(result_reg); |
| 630 | if (stash_exponent_copy) { |
| 631 | __ cmp(MemOperand(esp, 0), Immediate(0)); |
| 632 | } else { |
| 633 | __ cmp(exponent_operand, Immediate(0)); |
| 634 | } |
| 635 | if (CpuFeatures::IsSupported(CMOV)) { |
| 636 | CpuFeatureScope use_cmov(masm, CMOV); |
| 637 | __ cmov(greater, result_reg, scratch1); |
| 638 | } else { |
| 639 | Label skip_mov; |
| 640 | __ j(less_equal, &skip_mov, Label::kNear); |
| 641 | __ mov(result_reg, scratch1); |
| 642 | __ bind(&skip_mov); |
| 643 | } |
| 644 | |
| 645 | // Restore registers |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 646 | __ bind(&done); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 647 | if (stash_exponent_copy) { |
| 648 | __ add(esp, Immediate(kDoubleSize / 2)); |
| 649 | } |
| 650 | __ bind(&done_no_stash); |
| 651 | if (!final_result_reg.is(result_reg)) { |
| 652 | ASSERT(final_result_reg.is(ecx)); |
| 653 | __ mov(final_result_reg, result_reg); |
| 654 | } |
| 655 | __ pop(save_reg); |
| 656 | __ pop(scratch1); |
| 657 | __ ret(0); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 661 | void BinaryOpStub::Initialize() { |
| 662 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 663 | } |
| 664 | |
| 665 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 666 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 667 | __ pop(ecx); // Save return address. |
| 668 | __ push(edx); |
| 669 | __ push(eax); |
| 670 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 671 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 672 | |
| 673 | __ push(ecx); // Push return address. |
| 674 | |
| 675 | // Patch the caller to an appropriate specialized stub and return the |
| 676 | // operation result to the caller of the stub. |
| 677 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 678 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 679 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 680 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 681 | 1); |
| 682 | } |
| 683 | |
| 684 | |
| 685 | // Prepare for a type transition runtime call when the args are already on |
| 686 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 687 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 688 | __ pop(ecx); // Save return address. |
| 689 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 690 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 691 | |
| 692 | __ push(ecx); // Push return address. |
| 693 | |
| 694 | // Patch the caller to an appropriate specialized stub and return the |
| 695 | // operation result to the caller of the stub. |
| 696 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 697 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 698 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 699 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 700 | 1); |
| 701 | } |
| 702 | |
| 703 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 704 | static void BinaryOpStub_GenerateRegisterArgsPop(MacroAssembler* masm) { |
| 705 | __ pop(ecx); |
| 706 | __ pop(eax); |
| 707 | __ pop(edx); |
| 708 | __ push(ecx); |
| 709 | } |
| 710 | |
| 711 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 712 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 713 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 714 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 715 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 716 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 717 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 718 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 719 | Comment load_comment(masm, "-- Load arguments"); |
| 720 | Register left = edx; |
| 721 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 722 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 723 | left = eax; |
| 724 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 725 | __ mov(ebx, eax); |
| 726 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | |
| 730 | // 2. Prepare the smi check of both operands by oring them together. |
| 731 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 732 | Label not_smis; |
| 733 | Register combined = ecx; |
| 734 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 735 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 736 | case Token::BIT_OR: |
| 737 | // Perform the operation into eax and smi check the result. Preserve |
| 738 | // eax in case the result is not a smi. |
| 739 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 740 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 741 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 742 | combined = right; |
| 743 | break; |
| 744 | |
| 745 | case Token::BIT_XOR: |
| 746 | case Token::BIT_AND: |
| 747 | case Token::ADD: |
| 748 | case Token::SUB: |
| 749 | case Token::MUL: |
| 750 | case Token::DIV: |
| 751 | case Token::MOD: |
| 752 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 753 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 754 | break; |
| 755 | |
| 756 | case Token::SHL: |
| 757 | case Token::SAR: |
| 758 | case Token::SHR: |
| 759 | // Move the right operand into ecx for the shift operation, use eax |
| 760 | // for the smi check register. |
| 761 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 762 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 763 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 764 | combined = right; |
| 765 | break; |
| 766 | |
| 767 | default: |
| 768 | break; |
| 769 | } |
| 770 | |
| 771 | // 3. Perform the smi check of the operands. |
| 772 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 773 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 774 | |
| 775 | // 4. Operands are both smis, perform the operation leaving the result in |
| 776 | // eax and check the result if necessary. |
| 777 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 778 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 779 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 780 | case Token::BIT_OR: |
| 781 | // Nothing to do. |
| 782 | break; |
| 783 | |
| 784 | case Token::BIT_XOR: |
| 785 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 786 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 787 | break; |
| 788 | |
| 789 | case Token::BIT_AND: |
| 790 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 791 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 792 | break; |
| 793 | |
| 794 | case Token::SHL: |
| 795 | // Remove tags from operands (but keep sign). |
| 796 | __ SmiUntag(left); |
| 797 | __ SmiUntag(ecx); |
| 798 | // Perform the operation. |
| 799 | __ shl_cl(left); |
| 800 | // Check that the *signed* result fits in a smi. |
| 801 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 802 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 803 | // Tag the result and store it in register eax. |
| 804 | __ SmiTag(left); |
| 805 | __ mov(eax, left); |
| 806 | break; |
| 807 | |
| 808 | case Token::SAR: |
| 809 | // Remove tags from operands (but keep sign). |
| 810 | __ SmiUntag(left); |
| 811 | __ SmiUntag(ecx); |
| 812 | // Perform the operation. |
| 813 | __ sar_cl(left); |
| 814 | // Tag the result and store it in register eax. |
| 815 | __ SmiTag(left); |
| 816 | __ mov(eax, left); |
| 817 | break; |
| 818 | |
| 819 | case Token::SHR: |
| 820 | // Remove tags from operands (but keep sign). |
| 821 | __ SmiUntag(left); |
| 822 | __ SmiUntag(ecx); |
| 823 | // Perform the operation. |
| 824 | __ shr_cl(left); |
| 825 | // Check that the *unsigned* result fits in a smi. |
| 826 | // Neither of the two high-order bits can be set: |
| 827 | // - 0x80000000: high bit would be lost when smi tagging. |
| 828 | // - 0x40000000: this number would convert to negative when |
| 829 | // Smi tagging these two cases can only happen with shifts |
| 830 | // by 0 or 1 when handed a valid smi. |
| 831 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 832 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 833 | // Tag the result and store it in register eax. |
| 834 | __ SmiTag(left); |
| 835 | __ mov(eax, left); |
| 836 | break; |
| 837 | |
| 838 | case Token::ADD: |
| 839 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 840 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 841 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 842 | break; |
| 843 | |
| 844 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 845 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 846 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 847 | __ mov(eax, left); |
| 848 | break; |
| 849 | |
| 850 | case Token::MUL: |
| 851 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 852 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 853 | // We can't revert the multiplication if the result is not a smi |
| 854 | // so save the right operand. |
| 855 | __ mov(ebx, right); |
| 856 | // Remove tag from one of the operands (but keep sign). |
| 857 | __ SmiUntag(right); |
| 858 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 859 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 860 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 861 | // Check for negative zero result. Use combined = left | right. |
| 862 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 863 | break; |
| 864 | |
| 865 | case Token::DIV: |
| 866 | // We can't revert the division if the result is not a smi so |
| 867 | // save the left operand. |
| 868 | __ mov(edi, left); |
| 869 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 870 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 871 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 872 | // Sign extend left into edx:eax. |
| 873 | ASSERT(left.is(eax)); |
| 874 | __ cdq(); |
| 875 | // Divide edx:eax by right. |
| 876 | __ idiv(right); |
| 877 | // Check for the corner case of dividing the most negative smi by |
| 878 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 879 | // instruction. |
| 880 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 881 | __ cmp(eax, 0x40000000); |
| 882 | __ j(equal, &use_fp_on_smis); |
| 883 | // Check for negative zero result. Use combined = left | right. |
| 884 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 885 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 886 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 887 | __ j(not_zero, &use_fp_on_smis); |
| 888 | // Tag the result and store it in register eax. |
| 889 | __ SmiTag(eax); |
| 890 | break; |
| 891 | |
| 892 | case Token::MOD: |
| 893 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 894 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 895 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 896 | |
| 897 | // Sign extend left into edx:eax. |
| 898 | ASSERT(left.is(eax)); |
| 899 | __ cdq(); |
| 900 | // Divide edx:eax by right. |
| 901 | __ idiv(right); |
| 902 | // Check for negative zero result. Use combined = left | right. |
| 903 | __ NegativeZeroTest(edx, combined, slow); |
| 904 | // Move remainder to register eax. |
| 905 | __ mov(eax, edx); |
| 906 | break; |
| 907 | |
| 908 | default: |
| 909 | UNREACHABLE(); |
| 910 | } |
| 911 | |
| 912 | // 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] | 913 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 914 | case Token::ADD: |
| 915 | case Token::SUB: |
| 916 | case Token::MUL: |
| 917 | case Token::DIV: |
| 918 | __ ret(0); |
| 919 | break; |
| 920 | case Token::MOD: |
| 921 | case Token::BIT_OR: |
| 922 | case Token::BIT_AND: |
| 923 | case Token::BIT_XOR: |
| 924 | case Token::SAR: |
| 925 | case Token::SHL: |
| 926 | case Token::SHR: |
| 927 | __ ret(2 * kPointerSize); |
| 928 | break; |
| 929 | default: |
| 930 | UNREACHABLE(); |
| 931 | } |
| 932 | |
| 933 | // 6. For some operations emit inline code to perform floating point |
| 934 | // operations on known smis (e.g., if the result of the operation |
| 935 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 936 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 937 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 938 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 939 | // Undo the effects of some operations, and some register moves. |
| 940 | case Token::SHL: |
| 941 | // The arguments are saved on the stack, and only used from there. |
| 942 | break; |
| 943 | case Token::ADD: |
| 944 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 945 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 946 | break; |
| 947 | case Token::SUB: |
| 948 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 949 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 950 | break; |
| 951 | case Token::MUL: |
| 952 | // Right was clobbered but a copy is in ebx. |
| 953 | __ mov(right, ebx); |
| 954 | break; |
| 955 | case Token::DIV: |
| 956 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 957 | // division. They should be in eax, ebx for jump to not_smi. |
| 958 | __ mov(eax, edi); |
| 959 | break; |
| 960 | default: |
| 961 | // No other operators jump to use_fp_on_smis. |
| 962 | break; |
| 963 | } |
| 964 | __ jmp(¬_smis); |
| 965 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 966 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 967 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 968 | case Token::SHL: |
| 969 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 970 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 971 | __ bind(&use_fp_on_smis); |
| 972 | // Result we want is in left == edx, so we can put the allocated heap |
| 973 | // number in eax. |
| 974 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 975 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 976 | // It's OK to overwrite the arguments on the stack because we |
| 977 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 978 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 979 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 980 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 981 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 982 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 983 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 984 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 985 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 986 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 987 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 988 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 989 | } else { |
| 990 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 991 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 992 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 993 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 994 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 995 | __ ret(2 * kPointerSize); |
| 996 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 997 | } |
| 998 | |
| 999 | case Token::ADD: |
| 1000 | case Token::SUB: |
| 1001 | case Token::MUL: |
| 1002 | case Token::DIV: { |
| 1003 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1004 | __ bind(&use_fp_on_smis); |
| 1005 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1006 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1007 | case Token::ADD: |
| 1008 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1009 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1010 | break; |
| 1011 | case Token::SUB: |
| 1012 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1013 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1014 | break; |
| 1015 | case Token::MUL: |
| 1016 | // Right was clobbered but a copy is in ebx. |
| 1017 | __ mov(right, ebx); |
| 1018 | break; |
| 1019 | case Token::DIV: |
| 1020 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1021 | // division. |
| 1022 | __ mov(edx, edi); |
| 1023 | __ mov(eax, right); |
| 1024 | break; |
| 1025 | default: UNREACHABLE(); |
| 1026 | break; |
| 1027 | } |
| 1028 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1029 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1030 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1031 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1032 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1033 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1034 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1035 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1036 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1037 | default: UNREACHABLE(); |
| 1038 | } |
| 1039 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1040 | } else { // SSE2 not available, use FPU. |
| 1041 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1042 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1043 | case Token::ADD: __ faddp(1); break; |
| 1044 | case Token::SUB: __ fsubp(1); break; |
| 1045 | case Token::MUL: __ fmulp(1); break; |
| 1046 | case Token::DIV: __ fdivp(1); break; |
| 1047 | default: UNREACHABLE(); |
| 1048 | } |
| 1049 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1050 | } |
| 1051 | __ mov(eax, ecx); |
| 1052 | __ ret(0); |
| 1053 | break; |
| 1054 | } |
| 1055 | |
| 1056 | default: |
| 1057 | break; |
| 1058 | } |
| 1059 | } |
| 1060 | |
| 1061 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1062 | // edx and eax. |
| 1063 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1064 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1065 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1066 | case Token::BIT_OR: |
| 1067 | case Token::SHL: |
| 1068 | case Token::SAR: |
| 1069 | case Token::SHR: |
| 1070 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1071 | // check. |
| 1072 | __ mov(eax, ecx); |
| 1073 | break; |
| 1074 | |
| 1075 | case Token::DIV: |
| 1076 | case Token::MOD: |
| 1077 | // Operands are in eax, ebx at this point. |
| 1078 | __ mov(edx, eax); |
| 1079 | __ mov(eax, ebx); |
| 1080 | break; |
| 1081 | |
| 1082 | default: |
| 1083 | break; |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1088 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1089 | Label right_arg_changed, call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1090 | |
| 1091 | switch (op_) { |
| 1092 | case Token::ADD: |
| 1093 | case Token::SUB: |
| 1094 | case Token::MUL: |
| 1095 | case Token::DIV: |
| 1096 | break; |
| 1097 | case Token::MOD: |
| 1098 | case Token::BIT_OR: |
| 1099 | case Token::BIT_AND: |
| 1100 | case Token::BIT_XOR: |
| 1101 | case Token::SAR: |
| 1102 | case Token::SHL: |
| 1103 | case Token::SHR: |
| 1104 | GenerateRegisterArgsPush(masm); |
| 1105 | break; |
| 1106 | default: |
| 1107 | UNREACHABLE(); |
| 1108 | } |
| 1109 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1110 | if (op_ == Token::MOD && encoded_right_arg_.has_value) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1111 | // It is guaranteed that the value will fit into a Smi, because if it |
| 1112 | // didn't, we wouldn't be here, see BinaryOp_Patch. |
| 1113 | __ cmp(eax, Immediate(Smi::FromInt(fixed_right_arg_value()))); |
| 1114 | __ j(not_equal, &right_arg_changed); |
| 1115 | } |
| 1116 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1117 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1118 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1119 | BinaryOpStub_GenerateSmiCode( |
| 1120 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1121 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1122 | BinaryOpStub_GenerateSmiCode( |
| 1123 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1124 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1125 | |
| 1126 | // Code falls through if the result is not returned as either a smi or heap |
| 1127 | // number. |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1128 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1129 | switch (op_) { |
| 1130 | case Token::ADD: |
| 1131 | case Token::SUB: |
| 1132 | case Token::MUL: |
| 1133 | case Token::DIV: |
| 1134 | GenerateTypeTransition(masm); |
| 1135 | break; |
| 1136 | case Token::MOD: |
| 1137 | case Token::BIT_OR: |
| 1138 | case Token::BIT_AND: |
| 1139 | case Token::BIT_XOR: |
| 1140 | case Token::SAR: |
| 1141 | case Token::SHL: |
| 1142 | case Token::SHR: |
| 1143 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1144 | break; |
| 1145 | default: |
| 1146 | UNREACHABLE(); |
| 1147 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1148 | |
| 1149 | __ bind(&call_runtime); |
| 1150 | switch (op_) { |
| 1151 | case Token::ADD: |
| 1152 | case Token::SUB: |
| 1153 | case Token::MUL: |
| 1154 | case Token::DIV: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1155 | break; |
| 1156 | case Token::MOD: |
| 1157 | case Token::BIT_OR: |
| 1158 | case Token::BIT_AND: |
| 1159 | case Token::BIT_XOR: |
| 1160 | case Token::SAR: |
| 1161 | case Token::SHL: |
| 1162 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1163 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1164 | break; |
| 1165 | default: |
| 1166 | UNREACHABLE(); |
| 1167 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1168 | |
| 1169 | { |
| 1170 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1171 | __ push(edx); |
| 1172 | __ push(eax); |
| 1173 | GenerateCallRuntime(masm); |
| 1174 | } |
| 1175 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1179 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1180 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1181 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1182 | ASSERT(op_ == Token::ADD); |
| 1183 | // If both arguments are strings, call the string add stub. |
| 1184 | // Otherwise, do a transition. |
| 1185 | |
| 1186 | // Registers containing left and right operands respectively. |
| 1187 | Register left = edx; |
| 1188 | Register right = eax; |
| 1189 | |
| 1190 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1191 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1192 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1193 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1194 | |
| 1195 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1196 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1197 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1198 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1199 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1200 | StringAddStub string_add_stub( |
| 1201 | (StringAddFlags)(STRING_ADD_CHECK_NONE | STRING_ADD_ERECT_FRAME)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1202 | GenerateRegisterArgsPush(masm); |
| 1203 | __ TailCallStub(&string_add_stub); |
| 1204 | |
| 1205 | __ bind(&call_runtime); |
| 1206 | GenerateTypeTransition(masm); |
| 1207 | } |
| 1208 | |
| 1209 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1210 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1211 | Label* alloc_failure, |
| 1212 | OverwriteMode mode); |
| 1213 | |
| 1214 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1215 | // Input: |
| 1216 | // edx: left operand (tagged) |
| 1217 | // eax: right operand (tagged) |
| 1218 | // Output: |
| 1219 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1220 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1221 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1222 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1223 | |
| 1224 | // Floating point case. |
| 1225 | switch (op_) { |
| 1226 | case Token::ADD: |
| 1227 | case Token::SUB: |
| 1228 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1229 | case Token::DIV: |
| 1230 | case Token::MOD: { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1231 | Label not_floats, not_int32, right_arg_changed; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1232 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1233 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1234 | // It could be that only SMIs have been seen at either the left |
| 1235 | // or the right operand. For precise type feedback, patch the IC |
| 1236 | // again if this changes. |
| 1237 | // In theory, we would need the same check in the non-SSE2 case, |
| 1238 | // but since we don't support Crankshaft on such hardware we can |
| 1239 | // afford not to care about precise type feedback. |
| 1240 | if (left_type_ == BinaryOpIC::SMI) { |
| 1241 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1242 | } |
| 1243 | if (right_type_ == BinaryOpIC::SMI) { |
| 1244 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1245 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1246 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1247 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1248 | masm, ¬_int32, xmm0, ebx, ecx, xmm2); |
| 1249 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1250 | masm, ¬_int32, xmm1, edi, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1251 | if (op_ == Token::MOD) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1252 | if (encoded_right_arg_.has_value) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1253 | __ cmp(edi, Immediate(fixed_right_arg_value())); |
| 1254 | __ j(not_equal, &right_arg_changed); |
| 1255 | } |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1256 | GenerateRegisterArgsPush(masm); |
| 1257 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1258 | } else { |
| 1259 | switch (op_) { |
| 1260 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1261 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1262 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1263 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1264 | default: UNREACHABLE(); |
| 1265 | } |
| 1266 | // Check result type if it is currently Int32. |
| 1267 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1268 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1269 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1270 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1271 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1272 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1273 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1274 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1275 | } else { // SSE2 not available, use FPU. |
| 1276 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1277 | FloatingPointHelper::LoadFloatOperands( |
| 1278 | masm, |
| 1279 | ecx, |
| 1280 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1281 | if (op_ == Token::MOD) { |
| 1282 | // The operands are now on the FPU stack, but we don't need them. |
| 1283 | __ fstp(0); |
| 1284 | __ fstp(0); |
| 1285 | GenerateRegisterArgsPush(masm); |
| 1286 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1287 | } else { |
| 1288 | switch (op_) { |
| 1289 | case Token::ADD: __ faddp(1); break; |
| 1290 | case Token::SUB: __ fsubp(1); break; |
| 1291 | case Token::MUL: __ fmulp(1); break; |
| 1292 | case Token::DIV: __ fdivp(1); break; |
| 1293 | default: UNREACHABLE(); |
| 1294 | } |
| 1295 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1296 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1297 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1298 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1299 | __ ret(0); |
| 1300 | __ bind(&after_alloc_failure); |
| 1301 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1302 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1303 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | __ bind(¬_floats); |
| 1307 | __ bind(¬_int32); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1308 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1309 | GenerateTypeTransition(masm); |
| 1310 | break; |
| 1311 | } |
| 1312 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1313 | case Token::BIT_OR: |
| 1314 | case Token::BIT_AND: |
| 1315 | case Token::BIT_XOR: |
| 1316 | case Token::SAR: |
| 1317 | case Token::SHL: |
| 1318 | case Token::SHR: { |
| 1319 | GenerateRegisterArgsPush(masm); |
| 1320 | Label not_floats; |
| 1321 | Label not_int32; |
| 1322 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1323 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1324 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1325 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1326 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1327 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1328 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1329 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1330 | case Token::SAR: __ sar_cl(eax); break; |
| 1331 | case Token::SHL: __ shl_cl(eax); break; |
| 1332 | case Token::SHR: __ shr_cl(eax); break; |
| 1333 | default: UNREACHABLE(); |
| 1334 | } |
| 1335 | if (op_ == Token::SHR) { |
| 1336 | // Check if result is non-negative and fits in a smi. |
| 1337 | __ test(eax, Immediate(0xc0000000)); |
| 1338 | __ j(not_zero, &call_runtime); |
| 1339 | } else { |
| 1340 | // Check if result fits in a smi. |
| 1341 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1342 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1343 | } |
| 1344 | // Tag smi result and return. |
| 1345 | __ SmiTag(eax); |
| 1346 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1347 | |
| 1348 | // All ops except SHR return a signed int32 that we load in |
| 1349 | // a HeapNumber. |
| 1350 | if (op_ != Token::SHR) { |
| 1351 | __ bind(&non_smi_result); |
| 1352 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1353 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1354 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1355 | switch (mode_) { |
| 1356 | case OVERWRITE_LEFT: |
| 1357 | case OVERWRITE_RIGHT: |
| 1358 | // If the operand was an object, we skip the |
| 1359 | // allocation of a heap number. |
| 1360 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1361 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1362 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1363 | // Fall through! |
| 1364 | case NO_OVERWRITE: |
| 1365 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1366 | __ bind(&skip_allocation); |
| 1367 | break; |
| 1368 | default: UNREACHABLE(); |
| 1369 | } |
| 1370 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1371 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1372 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1373 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1374 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1375 | } else { |
| 1376 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1377 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1378 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1379 | } |
| 1380 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1381 | } |
| 1382 | |
| 1383 | __ bind(¬_floats); |
| 1384 | __ bind(¬_int32); |
| 1385 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1386 | break; |
| 1387 | } |
| 1388 | default: UNREACHABLE(); break; |
| 1389 | } |
| 1390 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1391 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1392 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1393 | __ bind(&call_runtime); |
| 1394 | |
| 1395 | switch (op_) { |
| 1396 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1397 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1398 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1399 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1400 | break; |
| 1401 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1402 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1403 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1404 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1405 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1406 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1407 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1408 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1409 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1410 | break; |
| 1411 | default: |
| 1412 | UNREACHABLE(); |
| 1413 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1414 | |
| 1415 | { |
| 1416 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1417 | __ push(edx); |
| 1418 | __ push(eax); |
| 1419 | GenerateCallRuntime(masm); |
| 1420 | } |
| 1421 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1425 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1426 | if (op_ == Token::ADD) { |
| 1427 | // Handle string addition here, because it is the only operation |
| 1428 | // that does not do a ToNumber conversion on the operands. |
| 1429 | GenerateAddStrings(masm); |
| 1430 | } |
| 1431 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1432 | Factory* factory = masm->isolate()->factory(); |
| 1433 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1434 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1435 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1436 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1437 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1438 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1439 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1440 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1441 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1442 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1443 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1444 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1445 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1446 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1447 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1448 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1449 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1450 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1451 | } |
| 1452 | __ bind(&done); |
| 1453 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1454 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1458 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1459 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1460 | |
| 1461 | // Floating point case. |
| 1462 | switch (op_) { |
| 1463 | case Token::ADD: |
| 1464 | case Token::SUB: |
| 1465 | case Token::MUL: |
| 1466 | case Token::DIV: { |
| 1467 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1468 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1469 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1470 | |
| 1471 | // It could be that only SMIs have been seen at either the left |
| 1472 | // or the right operand. For precise type feedback, patch the IC |
| 1473 | // again if this changes. |
| 1474 | // In theory, we would need the same check in the non-SSE2 case, |
| 1475 | // but since we don't support Crankshaft on such hardware we can |
| 1476 | // afford not to care about precise type feedback. |
| 1477 | if (left_type_ == BinaryOpIC::SMI) { |
| 1478 | __ JumpIfNotSmi(edx, ¬_floats); |
| 1479 | } |
| 1480 | if (right_type_ == BinaryOpIC::SMI) { |
| 1481 | __ JumpIfNotSmi(eax, ¬_floats); |
| 1482 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1483 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1484 | if (left_type_ == BinaryOpIC::INT32) { |
| 1485 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1486 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1487 | } |
| 1488 | if (right_type_ == BinaryOpIC::INT32) { |
| 1489 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1490 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1491 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1492 | |
| 1493 | switch (op_) { |
| 1494 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1495 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1496 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1497 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1498 | default: UNREACHABLE(); |
| 1499 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1500 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1501 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1502 | __ ret(0); |
| 1503 | } else { // SSE2 not available, use FPU. |
| 1504 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1505 | FloatingPointHelper::LoadFloatOperands( |
| 1506 | masm, |
| 1507 | ecx, |
| 1508 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1509 | switch (op_) { |
| 1510 | case Token::ADD: __ faddp(1); break; |
| 1511 | case Token::SUB: __ fsubp(1); break; |
| 1512 | case Token::MUL: __ fmulp(1); break; |
| 1513 | case Token::DIV: __ fdivp(1); break; |
| 1514 | default: UNREACHABLE(); |
| 1515 | } |
| 1516 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1517 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1518 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1519 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1520 | __ ret(0); |
| 1521 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1522 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1523 | __ jmp(&call_runtime); |
| 1524 | } |
| 1525 | |
| 1526 | __ bind(¬_floats); |
| 1527 | GenerateTypeTransition(masm); |
| 1528 | break; |
| 1529 | } |
| 1530 | |
| 1531 | case Token::MOD: { |
| 1532 | // For MOD we go directly to runtime in the non-smi case. |
| 1533 | break; |
| 1534 | } |
| 1535 | case Token::BIT_OR: |
| 1536 | case Token::BIT_AND: |
| 1537 | case Token::BIT_XOR: |
| 1538 | case Token::SAR: |
| 1539 | case Token::SHL: |
| 1540 | case Token::SHR: { |
| 1541 | GenerateRegisterArgsPush(masm); |
| 1542 | Label not_floats; |
| 1543 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1544 | // We do not check the input arguments here, as any value is |
| 1545 | // unconditionally truncated to an int32 anyway. To get the |
| 1546 | // right optimized code, int32 type feedback is just right. |
| 1547 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1548 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1549 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1550 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1551 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1552 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1553 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1554 | case Token::SAR: __ sar_cl(eax); break; |
| 1555 | case Token::SHL: __ shl_cl(eax); break; |
| 1556 | case Token::SHR: __ shr_cl(eax); break; |
| 1557 | default: UNREACHABLE(); |
| 1558 | } |
| 1559 | if (op_ == Token::SHR) { |
| 1560 | // Check if result is non-negative and fits in a smi. |
| 1561 | __ test(eax, Immediate(0xc0000000)); |
| 1562 | __ j(not_zero, &call_runtime); |
| 1563 | } else { |
| 1564 | // Check if result fits in a smi. |
| 1565 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1566 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1567 | } |
| 1568 | // Tag smi result and return. |
| 1569 | __ SmiTag(eax); |
| 1570 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1571 | |
| 1572 | // All ops except SHR return a signed int32 that we load in |
| 1573 | // a HeapNumber. |
| 1574 | if (op_ != Token::SHR) { |
| 1575 | __ bind(&non_smi_result); |
| 1576 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1577 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1578 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1579 | switch (mode_) { |
| 1580 | case OVERWRITE_LEFT: |
| 1581 | case OVERWRITE_RIGHT: |
| 1582 | // If the operand was an object, we skip the |
| 1583 | // allocation of a heap number. |
| 1584 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1585 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1586 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1587 | // Fall through! |
| 1588 | case NO_OVERWRITE: |
| 1589 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1590 | __ bind(&skip_allocation); |
| 1591 | break; |
| 1592 | default: UNREACHABLE(); |
| 1593 | } |
| 1594 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1595 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1596 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1597 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1598 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1599 | } else { |
| 1600 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1601 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1602 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1603 | } |
| 1604 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1605 | } |
| 1606 | |
| 1607 | __ bind(¬_floats); |
| 1608 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1609 | break; |
| 1610 | } |
| 1611 | default: UNREACHABLE(); break; |
| 1612 | } |
| 1613 | |
| 1614 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 1615 | // use the runtime system to get the correct result. |
| 1616 | __ bind(&call_runtime); |
| 1617 | |
| 1618 | switch (op_) { |
| 1619 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1620 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1621 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1622 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1623 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1624 | break; |
| 1625 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1626 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1627 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1628 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1629 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1630 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1631 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1632 | break; |
| 1633 | default: |
| 1634 | UNREACHABLE(); |
| 1635 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1636 | |
| 1637 | { |
| 1638 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1639 | __ push(edx); |
| 1640 | __ push(eax); |
| 1641 | GenerateCallRuntime(masm); |
| 1642 | } |
| 1643 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1644 | } |
| 1645 | |
| 1646 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1647 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1648 | Label call_runtime; |
| 1649 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1650 | Counters* counters = masm->isolate()->counters(); |
| 1651 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1652 | |
| 1653 | switch (op_) { |
| 1654 | case Token::ADD: |
| 1655 | case Token::SUB: |
| 1656 | case Token::MUL: |
| 1657 | case Token::DIV: |
| 1658 | break; |
| 1659 | case Token::MOD: |
| 1660 | case Token::BIT_OR: |
| 1661 | case Token::BIT_AND: |
| 1662 | case Token::BIT_XOR: |
| 1663 | case Token::SAR: |
| 1664 | case Token::SHL: |
| 1665 | case Token::SHR: |
| 1666 | GenerateRegisterArgsPush(masm); |
| 1667 | break; |
| 1668 | default: |
| 1669 | UNREACHABLE(); |
| 1670 | } |
| 1671 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1672 | BinaryOpStub_GenerateSmiCode( |
| 1673 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1674 | |
| 1675 | // Floating point case. |
| 1676 | switch (op_) { |
| 1677 | case Token::ADD: |
| 1678 | case Token::SUB: |
| 1679 | case Token::MUL: |
| 1680 | case Token::DIV: { |
| 1681 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1682 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1683 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1684 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1685 | |
| 1686 | switch (op_) { |
| 1687 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1688 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1689 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1690 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1691 | default: UNREACHABLE(); |
| 1692 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1693 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1694 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1695 | __ ret(0); |
| 1696 | } else { // SSE2 not available, use FPU. |
| 1697 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1698 | FloatingPointHelper::LoadFloatOperands( |
| 1699 | masm, |
| 1700 | ecx, |
| 1701 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1702 | switch (op_) { |
| 1703 | case Token::ADD: __ faddp(1); break; |
| 1704 | case Token::SUB: __ fsubp(1); break; |
| 1705 | case Token::MUL: __ fmulp(1); break; |
| 1706 | case Token::DIV: __ fdivp(1); break; |
| 1707 | default: UNREACHABLE(); |
| 1708 | } |
| 1709 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1710 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1711 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1712 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1713 | __ ret(0); |
| 1714 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1715 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1716 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1717 | } |
| 1718 | __ bind(¬_floats); |
| 1719 | break; |
| 1720 | } |
| 1721 | case Token::MOD: { |
| 1722 | // For MOD we go directly to runtime in the non-smi case. |
| 1723 | break; |
| 1724 | } |
| 1725 | case Token::BIT_OR: |
| 1726 | case Token::BIT_AND: |
| 1727 | case Token::BIT_XOR: |
| 1728 | case Token::SAR: |
| 1729 | case Token::SHL: |
| 1730 | case Token::SHR: { |
| 1731 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1732 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1733 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1734 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1735 | BinaryOpIC::GENERIC, |
| 1736 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1737 | &call_runtime); |
| 1738 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1739 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1740 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1741 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1742 | case Token::SAR: __ sar_cl(eax); break; |
| 1743 | case Token::SHL: __ shl_cl(eax); break; |
| 1744 | case Token::SHR: __ shr_cl(eax); break; |
| 1745 | default: UNREACHABLE(); |
| 1746 | } |
| 1747 | if (op_ == Token::SHR) { |
| 1748 | // Check if result is non-negative and fits in a smi. |
| 1749 | __ test(eax, Immediate(0xc0000000)); |
| 1750 | __ j(not_zero, &call_runtime); |
| 1751 | } else { |
| 1752 | // Check if result fits in a smi. |
| 1753 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1754 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1755 | } |
| 1756 | // Tag smi result and return. |
| 1757 | __ SmiTag(eax); |
| 1758 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 1759 | |
| 1760 | // All ops except SHR return a signed int32 that we load in |
| 1761 | // a HeapNumber. |
| 1762 | if (op_ != Token::SHR) { |
| 1763 | __ bind(&non_smi_result); |
| 1764 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1765 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1766 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1767 | switch (mode_) { |
| 1768 | case OVERWRITE_LEFT: |
| 1769 | case OVERWRITE_RIGHT: |
| 1770 | // If the operand was an object, we skip the |
| 1771 | // allocation of a heap number. |
| 1772 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1773 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1774 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1775 | // Fall through! |
| 1776 | case NO_OVERWRITE: |
| 1777 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1778 | __ bind(&skip_allocation); |
| 1779 | break; |
| 1780 | default: UNREACHABLE(); |
| 1781 | } |
| 1782 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1783 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1784 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1785 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1786 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1787 | } else { |
| 1788 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1789 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1790 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1791 | } |
| 1792 | __ ret(2 * kPointerSize); |
| 1793 | } |
| 1794 | break; |
| 1795 | } |
| 1796 | default: UNREACHABLE(); break; |
| 1797 | } |
| 1798 | |
| 1799 | // If all else fails, use the runtime system to get the correct |
| 1800 | // result. |
| 1801 | __ bind(&call_runtime); |
| 1802 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1803 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1804 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1805 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1806 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1807 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1808 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1809 | break; |
| 1810 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1811 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1812 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1813 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1814 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1815 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1816 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1817 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1818 | break; |
| 1819 | default: |
| 1820 | UNREACHABLE(); |
| 1821 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1822 | |
| 1823 | { |
| 1824 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1825 | __ push(edx); |
| 1826 | __ push(eax); |
| 1827 | GenerateCallRuntime(masm); |
| 1828 | } |
| 1829 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1830 | } |
| 1831 | |
| 1832 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1833 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1834 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1835 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1836 | |
| 1837 | // Registers containing left and right operands respectively. |
| 1838 | Register left = edx; |
| 1839 | Register right = eax; |
| 1840 | |
| 1841 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1842 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1843 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1844 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1845 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1846 | StringAddStub string_add_left_stub( |
| 1847 | (StringAddFlags)(STRING_ADD_CHECK_RIGHT | STRING_ADD_ERECT_FRAME)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1848 | GenerateRegisterArgsPush(masm); |
| 1849 | __ TailCallStub(&string_add_left_stub); |
| 1850 | |
| 1851 | // Left operand is not a string, test right. |
| 1852 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1853 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1854 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1855 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1856 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1857 | StringAddStub string_add_right_stub( |
| 1858 | (StringAddFlags)(STRING_ADD_CHECK_LEFT | STRING_ADD_ERECT_FRAME)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1859 | GenerateRegisterArgsPush(masm); |
| 1860 | __ TailCallStub(&string_add_right_stub); |
| 1861 | |
| 1862 | // Neither argument is a string. |
| 1863 | __ bind(&call_runtime); |
| 1864 | } |
| 1865 | |
| 1866 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1867 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1868 | Label* alloc_failure, |
| 1869 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1870 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1871 | switch (mode) { |
| 1872 | case OVERWRITE_LEFT: { |
| 1873 | // If the argument in edx is already an object, we skip the |
| 1874 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1875 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1876 | // Allocate a heap number for the result. Keep eax and edx intact |
| 1877 | // for the possible runtime call. |
| 1878 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 1879 | // Now edx can be overwritten losing one of the arguments as we are |
| 1880 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1881 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1882 | __ bind(&skip_allocation); |
| 1883 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1884 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1885 | break; |
| 1886 | } |
| 1887 | case OVERWRITE_RIGHT: |
| 1888 | // If the argument in eax is already an object, we skip the |
| 1889 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1890 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1891 | // Fall through! |
| 1892 | case NO_OVERWRITE: |
| 1893 | // Allocate a heap number for the result. Keep eax and edx intact |
| 1894 | // for the possible runtime call. |
| 1895 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 1896 | // Now eax can be overwritten losing one of the arguments as we are |
| 1897 | // now done and will not need it any more. |
| 1898 | __ mov(eax, ebx); |
| 1899 | __ bind(&skip_allocation); |
| 1900 | break; |
| 1901 | default: UNREACHABLE(); |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1906 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1907 | __ pop(ecx); |
| 1908 | __ push(edx); |
| 1909 | __ push(eax); |
| 1910 | __ push(ecx); |
| 1911 | } |
| 1912 | |
| 1913 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1914 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1915 | // TAGGED case: |
| 1916 | // Input: |
| 1917 | // esp[4]: tagged number input argument (should be number). |
| 1918 | // esp[0]: return address. |
| 1919 | // Output: |
| 1920 | // eax: tagged double result. |
| 1921 | // UNTAGGED case: |
| 1922 | // Input:: |
| 1923 | // esp[0]: return address. |
| 1924 | // xmm1: untagged double input argument |
| 1925 | // Output: |
| 1926 | // xmm1: untagged double result. |
| 1927 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1928 | Label runtime_call; |
| 1929 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1930 | Label skip_cache; |
| 1931 | const bool tagged = (argument_type_ == TAGGED); |
| 1932 | if (tagged) { |
| 1933 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1934 | Label input_not_smi; |
| 1935 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1936 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1937 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1938 | // Input is a smi. Untag and load it onto the FPU stack. |
| 1939 | // Then load the low and high words of the double into ebx, edx. |
| 1940 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1941 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1942 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1943 | __ mov(Operand(esp, 0), eax); |
| 1944 | __ fild_s(Operand(esp, 0)); |
| 1945 | __ fst_d(Operand(esp, 0)); |
| 1946 | __ pop(edx); |
| 1947 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1948 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1949 | __ bind(&input_not_smi); |
| 1950 | // Check if input is a HeapNumber. |
| 1951 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1952 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1953 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1954 | __ j(not_equal, &runtime_call); |
| 1955 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 1956 | // low and high words into ebx, edx. |
| 1957 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1958 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 1959 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1960 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1961 | __ bind(&loaded); |
| 1962 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1963 | CpuFeatureScope scope(masm, SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1964 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1965 | CpuFeatureScope sse4_scope(masm, SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1966 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1967 | } else { |
| 1968 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1969 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1970 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1971 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
| 1974 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1975 | // ebx = low 32 bits of double value |
| 1976 | // edx = high 32 bits of double value |
| 1977 | // Compute hash (the shifts are arithmetic): |
| 1978 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 1979 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1980 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1981 | __ mov(eax, ecx); |
| 1982 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1983 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1984 | __ mov(eax, ecx); |
| 1985 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1986 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1987 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1988 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1989 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1990 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1991 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1992 | // ebx = low 32 bits of double value. |
| 1993 | // edx = high 32 bits of double value. |
| 1994 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1995 | ExternalReference cache_array = |
| 1996 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 1997 | __ mov(eax, Immediate(cache_array)); |
| 1998 | int cache_array_index = |
| 1999 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2000 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2001 | // Eax points to the cache for the type type_. |
| 2002 | // 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] | 2003 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2004 | __ j(zero, &runtime_call_clear_stack); |
| 2005 | #ifdef DEBUG |
| 2006 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2007 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2008 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2009 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2010 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2011 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2012 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2013 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2014 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2015 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2016 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2017 | } |
| 2018 | #endif |
| 2019 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2020 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2021 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2022 | // 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] | 2023 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2024 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2025 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2026 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2027 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2028 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2029 | Counters* counters = masm->isolate()->counters(); |
| 2030 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2031 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2032 | if (tagged) { |
| 2033 | __ fstp(0); |
| 2034 | __ ret(kPointerSize); |
| 2035 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2036 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2037 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2038 | __ Ret(); |
| 2039 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2040 | |
| 2041 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2042 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2043 | // Update cache with new value. |
| 2044 | // We are short on registers, so use no_reg as scratch. |
| 2045 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2046 | if (tagged) { |
| 2047 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2048 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2049 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2050 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2051 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2052 | __ movdbl(Operand(esp, 0), xmm1); |
| 2053 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2054 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2055 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2056 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2057 | __ mov(Operand(ecx, 0), ebx); |
| 2058 | __ mov(Operand(ecx, kIntSize), edx); |
| 2059 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2060 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2061 | if (tagged) { |
| 2062 | __ ret(kPointerSize); |
| 2063 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2064 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2065 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2066 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2067 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2068 | // Skip cache and return answer directly, only in untagged case. |
| 2069 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2070 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2071 | __ movdbl(Operand(esp, 0), xmm1); |
| 2072 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2073 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2074 | __ fstp_d(Operand(esp, 0)); |
| 2075 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2076 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2077 | // We return the value in xmm1 without adding it to the cache, but |
| 2078 | // 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] | 2079 | { |
| 2080 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2081 | // Allocate an unused object bigger than a HeapNumber. |
| 2082 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2083 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2084 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2085 | __ Ret(); |
| 2086 | } |
| 2087 | |
| 2088 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2089 | if (tagged) { |
| 2090 | __ bind(&runtime_call_clear_stack); |
| 2091 | __ fstp(0); |
| 2092 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2093 | ExternalReference runtime = |
| 2094 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2095 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2096 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2097 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2098 | __ bind(&runtime_call_clear_stack); |
| 2099 | __ bind(&runtime_call); |
| 2100 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2101 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2102 | { |
| 2103 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2104 | __ push(eax); |
| 2105 | __ CallRuntime(RuntimeFunction(), 1); |
| 2106 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2107 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2108 | __ Ret(); |
| 2109 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2110 | } |
| 2111 | |
| 2112 | |
| 2113 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2114 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2115 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2116 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2117 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2118 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2119 | default: |
| 2120 | UNIMPLEMENTED(); |
| 2121 | return Runtime::kAbort; |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2126 | void TranscendentalCacheStub::GenerateOperation( |
| 2127 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2128 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2129 | // Input value is on FP stack, and also in ebx/edx. |
| 2130 | // Input value is possibly in xmm1. |
| 2131 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2132 | if (type == TranscendentalCache::SIN || |
| 2133 | type == TranscendentalCache::COS || |
| 2134 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2135 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2136 | // return NaN for infinities and NaN. They can share all code except |
| 2137 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2138 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2139 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2140 | // work. We must reduce it to the appropriate range. |
| 2141 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2142 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2143 | int supported_exponent_limit = |
| 2144 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2145 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2146 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2147 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2148 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2149 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2150 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2151 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2152 | __ fstp(0); |
| 2153 | // NaN is represented by 0x7ff8000000000000. |
| 2154 | __ push(Immediate(0x7ff80000)); |
| 2155 | __ push(Immediate(0)); |
| 2156 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2157 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2158 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2159 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2160 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2161 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2162 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2163 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2164 | __ fldpi(); |
| 2165 | __ fadd(0); |
| 2166 | __ fld(1); |
| 2167 | // FPU Stack: input, 2*pi, input. |
| 2168 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2169 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2170 | __ fwait(); |
| 2171 | __ fnstsw_ax(); |
| 2172 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2173 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2174 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2175 | __ fnclex(); |
| 2176 | __ bind(&no_exceptions); |
| 2177 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2178 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2179 | // Compute st(0) % st(1) |
| 2180 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2181 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2182 | __ bind(&partial_remainder_loop); |
| 2183 | __ fprem1(); |
| 2184 | __ fwait(); |
| 2185 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2186 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2187 | // If C2 is set, computation only has partial result. Loop to |
| 2188 | // continue computation. |
| 2189 | __ j(not_zero, &partial_remainder_loop); |
| 2190 | } |
| 2191 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2192 | __ fstp(2); |
| 2193 | __ fstp(0); |
| 2194 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2195 | |
| 2196 | // FPU Stack: input % 2*pi |
| 2197 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2198 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2199 | case TranscendentalCache::SIN: |
| 2200 | __ fsin(); |
| 2201 | break; |
| 2202 | case TranscendentalCache::COS: |
| 2203 | __ fcos(); |
| 2204 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2205 | case TranscendentalCache::TAN: |
| 2206 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2207 | // FP register stack. |
| 2208 | __ fptan(); |
| 2209 | __ fstp(0); // Pop FP register stack. |
| 2210 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2211 | default: |
| 2212 | UNREACHABLE(); |
| 2213 | } |
| 2214 | __ bind(&done); |
| 2215 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2216 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2217 | __ fldln2(); |
| 2218 | __ fxch(); |
| 2219 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2220 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2224 | // Input: edx, eax are the left and right objects of a bit op. |
| 2225 | // 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] | 2226 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2227 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2228 | MacroAssembler* masm, |
| 2229 | bool use_sse3, |
| 2230 | BinaryOpIC::TypeInfo left_type, |
| 2231 | BinaryOpIC::TypeInfo right_type, |
| 2232 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2233 | // Check float operands. |
| 2234 | Label arg1_is_object, check_undefined_arg1; |
| 2235 | Label arg2_is_object, check_undefined_arg2; |
| 2236 | Label load_arg2, done; |
| 2237 | |
| 2238 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2239 | if (left_type == BinaryOpIC::SMI) { |
| 2240 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2241 | } else { |
| 2242 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2243 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2244 | |
| 2245 | __ SmiUntag(edx); |
| 2246 | __ jmp(&load_arg2); |
| 2247 | |
| 2248 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2249 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2250 | Factory* factory = masm->isolate()->factory(); |
| 2251 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2252 | __ j(not_equal, conversion_failure); |
| 2253 | __ mov(edx, Immediate(0)); |
| 2254 | __ jmp(&load_arg2); |
| 2255 | |
| 2256 | __ bind(&arg1_is_object); |
| 2257 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2258 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2259 | __ j(not_equal, &check_undefined_arg1); |
| 2260 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame^] | 2261 | __ TruncateHeapNumberToI(edx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2262 | |
| 2263 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2264 | __ bind(&load_arg2); |
| 2265 | |
| 2266 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2267 | if (right_type == BinaryOpIC::SMI) { |
| 2268 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2269 | } else { |
| 2270 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2271 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2272 | |
| 2273 | __ SmiUntag(eax); |
| 2274 | __ mov(ecx, eax); |
| 2275 | __ jmp(&done); |
| 2276 | |
| 2277 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2278 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2279 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2280 | __ j(not_equal, conversion_failure); |
| 2281 | __ mov(ecx, Immediate(0)); |
| 2282 | __ jmp(&done); |
| 2283 | |
| 2284 | __ bind(&arg2_is_object); |
| 2285 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2286 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2287 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2288 | // 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] | 2289 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame^] | 2290 | __ TruncateHeapNumberToI(ecx, eax); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2291 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2292 | __ bind(&done); |
| 2293 | __ mov(eax, edx); |
| 2294 | } |
| 2295 | |
| 2296 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2297 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2298 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2299 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2300 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2301 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2302 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2303 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2304 | |
| 2305 | __ bind(&load_smi); |
| 2306 | __ SmiUntag(number); |
| 2307 | __ push(number); |
| 2308 | __ fild_s(Operand(esp, 0)); |
| 2309 | __ pop(number); |
| 2310 | |
| 2311 | __ bind(&done); |
| 2312 | } |
| 2313 | |
| 2314 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2315 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2316 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2317 | 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] | 2318 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2319 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2320 | Factory* factory = masm->isolate()->factory(); |
| 2321 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2322 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2323 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2324 | __ bind(&load_eax); |
| 2325 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2326 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2327 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2328 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2329 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2330 | __ bind(&load_smi_edx); |
| 2331 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2332 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2333 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2334 | __ jmp(&load_eax); |
| 2335 | __ bind(&load_smi_eax); |
| 2336 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2337 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2338 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2339 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2340 | __ bind(&load_float_eax); |
| 2341 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2342 | __ bind(&done); |
| 2343 | } |
| 2344 | |
| 2345 | |
| 2346 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2347 | Register scratch) { |
| 2348 | const Register left = edx; |
| 2349 | const Register right = eax; |
| 2350 | __ mov(scratch, left); |
| 2351 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2352 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2353 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2354 | |
| 2355 | __ mov(scratch, right); |
| 2356 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2357 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2361 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2362 | Label* non_int32, |
| 2363 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2364 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2365 | Register scratch, |
| 2366 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2367 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2368 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2369 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2370 | __ movmskps(scratch, xmm_scratch); |
| 2371 | // Two least significant bits should be both set. |
| 2372 | __ not_(scratch); |
| 2373 | __ test(scratch, Immediate(3)); |
| 2374 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2375 | } |
| 2376 | |
| 2377 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2378 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2379 | Register scratch, |
| 2380 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2381 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2382 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2383 | __ mov(scratch, edx); |
| 2384 | } else { |
| 2385 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2386 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2387 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2388 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2389 | __ bind(&done_load_1); |
| 2390 | |
| 2391 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2392 | __ mov(scratch, eax); |
| 2393 | } else { |
| 2394 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2395 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2396 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2397 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2398 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2399 | |
| 2400 | __ bind(&load_smi_1); |
| 2401 | __ SmiUntag(scratch); |
| 2402 | __ push(scratch); |
| 2403 | __ fild_s(Operand(esp, 0)); |
| 2404 | __ pop(scratch); |
| 2405 | __ jmp(&done_load_1); |
| 2406 | |
| 2407 | __ bind(&load_smi_2); |
| 2408 | __ SmiUntag(scratch); |
| 2409 | __ push(scratch); |
| 2410 | __ fild_s(Operand(esp, 0)); |
| 2411 | __ pop(scratch); |
| 2412 | |
| 2413 | __ bind(&done); |
| 2414 | } |
| 2415 | |
| 2416 | |
| 2417 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2418 | Register scratch) { |
| 2419 | const Register left = edx; |
| 2420 | const Register right = eax; |
| 2421 | __ mov(scratch, left); |
| 2422 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2423 | __ SmiUntag(scratch); |
| 2424 | __ push(scratch); |
| 2425 | __ fild_s(Operand(esp, 0)); |
| 2426 | |
| 2427 | __ mov(scratch, right); |
| 2428 | __ SmiUntag(scratch); |
| 2429 | __ mov(Operand(esp, 0), scratch); |
| 2430 | __ fild_s(Operand(esp, 0)); |
| 2431 | __ pop(scratch); |
| 2432 | } |
| 2433 | |
| 2434 | |
| 2435 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2436 | Label* non_float, |
| 2437 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2438 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2439 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2440 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2441 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2442 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2443 | Factory* factory = masm->isolate()->factory(); |
| 2444 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2445 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2446 | |
| 2447 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2448 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2449 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2450 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2451 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2452 | |
| 2453 | // Fall-through: Both operands are numbers. |
| 2454 | __ bind(&done); |
| 2455 | } |
| 2456 | |
| 2457 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2458 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2459 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2460 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2461 | const Register exponent = eax; |
| 2462 | const Register base = edx; |
| 2463 | const Register scratch = ecx; |
| 2464 | const XMMRegister double_result = xmm3; |
| 2465 | const XMMRegister double_base = xmm2; |
| 2466 | const XMMRegister double_exponent = xmm1; |
| 2467 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2468 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2469 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2470 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2471 | // Save 1 in double_result - we need this several times later on. |
| 2472 | __ mov(scratch, Immediate(1)); |
| 2473 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2474 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2475 | if (exponent_type_ == ON_STACK) { |
| 2476 | Label base_is_smi, unpack_exponent; |
| 2477 | // The exponent and base are supplied as arguments on the stack. |
| 2478 | // This can only happen if the stub is called from non-optimized code. |
| 2479 | // Load input parameters from stack. |
| 2480 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 2481 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 2482 | |
| 2483 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2484 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 2485 | factory->heap_number_map()); |
| 2486 | __ j(not_equal, &call_runtime); |
| 2487 | |
| 2488 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2489 | __ jmp(&unpack_exponent, Label::kNear); |
| 2490 | |
| 2491 | __ bind(&base_is_smi); |
| 2492 | __ SmiUntag(base); |
| 2493 | __ cvtsi2sd(double_base, base); |
| 2494 | |
| 2495 | __ bind(&unpack_exponent); |
| 2496 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2497 | __ SmiUntag(exponent); |
| 2498 | __ jmp(&int_exponent); |
| 2499 | |
| 2500 | __ bind(&exponent_not_smi); |
| 2501 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2502 | factory->heap_number_map()); |
| 2503 | __ j(not_equal, &call_runtime); |
| 2504 | __ movdbl(double_exponent, |
| 2505 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2506 | } else if (exponent_type_ == TAGGED) { |
| 2507 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2508 | __ SmiUntag(exponent); |
| 2509 | __ jmp(&int_exponent); |
| 2510 | |
| 2511 | __ bind(&exponent_not_smi); |
| 2512 | __ movdbl(double_exponent, |
| 2513 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2514 | } |
| 2515 | |
| 2516 | if (exponent_type_ != INTEGER) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame^] | 2517 | Label fast_power, try_arithmetic_simplification; |
| 2518 | __ DoubleToI(exponent, double_exponent, double_scratch, |
| 2519 | TREAT_MINUS_ZERO_AS_ZERO, &try_arithmetic_simplification); |
| 2520 | __ jmp(&int_exponent); |
| 2521 | |
| 2522 | __ bind(&try_arithmetic_simplification); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2523 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame^] | 2524 | __ cvttsd2si(exponent, Operand(double_exponent)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2525 | __ cmp(exponent, Immediate(0x80000000u)); |
| 2526 | __ j(equal, &call_runtime); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2527 | |
| 2528 | if (exponent_type_ == ON_STACK) { |
| 2529 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 2530 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 2531 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 2532 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 2533 | // Test for 0.5. |
| 2534 | // Load double_scratch with 0.5. |
| 2535 | __ mov(scratch, Immediate(0x3F000000u)); |
| 2536 | __ movd(double_scratch, scratch); |
| 2537 | __ cvtss2sd(double_scratch, double_scratch); |
| 2538 | // Already ruled out NaNs for exponent. |
| 2539 | __ ucomisd(double_scratch, double_exponent); |
| 2540 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 2541 | |
| 2542 | // Calculates square root of base. Check for the special case of |
| 2543 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 2544 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2545 | // 9 bits set and the lowest 23 bits cleared. |
| 2546 | __ mov(scratch, 0xFF800000u); |
| 2547 | __ movd(double_scratch, scratch); |
| 2548 | __ cvtss2sd(double_scratch, double_scratch); |
| 2549 | __ ucomisd(double_base, double_scratch); |
| 2550 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2551 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2552 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 2553 | __ j(carry, &continue_sqrt, Label::kNear); |
| 2554 | |
| 2555 | // Set result to Infinity in the special case. |
| 2556 | __ xorps(double_result, double_result); |
| 2557 | __ subsd(double_result, double_scratch); |
| 2558 | __ jmp(&done); |
| 2559 | |
| 2560 | __ bind(&continue_sqrt); |
| 2561 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2562 | __ xorps(double_scratch, double_scratch); |
| 2563 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 2564 | __ sqrtsd(double_result, double_scratch); |
| 2565 | __ jmp(&done); |
| 2566 | |
| 2567 | // Test for -0.5. |
| 2568 | __ bind(¬_plus_half); |
| 2569 | // Load double_exponent with -0.5 by substracting 1. |
| 2570 | __ subsd(double_scratch, double_result); |
| 2571 | // Already ruled out NaNs for exponent. |
| 2572 | __ ucomisd(double_scratch, double_exponent); |
| 2573 | __ j(not_equal, &fast_power, Label::kNear); |
| 2574 | |
| 2575 | // Calculates reciprocal of square root of base. Check for the special |
| 2576 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 2577 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2578 | // 9 bits set and the lowest 23 bits cleared. |
| 2579 | __ mov(scratch, 0xFF800000u); |
| 2580 | __ movd(double_scratch, scratch); |
| 2581 | __ cvtss2sd(double_scratch, double_scratch); |
| 2582 | __ ucomisd(double_base, double_scratch); |
| 2583 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2584 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2585 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 2586 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 2587 | |
| 2588 | // Set result to 0 in the special case. |
| 2589 | __ xorps(double_result, double_result); |
| 2590 | __ jmp(&done); |
| 2591 | |
| 2592 | __ bind(&continue_rsqrt); |
| 2593 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2594 | __ xorps(double_exponent, double_exponent); |
| 2595 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 2596 | __ sqrtsd(double_exponent, double_exponent); |
| 2597 | __ divsd(double_result, double_exponent); |
| 2598 | __ jmp(&done); |
| 2599 | } |
| 2600 | |
| 2601 | // Using FPU instructions to calculate power. |
| 2602 | Label fast_power_failed; |
| 2603 | __ bind(&fast_power); |
| 2604 | __ fnclex(); // Clear flags to catch exceptions later. |
| 2605 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 2606 | __ sub(esp, Immediate(kDoubleSize)); |
| 2607 | __ movdbl(Operand(esp, 0), double_exponent); |
| 2608 | __ fld_d(Operand(esp, 0)); // E |
| 2609 | __ movdbl(Operand(esp, 0), double_base); |
| 2610 | __ fld_d(Operand(esp, 0)); // B, E |
| 2611 | |
| 2612 | // Exponent is in st(1) and base is in st(0) |
| 2613 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 2614 | // FYL2X calculates st(1) * log2(st(0)) |
| 2615 | __ fyl2x(); // X |
| 2616 | __ fld(0); // X, X |
| 2617 | __ frndint(); // rnd(X), X |
| 2618 | __ fsub(1); // rnd(X), X-rnd(X) |
| 2619 | __ fxch(1); // X - rnd(X), rnd(X) |
| 2620 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 2621 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 2622 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2623 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2624 | // FSCALE calculates st(0) * 2^st(1) |
| 2625 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2626 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2627 | // Bail out to runtime in case of exceptions in the status word. |
| 2628 | __ fnstsw_ax(); |
| 2629 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 2630 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 2631 | __ fstp_d(Operand(esp, 0)); |
| 2632 | __ movdbl(double_result, Operand(esp, 0)); |
| 2633 | __ add(esp, Immediate(kDoubleSize)); |
| 2634 | __ jmp(&done); |
| 2635 | |
| 2636 | __ bind(&fast_power_failed); |
| 2637 | __ fninit(); |
| 2638 | __ add(esp, Immediate(kDoubleSize)); |
| 2639 | __ jmp(&call_runtime); |
| 2640 | } |
| 2641 | |
| 2642 | // Calculate power with integer exponent. |
| 2643 | __ bind(&int_exponent); |
| 2644 | const XMMRegister double_scratch2 = double_exponent; |
| 2645 | __ mov(scratch, exponent); // Back up exponent. |
| 2646 | __ movsd(double_scratch, double_base); // Back up base. |
| 2647 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2648 | |
| 2649 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2650 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2651 | __ test(scratch, scratch); |
| 2652 | __ j(positive, &no_neg, Label::kNear); |
| 2653 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2654 | __ bind(&no_neg); |
| 2655 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2656 | __ j(zero, &while_false, Label::kNear); |
| 2657 | __ shr(scratch, 1); |
| 2658 | // Above condition means CF==0 && ZF==0. This means that the |
| 2659 | // bit that has been shifted out is 0 and the result is not 0. |
| 2660 | __ j(above, &while_true, Label::kNear); |
| 2661 | __ movsd(double_result, double_scratch); |
| 2662 | __ j(zero, &while_false, Label::kNear); |
| 2663 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2664 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2665 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2666 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2667 | __ j(above, &while_true, Label::kNear); |
| 2668 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2669 | __ j(not_zero, &while_true); |
| 2670 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2671 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2672 | // scratch has the original value of the exponent - if the exponent is |
| 2673 | // negative, return 1/result. |
| 2674 | __ test(exponent, exponent); |
| 2675 | __ j(positive, &done); |
| 2676 | __ divsd(double_scratch2, double_result); |
| 2677 | __ movsd(double_result, double_scratch2); |
| 2678 | // Test whether result is zero. Bail out to check for subnormal result. |
| 2679 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 2680 | __ xorps(double_scratch2, double_scratch2); |
| 2681 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 2682 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 2683 | // and may not have contained the exponent value in the first place when the |
| 2684 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 2685 | __ j(not_equal, &done); |
| 2686 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2687 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2688 | // Returning or bailing out. |
| 2689 | Counters* counters = masm->isolate()->counters(); |
| 2690 | if (exponent_type_ == ON_STACK) { |
| 2691 | // The arguments are still on the stack. |
| 2692 | __ bind(&call_runtime); |
| 2693 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2694 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2695 | // The stub is called from non-optimized code, which expects the result |
| 2696 | // as heap number in exponent. |
| 2697 | __ bind(&done); |
| 2698 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 2699 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 2700 | __ IncrementCounter(counters->math_pow(), 1); |
| 2701 | __ ret(2 * kPointerSize); |
| 2702 | } else { |
| 2703 | __ bind(&call_runtime); |
| 2704 | { |
| 2705 | AllowExternalCallThatCantCauseGC scope(masm); |
| 2706 | __ PrepareCallCFunction(4, scratch); |
| 2707 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 2708 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 2709 | __ CallCFunction( |
| 2710 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 2711 | } |
| 2712 | // Return value is in st(0) on ia32. |
| 2713 | // Store it into the (fixed) result register. |
| 2714 | __ sub(esp, Immediate(kDoubleSize)); |
| 2715 | __ fstp_d(Operand(esp, 0)); |
| 2716 | __ movdbl(double_result, Operand(esp, 0)); |
| 2717 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2718 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2719 | __ bind(&done); |
| 2720 | __ IncrementCounter(counters->math_pow(), 1); |
| 2721 | __ ret(0); |
| 2722 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2726 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 2727 | // ----------- S t a t e ------------- |
| 2728 | // -- ecx : name |
| 2729 | // -- edx : receiver |
| 2730 | // -- esp[0] : return address |
| 2731 | // ----------------------------------- |
| 2732 | Label miss; |
| 2733 | |
| 2734 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2735 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2736 | __ j(not_equal, &miss); |
| 2737 | } |
| 2738 | |
| 2739 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 2740 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2741 | StubCompiler::TailCallBuiltin( |
| 2742 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | |
| 2746 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 2747 | // ----------- S t a t e ------------- |
| 2748 | // -- ecx : name |
| 2749 | // -- edx : receiver |
| 2750 | // -- esp[0] : return address |
| 2751 | // ----------------------------------- |
| 2752 | Label miss; |
| 2753 | |
| 2754 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2755 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2756 | __ j(not_equal, &miss); |
| 2757 | } |
| 2758 | |
| 2759 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 2760 | support_wrapper_); |
| 2761 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2762 | StubCompiler::TailCallBuiltin( |
| 2763 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2764 | } |
| 2765 | |
| 2766 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2767 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 2768 | // ----------- S t a t e ------------- |
| 2769 | // -- eax : value |
| 2770 | // -- ecx : name |
| 2771 | // -- edx : receiver |
| 2772 | // -- esp[0] : return address |
| 2773 | // ----------------------------------- |
| 2774 | // |
| 2775 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 2776 | // (currently anything except for external arrays which means anything with |
| 2777 | // elements of FixedArray type). Value must be a number, but only smis are |
| 2778 | // accepted as the most common case. |
| 2779 | |
| 2780 | Label miss; |
| 2781 | |
| 2782 | Register receiver = edx; |
| 2783 | Register value = eax; |
| 2784 | Register scratch = ebx; |
| 2785 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2786 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2787 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2788 | __ j(not_equal, &miss); |
| 2789 | } |
| 2790 | |
| 2791 | // Check that the receiver isn't a smi. |
| 2792 | __ JumpIfSmi(receiver, &miss); |
| 2793 | |
| 2794 | // Check that the object is a JS array. |
| 2795 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 2796 | __ j(not_equal, &miss); |
| 2797 | |
| 2798 | // Check that elements are FixedArray. |
| 2799 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 2800 | // fast elements (including COW). |
| 2801 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 2802 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 2803 | __ j(not_equal, &miss); |
| 2804 | |
| 2805 | // Check that the array has fast properties, otherwise the length |
| 2806 | // property might have been redefined. |
| 2807 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 2808 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 2809 | Heap::kHashTableMapRootIndex); |
| 2810 | __ j(equal, &miss); |
| 2811 | |
| 2812 | // Check that value is a smi. |
| 2813 | __ JumpIfNotSmi(value, &miss); |
| 2814 | |
| 2815 | // Prepare tail call to StoreIC_ArrayLength. |
| 2816 | __ pop(scratch); |
| 2817 | __ push(receiver); |
| 2818 | __ push(value); |
| 2819 | __ push(scratch); // return address |
| 2820 | |
| 2821 | ExternalReference ref = |
| 2822 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 2823 | __ TailCallExternalReference(ref, 2, 1); |
| 2824 | |
| 2825 | __ bind(&miss); |
| 2826 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2827 | StubCompiler::TailCallBuiltin( |
| 2828 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2829 | } |
| 2830 | |
| 2831 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2832 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 2833 | // The key is in edx and the parameter count is in eax. |
| 2834 | |
| 2835 | // The displacement is used for skipping the frame pointer on the |
| 2836 | // stack. It is the offset of the last parameter (if any) relative |
| 2837 | // to the frame pointer. |
| 2838 | static const int kDisplacement = 1 * kPointerSize; |
| 2839 | |
| 2840 | // Check that the key is a smi. |
| 2841 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2842 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2843 | |
| 2844 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2845 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2846 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2847 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2848 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2849 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2850 | |
| 2851 | // Check index against formal parameters count limit passed in |
| 2852 | // through register eax. Use unsigned comparison to get negative |
| 2853 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2854 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2855 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2856 | |
| 2857 | // Read the argument from the stack and return it. |
| 2858 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2859 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 2860 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 2861 | __ neg(edx); |
| 2862 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 2863 | __ ret(0); |
| 2864 | |
| 2865 | // Arguments adaptor case: Check index against actual arguments |
| 2866 | // limit found in the arguments adaptor frame. Use unsigned |
| 2867 | // comparison to get negative check for free. |
| 2868 | __ bind(&adaptor); |
| 2869 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2870 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2871 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2872 | |
| 2873 | // Read the argument from the stack and return it. |
| 2874 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2875 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 2876 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 2877 | __ neg(edx); |
| 2878 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 2879 | __ ret(0); |
| 2880 | |
| 2881 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 2882 | // by calling the runtime system. |
| 2883 | __ bind(&slow); |
| 2884 | __ pop(ebx); // Return address. |
| 2885 | __ push(edx); |
| 2886 | __ push(ebx); |
| 2887 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 2888 | } |
| 2889 | |
| 2890 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2891 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2892 | // esp[0] : return address |
| 2893 | // esp[4] : number of parameters |
| 2894 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2895 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2896 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2897 | // Check if the calling frame is an arguments adaptor frame. |
| 2898 | Label runtime; |
| 2899 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2900 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2901 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2902 | __ j(not_equal, &runtime, Label::kNear); |
| 2903 | |
| 2904 | // Patch the arguments.length and the parameters pointer. |
| 2905 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2906 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 2907 | __ lea(edx, Operand(edx, ecx, times_2, |
| 2908 | StandardFrameConstants::kCallerSPOffset)); |
| 2909 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 2910 | |
| 2911 | __ bind(&runtime); |
| 2912 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 2913 | } |
| 2914 | |
| 2915 | |
| 2916 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2917 | Isolate* isolate = masm->isolate(); |
| 2918 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2919 | // esp[0] : return address |
| 2920 | // esp[4] : number of parameters (tagged) |
| 2921 | // esp[8] : receiver displacement |
| 2922 | // esp[12] : function |
| 2923 | |
| 2924 | // ebx = parameter count (tagged) |
| 2925 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 2926 | |
| 2927 | // Check if the calling frame is an arguments adaptor frame. |
| 2928 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 2929 | // Generate* functions. |
| 2930 | Label runtime; |
| 2931 | Label adaptor_frame, try_allocate; |
| 2932 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2933 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2934 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2935 | __ j(equal, &adaptor_frame, Label::kNear); |
| 2936 | |
| 2937 | // No adaptor, parameter count = argument count. |
| 2938 | __ mov(ecx, ebx); |
| 2939 | __ jmp(&try_allocate, Label::kNear); |
| 2940 | |
| 2941 | // We have an adaptor frame. Patch the parameters pointer. |
| 2942 | __ bind(&adaptor_frame); |
| 2943 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2944 | __ lea(edx, Operand(edx, ecx, times_2, |
| 2945 | StandardFrameConstants::kCallerSPOffset)); |
| 2946 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 2947 | |
| 2948 | // ebx = parameter count (tagged) |
| 2949 | // ecx = argument count (tagged) |
| 2950 | // esp[4] = parameter count (tagged) |
| 2951 | // esp[8] = address of receiver argument |
| 2952 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2953 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2954 | __ j(less_equal, &try_allocate, Label::kNear); |
| 2955 | __ mov(ebx, ecx); |
| 2956 | |
| 2957 | __ bind(&try_allocate); |
| 2958 | |
| 2959 | // Save mapped parameter count. |
| 2960 | __ push(ebx); |
| 2961 | |
| 2962 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 2963 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 2964 | const int kParameterMapHeaderSize = |
| 2965 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 2966 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2967 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2968 | __ j(zero, &no_parameter_map, Label::kNear); |
| 2969 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 2970 | __ bind(&no_parameter_map); |
| 2971 | |
| 2972 | // 2. Backing store. |
| 2973 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 2974 | |
| 2975 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2976 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2977 | |
| 2978 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2979 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2980 | |
| 2981 | // eax = address of new object(s) (tagged) |
| 2982 | // ecx = argument count (tagged) |
| 2983 | // esp[0] = mapped parameter count (tagged) |
| 2984 | // esp[8] = parameter count (tagged) |
| 2985 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2986 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2987 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2988 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2989 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2990 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2991 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2992 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 2993 | __ mov(edi, Operand(edi, |
| 2994 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 2995 | __ jmp(©, Label::kNear); |
| 2996 | |
| 2997 | __ bind(&has_mapped_parameters); |
| 2998 | __ mov(edi, Operand(edi, |
| 2999 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3000 | __ bind(©); |
| 3001 | |
| 3002 | // eax = address of new object (tagged) |
| 3003 | // ebx = mapped parameter count (tagged) |
| 3004 | // ecx = argument count (tagged) |
| 3005 | // edi = address of boilerplate object (tagged) |
| 3006 | // esp[0] = mapped parameter count (tagged) |
| 3007 | // esp[8] = parameter count (tagged) |
| 3008 | // esp[12] = address of receiver argument |
| 3009 | // Copy the JS object part. |
| 3010 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3011 | __ mov(edx, FieldOperand(edi, i)); |
| 3012 | __ mov(FieldOperand(eax, i), edx); |
| 3013 | } |
| 3014 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3015 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3016 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3017 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3018 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3019 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3020 | edx); |
| 3021 | |
| 3022 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3023 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3024 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3025 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3026 | ecx); |
| 3027 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3028 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3029 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3030 | // backing store. |
| 3031 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3032 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3033 | |
| 3034 | // eax = address of new object (tagged) |
| 3035 | // ebx = mapped parameter count (tagged) |
| 3036 | // ecx = argument count (tagged) |
| 3037 | // edi = address of parameter map or backing store (tagged) |
| 3038 | // esp[0] = mapped parameter count (tagged) |
| 3039 | // esp[8] = parameter count (tagged) |
| 3040 | // esp[12] = address of receiver argument |
| 3041 | // Free a register. |
| 3042 | __ push(eax); |
| 3043 | |
| 3044 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3045 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3046 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3047 | __ j(zero, &skip_parameter_map); |
| 3048 | |
| 3049 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3050 | Immediate(isolate->factory()->non_strict_arguments_elements_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3051 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3052 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3053 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3054 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3055 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3056 | |
| 3057 | // Copy the parameter slots and the holes in the arguments. |
| 3058 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3059 | // where parameters are stored in reverse order, at |
| 3060 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3061 | // The mapped parameter thus need to get indices |
| 3062 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3063 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3064 | // We loop from right to left. |
| 3065 | Label parameters_loop, parameters_test; |
| 3066 | __ push(ecx); |
| 3067 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3068 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3069 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3070 | __ sub(ebx, eax); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3071 | __ mov(ecx, isolate->factory()->the_hole_value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3072 | __ mov(edx, edi); |
| 3073 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3074 | // eax = loop variable (tagged) |
| 3075 | // ebx = mapping index (tagged) |
| 3076 | // ecx = the hole value |
| 3077 | // edx = address of parameter map (tagged) |
| 3078 | // edi = address of backing store (tagged) |
| 3079 | // esp[0] = argument count (tagged) |
| 3080 | // esp[4] = address of new object (tagged) |
| 3081 | // esp[8] = mapped parameter count (tagged) |
| 3082 | // esp[16] = parameter count (tagged) |
| 3083 | // esp[20] = address of receiver argument |
| 3084 | __ jmp(¶meters_test, Label::kNear); |
| 3085 | |
| 3086 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3087 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3088 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3089 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3090 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3091 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3092 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3093 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3094 | __ pop(ecx); |
| 3095 | |
| 3096 | __ bind(&skip_parameter_map); |
| 3097 | |
| 3098 | // ecx = argument count (tagged) |
| 3099 | // edi = address of backing store (tagged) |
| 3100 | // esp[0] = address of new object (tagged) |
| 3101 | // esp[4] = mapped parameter count (tagged) |
| 3102 | // esp[12] = parameter count (tagged) |
| 3103 | // esp[16] = address of receiver argument |
| 3104 | // Copy arguments header and remaining slots (if there are any). |
| 3105 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3106 | Immediate(isolate->factory()->fixed_array_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3107 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3108 | |
| 3109 | Label arguments_loop, arguments_test; |
| 3110 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3111 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3112 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3113 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3114 | __ jmp(&arguments_test, Label::kNear); |
| 3115 | |
| 3116 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3117 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3118 | __ mov(eax, Operand(edx, 0)); |
| 3119 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3120 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3121 | |
| 3122 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3123 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3124 | __ j(less, &arguments_loop, Label::kNear); |
| 3125 | |
| 3126 | // Restore. |
| 3127 | __ pop(eax); // Address of arguments object. |
| 3128 | __ pop(ebx); // Parameter count. |
| 3129 | |
| 3130 | // Return and remove the on-stack parameters. |
| 3131 | __ ret(3 * kPointerSize); |
| 3132 | |
| 3133 | // Do the runtime call to allocate the arguments object. |
| 3134 | __ bind(&runtime); |
| 3135 | __ pop(eax); // Remove saved parameter count. |
| 3136 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3137 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | |
| 3141 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3142 | Isolate* isolate = masm->isolate(); |
| 3143 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3144 | // esp[0] : return address |
| 3145 | // esp[4] : number of parameters |
| 3146 | // esp[8] : receiver displacement |
| 3147 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3148 | |
| 3149 | // Check if the calling frame is an arguments adaptor frame. |
| 3150 | Label adaptor_frame, try_allocate, runtime; |
| 3151 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3152 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3153 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3154 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3155 | |
| 3156 | // Get the length from the frame. |
| 3157 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3158 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3159 | |
| 3160 | // Patch the arguments.length and the parameters pointer. |
| 3161 | __ bind(&adaptor_frame); |
| 3162 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3163 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3164 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3165 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3166 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3167 | |
| 3168 | // Try the new space allocation. Start out with computing the size of |
| 3169 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3170 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3171 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3172 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3173 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3174 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3175 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3176 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3177 | |
| 3178 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3179 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3180 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3181 | // Get the arguments boilerplate from the current native context. |
| 3182 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3183 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3184 | const int offset = |
| 3185 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3186 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3187 | |
| 3188 | // Copy the JS object part. |
| 3189 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3190 | __ mov(ebx, FieldOperand(edi, i)); |
| 3191 | __ mov(FieldOperand(eax, i), ebx); |
| 3192 | } |
| 3193 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3194 | // 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] | 3195 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3196 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3197 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3198 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3199 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3200 | |
| 3201 | // If there are no actual arguments, we're done. |
| 3202 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3203 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3204 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3205 | |
| 3206 | // Get the parameters pointer from the stack. |
| 3207 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3208 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3209 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3210 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3211 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3212 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3213 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3214 | Immediate(isolate->factory()->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3215 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3216 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3217 | // Untag the length for the loop below. |
| 3218 | __ SmiUntag(ecx); |
| 3219 | |
| 3220 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3221 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3222 | __ bind(&loop); |
| 3223 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3224 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3225 | __ add(edi, Immediate(kPointerSize)); |
| 3226 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3227 | __ dec(ecx); |
| 3228 | __ j(not_zero, &loop); |
| 3229 | |
| 3230 | // Return and remove the on-stack parameters. |
| 3231 | __ bind(&done); |
| 3232 | __ ret(3 * kPointerSize); |
| 3233 | |
| 3234 | // Do the runtime call to allocate the arguments object. |
| 3235 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3236 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | |
| 3240 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3241 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3242 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3243 | // at compilation. |
| 3244 | #ifdef V8_INTERPRETED_REGEXP |
| 3245 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3246 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3247 | |
| 3248 | // Stack frame on entry. |
| 3249 | // esp[0]: return address |
| 3250 | // esp[4]: last_match_info (expected JSArray) |
| 3251 | // esp[8]: previous index |
| 3252 | // esp[12]: subject string |
| 3253 | // esp[16]: JSRegExp object |
| 3254 | |
| 3255 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3256 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3257 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3258 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3259 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3260 | Label runtime; |
| 3261 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3262 | |
| 3263 | // Ensure that a RegExp stack is allocated. |
| 3264 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3265 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3266 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3267 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3268 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3269 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3270 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3271 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3272 | |
| 3273 | // Check that the first argument is a JSRegExp object. |
| 3274 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3275 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3276 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3277 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3278 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3279 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3280 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3281 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3282 | if (FLAG_debug_code) { |
| 3283 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3284 | __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3285 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3286 | __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3287 | } |
| 3288 | |
| 3289 | // ecx: RegExp data (FixedArray) |
| 3290 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3291 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3292 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3293 | __ j(not_equal, &runtime); |
| 3294 | |
| 3295 | // ecx: RegExp data (FixedArray) |
| 3296 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3297 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3298 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3299 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3300 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3301 | STATIC_ASSERT(kSmiTag == 0); |
| 3302 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3303 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3304 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3305 | __ j(above, &runtime); |
| 3306 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3307 | // Reset offset for possibly sliced string. |
| 3308 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3309 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3310 | __ JumpIfSmi(eax, &runtime); |
| 3311 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3312 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3313 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3314 | |
| 3315 | // eax: subject string |
| 3316 | // edx: subject string |
| 3317 | // ebx: subject string instance type |
| 3318 | // ecx: RegExp data (FixedArray) |
| 3319 | // Handle subject string according to its encoding and representation: |
| 3320 | // (1) Sequential two byte? If yes, go to (9). |
| 3321 | // (2) Sequential one byte? If yes, go to (6). |
| 3322 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3323 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3324 | // Otherwise bailout. |
| 3325 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3326 | // (5b) Is subject external? If yes, go to (8). |
| 3327 | // (6) One byte sequential. Load regexp code for one byte. |
| 3328 | // (E) Carry on. |
| 3329 | /// [...] |
| 3330 | |
| 3331 | // Deferred code at the end of the stub: |
| 3332 | // (7) Not a long external string? If yes, go to (10). |
| 3333 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3334 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3335 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3336 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3337 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3338 | |
| 3339 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3340 | external_string /* 8 */, check_underlying /* 5a */, |
| 3341 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3342 | not_long_external /* 10 */; |
| 3343 | |
| 3344 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3345 | __ and_(ebx, kIsNotStringMask | |
| 3346 | kStringRepresentationMask | |
| 3347 | kStringEncodingMask | |
| 3348 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3349 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3350 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3351 | |
| 3352 | // (2) Sequential one byte? If yes, go to (6). |
| 3353 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3354 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3355 | kStringRepresentationMask | |
| 3356 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3357 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3358 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3359 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3360 | // We check whether the subject string is a cons, since sequential strings |
| 3361 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3362 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3363 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3364 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3365 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3366 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3367 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3368 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3369 | // (4) Cons string. Check that it's flat. |
| 3370 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3371 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3372 | __ j(not_equal, &runtime); |
| 3373 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3374 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3375 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3376 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3377 | |
| 3378 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3379 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3380 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3381 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3382 | // (5b) Is subject external? If yes, go to (8). |
| 3383 | __ test_b(ebx, kStringRepresentationMask); |
| 3384 | // The underlying external string is never a short external string. |
| 3385 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3386 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3387 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3388 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3389 | // eax: sequential subject string (or look-alike, external string) |
| 3390 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3391 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3392 | // (6) One byte sequential. Load regexp code for one byte. |
| 3393 | __ bind(&seq_one_byte_string); |
| 3394 | // Load previous index and check range before edx is overwritten. We have |
| 3395 | // to use edx instead of eax here because it might have been only made to |
| 3396 | // look like a sequential string when it actually is an external string. |
| 3397 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3398 | __ JumpIfNotSmi(ebx, &runtime); |
| 3399 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3400 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3401 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3402 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3403 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3404 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3405 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3406 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3407 | // Check that the irregexp code has been generated for the actual string |
| 3408 | // 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] | 3409 | // a smi (code flushing support). |
| 3410 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3411 | |
| 3412 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3413 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3414 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3415 | // 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] | 3416 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3417 | Counters* counters = masm->isolate()->counters(); |
| 3418 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3419 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3420 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3421 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3422 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3423 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3424 | // Argument 9: Pass current isolate address. |
| 3425 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3426 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3427 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3428 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3429 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3430 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3431 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3432 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3433 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3434 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3435 | |
| 3436 | // Argument 6: Set the number of capture registers to zero to force global |
| 3437 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3438 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3439 | |
| 3440 | // Argument 5: static offsets vector buffer. |
| 3441 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3442 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3443 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3444 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3445 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3446 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3447 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3448 | |
| 3449 | // Argument 1: Original subject string. |
| 3450 | // The original subject is in the previous stack frame. Therefore we have to |
| 3451 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3452 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3453 | // and thereby moves up esp by one kPointerSize.) |
| 3454 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3455 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3456 | |
| 3457 | // esi: original subject string |
| 3458 | // eax: underlying subject string |
| 3459 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3460 | // 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] | 3461 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3462 | // Argument 4: End of string data |
| 3463 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3464 | // Prepare start and end index of the input. |
| 3465 | // Load the length from the original sliced string if that is the case. |
| 3466 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3467 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3468 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3469 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3470 | |
| 3471 | // ebx: start index of the input string |
| 3472 | // esi: end index of the input string |
| 3473 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3474 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3475 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3476 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3477 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3478 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3479 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3480 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3481 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3482 | |
| 3483 | __ bind(&setup_two_byte); |
| 3484 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3485 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3486 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3487 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3488 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3489 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3490 | |
| 3491 | __ bind(&setup_rest); |
| 3492 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3493 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3494 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3495 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3496 | |
| 3497 | // Drop arguments and come back to JS mode. |
| 3498 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3499 | |
| 3500 | // Check the result. |
| 3501 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3502 | __ cmp(eax, 1); |
| 3503 | // We expect exactly one result since we force the called regexp to behave |
| 3504 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3505 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3506 | Label failure; |
| 3507 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3508 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3509 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3510 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3511 | __ j(not_equal, &runtime); |
| 3512 | // Result must now be exception. If there is no pending exception already a |
| 3513 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3514 | // haven't created the exception yet. Handle that in the runtime system. |
| 3515 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3516 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3517 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3518 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3519 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3520 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3521 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3522 | // For exception, throw the exception again. |
| 3523 | |
| 3524 | // Clear the pending exception variable. |
| 3525 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3526 | |
| 3527 | // Special handling of termination exceptions which are uncatchable |
| 3528 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3529 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3530 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3531 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3532 | |
| 3533 | // Handle normal exception by following handler chain. |
| 3534 | __ Throw(eax); |
| 3535 | |
| 3536 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3537 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3538 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3539 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3540 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3541 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3542 | __ ret(4 * kPointerSize); |
| 3543 | |
| 3544 | // Load RegExp data. |
| 3545 | __ bind(&success); |
| 3546 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3547 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3548 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3549 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3550 | STATIC_ASSERT(kSmiTag == 0); |
| 3551 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3552 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3553 | |
| 3554 | // edx: Number of capture registers |
| 3555 | // 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] | 3556 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3557 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3558 | __ JumpIfSmi(eax, &runtime); |
| 3559 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3560 | __ j(not_equal, &runtime); |
| 3561 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3562 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3563 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 3564 | __ cmp(eax, factory->fixed_array_map()); |
| 3565 | __ j(not_equal, &runtime); |
| 3566 | // Check that the last match info has space for the capture registers and the |
| 3567 | // additional information. |
| 3568 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3569 | __ SmiUntag(eax); |
| 3570 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3571 | __ cmp(edx, eax); |
| 3572 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3573 | |
| 3574 | // ebx: last_match_info backing store (FixedArray) |
| 3575 | // edx: number of capture registers |
| 3576 | // Store the capture count. |
| 3577 | __ SmiTag(edx); // Number of capture registers to smi. |
| 3578 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 3579 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 3580 | // Store last subject and last input. |
| 3581 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3582 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3583 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3584 | __ RecordWriteField(ebx, |
| 3585 | RegExpImpl::kLastSubjectOffset, |
| 3586 | eax, |
| 3587 | edi, |
| 3588 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3589 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3590 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3591 | __ RecordWriteField(ebx, |
| 3592 | RegExpImpl::kLastInputOffset, |
| 3593 | eax, |
| 3594 | edi, |
| 3595 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3596 | |
| 3597 | // Get the static offsets vector filled by the native regexp code. |
| 3598 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3599 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3600 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 3601 | |
| 3602 | // ebx: last_match_info backing store (FixedArray) |
| 3603 | // ecx: offsets vector |
| 3604 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3605 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3606 | // Capture register counter starts from number of capture registers and |
| 3607 | // counts down until wraping after zero. |
| 3608 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3609 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3610 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3611 | // Read the value from the static offsets vector buffer. |
| 3612 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 3613 | __ SmiTag(edi); |
| 3614 | // Store the smi value in the last match info. |
| 3615 | __ mov(FieldOperand(ebx, |
| 3616 | edx, |
| 3617 | times_pointer_size, |
| 3618 | RegExpImpl::kFirstCaptureOffset), |
| 3619 | edi); |
| 3620 | __ jmp(&next_capture); |
| 3621 | __ bind(&done); |
| 3622 | |
| 3623 | // Return last match info. |
| 3624 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 3625 | __ ret(4 * kPointerSize); |
| 3626 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3627 | // Do the runtime call to execute the regexp. |
| 3628 | __ bind(&runtime); |
| 3629 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3630 | |
| 3631 | // Deferred code for string handling. |
| 3632 | // (7) Not a long external string? If yes, go to (10). |
| 3633 | __ bind(¬_seq_nor_cons); |
| 3634 | // Compare flags are still set from (3). |
| 3635 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 3636 | |
| 3637 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3638 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3639 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3640 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3641 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3642 | if (FLAG_debug_code) { |
| 3643 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 3644 | // Sequential strings have already been ruled out. |
| 3645 | __ test_b(ebx, kIsIndirectStringMask); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3646 | __ Assert(zero, kExternalStringExpectedButNotFound); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3647 | } |
| 3648 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 3649 | // 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] | 3650 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3651 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3652 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3653 | // (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] | 3654 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3655 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3656 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3657 | // eax: sequential subject string (or look-alike, external string) |
| 3658 | // edx: original subject string |
| 3659 | // ecx: RegExp data (FixedArray) |
| 3660 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3661 | __ bind(&seq_two_byte_string); |
| 3662 | // Load previous index and check range before edx is overwritten. We have |
| 3663 | // to use edx instead of eax here because it might have been only made to |
| 3664 | // look like a sequential string when it actually is an external string. |
| 3665 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3666 | __ JumpIfNotSmi(ebx, &runtime); |
| 3667 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3668 | __ j(above_equal, &runtime); |
| 3669 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 3670 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 3671 | __ jmp(&check_code); // Go to (E). |
| 3672 | |
| 3673 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 3674 | __ bind(¬_long_external); |
| 3675 | // Catch non-string subject or short external string. |
| 3676 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3677 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 3678 | __ j(not_zero, &runtime); |
| 3679 | |
| 3680 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3681 | // Load offset into edi and replace subject string with parent. |
| 3682 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3683 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3684 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3685 | #endif // V8_INTERPRETED_REGEXP |
| 3686 | } |
| 3687 | |
| 3688 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3689 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 3690 | const int kMaxInlineLength = 100; |
| 3691 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3692 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3693 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3694 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3695 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3696 | __ j(above, &slowcase); |
| 3697 | // Smi-tagging is equivalent to multiplying by 2. |
| 3698 | STATIC_ASSERT(kSmiTag == 0); |
| 3699 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3700 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 3701 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 3702 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3703 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 3704 | times_pointer_size, |
| 3705 | ebx, // In: Number of elements as a smi |
| 3706 | REGISTER_VALUE_IS_SMI, |
| 3707 | eax, // Out: Start of allocation (tagged). |
| 3708 | ecx, // Out: End of allocation. |
| 3709 | edx, // Scratch register |
| 3710 | &slowcase, |
| 3711 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3712 | // eax: Start of allocated area, object-tagged. |
| 3713 | |
| 3714 | // Set JSArray map to global.regexp_result_map(). |
| 3715 | // Set empty properties FixedArray. |
| 3716 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 3717 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3718 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3719 | Factory* factory = masm->isolate()->factory(); |
| 3720 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3721 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3722 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3723 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 3724 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 3725 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 3726 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 3727 | |
| 3728 | // Set input, index and length fields from arguments. |
| 3729 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 3730 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 3731 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 3732 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 3733 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 3734 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 3735 | |
| 3736 | // Fill out the elements FixedArray. |
| 3737 | // eax: JSArray. |
| 3738 | // ebx: FixedArray. |
| 3739 | // ecx: Number of elements in array, as smi. |
| 3740 | |
| 3741 | // Set map. |
| 3742 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3743 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3744 | // Set length. |
| 3745 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3746 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3747 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3748 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3749 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3750 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3751 | // eax: JSArray. |
| 3752 | // ecx: Number of elements to fill. |
| 3753 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3754 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3755 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3756 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3757 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3758 | __ 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] | 3759 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3760 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 3761 | __ jmp(&loop); |
| 3762 | |
| 3763 | __ bind(&done); |
| 3764 | __ ret(3 * kPointerSize); |
| 3765 | |
| 3766 | __ bind(&slowcase); |
| 3767 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 3768 | } |
| 3769 | |
| 3770 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3771 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 3772 | Register object, |
| 3773 | Register result, |
| 3774 | Register scratch1, |
| 3775 | Register scratch2, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3776 | Label* not_found) { |
| 3777 | // Use of registers. Register result is used as a temporary. |
| 3778 | Register number_string_cache = result; |
| 3779 | Register mask = scratch1; |
| 3780 | Register scratch = scratch2; |
| 3781 | |
| 3782 | // Load the number string cache. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3783 | __ LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3784 | // Make the hash mask from the length of the number string cache. It |
| 3785 | // contains two elements (number and string) for each cache entry. |
| 3786 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 3787 | __ 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] | 3788 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3789 | |
| 3790 | // Calculate the entry in the number string cache. The hash value in the |
| 3791 | // number string cache for smis is just the smi value, and the hash for |
| 3792 | // doubles is the xor of the upper and lower words. See |
| 3793 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3794 | Label smi_hash_calculated; |
| 3795 | Label load_result_from_cache; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3796 | Label not_smi; |
| 3797 | STATIC_ASSERT(kSmiTag == 0); |
| 3798 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
| 3799 | __ mov(scratch, object); |
| 3800 | __ SmiUntag(scratch); |
| 3801 | __ jmp(&smi_hash_calculated, Label::kNear); |
| 3802 | __ bind(¬_smi); |
| 3803 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
| 3804 | masm->isolate()->factory()->heap_number_map()); |
| 3805 | __ j(not_equal, not_found); |
| 3806 | STATIC_ASSERT(8 == kDoubleSize); |
| 3807 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 3808 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 3809 | // Object is heap number and hash is now in scratch. Calculate cache index. |
| 3810 | __ and_(scratch, mask); |
| 3811 | Register index = scratch; |
| 3812 | Register probe = mask; |
| 3813 | __ mov(probe, |
| 3814 | FieldOperand(number_string_cache, |
| 3815 | index, |
| 3816 | times_twice_pointer_size, |
| 3817 | FixedArray::kHeaderSize)); |
| 3818 | __ JumpIfSmi(probe, not_found); |
| 3819 | if (CpuFeatures::IsSupported(SSE2)) { |
| 3820 | CpuFeatureScope fscope(masm, SSE2); |
| 3821 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 3822 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 3823 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3824 | } else { |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3825 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 3826 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 3827 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3828 | } |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3829 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 3830 | __ j(not_equal, not_found); // The cache did not contain this value. |
| 3831 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3832 | |
| 3833 | __ bind(&smi_hash_calculated); |
| 3834 | // 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] | 3835 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3836 | // Check if the entry is the smi we are looking for. |
| 3837 | __ cmp(object, |
| 3838 | FieldOperand(number_string_cache, |
| 3839 | index, |
| 3840 | times_twice_pointer_size, |
| 3841 | FixedArray::kHeaderSize)); |
| 3842 | __ j(not_equal, not_found); |
| 3843 | |
| 3844 | // Get the result from the cache. |
| 3845 | __ bind(&load_result_from_cache); |
| 3846 | __ mov(result, |
| 3847 | FieldOperand(number_string_cache, |
| 3848 | index, |
| 3849 | times_twice_pointer_size, |
| 3850 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3851 | Counters* counters = masm->isolate()->counters(); |
| 3852 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3853 | } |
| 3854 | |
| 3855 | |
| 3856 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 3857 | Label runtime; |
| 3858 | |
| 3859 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 3860 | |
| 3861 | // Generate code to lookup number in the number string cache. |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3862 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3863 | __ ret(1 * kPointerSize); |
| 3864 | |
| 3865 | __ bind(&runtime); |
| 3866 | // Handle number to string in the runtime system if not found in the cache. |
| 3867 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 3868 | } |
| 3869 | |
| 3870 | |
| 3871 | static int NegativeComparisonResult(Condition cc) { |
| 3872 | ASSERT(cc != equal); |
| 3873 | ASSERT((cc == less) || (cc == less_equal) |
| 3874 | || (cc == greater) || (cc == greater_equal)); |
| 3875 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 3876 | } |
| 3877 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3878 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3879 | static void CheckInputType(MacroAssembler* masm, |
| 3880 | Register input, |
| 3881 | CompareIC::State expected, |
| 3882 | Label* fail) { |
| 3883 | Label ok; |
| 3884 | if (expected == CompareIC::SMI) { |
| 3885 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3886 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3887 | __ JumpIfSmi(input, &ok); |
| 3888 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 3889 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 3890 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3891 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3892 | // 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] | 3893 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 3894 | __ bind(&ok); |
| 3895 | } |
| 3896 | |
| 3897 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3898 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 3899 | Label* label, |
| 3900 | Register object, |
| 3901 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3902 | __ JumpIfSmi(object, label); |
| 3903 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 3904 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3905 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 3906 | __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 3907 | __ j(not_zero, label); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | |
| 3911 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 3912 | Label check_unequal_objects; |
| 3913 | Condition cc = GetCondition(); |
| 3914 | |
| 3915 | Label miss; |
| 3916 | CheckInputType(masm, edx, left_, &miss); |
| 3917 | CheckInputType(masm, eax, right_, &miss); |
| 3918 | |
| 3919 | // Compare two smis. |
| 3920 | Label non_smi, smi_done; |
| 3921 | __ mov(ecx, edx); |
| 3922 | __ or_(ecx, eax); |
| 3923 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 3924 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 3925 | __ j(no_overflow, &smi_done, Label::kNear); |
| 3926 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 3927 | __ bind(&smi_done); |
| 3928 | __ mov(eax, edx); |
| 3929 | __ ret(0); |
| 3930 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3931 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3932 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 3933 | // it is certain that at least one operand isn't a smi. |
| 3934 | |
| 3935 | // Identical objects can be compared fast, but there are some tricky cases |
| 3936 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3937 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3938 | { |
| 3939 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3940 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3941 | __ j(not_equal, ¬_identical); |
| 3942 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3943 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3944 | // Check for undefined. undefined OP undefined is false even though |
| 3945 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3946 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3947 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3948 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3949 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3950 | __ ret(0); |
| 3951 | __ bind(&check_for_nan); |
| 3952 | } |
| 3953 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3954 | // Test for NaN. Compare heap numbers in a general way, |
| 3955 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3956 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 3957 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3958 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3959 | if (cc != equal) { |
| 3960 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 3961 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 3962 | __ j(above_equal, ¬_identical); |
| 3963 | } |
| 3964 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3965 | __ ret(0); |
| 3966 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3967 | |
| 3968 | __ bind(¬_identical); |
| 3969 | } |
| 3970 | |
| 3971 | // Strict equality can quickly decide whether objects are equal. |
| 3972 | // 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] | 3973 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3974 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3975 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3976 | // If we're doing a strict equality comparison, we don't have to do |
| 3977 | // type conversion, so we generate code to do fast comparison for objects |
| 3978 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 3979 | // slow-case code. |
| 3980 | // If either is a Smi (we know that not both are), then they can only |
| 3981 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 3982 | STATIC_ASSERT(kSmiTag == 0); |
| 3983 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 3984 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3985 | __ and_(ecx, eax); |
| 3986 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3987 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3988 | // One operand is a smi. |
| 3989 | |
| 3990 | // Check whether the non-smi is a heap number. |
| 3991 | STATIC_ASSERT(kSmiTagMask == 1); |
| 3992 | // 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] | 3993 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3994 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3995 | __ xor_(ebx, eax); |
| 3996 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 3997 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3998 | // if eax was smi, ebx is now edx, else eax. |
| 3999 | |
| 4000 | // Check if the non-smi operand is a heap number. |
| 4001 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4002 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4003 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4004 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4005 | // Return non-equal (ebx is not zero) |
| 4006 | __ mov(eax, ebx); |
| 4007 | __ ret(0); |
| 4008 | |
| 4009 | __ bind(¬_smis); |
| 4010 | // If either operand is a JSObject or an oddball value, then they are not |
| 4011 | // equal since their pointers are different |
| 4012 | // There is no test for undetectability in strict equality. |
| 4013 | |
| 4014 | // Get the type of the first operand. |
| 4015 | // 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] | 4016 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4017 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4018 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4019 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4020 | |
| 4021 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4022 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4023 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4024 | __ bind(&return_not_equal); |
| 4025 | __ ret(0); |
| 4026 | |
| 4027 | __ bind(&first_non_object); |
| 4028 | // Check for oddballs: true, false, null, undefined. |
| 4029 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4030 | __ j(equal, &return_not_equal); |
| 4031 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4032 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4033 | __ j(above_equal, &return_not_equal); |
| 4034 | |
| 4035 | // Check for oddballs: true, false, null, undefined. |
| 4036 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4037 | __ j(equal, &return_not_equal); |
| 4038 | |
| 4039 | // Fall through to the general case. |
| 4040 | __ bind(&slow); |
| 4041 | } |
| 4042 | |
| 4043 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4044 | Label non_number_comparison; |
| 4045 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4046 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4047 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4048 | CpuFeatureScope use_sse2(masm, SSE2); |
| 4049 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4050 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4051 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4052 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4053 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4054 | // Don't base result on EFLAGS when a NaN is involved. |
| 4055 | __ j(parity_even, &unordered, Label::kNear); |
| 4056 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4057 | __ mov(eax, 0); // equal |
| 4058 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4059 | __ cmov(above, eax, ecx); |
| 4060 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4061 | __ cmov(below, eax, ecx); |
| 4062 | __ ret(0); |
| 4063 | } else { |
| 4064 | FloatingPointHelper::CheckFloatOperands( |
| 4065 | masm, &non_number_comparison, ebx); |
| 4066 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4067 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4068 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4069 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4070 | // Don't base result on EFLAGS when a NaN is involved. |
| 4071 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4072 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4073 | Label below_label, above_label; |
| 4074 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4075 | __ j(below, &below_label, Label::kNear); |
| 4076 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4077 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4078 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4079 | __ ret(0); |
| 4080 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4081 | __ bind(&below_label); |
| 4082 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4083 | __ ret(0); |
| 4084 | |
| 4085 | __ bind(&above_label); |
| 4086 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4087 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4088 | } |
| 4089 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4090 | // If one of the numbers was NaN, then the result is always false. |
| 4091 | // The cc is never not-equal. |
| 4092 | __ bind(&unordered); |
| 4093 | ASSERT(cc != not_equal); |
| 4094 | if (cc == less || cc == less_equal) { |
| 4095 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4096 | } else { |
| 4097 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4098 | } |
| 4099 | __ ret(0); |
| 4100 | |
| 4101 | // The number comparison code did not provide a valid result. |
| 4102 | __ bind(&non_number_comparison); |
| 4103 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4104 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4105 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4106 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4107 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 4108 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4109 | |
| 4110 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4111 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4112 | // non-zero value, which indicates not equal, so just return. |
| 4113 | __ ret(0); |
| 4114 | } |
| 4115 | |
| 4116 | __ bind(&check_for_strings); |
| 4117 | |
| 4118 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4119 | &check_unequal_objects); |
| 4120 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4121 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4122 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4123 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4124 | edx, |
| 4125 | eax, |
| 4126 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4127 | ebx); |
| 4128 | } else { |
| 4129 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4130 | edx, |
| 4131 | eax, |
| 4132 | ecx, |
| 4133 | ebx, |
| 4134 | edi); |
| 4135 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4136 | #ifdef DEBUG |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4137 | __ Abort(kUnexpectedFallThroughFromStringComparison); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4138 | #endif |
| 4139 | |
| 4140 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4141 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4142 | // Non-strict equality. Objects are unequal if |
| 4143 | // they are both JSObjects and not undetectable, |
| 4144 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4145 | Label not_both_objects; |
| 4146 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4147 | // At most one is a smi, so we can test for smi by adding the two. |
| 4148 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4149 | // a heap object has the low bit clear. |
| 4150 | STATIC_ASSERT(kSmiTag == 0); |
| 4151 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4152 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4153 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4154 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4155 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4156 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4157 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4158 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4159 | // We do not bail out after this point. Both are JSObjects, and |
| 4160 | // they are equal if and only if both are undetectable. |
| 4161 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4162 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4163 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4164 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4165 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4166 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4167 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4168 | // The objects are both undetectable, so they both compare as the value |
| 4169 | // undefined, and are equal. |
| 4170 | __ Set(eax, Immediate(EQUAL)); |
| 4171 | __ bind(&return_unequal); |
| 4172 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4173 | // or return equal if we fell through to here. |
| 4174 | __ ret(0); // rax, rdx were pushed |
| 4175 | __ bind(¬_both_objects); |
| 4176 | } |
| 4177 | |
| 4178 | // Push arguments below the return address. |
| 4179 | __ pop(ecx); |
| 4180 | __ push(edx); |
| 4181 | __ push(eax); |
| 4182 | |
| 4183 | // Figure out which native to call and setup the arguments. |
| 4184 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4185 | if (cc == equal) { |
| 4186 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4187 | } else { |
| 4188 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4189 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | // Restore return address on the stack. |
| 4193 | __ push(ecx); |
| 4194 | |
| 4195 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4196 | // tagged as a small integer. |
| 4197 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4198 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4199 | __ bind(&miss); |
| 4200 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4201 | } |
| 4202 | |
| 4203 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4204 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4205 | // Cache the called function in a global property cell. Cache states |
| 4206 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4207 | // megamorphic. |
| 4208 | // ebx : cache cell for call target |
| 4209 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4210 | Isolate* isolate = masm->isolate(); |
| 4211 | Label initialize, done, miss, megamorphic, not_array_function; |
| 4212 | |
| 4213 | // Load the cache state into ecx. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4214 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4215 | |
| 4216 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4217 | // function without changing the state. |
| 4218 | __ cmp(ecx, edi); |
| 4219 | __ j(equal, &done); |
| 4220 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4221 | __ j(equal, &done); |
| 4222 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4223 | // If we came here, we need to see if we are the array function. |
| 4224 | // If we didn't have a matching function, and we didn't find the megamorph |
| 4225 | // sentinel, then we have in the cell either some other function or an |
| 4226 | // AllocationSite. Do a map check on the object in ecx. |
| 4227 | Handle<Map> allocation_site_map( |
| 4228 | masm->isolate()->heap()->allocation_site_map(), |
| 4229 | masm->isolate()); |
| 4230 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 4231 | __ j(not_equal, &miss); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4232 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4233 | // Load the global or builtins object from the current context |
| 4234 | __ LoadGlobalContext(ecx); |
| 4235 | // Make sure the function is the Array() function |
| 4236 | __ cmp(edi, Operand(ecx, |
| 4237 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4238 | __ j(not_equal, &megamorphic); |
| 4239 | __ jmp(&done); |
| 4240 | |
| 4241 | __ bind(&miss); |
| 4242 | |
| 4243 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4244 | // megamorphic. |
| 4245 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4246 | __ j(equal, &initialize); |
| 4247 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4248 | // write-barrier is needed. |
| 4249 | __ bind(&megamorphic); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4250 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4251 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4252 | __ jmp(&done, Label::kNear); |
| 4253 | |
| 4254 | // An uninitialized cache is patched with the function or sentinel to |
| 4255 | // indicate the ElementsKind if function is the Array constructor. |
| 4256 | __ bind(&initialize); |
| 4257 | __ LoadGlobalContext(ecx); |
| 4258 | // Make sure the function is the Array() function |
| 4259 | __ cmp(edi, Operand(ecx, |
| 4260 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4261 | __ j(not_equal, ¬_array_function); |
| 4262 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4263 | // The target function is the Array constructor, |
| 4264 | // Create an AllocationSite if we don't already have it, store it in the cell |
| 4265 | { |
| 4266 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4267 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 4268 | __ SmiTag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4269 | __ push(eax); |
| 4270 | __ push(edi); |
| 4271 | __ push(ebx); |
| 4272 | |
| 4273 | CreateAllocationSiteStub create_stub; |
| 4274 | __ CallStub(&create_stub); |
| 4275 | |
| 4276 | __ pop(ebx); |
| 4277 | __ pop(edi); |
| 4278 | __ pop(eax); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 4279 | __ SmiUntag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4280 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4281 | __ jmp(&done); |
| 4282 | |
| 4283 | __ bind(¬_array_function); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4284 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4285 | // No need for a write barrier here - cells are rescanned. |
| 4286 | |
| 4287 | __ bind(&done); |
| 4288 | } |
| 4289 | |
| 4290 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4291 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4292 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4293 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4294 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4295 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4296 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4297 | // The receiver might implicitly be the global object. This is |
| 4298 | // indicated by passing the hole as the receiver to the call |
| 4299 | // function stub. |
| 4300 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4301 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4302 | // Get the receiver from the stack. |
| 4303 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4304 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4305 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4306 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4307 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4308 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4309 | __ mov(ecx, GlobalObjectOperand()); |
| 4310 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4311 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4312 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4313 | } |
| 4314 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4315 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4316 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4317 | // Goto slow case if we do not have a function. |
| 4318 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4319 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4320 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4321 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4322 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4323 | } |
| 4324 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4325 | // Fast-case: Just invoke the function. |
| 4326 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4327 | |
| 4328 | if (ReceiverMightBeImplicit()) { |
| 4329 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4330 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4331 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4332 | __ InvokeFunction(edi, |
| 4333 | actual, |
| 4334 | JUMP_FUNCTION, |
| 4335 | NullCallWrapper(), |
| 4336 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4337 | __ bind(&call_as_function); |
| 4338 | } |
| 4339 | __ InvokeFunction(edi, |
| 4340 | actual, |
| 4341 | JUMP_FUNCTION, |
| 4342 | NullCallWrapper(), |
| 4343 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4344 | |
| 4345 | // Slow-case: Non-function called. |
| 4346 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4347 | if (RecordCallTarget()) { |
| 4348 | // 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] | 4349 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4350 | // object (undefined) so no write barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4351 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4352 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4353 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4354 | // Check for function proxy. |
| 4355 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4356 | __ j(not_equal, &non_function); |
| 4357 | __ pop(ecx); |
| 4358 | __ push(edi); // put proxy as additional argument under return address |
| 4359 | __ push(ecx); |
| 4360 | __ Set(eax, Immediate(argc_ + 1)); |
| 4361 | __ Set(ebx, Immediate(0)); |
| 4362 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4363 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4364 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4365 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4366 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4367 | } |
| 4368 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4369 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4370 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4371 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4372 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4373 | __ Set(eax, Immediate(argc_)); |
| 4374 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4375 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4376 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4377 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4378 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4379 | } |
| 4380 | |
| 4381 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4382 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4383 | // eax : number of arguments |
| 4384 | // ebx : cache cell for call target |
| 4385 | // edi : constructor function |
| 4386 | Label slow, non_function_call; |
| 4387 | |
| 4388 | // Check that function is not a smi. |
| 4389 | __ JumpIfSmi(edi, &non_function_call); |
| 4390 | // Check that function is a JSFunction. |
| 4391 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4392 | __ j(not_equal, &slow); |
| 4393 | |
| 4394 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4395 | GenerateRecordCallTarget(masm); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4396 | } |
| 4397 | |
| 4398 | // Jump to the function-specific construct stub. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4399 | Register jmp_reg = ecx; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4400 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4401 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 4402 | SharedFunctionInfo::kConstructStubOffset)); |
| 4403 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 4404 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4405 | |
| 4406 | // edi: called object |
| 4407 | // eax: number of arguments |
| 4408 | // ecx: object map |
| 4409 | Label do_call; |
| 4410 | __ bind(&slow); |
| 4411 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4412 | __ j(not_equal, &non_function_call); |
| 4413 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4414 | __ jmp(&do_call); |
| 4415 | |
| 4416 | __ bind(&non_function_call); |
| 4417 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4418 | __ bind(&do_call); |
| 4419 | // Set expected number of arguments to zero (not changing eax). |
| 4420 | __ Set(ebx, Immediate(0)); |
| 4421 | Handle<Code> arguments_adaptor = |
| 4422 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4423 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4424 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4425 | } |
| 4426 | |
| 4427 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4428 | bool CEntryStub::NeedsImmovableCode() { |
| 4429 | return false; |
| 4430 | } |
| 4431 | |
| 4432 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4433 | bool CEntryStub::IsPregenerated() { |
| 4434 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4435 | result_size_ == 1; |
| 4436 | } |
| 4437 | |
| 4438 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4439 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4440 | CEntryStub::GenerateAheadOfTime(isolate); |
| 4441 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4442 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4443 | // 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] | 4444 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4445 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4446 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4450 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4451 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4452 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4453 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4454 | // which would lead to code stub initialization state being messed up. |
| 4455 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4456 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 4457 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4458 | } |
| 4459 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4460 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4461 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4462 | } |
| 4463 | |
| 4464 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4465 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4466 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4467 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4468 | code->set_is_pregenerated(true); |
| 4469 | } |
| 4470 | |
| 4471 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4472 | static void JumpIfOOM(MacroAssembler* masm, |
| 4473 | Register value, |
| 4474 | Register scratch, |
| 4475 | Label* oom_label) { |
| 4476 | __ mov(scratch, value); |
| 4477 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 4478 | STATIC_ASSERT(kFailureTag == 3); |
| 4479 | __ and_(scratch, 0xf); |
| 4480 | __ cmp(scratch, 0xf); |
| 4481 | __ j(equal, oom_label); |
| 4482 | } |
| 4483 | |
| 4484 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4485 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4486 | Label* throw_normal_exception, |
| 4487 | Label* throw_termination_exception, |
| 4488 | Label* throw_out_of_memory_exception, |
| 4489 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4490 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4491 | // eax: result parameter for PerformGC, if any |
| 4492 | // ebx: pointer to C function (C callee-saved) |
| 4493 | // ebp: frame pointer (restored after C call) |
| 4494 | // esp: stack pointer (restored after C call) |
| 4495 | // edi: number of arguments including receiver (C callee-saved) |
| 4496 | // esi: pointer to the first argument (C callee-saved) |
| 4497 | |
| 4498 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4499 | |
| 4500 | // Check stack alignment. |
| 4501 | if (FLAG_debug_code) { |
| 4502 | __ CheckStackAlignment(); |
| 4503 | } |
| 4504 | |
| 4505 | if (do_gc) { |
| 4506 | // Pass failure code returned from last attempt as first argument to |
| 4507 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4508 | // stack alignment is known to be correct. This function takes one argument |
| 4509 | // which is passed on the stack, and we know that the stack has been |
| 4510 | // prepared to pass at least one argument. |
| 4511 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4512 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4513 | } |
| 4514 | |
| 4515 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4516 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4517 | if (always_allocate_scope) { |
| 4518 | __ inc(Operand::StaticVariable(scope_depth)); |
| 4519 | } |
| 4520 | |
| 4521 | // Call C function. |
| 4522 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 4523 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4524 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4525 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4526 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4527 | // Result is in eax or edx:eax - do not destroy these registers! |
| 4528 | |
| 4529 | if (always_allocate_scope) { |
| 4530 | __ dec(Operand::StaticVariable(scope_depth)); |
| 4531 | } |
| 4532 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4533 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 4534 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4535 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4536 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4537 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4538 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4539 | __ int3(); |
| 4540 | __ bind(&okay); |
| 4541 | } |
| 4542 | |
| 4543 | // Check for failure result. |
| 4544 | Label failure_returned; |
| 4545 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4546 | __ lea(ecx, Operand(eax, 1)); |
| 4547 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 4548 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4549 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4550 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4551 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4552 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4553 | |
| 4554 | // Check that there is no pending exception, otherwise we |
| 4555 | // should have returned some failure value. |
| 4556 | if (FLAG_debug_code) { |
| 4557 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4558 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4559 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4560 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 4561 | // 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] | 4562 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4563 | __ int3(); |
| 4564 | __ bind(&okay); |
| 4565 | __ pop(edx); |
| 4566 | } |
| 4567 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4568 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4569 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4570 | __ ret(0); |
| 4571 | |
| 4572 | // Handling of failure. |
| 4573 | __ bind(&failure_returned); |
| 4574 | |
| 4575 | Label retry; |
| 4576 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 4577 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4578 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4579 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4580 | |
| 4581 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4582 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4583 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4584 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4585 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4586 | |
| 4587 | // See if we just retrieved an OOM exception. |
| 4588 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 4589 | |
| 4590 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4591 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4592 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 4593 | |
| 4594 | // Special handling of termination exceptions which are uncatchable |
| 4595 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4596 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4597 | __ j(equal, throw_termination_exception); |
| 4598 | |
| 4599 | // Handle normal exception. |
| 4600 | __ jmp(throw_normal_exception); |
| 4601 | |
| 4602 | // Retry. |
| 4603 | __ bind(&retry); |
| 4604 | } |
| 4605 | |
| 4606 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4607 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4608 | // eax: number of arguments including receiver |
| 4609 | // ebx: pointer to C function (C callee-saved) |
| 4610 | // ebp: frame pointer (restored after C call) |
| 4611 | // esp: stack pointer (restored after C call) |
| 4612 | // esi: current context (C callee-saved) |
| 4613 | // edi: JS function of the caller (C callee-saved) |
| 4614 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4615 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 4616 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4617 | // NOTE: Invocations of builtins may return failure objects instead |
| 4618 | // of a proper result. The builtin entry handles this by performing |
| 4619 | // a garbage collection and retrying the builtin (twice). |
| 4620 | |
| 4621 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4622 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4623 | |
| 4624 | // eax: result parameter for PerformGC, if any (setup below) |
| 4625 | // ebx: pointer to builtin function (C callee-saved) |
| 4626 | // ebp: frame pointer (restored after C call) |
| 4627 | // esp: stack pointer (restored after C call) |
| 4628 | // edi: number of arguments including receiver (C callee-saved) |
| 4629 | // esi: argv pointer (C callee-saved) |
| 4630 | |
| 4631 | Label throw_normal_exception; |
| 4632 | Label throw_termination_exception; |
| 4633 | Label throw_out_of_memory_exception; |
| 4634 | |
| 4635 | // Call into the runtime system. |
| 4636 | GenerateCore(masm, |
| 4637 | &throw_normal_exception, |
| 4638 | &throw_termination_exception, |
| 4639 | &throw_out_of_memory_exception, |
| 4640 | false, |
| 4641 | false); |
| 4642 | |
| 4643 | // Do space-specific GC and retry runtime call. |
| 4644 | GenerateCore(masm, |
| 4645 | &throw_normal_exception, |
| 4646 | &throw_termination_exception, |
| 4647 | &throw_out_of_memory_exception, |
| 4648 | true, |
| 4649 | false); |
| 4650 | |
| 4651 | // Do full GC and retry runtime call one final time. |
| 4652 | Failure* failure = Failure::InternalError(); |
| 4653 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 4654 | GenerateCore(masm, |
| 4655 | &throw_normal_exception, |
| 4656 | &throw_termination_exception, |
| 4657 | &throw_out_of_memory_exception, |
| 4658 | true, |
| 4659 | true); |
| 4660 | |
| 4661 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4662 | // Set external caught exception to false. |
| 4663 | Isolate* isolate = masm->isolate(); |
| 4664 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 4665 | isolate); |
| 4666 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 4667 | |
| 4668 | // Set pending exception and eax to out of memory exception. |
| 4669 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 4670 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4671 | Label already_have_failure; |
| 4672 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 4673 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 4674 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4675 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4676 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4677 | |
| 4678 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4679 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4680 | |
| 4681 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4682 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4683 | } |
| 4684 | |
| 4685 | |
| 4686 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4687 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4688 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4689 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4690 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 4691 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4692 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4693 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4694 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4695 | |
| 4696 | // Push marker in two places. |
| 4697 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4698 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 4699 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 4700 | // Save callee-saved registers (C calling conventions). |
| 4701 | __ push(edi); |
| 4702 | __ push(esi); |
| 4703 | __ push(ebx); |
| 4704 | |
| 4705 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4706 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4707 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 4708 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4709 | // 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] | 4710 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4711 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4712 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4713 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4714 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4715 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 4716 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4717 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4718 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4719 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4720 | // Jump to a faked try block that does the invoke, with a faked catch |
| 4721 | // block that sets the pending exception. |
| 4722 | __ jmp(&invoke); |
| 4723 | __ bind(&handler_entry); |
| 4724 | handler_offset_ = handler_entry.pos(); |
| 4725 | // Caught exception: Store result (exception) in the pending exception |
| 4726 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4727 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4728 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4729 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4730 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 4731 | __ jmp(&exit); |
| 4732 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4733 | // Invoke: Link this frame into the handler chain. There's only one |
| 4734 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4735 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4736 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4737 | |
| 4738 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4739 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4740 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4741 | |
| 4742 | // Fake a receiver (NULL). |
| 4743 | __ push(Immediate(0)); // receiver |
| 4744 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4745 | // Invoke the function by calling through JS entry trampoline builtin and |
| 4746 | // pop the faked function when we return. Notice that we cannot store a |
| 4747 | // reference to the trampoline code directly in this stub, because the |
| 4748 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4749 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4750 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 4751 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4752 | __ mov(edx, Immediate(construct_entry)); |
| 4753 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4754 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4755 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4756 | __ mov(edx, Immediate(entry)); |
| 4757 | } |
| 4758 | __ mov(edx, Operand(edx, 0)); // deref address |
| 4759 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4760 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4761 | |
| 4762 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4763 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4764 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4765 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4766 | // Check if the current stack frame is marked as the outermost JS frame. |
| 4767 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4768 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4769 | __ j(not_equal, ¬_outermost_js_2); |
| 4770 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 4771 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4772 | |
| 4773 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4774 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4775 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4776 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4777 | |
| 4778 | // Restore callee-saved registers (C calling conventions). |
| 4779 | __ pop(ebx); |
| 4780 | __ pop(esi); |
| 4781 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4782 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4783 | |
| 4784 | // Restore frame pointer and return. |
| 4785 | __ pop(ebp); |
| 4786 | __ ret(0); |
| 4787 | } |
| 4788 | |
| 4789 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4790 | // Generate stub code for instanceof. |
| 4791 | // This code can patch a call site inlined cache of the instance of check, |
| 4792 | // which looks like this. |
| 4793 | // |
| 4794 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 4795 | // 75 0a jne <some near label> |
| 4796 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 4797 | // |
| 4798 | // If call site patching is requested the stack will have the delta from the |
| 4799 | // return address to the cmp instruction just below the return address. This |
| 4800 | // also means that call site patching can only take place with arguments in |
| 4801 | // registers. TOS looks like this when call site patching is requested |
| 4802 | // |
| 4803 | // esp[0] : return address |
| 4804 | // esp[4] : delta from return address to cmp instruction |
| 4805 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4806 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4807 | // Call site inlining and patching implies arguments in registers. |
| 4808 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 4809 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4810 | // Fixed register usage throughout the stub. |
| 4811 | Register object = eax; // Object (lhs). |
| 4812 | Register map = ebx; // Map of the object. |
| 4813 | Register function = edx; // Function (rhs). |
| 4814 | Register prototype = edi; // Prototype of the function. |
| 4815 | Register scratch = ecx; |
| 4816 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4817 | // Constants describing the call site code to patch. |
| 4818 | static const int kDeltaToCmpImmediate = 2; |
| 4819 | static const int kDeltaToMov = 8; |
| 4820 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4821 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 4822 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4823 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 4824 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4825 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 4826 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 4827 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4828 | // Get the object and function - they are always both needed. |
| 4829 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4830 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4831 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 4832 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 4833 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4834 | |
| 4835 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4836 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4837 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4838 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4839 | // If there is a call site cache don't look in the global cache, but do the |
| 4840 | // real lookup and update the call site cache. |
| 4841 | if (!HasCallSiteInlineCheck()) { |
| 4842 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4843 | Label miss; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4844 | __ CompareRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4845 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4846 | __ CompareRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4847 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4848 | __ LoadRoot(eax, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4849 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 4850 | __ bind(&miss); |
| 4851 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4852 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4853 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4854 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4855 | |
| 4856 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4857 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4858 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4859 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4860 | // Update the global instanceof or call site inlined cache with the current |
| 4861 | // map and function. The cached answer will be set when it is known below. |
| 4862 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4863 | __ StoreRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
| 4864 | __ StoreRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4865 | } else { |
| 4866 | // The constants for the code patching are based on no push instructions |
| 4867 | // at the call site. |
| 4868 | ASSERT(HasArgsInRegisters()); |
| 4869 | // Get return address and delta to inlined map check. |
| 4870 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 4871 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 4872 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4873 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4874 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp1); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4875 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4876 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4877 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4878 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 4879 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4880 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4881 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4882 | // Loop through the prototype chain of the object looking for the function |
| 4883 | // prototype. |
| 4884 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4885 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4886 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4887 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4888 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4889 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4890 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4891 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4892 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 4893 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4894 | __ jmp(&loop); |
| 4895 | |
| 4896 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4897 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4898 | __ mov(eax, Immediate(0)); |
| 4899 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4900 | } else { |
| 4901 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4902 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4903 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 4904 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 4905 | if (FLAG_debug_code) { |
| 4906 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4907 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4908 | } |
| 4909 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 4910 | if (!ReturnTrueFalseObject()) { |
| 4911 | __ Set(eax, Immediate(0)); |
| 4912 | } |
| 4913 | } |
| 4914 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4915 | |
| 4916 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4917 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4918 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4919 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4920 | } else { |
| 4921 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4922 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4923 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 4924 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 4925 | if (FLAG_debug_code) { |
| 4926 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4927 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4928 | } |
| 4929 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 4930 | if (!ReturnTrueFalseObject()) { |
| 4931 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 4932 | } |
| 4933 | } |
| 4934 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4935 | |
| 4936 | Label object_not_null, object_not_null_or_smi; |
| 4937 | __ bind(¬_js_object); |
| 4938 | // Before null, smi and string value checks, check that the rhs is a function |
| 4939 | // 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] | 4940 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4941 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4942 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4943 | |
| 4944 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4945 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4946 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4947 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4948 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4949 | |
| 4950 | __ bind(&object_not_null); |
| 4951 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4952 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4953 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4954 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4955 | |
| 4956 | __ bind(&object_not_null_or_smi); |
| 4957 | // String values is not instance of anything. |
| 4958 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4959 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4960 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4961 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4962 | |
| 4963 | // Slow-case: Go through the JavaScript implementation. |
| 4964 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4965 | if (!ReturnTrueFalseObject()) { |
| 4966 | // Tail call the builtin which returns 0 or 1. |
| 4967 | if (HasArgsInRegisters()) { |
| 4968 | // Push arguments below return address. |
| 4969 | __ pop(scratch); |
| 4970 | __ push(object); |
| 4971 | __ push(function); |
| 4972 | __ push(scratch); |
| 4973 | } |
| 4974 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 4975 | } else { |
| 4976 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4977 | { |
| 4978 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4979 | __ push(object); |
| 4980 | __ push(function); |
| 4981 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 4982 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4983 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4984 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4985 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4986 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4987 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4988 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4989 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4990 | __ bind(&done); |
| 4991 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4992 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4993 | } |
| 4994 | |
| 4995 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4996 | Register InstanceofStub::left() { return eax; } |
| 4997 | |
| 4998 | |
| 4999 | Register InstanceofStub::right() { return edx; } |
| 5000 | |
| 5001 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5002 | // ------------------------------------------------------------------------- |
| 5003 | // StringCharCodeAtGenerator |
| 5004 | |
| 5005 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5006 | // If the receiver is a smi trigger the non-string case. |
| 5007 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5008 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5009 | |
| 5010 | // Fetch the instance type of the receiver into result register. |
| 5011 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5012 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5013 | // If the receiver is not a string trigger the non-string case. |
| 5014 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5015 | __ j(not_zero, receiver_not_string_); |
| 5016 | |
| 5017 | // If the index is non-smi trigger the non-smi case. |
| 5018 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5019 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5020 | __ bind(&got_smi_index_); |
| 5021 | |
| 5022 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5023 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5024 | __ j(above_equal, index_out_of_range_); |
| 5025 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5026 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5027 | |
| 5028 | Factory* factory = masm->isolate()->factory(); |
| 5029 | StringCharLoadGenerator::Generate( |
| 5030 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5031 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5032 | __ SmiTag(result_); |
| 5033 | __ bind(&exit_); |
| 5034 | } |
| 5035 | |
| 5036 | |
| 5037 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5038 | MacroAssembler* masm, |
| 5039 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5040 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5041 | |
| 5042 | // Index is not a smi. |
| 5043 | __ bind(&index_not_smi_); |
| 5044 | // 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] | 5045 | __ CheckMap(index_, |
| 5046 | masm->isolate()->factory()->heap_number_map(), |
| 5047 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5048 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5049 | call_helper.BeforeCall(masm); |
| 5050 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5051 | __ push(index_); // Consumed by runtime conversion function. |
| 5052 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5053 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5054 | } else { |
| 5055 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5056 | // NumberToSmi discards numbers that are not exact integers. |
| 5057 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5058 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5059 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5060 | // Save the conversion result before the pop instructions below |
| 5061 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5062 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5063 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5064 | __ pop(object_); |
| 5065 | // Reload the instance type. |
| 5066 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5067 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5068 | call_helper.AfterCall(masm); |
| 5069 | // If index is still not a smi, it must be out of range. |
| 5070 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5071 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5072 | // Otherwise, return to the fast path. |
| 5073 | __ jmp(&got_smi_index_); |
| 5074 | |
| 5075 | // Call runtime. We get here when the receiver is a string and the |
| 5076 | // index is a number, but the code of getting the actual character |
| 5077 | // is too complex (e.g., when the string needs to be flattened). |
| 5078 | __ bind(&call_runtime_); |
| 5079 | call_helper.BeforeCall(masm); |
| 5080 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5081 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5082 | __ push(index_); |
| 5083 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5084 | if (!result_.is(eax)) { |
| 5085 | __ mov(result_, eax); |
| 5086 | } |
| 5087 | call_helper.AfterCall(masm); |
| 5088 | __ jmp(&exit_); |
| 5089 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5090 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | |
| 5094 | // ------------------------------------------------------------------------- |
| 5095 | // StringCharFromCodeGenerator |
| 5096 | |
| 5097 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5098 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5099 | STATIC_ASSERT(kSmiTag == 0); |
| 5100 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5101 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5102 | __ test(code_, |
| 5103 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5104 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5105 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5106 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5107 | Factory* factory = masm->isolate()->factory(); |
| 5108 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5109 | STATIC_ASSERT(kSmiTag == 0); |
| 5110 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5111 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5112 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5113 | __ mov(result_, FieldOperand(result_, |
| 5114 | code_, times_half_pointer_size, |
| 5115 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5116 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5117 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5118 | __ bind(&exit_); |
| 5119 | } |
| 5120 | |
| 5121 | |
| 5122 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5123 | MacroAssembler* masm, |
| 5124 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5125 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5126 | |
| 5127 | __ bind(&slow_case_); |
| 5128 | call_helper.BeforeCall(masm); |
| 5129 | __ push(code_); |
| 5130 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5131 | if (!result_.is(eax)) { |
| 5132 | __ mov(result_, eax); |
| 5133 | } |
| 5134 | call_helper.AfterCall(masm); |
| 5135 | __ jmp(&exit_); |
| 5136 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5137 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5138 | } |
| 5139 | |
| 5140 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5141 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5142 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5143 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5144 | |
| 5145 | // Load the two arguments. |
| 5146 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5147 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5148 | |
| 5149 | // Make sure that both arguments are strings if not known in advance. |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5150 | // Otherwise, at least one of the arguments is definitely a string, |
| 5151 | // and we convert the one that is not known to be a string. |
| 5152 | if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) { |
| 5153 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT); |
| 5154 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5155 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5156 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5157 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5158 | |
| 5159 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5160 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5161 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5162 | __ j(above_equal, &call_runtime); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5163 | } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) { |
| 5164 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0); |
| 5165 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5166 | &call_builtin); |
| 5167 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5168 | } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) { |
| 5169 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0); |
| 5170 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5171 | &call_builtin); |
| 5172 | builtin_id = Builtins::STRING_ADD_LEFT; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | // Both arguments are strings. |
| 5176 | // eax: first string |
| 5177 | // edx: second string |
| 5178 | // 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] | 5179 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5180 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5181 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5182 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5183 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5184 | // 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] | 5185 | Counters* counters = masm->isolate()->counters(); |
| 5186 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5187 | __ ret(2 * kPointerSize); |
| 5188 | __ bind(&second_not_zero_length); |
| 5189 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5190 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5191 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5192 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5193 | // First string is empty, result is second string which is in edx. |
| 5194 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5195 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5196 | __ ret(2 * kPointerSize); |
| 5197 | |
| 5198 | // Both strings are non-empty. |
| 5199 | // eax: first string |
| 5200 | // ebx: length of first string as a smi |
| 5201 | // ecx: length of second string as a smi |
| 5202 | // edx: second string |
| 5203 | // Look at the length of the result of adding the two strings. |
| 5204 | Label string_add_flat_result, longer_than_two; |
| 5205 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5206 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5207 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5208 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5209 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5210 | // Use the string table when adding two one character strings, as it |
| 5211 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5212 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5213 | __ j(not_equal, &longer_than_two); |
| 5214 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5215 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5216 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5217 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5218 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5219 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5220 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5221 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5222 | // 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] | 5223 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5224 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5225 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5226 | masm, ebx, ecx, eax, edx, edi, |
| 5227 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5228 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5229 | __ ret(2 * kPointerSize); |
| 5230 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5231 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5232 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5233 | // Reload the arguments. |
| 5234 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5235 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5236 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5237 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5238 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5239 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5240 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5241 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5242 | // Pack both characters in ebx. |
| 5243 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5244 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5245 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5246 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5247 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5248 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5249 | |
| 5250 | __ bind(&longer_than_two); |
| 5251 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5252 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5253 | __ j(below, &string_add_flat_result); |
| 5254 | |
| 5255 | // 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] | 5256 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5257 | Label non_ascii, allocated, ascii_data; |
| 5258 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5259 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5260 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5261 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5262 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5263 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5264 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5265 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5266 | __ j(zero, &non_ascii); |
| 5267 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5268 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5269 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5270 | __ bind(&allocated); |
| 5271 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5272 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5273 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5274 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5275 | Immediate(String::kEmptyHashField)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5276 | |
| 5277 | Label skip_write_barrier, after_writing; |
| 5278 | ExternalReference high_promotion_mode = ExternalReference:: |
| 5279 | new_space_high_promotion_mode_active_address(masm->isolate()); |
| 5280 | __ test(Operand::StaticVariable(high_promotion_mode), Immediate(1)); |
| 5281 | __ j(zero, &skip_write_barrier); |
| 5282 | |
| 5283 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5284 | __ RecordWriteField(ecx, |
| 5285 | ConsString::kFirstOffset, |
| 5286 | eax, |
| 5287 | ebx, |
| 5288 | kDontSaveFPRegs); |
| 5289 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5290 | __ RecordWriteField(ecx, |
| 5291 | ConsString::kSecondOffset, |
| 5292 | edx, |
| 5293 | ebx, |
| 5294 | kDontSaveFPRegs); |
| 5295 | __ jmp(&after_writing); |
| 5296 | |
| 5297 | __ bind(&skip_write_barrier); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5298 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5299 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5300 | |
| 5301 | __ bind(&after_writing); |
| 5302 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5303 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5304 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5305 | __ ret(2 * kPointerSize); |
| 5306 | __ bind(&non_ascii); |
| 5307 | // 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] | 5308 | // to contain only one byte characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5309 | // ecx: first instance type AND second instance type. |
| 5310 | // edi: second instance type. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5311 | __ test(ecx, Immediate(kOneByteDataHintMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5312 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5313 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5314 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5315 | __ xor_(edi, ecx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5316 | STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0); |
| 5317 | __ and_(edi, kOneByteStringTag | kOneByteDataHintTag); |
| 5318 | __ cmp(edi, kOneByteStringTag | kOneByteDataHintTag); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5319 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5320 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5321 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5322 | __ jmp(&allocated); |
| 5323 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5324 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5325 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5326 | // Handle creating a flat result from either external or sequential strings. |
| 5327 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5328 | // eax: first string |
| 5329 | // ebx: length of resulting flat string as a smi |
| 5330 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5331 | Label first_prepared, second_prepared; |
| 5332 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5333 | __ bind(&string_add_flat_result); |
| 5334 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5335 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5336 | // ecx: instance type of first string |
| 5337 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5338 | __ test_b(ecx, kStringRepresentationMask); |
| 5339 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5340 | // Rule out short external string and load string resource. |
| 5341 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5342 | __ test_b(ecx, kShortExternalStringMask); |
| 5343 | __ j(not_zero, &call_runtime); |
| 5344 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5345 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5346 | __ jmp(&first_prepared, Label::kNear); |
| 5347 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5348 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5349 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5350 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5351 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5352 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5353 | // Check whether both strings have same encoding. |
| 5354 | // edi: instance type of second string |
| 5355 | __ xor_(ecx, edi); |
| 5356 | __ test_b(ecx, kStringEncodingMask); |
| 5357 | __ j(not_zero, &call_runtime); |
| 5358 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5359 | __ test_b(edi, kStringRepresentationMask); |
| 5360 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5361 | // Rule out short external string and load string resource. |
| 5362 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5363 | __ test_b(edi, kShortExternalStringMask); |
| 5364 | __ j(not_zero, &call_runtime); |
| 5365 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5366 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5367 | __ jmp(&second_prepared, Label::kNear); |
| 5368 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5369 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5370 | __ bind(&second_prepared); |
| 5371 | |
| 5372 | // Push the addresses of both strings' first characters onto the stack. |
| 5373 | __ push(edx); |
| 5374 | __ push(eax); |
| 5375 | |
| 5376 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5377 | // edi: instance type of second string |
| 5378 | // First string and second string have the same encoding. |
| 5379 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5380 | __ test_b(edi, kStringEncodingMask); |
| 5381 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5382 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5383 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5384 | // ebx: length of resulting flat string as a smi |
| 5385 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5386 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5387 | // eax: result string |
| 5388 | __ mov(ecx, eax); |
| 5389 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5390 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5391 | // Load first argument's length and first character location. Account for |
| 5392 | // values currently on the stack when fetching arguments from it. |
| 5393 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5394 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5395 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5396 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5397 | // eax: result string |
| 5398 | // ecx: first character of result |
| 5399 | // edx: first char of first argument |
| 5400 | // edi: length of first argument |
| 5401 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5402 | // Load second argument's length and first character location. Account for |
| 5403 | // values currently on the stack when fetching arguments from it. |
| 5404 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5405 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5406 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5407 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5408 | // eax: result string |
| 5409 | // ecx: next character of result |
| 5410 | // edx: first char of second argument |
| 5411 | // edi: length of second argument |
| 5412 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5413 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5414 | __ ret(2 * kPointerSize); |
| 5415 | |
| 5416 | // Handle creating a flat two byte result. |
| 5417 | // eax: first string - known to be two byte |
| 5418 | // ebx: length of resulting flat string as a smi |
| 5419 | // edx: second string |
| 5420 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5421 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5422 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5423 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5424 | // eax: result string |
| 5425 | __ mov(ecx, eax); |
| 5426 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5427 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5428 | // Load second argument's length and first character location. Account for |
| 5429 | // values currently on the stack when fetching arguments from it. |
| 5430 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5431 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5432 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5433 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5434 | // eax: result string |
| 5435 | // ecx: first character of result |
| 5436 | // edx: first char of first argument |
| 5437 | // edi: length of first argument |
| 5438 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5439 | // Load second argument's length and first character location. Account for |
| 5440 | // values currently on the stack when fetching arguments from it. |
| 5441 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5442 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5443 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5444 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5445 | // eax: result string |
| 5446 | // ecx: next character of result |
| 5447 | // edx: first char of second argument |
| 5448 | // edi: length of second argument |
| 5449 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5450 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5451 | __ ret(2 * kPointerSize); |
| 5452 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5453 | // Recover stack pointer before jumping to runtime. |
| 5454 | __ bind(&call_runtime_drop_two); |
| 5455 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5456 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5457 | __ bind(&call_runtime); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5458 | if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) { |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5459 | GenerateRegisterArgsPop(masm, ecx); |
| 5460 | // Build a frame |
| 5461 | { |
| 5462 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5463 | GenerateRegisterArgsPush(masm); |
| 5464 | __ CallRuntime(Runtime::kStringAdd, 2); |
| 5465 | } |
| 5466 | __ ret(0); |
| 5467 | } else { |
| 5468 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
| 5469 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5470 | |
| 5471 | if (call_builtin.is_linked()) { |
| 5472 | __ bind(&call_builtin); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5473 | if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) { |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5474 | GenerateRegisterArgsPop(masm, ecx); |
| 5475 | // Build a frame |
| 5476 | { |
| 5477 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5478 | GenerateRegisterArgsPush(masm); |
| 5479 | __ InvokeBuiltin(builtin_id, CALL_FUNCTION); |
| 5480 | } |
| 5481 | __ ret(0); |
| 5482 | } else { |
| 5483 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5484 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5489 | void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
| 5490 | __ push(eax); |
| 5491 | __ push(edx); |
| 5492 | } |
| 5493 | |
| 5494 | |
| 5495 | void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm, |
| 5496 | Register temp) { |
| 5497 | __ pop(temp); |
| 5498 | __ pop(edx); |
| 5499 | __ pop(eax); |
| 5500 | __ push(temp); |
| 5501 | } |
| 5502 | |
| 5503 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5504 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5505 | int stack_offset, |
| 5506 | Register arg, |
| 5507 | Register scratch1, |
| 5508 | Register scratch2, |
| 5509 | Register scratch3, |
| 5510 | Label* slow) { |
| 5511 | // First check if the argument is already a string. |
| 5512 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5513 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5514 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5515 | __ j(below, &done); |
| 5516 | |
| 5517 | // Check the number to string cache. |
| 5518 | Label not_cached; |
| 5519 | __ bind(¬_string); |
| 5520 | // Puts the cached result into scratch1. |
| 5521 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 5522 | arg, |
| 5523 | scratch1, |
| 5524 | scratch2, |
| 5525 | scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5526 | ¬_cached); |
| 5527 | __ mov(arg, scratch1); |
| 5528 | __ mov(Operand(esp, stack_offset), arg); |
| 5529 | __ jmp(&done); |
| 5530 | |
| 5531 | // Check if the argument is a safe string wrapper. |
| 5532 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5533 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5534 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 5535 | __ j(not_equal, slow); |
| 5536 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 5537 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 5538 | __ j(zero, slow); |
| 5539 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 5540 | __ mov(Operand(esp, stack_offset), arg); |
| 5541 | |
| 5542 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5543 | } |
| 5544 | |
| 5545 | |
| 5546 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5547 | Register dest, |
| 5548 | Register src, |
| 5549 | Register count, |
| 5550 | Register scratch, |
| 5551 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5552 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5553 | __ bind(&loop); |
| 5554 | // This loop just copies one character at a time, as it is only used for very |
| 5555 | // short strings. |
| 5556 | if (ascii) { |
| 5557 | __ mov_b(scratch, Operand(src, 0)); |
| 5558 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5559 | __ add(src, Immediate(1)); |
| 5560 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5561 | } else { |
| 5562 | __ mov_w(scratch, Operand(src, 0)); |
| 5563 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5564 | __ add(src, Immediate(2)); |
| 5565 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5566 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5567 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5568 | __ j(not_zero, &loop); |
| 5569 | } |
| 5570 | |
| 5571 | |
| 5572 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 5573 | Register dest, |
| 5574 | Register src, |
| 5575 | Register count, |
| 5576 | Register scratch, |
| 5577 | bool ascii) { |
| 5578 | // Copy characters using rep movs of doublewords. |
| 5579 | // The destination is aligned on a 4 byte boundary because we are |
| 5580 | // copying to the beginning of a newly allocated string. |
| 5581 | ASSERT(dest.is(edi)); // rep movs destination |
| 5582 | ASSERT(src.is(esi)); // rep movs source |
| 5583 | ASSERT(count.is(ecx)); // rep movs count |
| 5584 | ASSERT(!scratch.is(dest)); |
| 5585 | ASSERT(!scratch.is(src)); |
| 5586 | ASSERT(!scratch.is(count)); |
| 5587 | |
| 5588 | // Nothing to do for zero characters. |
| 5589 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5590 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5591 | __ j(zero, &done); |
| 5592 | |
| 5593 | // Make count the number of bytes to copy. |
| 5594 | if (!ascii) { |
| 5595 | __ shl(count, 1); |
| 5596 | } |
| 5597 | |
| 5598 | // 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] | 5599 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5600 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5601 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5602 | |
| 5603 | // Copy from edi to esi using rep movs instruction. |
| 5604 | __ mov(scratch, count); |
| 5605 | __ sar(count, 2); // Number of doublewords to copy. |
| 5606 | __ cld(); |
| 5607 | __ rep_movs(); |
| 5608 | |
| 5609 | // Find number of bytes left. |
| 5610 | __ mov(count, scratch); |
| 5611 | __ and_(count, 3); |
| 5612 | |
| 5613 | // Check if there are more bytes to copy. |
| 5614 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5615 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5616 | __ j(zero, &done); |
| 5617 | |
| 5618 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5619 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5620 | __ bind(&loop); |
| 5621 | __ mov_b(scratch, Operand(src, 0)); |
| 5622 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5623 | __ add(src, Immediate(1)); |
| 5624 | __ add(dest, Immediate(1)); |
| 5625 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5626 | __ j(not_zero, &loop); |
| 5627 | |
| 5628 | __ bind(&done); |
| 5629 | } |
| 5630 | |
| 5631 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5632 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5633 | Register c1, |
| 5634 | Register c2, |
| 5635 | Register scratch1, |
| 5636 | Register scratch2, |
| 5637 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5638 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5639 | Label* not_found) { |
| 5640 | // Register scratch3 is the general scratch register in this function. |
| 5641 | Register scratch = scratch3; |
| 5642 | |
| 5643 | // 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] | 5644 | // 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] | 5645 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5646 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5647 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5648 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5649 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5650 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5651 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5652 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5653 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5654 | |
| 5655 | __ bind(¬_array_index); |
| 5656 | // Calculate the two character string hash. |
| 5657 | Register hash = scratch1; |
| 5658 | GenerateHashInit(masm, hash, c1, scratch); |
| 5659 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 5660 | GenerateHashGetHash(masm, hash, scratch); |
| 5661 | |
| 5662 | // Collect the two characters in a register. |
| 5663 | Register chars = c1; |
| 5664 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5665 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5666 | |
| 5667 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5668 | // hash: hash of two character string. |
| 5669 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5670 | // Load the string table. |
| 5671 | Register string_table = c2; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5672 | __ LoadRoot(string_table, Heap::kStringTableRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5673 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5674 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5675 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5676 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5677 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5678 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5679 | |
| 5680 | // Registers |
| 5681 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5682 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5683 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5684 | // mask: capacity mask |
| 5685 | // scratch: - |
| 5686 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5687 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5688 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5689 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5690 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5691 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5692 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5693 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5694 | __ mov(scratch, hash); |
| 5695 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5696 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5697 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5698 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5699 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5700 | // Load the entry from the string table. |
| 5701 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5702 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5703 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5704 | scratch, |
| 5705 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5706 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5707 | |
| 5708 | // 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] | 5709 | Factory* factory = masm->isolate()->factory(); |
| 5710 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5711 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5712 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5713 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5714 | |
| 5715 | // If length is not 2 the string is not a candidate. |
| 5716 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 5717 | Immediate(Smi::FromInt(2))); |
| 5718 | __ j(not_equal, &next_probe[i]); |
| 5719 | |
| 5720 | // As we are out of registers save the mask on the stack and use that |
| 5721 | // register as a temporary. |
| 5722 | __ push(mask); |
| 5723 | Register temp = mask; |
| 5724 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5725 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5726 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 5727 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 5728 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 5729 | temp, temp, &next_probe_pop_mask[i]); |
| 5730 | |
| 5731 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5732 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5733 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5734 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5735 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5736 | __ bind(&next_probe_pop_mask[i]); |
| 5737 | __ pop(mask); |
| 5738 | __ bind(&next_probe[i]); |
| 5739 | } |
| 5740 | |
| 5741 | // No matching 2 character string found by probing. |
| 5742 | __ jmp(not_found); |
| 5743 | |
| 5744 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5745 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5746 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5747 | __ pop(mask); // Pop saved mask from the stack. |
| 5748 | if (!result.is(eax)) { |
| 5749 | __ mov(eax, result); |
| 5750 | } |
| 5751 | } |
| 5752 | |
| 5753 | |
| 5754 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 5755 | Register hash, |
| 5756 | Register character, |
| 5757 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5758 | // hash = (seed + character) + ((seed + character) << 10); |
| 5759 | if (Serializer::enabled()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5760 | __ LoadRoot(scratch, Heap::kHashSeedRootIndex); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5761 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5762 | __ add(scratch, character); |
| 5763 | __ mov(hash, scratch); |
| 5764 | __ shl(scratch, 10); |
| 5765 | __ add(hash, scratch); |
| 5766 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5767 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5768 | __ lea(scratch, Operand(character, seed)); |
| 5769 | __ shl(scratch, 10); |
| 5770 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 5771 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5772 | // hash ^= hash >> 6; |
| 5773 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5774 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5775 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5776 | } |
| 5777 | |
| 5778 | |
| 5779 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 5780 | Register hash, |
| 5781 | Register character, |
| 5782 | Register scratch) { |
| 5783 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5784 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5785 | // hash += hash << 10; |
| 5786 | __ mov(scratch, hash); |
| 5787 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5788 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5789 | // hash ^= hash >> 6; |
| 5790 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5791 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5792 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5793 | } |
| 5794 | |
| 5795 | |
| 5796 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 5797 | Register hash, |
| 5798 | Register scratch) { |
| 5799 | // hash += hash << 3; |
| 5800 | __ mov(scratch, hash); |
| 5801 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5802 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5803 | // hash ^= hash >> 11; |
| 5804 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5805 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5806 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5807 | // hash += hash << 15; |
| 5808 | __ mov(scratch, hash); |
| 5809 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5810 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5811 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5812 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5813 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5814 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5815 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5816 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5817 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5818 | __ bind(&hash_not_zero); |
| 5819 | } |
| 5820 | |
| 5821 | |
| 5822 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 5823 | Label runtime; |
| 5824 | |
| 5825 | // Stack frame on entry. |
| 5826 | // esp[0]: return address |
| 5827 | // esp[4]: to |
| 5828 | // esp[8]: from |
| 5829 | // esp[12]: string |
| 5830 | |
| 5831 | // Make sure first argument is a string. |
| 5832 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 5833 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5834 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5835 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 5836 | __ j(NegateCondition(is_string), &runtime); |
| 5837 | |
| 5838 | // eax: string |
| 5839 | // ebx: instance type |
| 5840 | |
| 5841 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5842 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5843 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5844 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5845 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5846 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5847 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5848 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5849 | // Shorter than original string's length: an actual substring. |
| 5850 | __ j(below, ¬_original_string, Label::kNear); |
| 5851 | // Longer than original string's length or negative: unsafe arguments. |
| 5852 | __ j(above, &runtime); |
| 5853 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5854 | Counters* counters = masm->isolate()->counters(); |
| 5855 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 5856 | __ ret(3 * kPointerSize); |
| 5857 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5858 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 5859 | Label single_char; |
| 5860 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 5861 | __ j(equal, &single_char); |
| 5862 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5863 | // eax: string |
| 5864 | // ebx: instance type |
| 5865 | // ecx: sub string length (smi) |
| 5866 | // edx: from index (smi) |
| 5867 | // Deal with different string types: update the index if necessary |
| 5868 | // and put the underlying string into edi. |
| 5869 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 5870 | // If the string is not indirect, it can only be sequential or external. |
| 5871 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 5872 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 5873 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 5874 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 5875 | |
| 5876 | Factory* factory = masm->isolate()->factory(); |
| 5877 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 5878 | __ j(not_zero, &sliced_string, Label::kNear); |
| 5879 | // Cons string. Check whether it is flat, then fetch first part. |
| 5880 | // Flat cons strings have an empty second part. |
| 5881 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 5882 | factory->empty_string()); |
| 5883 | __ j(not_equal, &runtime); |
| 5884 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 5885 | // Update instance type. |
| 5886 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 5887 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 5888 | __ jmp(&underlying_unpacked, Label::kNear); |
| 5889 | |
| 5890 | __ bind(&sliced_string); |
| 5891 | // Sliced string. Fetch parent and adjust start index by offset. |
| 5892 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 5893 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 5894 | // Update instance type. |
| 5895 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 5896 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 5897 | __ jmp(&underlying_unpacked, Label::kNear); |
| 5898 | |
| 5899 | __ bind(&seq_or_external_string); |
| 5900 | // Sequential or external string. Just move string to the expected register. |
| 5901 | __ mov(edi, eax); |
| 5902 | |
| 5903 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5904 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5905 | if (FLAG_string_slices) { |
| 5906 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5907 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5908 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5909 | // edx: adjusted start index (smi) |
| 5910 | // ecx: length (smi) |
| 5911 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 5912 | // Short slice. Copy instead of slicing. |
| 5913 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5914 | // Allocate new sliced string. At this point we do not reload the instance |
| 5915 | // type including the string encoding because we simply rely on the info |
| 5916 | // provided by the original string. It does not matter if the original |
| 5917 | // string's encoding is wrong because we always have to recheck encoding of |
| 5918 | // the newly created string's parent anyways due to externalized strings. |
| 5919 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5920 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5921 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5922 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5923 | __ j(zero, &two_byte_slice, Label::kNear); |
| 5924 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 5925 | __ jmp(&set_slice_header, Label::kNear); |
| 5926 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5927 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5928 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5929 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5930 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 5931 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 5932 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 5933 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5934 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 5935 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5936 | |
| 5937 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5938 | } |
| 5939 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5940 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5941 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5942 | // edx: adjusted start index (smi) |
| 5943 | // ecx: length (smi) |
| 5944 | // The subject string can only be external or sequential string of either |
| 5945 | // encoding at this point. |
| 5946 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 5947 | STATIC_ASSERT(kExternalStringTag != 0); |
| 5948 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5949 | __ test_b(ebx, kExternalStringTag); |
| 5950 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5951 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5952 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5953 | // Rule out short external strings. |
| 5954 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 5955 | __ test_b(ebx, kShortExternalStringMask); |
| 5956 | __ j(not_zero, &runtime); |
| 5957 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 5958 | // 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] | 5959 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5960 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5961 | |
| 5962 | __ bind(&sequential_string); |
| 5963 | // Stash away (adjusted) index and (underlying) string. |
| 5964 | __ push(edx); |
| 5965 | __ push(edi); |
| 5966 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5967 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5968 | __ test_b(ebx, kStringEncodingMask); |
| 5969 | __ j(zero, &two_byte_sequential); |
| 5970 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5971 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5972 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5973 | |
| 5974 | // eax: result string |
| 5975 | // ecx: result string length |
| 5976 | __ mov(edx, esi); // esi used by following code. |
| 5977 | // Locate first character of result. |
| 5978 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5979 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5980 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5981 | __ pop(esi); |
| 5982 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5983 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5984 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5985 | |
| 5986 | // eax: result string |
| 5987 | // ecx: result length |
| 5988 | // edx: original value of esi |
| 5989 | // edi: first character of result |
| 5990 | // esi: character of sub string start |
| 5991 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 5992 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5993 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5994 | __ ret(3 * kPointerSize); |
| 5995 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5996 | __ bind(&two_byte_sequential); |
| 5997 | // Sequential two-byte string. Allocate the result. |
| 5998 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5999 | |
| 6000 | // eax: result string |
| 6001 | // ecx: result string length |
| 6002 | __ mov(edx, esi); // esi used by following code. |
| 6003 | // Locate first character of result. |
| 6004 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6005 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6006 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6007 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6008 | __ pop(esi); |
| 6009 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6010 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6011 | // byte character. |
| 6012 | STATIC_ASSERT(kSmiTag == 0); |
| 6013 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6014 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6015 | |
| 6016 | // eax: result string |
| 6017 | // ecx: result length |
| 6018 | // edx: original value of esi |
| 6019 | // edi: first character of result |
| 6020 | // esi: character of sub string start |
| 6021 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6022 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6023 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6024 | __ ret(3 * kPointerSize); |
| 6025 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6026 | // Drop pushed values on the stack before tail call. |
| 6027 | __ bind(&runtime_drop_two); |
| 6028 | __ Drop(2); |
| 6029 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6030 | // Just jump to runtime to create the sub string. |
| 6031 | __ bind(&runtime); |
| 6032 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6033 | |
| 6034 | __ bind(&single_char); |
| 6035 | // eax: string |
| 6036 | // ebx: instance type |
| 6037 | // ecx: sub string length (smi) |
| 6038 | // edx: from index (smi) |
| 6039 | StringCharAtGenerator generator( |
| 6040 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6041 | generator.GenerateFast(masm); |
| 6042 | __ ret(3 * kPointerSize); |
| 6043 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6044 | } |
| 6045 | |
| 6046 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6047 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6048 | Register left, |
| 6049 | Register right, |
| 6050 | Register scratch1, |
| 6051 | Register scratch2) { |
| 6052 | Register length = scratch1; |
| 6053 | |
| 6054 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6055 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6056 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6057 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6058 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6059 | __ bind(&strings_not_equal); |
| 6060 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6061 | __ ret(0); |
| 6062 | |
| 6063 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6064 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6065 | __ bind(&check_zero_length); |
| 6066 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6067 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6068 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6069 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6070 | __ ret(0); |
| 6071 | |
| 6072 | // Compare characters. |
| 6073 | __ bind(&compare_chars); |
| 6074 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6075 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6076 | |
| 6077 | // Characters are equal. |
| 6078 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6079 | __ ret(0); |
| 6080 | } |
| 6081 | |
| 6082 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6083 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6084 | Register left, |
| 6085 | Register right, |
| 6086 | Register scratch1, |
| 6087 | Register scratch2, |
| 6088 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6089 | Counters* counters = masm->isolate()->counters(); |
| 6090 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6091 | |
| 6092 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6093 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6094 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6095 | __ mov(scratch3, scratch1); |
| 6096 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6097 | |
| 6098 | Register length_delta = scratch3; |
| 6099 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6100 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6101 | // 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] | 6102 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6103 | __ bind(&left_shorter); |
| 6104 | |
| 6105 | Register min_length = scratch1; |
| 6106 | |
| 6107 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6108 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6109 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6110 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6111 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6112 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6113 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6114 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6115 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6116 | |
| 6117 | // Compare lengths - strings up to min-length are equal. |
| 6118 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6119 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6120 | Label length_not_equal; |
| 6121 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6122 | |
| 6123 | // Result is EQUAL. |
| 6124 | STATIC_ASSERT(EQUAL == 0); |
| 6125 | STATIC_ASSERT(kSmiTag == 0); |
| 6126 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6127 | __ ret(0); |
| 6128 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6129 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6130 | Label result_less; |
| 6131 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6132 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6133 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6134 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6135 | __ j(above, &result_greater, Label::kNear); |
| 6136 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6137 | |
| 6138 | // Result is LESS. |
| 6139 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6140 | __ ret(0); |
| 6141 | |
| 6142 | // Result is GREATER. |
| 6143 | __ bind(&result_greater); |
| 6144 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6145 | __ ret(0); |
| 6146 | } |
| 6147 | |
| 6148 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6149 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6150 | MacroAssembler* masm, |
| 6151 | Register left, |
| 6152 | Register right, |
| 6153 | Register length, |
| 6154 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6155 | Label* chars_not_equal, |
| 6156 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6157 | // Change index to run from -length to -1 by adding length to string |
| 6158 | // start. This means that loop ends when index reaches zero, which |
| 6159 | // doesn't need an additional compare. |
| 6160 | __ SmiUntag(length); |
| 6161 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6162 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6163 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6164 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6165 | __ neg(length); |
| 6166 | Register index = length; // index = -length; |
| 6167 | |
| 6168 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6169 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6170 | __ bind(&loop); |
| 6171 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6172 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6173 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6174 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6175 | __ j(not_zero, &loop); |
| 6176 | } |
| 6177 | |
| 6178 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6179 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6180 | Label runtime; |
| 6181 | |
| 6182 | // Stack frame on entry. |
| 6183 | // esp[0]: return address |
| 6184 | // esp[4]: right string |
| 6185 | // esp[8]: left string |
| 6186 | |
| 6187 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6188 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6189 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6190 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6191 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6192 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6193 | STATIC_ASSERT(EQUAL == 0); |
| 6194 | STATIC_ASSERT(kSmiTag == 0); |
| 6195 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6196 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6197 | __ ret(2 * kPointerSize); |
| 6198 | |
| 6199 | __ bind(¬_same); |
| 6200 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6201 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6202 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6203 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6204 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6205 | // Drop arguments from the stack. |
| 6206 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6207 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6208 | __ push(ecx); |
| 6209 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6210 | |
| 6211 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6212 | // tagged as a small integer. |
| 6213 | __ bind(&runtime); |
| 6214 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6215 | } |
| 6216 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6217 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6218 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6219 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6220 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6221 | __ mov(ecx, edx); |
| 6222 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6223 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6224 | |
| 6225 | if (GetCondition() == equal) { |
| 6226 | // 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] | 6227 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6228 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6229 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6230 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6231 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6232 | // Correct sign of result in case of overflow. |
| 6233 | __ not_(edx); |
| 6234 | __ bind(&done); |
| 6235 | __ mov(eax, edx); |
| 6236 | } |
| 6237 | __ ret(0); |
| 6238 | |
| 6239 | __ bind(&miss); |
| 6240 | GenerateMiss(masm); |
| 6241 | } |
| 6242 | |
| 6243 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6244 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6245 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6246 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6247 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6248 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6249 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6250 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6251 | if (left_ == CompareIC::SMI) { |
| 6252 | __ JumpIfNotSmi(edx, &miss); |
| 6253 | } |
| 6254 | if (right_ == CompareIC::SMI) { |
| 6255 | __ JumpIfNotSmi(eax, &miss); |
| 6256 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6257 | |
| 6258 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6259 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6260 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6261 | CpuFeatureScope scope1(masm, SSE2); |
| 6262 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6263 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6264 | // Load left and right operand. |
| 6265 | Label done, left, left_smi, right_smi; |
| 6266 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6267 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6268 | masm->isolate()->factory()->heap_number_map()); |
| 6269 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6270 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6271 | __ jmp(&left, Label::kNear); |
| 6272 | __ bind(&right_smi); |
| 6273 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6274 | __ SmiUntag(ecx); |
| 6275 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6276 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6277 | __ bind(&left); |
| 6278 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6279 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6280 | masm->isolate()->factory()->heap_number_map()); |
| 6281 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6282 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6283 | __ jmp(&done); |
| 6284 | __ bind(&left_smi); |
| 6285 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6286 | __ SmiUntag(ecx); |
| 6287 | __ cvtsi2sd(xmm0, ecx); |
| 6288 | |
| 6289 | __ bind(&done); |
| 6290 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6291 | __ ucomisd(xmm0, xmm1); |
| 6292 | |
| 6293 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6294 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6295 | |
| 6296 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6297 | // Performing mov, because xor would destroy the flag register. |
| 6298 | __ mov(eax, 0); // equal |
| 6299 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6300 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6301 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6302 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6303 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6304 | } else { |
| 6305 | __ mov(ecx, edx); |
| 6306 | __ and_(ecx, eax); |
| 6307 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6308 | |
| 6309 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6310 | masm->isolate()->factory()->heap_number_map()); |
| 6311 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6312 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6313 | masm->isolate()->factory()->heap_number_map()); |
| 6314 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6315 | } |
| 6316 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6317 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6318 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6319 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6320 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6321 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6322 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6323 | __ bind(&maybe_undefined1); |
| 6324 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6325 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6326 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6327 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6328 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6329 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6330 | __ jmp(&unordered); |
| 6331 | } |
| 6332 | |
| 6333 | __ bind(&maybe_undefined2); |
| 6334 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6335 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6336 | __ j(equal, &unordered); |
| 6337 | } |
| 6338 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6339 | __ bind(&miss); |
| 6340 | GenerateMiss(masm); |
| 6341 | } |
| 6342 | |
| 6343 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6344 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 6345 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6346 | ASSERT(GetCondition() == equal); |
| 6347 | |
| 6348 | // Registers containing left and right operands respectively. |
| 6349 | Register left = edx; |
| 6350 | Register right = eax; |
| 6351 | Register tmp1 = ecx; |
| 6352 | Register tmp2 = ebx; |
| 6353 | |
| 6354 | // Check that both operands are heap objects. |
| 6355 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6356 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6357 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6358 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6359 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6360 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6361 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6362 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6363 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6364 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6365 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 6366 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 6367 | __ or_(tmp1, tmp2); |
| 6368 | __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 6369 | __ j(not_zero, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6370 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6371 | // Internalized strings are compared by identity. |
| 6372 | Label done; |
| 6373 | __ cmp(left, right); |
| 6374 | // Make sure eax is non-zero. At this point input operands are |
| 6375 | // guaranteed to be non-zero. |
| 6376 | ASSERT(right.is(eax)); |
| 6377 | __ j(not_equal, &done, Label::kNear); |
| 6378 | STATIC_ASSERT(EQUAL == 0); |
| 6379 | STATIC_ASSERT(kSmiTag == 0); |
| 6380 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6381 | __ bind(&done); |
| 6382 | __ ret(0); |
| 6383 | |
| 6384 | __ bind(&miss); |
| 6385 | GenerateMiss(masm); |
| 6386 | } |
| 6387 | |
| 6388 | |
| 6389 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 6390 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 6391 | ASSERT(GetCondition() == equal); |
| 6392 | |
| 6393 | // Registers containing left and right operands respectively. |
| 6394 | Register left = edx; |
| 6395 | Register right = eax; |
| 6396 | Register tmp1 = ecx; |
| 6397 | Register tmp2 = ebx; |
| 6398 | |
| 6399 | // Check that both operands are heap objects. |
| 6400 | Label miss; |
| 6401 | __ mov(tmp1, left); |
| 6402 | STATIC_ASSERT(kSmiTag == 0); |
| 6403 | __ and_(tmp1, right); |
| 6404 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 6405 | |
| 6406 | // Check that both operands are unique names. This leaves the instance |
| 6407 | // types loaded in tmp1 and tmp2. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6408 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6409 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6410 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6411 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6412 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6413 | __ JumpIfNotUniqueName(tmp1, &miss, Label::kNear); |
| 6414 | __ JumpIfNotUniqueName(tmp2, &miss, Label::kNear); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6415 | |
| 6416 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6417 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6418 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6419 | // Make sure eax is non-zero. At this point input operands are |
| 6420 | // guaranteed to be non-zero. |
| 6421 | ASSERT(right.is(eax)); |
| 6422 | __ j(not_equal, &done, Label::kNear); |
| 6423 | STATIC_ASSERT(EQUAL == 0); |
| 6424 | STATIC_ASSERT(kSmiTag == 0); |
| 6425 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6426 | __ bind(&done); |
| 6427 | __ ret(0); |
| 6428 | |
| 6429 | __ bind(&miss); |
| 6430 | GenerateMiss(masm); |
| 6431 | } |
| 6432 | |
| 6433 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6434 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6435 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6436 | Label miss; |
| 6437 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6438 | bool equality = Token::IsEqualityOp(op_); |
| 6439 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6440 | // Registers containing left and right operands respectively. |
| 6441 | Register left = edx; |
| 6442 | Register right = eax; |
| 6443 | Register tmp1 = ecx; |
| 6444 | Register tmp2 = ebx; |
| 6445 | Register tmp3 = edi; |
| 6446 | |
| 6447 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6448 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6449 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6450 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6451 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6452 | |
| 6453 | // Check that both operands are strings. This leaves the instance |
| 6454 | // types loaded in tmp1 and tmp2. |
| 6455 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6456 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6457 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6458 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6459 | __ mov(tmp3, tmp1); |
| 6460 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6461 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6462 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6463 | __ j(not_zero, &miss); |
| 6464 | |
| 6465 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6466 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6467 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6468 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6469 | STATIC_ASSERT(EQUAL == 0); |
| 6470 | STATIC_ASSERT(kSmiTag == 0); |
| 6471 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6472 | __ ret(0); |
| 6473 | |
| 6474 | // Handle not identical strings. |
| 6475 | __ bind(¬_same); |
| 6476 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6477 | // 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] | 6478 | // 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] | 6479 | // non-equality compare, we still need to determine the order. We |
| 6480 | // also know they are both strings. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6481 | if (equality) { |
| 6482 | Label do_compare; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 6483 | STATIC_ASSERT(kInternalizedTag == 0); |
| 6484 | __ or_(tmp1, tmp2); |
| 6485 | __ test(tmp1, Immediate(kIsNotInternalizedMask)); |
| 6486 | __ j(not_zero, &do_compare, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6487 | // Make sure eax is non-zero. At this point input operands are |
| 6488 | // guaranteed to be non-zero. |
| 6489 | ASSERT(right.is(eax)); |
| 6490 | __ ret(0); |
| 6491 | __ bind(&do_compare); |
| 6492 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6493 | |
| 6494 | // Check that both strings are sequential ASCII. |
| 6495 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6496 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6497 | |
| 6498 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6499 | if (equality) { |
| 6500 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6501 | masm, left, right, tmp1, tmp2); |
| 6502 | } else { |
| 6503 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6504 | masm, left, right, tmp1, tmp2, tmp3); |
| 6505 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6506 | |
| 6507 | // Handle more complex cases in runtime. |
| 6508 | __ bind(&runtime); |
| 6509 | __ pop(tmp1); // Return address. |
| 6510 | __ push(left); |
| 6511 | __ push(right); |
| 6512 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6513 | if (equality) { |
| 6514 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6515 | } else { |
| 6516 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6517 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6518 | |
| 6519 | __ bind(&miss); |
| 6520 | GenerateMiss(masm); |
| 6521 | } |
| 6522 | |
| 6523 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6524 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6525 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6526 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6527 | __ mov(ecx, edx); |
| 6528 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6529 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6530 | |
| 6531 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6532 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6533 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6534 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6535 | |
| 6536 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6537 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6538 | __ ret(0); |
| 6539 | |
| 6540 | __ bind(&miss); |
| 6541 | GenerateMiss(masm); |
| 6542 | } |
| 6543 | |
| 6544 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6545 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6546 | Label miss; |
| 6547 | __ mov(ecx, edx); |
| 6548 | __ and_(ecx, eax); |
| 6549 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6550 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6551 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 6552 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 6553 | __ cmp(ecx, known_map_); |
| 6554 | __ j(not_equal, &miss, Label::kNear); |
| 6555 | __ cmp(ebx, known_map_); |
| 6556 | __ j(not_equal, &miss, Label::kNear); |
| 6557 | |
| 6558 | __ sub(eax, edx); |
| 6559 | __ ret(0); |
| 6560 | |
| 6561 | __ bind(&miss); |
| 6562 | GenerateMiss(masm); |
| 6563 | } |
| 6564 | |
| 6565 | |
| 6566 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6567 | { |
| 6568 | // Call the runtime system in a fresh internal frame. |
| 6569 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 6570 | masm->isolate()); |
| 6571 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6572 | __ push(edx); // Preserve edx and eax. |
| 6573 | __ push(eax); |
| 6574 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6575 | __ push(eax); |
| 6576 | __ push(Immediate(Smi::FromInt(op_))); |
| 6577 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6578 | // Compute the entry point of the rewritten stub. |
| 6579 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 6580 | __ pop(eax); |
| 6581 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6582 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6583 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6584 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6585 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6586 | } |
| 6587 | |
| 6588 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6589 | // Helper function used to check that the dictionary doesn't contain |
| 6590 | // the property. This function may return false negatives, so miss_label |
| 6591 | // must always call a backup property check that is complete. |
| 6592 | // 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] | 6593 | // Name must be a unique name and receiver must be a heap object. |
| 6594 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6595 | Label* miss, |
| 6596 | Label* done, |
| 6597 | Register properties, |
| 6598 | Handle<Name> name, |
| 6599 | Register r0) { |
| 6600 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6601 | |
| 6602 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6603 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6604 | // undefined value), it guarantees the hash table doesn't contain the |
| 6605 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6606 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6607 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6608 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6609 | Register index = r0; |
| 6610 | // Capacity is smi 2^n. |
| 6611 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 6612 | __ dec(index); |
| 6613 | __ and_(index, |
| 6614 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6615 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6616 | |
| 6617 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6618 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6619 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6620 | Register entity_name = r0; |
| 6621 | // Having undefined at this place means the name is not contained. |
| 6622 | ASSERT_EQ(kSmiTagSize, 1); |
| 6623 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 6624 | kElementsStartOffset - kHeapObjectTag)); |
| 6625 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 6626 | __ j(equal, done); |
| 6627 | |
| 6628 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6629 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6630 | __ j(equal, miss); |
| 6631 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6632 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6633 | // Check for the hole and skip. |
| 6634 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6635 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6636 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6637 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6638 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6639 | __ JumpIfNotUniqueName(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6640 | miss); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6641 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6642 | } |
| 6643 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6644 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6645 | __ push(Immediate(Handle<Object>(name))); |
| 6646 | __ push(Immediate(name->Hash())); |
| 6647 | __ CallStub(&stub); |
| 6648 | __ test(r0, r0); |
| 6649 | __ j(not_zero, miss); |
| 6650 | __ jmp(done); |
| 6651 | } |
| 6652 | |
| 6653 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6654 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6655 | // |done| label if a property with the given name is found leaving the |
| 6656 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 6657 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6658 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6659 | Label* miss, |
| 6660 | Label* done, |
| 6661 | Register elements, |
| 6662 | Register name, |
| 6663 | Register r0, |
| 6664 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6665 | ASSERT(!elements.is(r0)); |
| 6666 | ASSERT(!elements.is(r1)); |
| 6667 | ASSERT(!name.is(r0)); |
| 6668 | ASSERT(!name.is(r1)); |
| 6669 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6670 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6671 | |
| 6672 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 6673 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 6674 | __ dec(r1); |
| 6675 | |
| 6676 | // Generate an unrolled loop that performs a few probes before |
| 6677 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6678 | // cover ~93% of loads from dictionaries. |
| 6679 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6680 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6681 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 6682 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6683 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6684 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6685 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6686 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6687 | |
| 6688 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6689 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6690 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 6691 | |
| 6692 | // Check if the key is identical to the name. |
| 6693 | __ cmp(name, Operand(elements, |
| 6694 | r0, |
| 6695 | times_4, |
| 6696 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6697 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6698 | } |
| 6699 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6700 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6701 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6702 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 6703 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6704 | __ push(r0); |
| 6705 | __ CallStub(&stub); |
| 6706 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6707 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6708 | __ j(zero, miss); |
| 6709 | __ jmp(done); |
| 6710 | } |
| 6711 | |
| 6712 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6713 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6714 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 6715 | // 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] | 6716 | // Stack frame on entry: |
| 6717 | // esp[0 * kPointerSize]: return address. |
| 6718 | // esp[1 * kPointerSize]: key's hash. |
| 6719 | // esp[2 * kPointerSize]: key. |
| 6720 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6721 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6722 | // result_: used as scratch. |
| 6723 | // index_: will hold an index of entry if lookup is successful. |
| 6724 | // might alias with result_. |
| 6725 | // Returns: |
| 6726 | // result_ is zero if lookup failed, non zero otherwise. |
| 6727 | |
| 6728 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 6729 | |
| 6730 | Register scratch = result_; |
| 6731 | |
| 6732 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 6733 | __ dec(scratch); |
| 6734 | __ SmiUntag(scratch); |
| 6735 | __ push(scratch); |
| 6736 | |
| 6737 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6738 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6739 | // undefined value), it guarantees the hash table doesn't contain the |
| 6740 | // property. It's true even if some slots represent deleted properties |
| 6741 | // (their names are the null value). |
| 6742 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 6743 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6744 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 6745 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6746 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6747 | } |
| 6748 | __ and_(scratch, Operand(esp, 0)); |
| 6749 | |
| 6750 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6751 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6752 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 6753 | |
| 6754 | // Having undefined at this place means the name is not contained. |
| 6755 | ASSERT_EQ(kSmiTagSize, 1); |
| 6756 | __ mov(scratch, Operand(dictionary_, |
| 6757 | index_, |
| 6758 | times_pointer_size, |
| 6759 | kElementsStartOffset - kHeapObjectTag)); |
| 6760 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 6761 | __ j(equal, ¬_in_dictionary); |
| 6762 | |
| 6763 | // Stop if found the property. |
| 6764 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 6765 | __ j(equal, &in_dictionary); |
| 6766 | |
| 6767 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6768 | // 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] | 6769 | // 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] | 6770 | // key we are looking for. |
| 6771 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6772 | // Check if the entry name is not a unique name. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6773 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6774 | __ JumpIfNotUniqueName(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 6775 | &maybe_in_dictionary); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6776 | } |
| 6777 | } |
| 6778 | |
| 6779 | __ bind(&maybe_in_dictionary); |
| 6780 | // If we are doing negative lookup then probing failure should be |
| 6781 | // treated as a lookup success. For positive lookup probing failure |
| 6782 | // should be treated as lookup failure. |
| 6783 | if (mode_ == POSITIVE_LOOKUP) { |
| 6784 | __ mov(result_, Immediate(0)); |
| 6785 | __ Drop(1); |
| 6786 | __ ret(2 * kPointerSize); |
| 6787 | } |
| 6788 | |
| 6789 | __ bind(&in_dictionary); |
| 6790 | __ mov(result_, Immediate(1)); |
| 6791 | __ Drop(1); |
| 6792 | __ ret(2 * kPointerSize); |
| 6793 | |
| 6794 | __ bind(¬_in_dictionary); |
| 6795 | __ mov(result_, Immediate(0)); |
| 6796 | __ Drop(1); |
| 6797 | __ ret(2 * kPointerSize); |
| 6798 | } |
| 6799 | |
| 6800 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6801 | struct AheadOfTimeWriteBarrierStubList { |
| 6802 | Register object, value, address; |
| 6803 | RememberedSetAction action; |
| 6804 | }; |
| 6805 | |
| 6806 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6807 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 6808 | |
| 6809 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6810 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6811 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6812 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6813 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 6814 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6815 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6816 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6817 | // Used in StoreStubCompiler::CompileStoreField and |
| 6818 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6819 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6820 | // GenerateStoreField calls the stub with two different permutations of |
| 6821 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6822 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6823 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6824 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6825 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6826 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6827 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6828 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 6829 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 6830 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 6831 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6832 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6833 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 6834 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6835 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6836 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 6837 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 6838 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6839 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6840 | // FastNewClosureStub and StringAddStub::Generate |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 6841 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6842 | // StringAddStub::Generate |
| 6843 | { REG(ecx), REG(eax), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6844 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6845 | { 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] | 6846 | }; |
| 6847 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6848 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6849 | |
| 6850 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6851 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6852 | !entry->object.is(no_reg); |
| 6853 | entry++) { |
| 6854 | if (object_.is(entry->object) && |
| 6855 | value_.is(entry->value) && |
| 6856 | address_.is(entry->address) && |
| 6857 | remembered_set_action_ == entry->action && |
| 6858 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 6859 | return true; |
| 6860 | } |
| 6861 | } |
| 6862 | return false; |
| 6863 | } |
| 6864 | |
| 6865 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6866 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 6867 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6868 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
| 6869 | stub.GetCode(isolate)->set_is_pregenerated(true); |
| 6870 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6871 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6872 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6873 | } |
| 6874 | } |
| 6875 | |
| 6876 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6877 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6878 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6879 | !entry->object.is(no_reg); |
| 6880 | entry++) { |
| 6881 | RecordWriteStub stub(entry->object, |
| 6882 | entry->value, |
| 6883 | entry->address, |
| 6884 | entry->action, |
| 6885 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6886 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6887 | } |
| 6888 | } |
| 6889 | |
| 6890 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 6891 | bool CodeStub::CanUseFPRegisters() { |
| 6892 | return CpuFeatures::IsSupported(SSE2); |
| 6893 | } |
| 6894 | |
| 6895 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6896 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 6897 | // the value has just been written into the object, now this stub makes sure |
| 6898 | // we keep the GC informed. The word in the object where the value has been |
| 6899 | // written is in the address register. |
| 6900 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 6901 | Label skip_to_incremental_noncompacting; |
| 6902 | Label skip_to_incremental_compacting; |
| 6903 | |
| 6904 | // The first two instructions are generated with labels so as to get the |
| 6905 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 6906 | // forth between a compare instructions (a nop in this position) and the |
| 6907 | // real branch when we start and stop incremental heap marking. |
| 6908 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 6909 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 6910 | |
| 6911 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 6912 | __ RememberedSetHelper(object_, |
| 6913 | address_, |
| 6914 | value_, |
| 6915 | save_fp_regs_mode_, |
| 6916 | MacroAssembler::kReturnAtEnd); |
| 6917 | } else { |
| 6918 | __ ret(0); |
| 6919 | } |
| 6920 | |
| 6921 | __ bind(&skip_to_incremental_noncompacting); |
| 6922 | GenerateIncremental(masm, INCREMENTAL); |
| 6923 | |
| 6924 | __ bind(&skip_to_incremental_compacting); |
| 6925 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 6926 | |
| 6927 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 6928 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 6929 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 6930 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 6931 | } |
| 6932 | |
| 6933 | |
| 6934 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 6935 | regs_.Save(masm); |
| 6936 | |
| 6937 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 6938 | Label dont_need_remembered_set; |
| 6939 | |
| 6940 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 6941 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 6942 | regs_.scratch0(), |
| 6943 | &dont_need_remembered_set); |
| 6944 | |
| 6945 | __ CheckPageFlag(regs_.object(), |
| 6946 | regs_.scratch0(), |
| 6947 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 6948 | not_zero, |
| 6949 | &dont_need_remembered_set); |
| 6950 | |
| 6951 | // First notify the incremental marker if necessary, then update the |
| 6952 | // remembered set. |
| 6953 | CheckNeedsToInformIncrementalMarker( |
| 6954 | masm, |
| 6955 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 6956 | mode); |
| 6957 | InformIncrementalMarker(masm, mode); |
| 6958 | regs_.Restore(masm); |
| 6959 | __ RememberedSetHelper(object_, |
| 6960 | address_, |
| 6961 | value_, |
| 6962 | save_fp_regs_mode_, |
| 6963 | MacroAssembler::kReturnAtEnd); |
| 6964 | |
| 6965 | __ bind(&dont_need_remembered_set); |
| 6966 | } |
| 6967 | |
| 6968 | CheckNeedsToInformIncrementalMarker( |
| 6969 | masm, |
| 6970 | kReturnOnNoNeedToInformIncrementalMarker, |
| 6971 | mode); |
| 6972 | InformIncrementalMarker(masm, mode); |
| 6973 | regs_.Restore(masm); |
| 6974 | __ ret(0); |
| 6975 | } |
| 6976 | |
| 6977 | |
| 6978 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 6979 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 6980 | int argument_count = 3; |
| 6981 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 6982 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 6983 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6984 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 6985 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6986 | |
| 6987 | AllowExternalCallThatCantCauseGC scope(masm); |
| 6988 | if (mode == INCREMENTAL_COMPACTION) { |
| 6989 | __ CallCFunction( |
| 6990 | ExternalReference::incremental_evacuation_record_write_function( |
| 6991 | masm->isolate()), |
| 6992 | argument_count); |
| 6993 | } else { |
| 6994 | ASSERT(mode == INCREMENTAL); |
| 6995 | __ CallCFunction( |
| 6996 | ExternalReference::incremental_marking_record_write_function( |
| 6997 | masm->isolate()), |
| 6998 | argument_count); |
| 6999 | } |
| 7000 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7001 | } |
| 7002 | |
| 7003 | |
| 7004 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7005 | MacroAssembler* masm, |
| 7006 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7007 | Mode mode) { |
| 7008 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7009 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7010 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7011 | __ and_(regs_.scratch0(), regs_.object()); |
| 7012 | __ mov(regs_.scratch1(), |
| 7013 | Operand(regs_.scratch0(), |
| 7014 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7015 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7016 | __ mov(Operand(regs_.scratch0(), |
| 7017 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7018 | regs_.scratch1()); |
| 7019 | __ j(negative, &need_incremental); |
| 7020 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7021 | // Let's look at the color of the object: If it is not black we don't have |
| 7022 | // to inform the incremental marker. |
| 7023 | __ JumpIfBlack(regs_.object(), |
| 7024 | regs_.scratch0(), |
| 7025 | regs_.scratch1(), |
| 7026 | &object_is_black, |
| 7027 | Label::kNear); |
| 7028 | |
| 7029 | regs_.Restore(masm); |
| 7030 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7031 | __ RememberedSetHelper(object_, |
| 7032 | address_, |
| 7033 | value_, |
| 7034 | save_fp_regs_mode_, |
| 7035 | MacroAssembler::kReturnAtEnd); |
| 7036 | } else { |
| 7037 | __ ret(0); |
| 7038 | } |
| 7039 | |
| 7040 | __ bind(&object_is_black); |
| 7041 | |
| 7042 | // Get the value from the slot. |
| 7043 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7044 | |
| 7045 | if (mode == INCREMENTAL_COMPACTION) { |
| 7046 | Label ensure_not_white; |
| 7047 | |
| 7048 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7049 | regs_.scratch1(), // Scratch. |
| 7050 | MemoryChunk::kEvacuationCandidateMask, |
| 7051 | zero, |
| 7052 | &ensure_not_white, |
| 7053 | Label::kNear); |
| 7054 | |
| 7055 | __ CheckPageFlag(regs_.object(), |
| 7056 | regs_.scratch1(), // Scratch. |
| 7057 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7058 | not_zero, |
| 7059 | &ensure_not_white, |
| 7060 | Label::kNear); |
| 7061 | |
| 7062 | __ jmp(&need_incremental); |
| 7063 | |
| 7064 | __ bind(&ensure_not_white); |
| 7065 | } |
| 7066 | |
| 7067 | // We need an extra register for this, so we push the object register |
| 7068 | // temporarily. |
| 7069 | __ push(regs_.object()); |
| 7070 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7071 | regs_.scratch1(), // Scratch. |
| 7072 | regs_.object(), // Scratch. |
| 7073 | &need_incremental_pop_object, |
| 7074 | Label::kNear); |
| 7075 | __ pop(regs_.object()); |
| 7076 | |
| 7077 | regs_.Restore(masm); |
| 7078 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7079 | __ RememberedSetHelper(object_, |
| 7080 | address_, |
| 7081 | value_, |
| 7082 | save_fp_regs_mode_, |
| 7083 | MacroAssembler::kReturnAtEnd); |
| 7084 | } else { |
| 7085 | __ ret(0); |
| 7086 | } |
| 7087 | |
| 7088 | __ bind(&need_incremental_pop_object); |
| 7089 | __ pop(regs_.object()); |
| 7090 | |
| 7091 | __ bind(&need_incremental); |
| 7092 | |
| 7093 | // Fall through when we need to inform the incremental marker. |
| 7094 | } |
| 7095 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7096 | |
| 7097 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7098 | // ----------- S t a t e ------------- |
| 7099 | // -- eax : element value to store |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7100 | // -- ecx : element index as smi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7101 | // -- esp[0] : return address |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7102 | // -- esp[4] : array literal index in function |
| 7103 | // -- esp[8] : array literal |
| 7104 | // clobbers ebx, edx, edi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7105 | // ----------------------------------- |
| 7106 | |
| 7107 | Label element_done; |
| 7108 | Label double_elements; |
| 7109 | Label smi_element; |
| 7110 | Label slow_elements; |
| 7111 | Label slow_elements_from_double; |
| 7112 | Label fast_elements; |
| 7113 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7114 | // Get array literal index, array literal and its map. |
| 7115 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 7116 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 7117 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 7118 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7119 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7120 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7121 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7122 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7123 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7124 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7125 | // Store into the array literal requires a elements transition. Call into |
| 7126 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7127 | |
| 7128 | __ bind(&slow_elements); |
| 7129 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7130 | // call. |
| 7131 | __ push(ebx); |
| 7132 | __ push(ecx); |
| 7133 | __ push(eax); |
| 7134 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7135 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7136 | __ push(edx); |
| 7137 | __ push(edi); // Return return address so that tail call returns to right |
| 7138 | // place. |
| 7139 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7140 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7141 | __ bind(&slow_elements_from_double); |
| 7142 | __ pop(edx); |
| 7143 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7144 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7145 | // 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] | 7146 | __ bind(&fast_elements); |
| 7147 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7148 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7149 | FixedArrayBase::kHeaderSize)); |
| 7150 | __ mov(Operand(ecx, 0), eax); |
| 7151 | // Update the write barrier for the array store. |
| 7152 | __ RecordWrite(ebx, ecx, eax, |
| 7153 | kDontSaveFPRegs, |
| 7154 | EMIT_REMEMBERED_SET, |
| 7155 | OMIT_SMI_CHECK); |
| 7156 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7157 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7158 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7159 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7160 | __ bind(&smi_element); |
| 7161 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7162 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7163 | FixedArrayBase::kHeaderSize), eax); |
| 7164 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7165 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7166 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7167 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7168 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7169 | __ push(edx); |
| 7170 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7171 | __ StoreNumberToDoubleElements(eax, |
| 7172 | edx, |
| 7173 | ecx, |
| 7174 | edi, |
| 7175 | xmm0, |
| 7176 | &slow_elements_from_double, |
| 7177 | false); |
| 7178 | __ pop(edx); |
| 7179 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7180 | } |
| 7181 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7182 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7183 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7184 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7185 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7186 | int parameter_count_offset = |
| 7187 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7188 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7189 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7190 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7191 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 7192 | ? kPointerSize |
| 7193 | : 0; |
| 7194 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7195 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7196 | } |
| 7197 | |
| 7198 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7199 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7200 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 7201 | // It's always safe to call the entry hook stub, as the hook itself |
| 7202 | // is not allowed to call back to V8. |
| 7203 | AllowStubCallsScope allow_stub_calls(masm, true); |
| 7204 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7205 | ProfileEntryHookStub stub; |
| 7206 | masm->CallStub(&stub); |
| 7207 | } |
| 7208 | } |
| 7209 | |
| 7210 | |
| 7211 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7212 | // Save volatile registers. |
| 7213 | const int kNumSavedRegisters = 3; |
| 7214 | __ push(eax); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7215 | __ push(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7216 | __ push(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7217 | |
| 7218 | // Calculate and push the original stack pointer. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7219 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7220 | __ push(eax); |
| 7221 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7222 | // Retrieve our return address and use it to calculate the calling |
| 7223 | // function's address. |
| 7224 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7225 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7226 | __ push(eax); |
| 7227 | |
| 7228 | // Call the entry hook. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7229 | ASSERT(masm->isolate()->function_entry_hook() != NULL); |
| 7230 | __ call(FUNCTION_ADDR(masm->isolate()->function_entry_hook()), |
| 7231 | RelocInfo::RUNTIME_ENTRY); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7232 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7233 | |
| 7234 | // Restore ecx. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7235 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7236 | __ pop(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7237 | __ pop(eax); |
| 7238 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7239 | __ ret(0); |
| 7240 | } |
| 7241 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7242 | |
| 7243 | template<class T> |
| 7244 | static void CreateArrayDispatch(MacroAssembler* masm) { |
| 7245 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7246 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7247 | for (int i = 0; i <= last_index; ++i) { |
| 7248 | Label next; |
| 7249 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7250 | __ cmp(edx, kind); |
| 7251 | __ j(not_equal, &next); |
| 7252 | T stub(kind); |
| 7253 | __ TailCallStub(&stub); |
| 7254 | __ bind(&next); |
| 7255 | } |
| 7256 | |
| 7257 | // If we reached this point there is a problem. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7258 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7259 | } |
| 7260 | |
| 7261 | |
| 7262 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm) { |
| 7263 | // ebx - type info cell |
| 7264 | // edx - kind |
| 7265 | // eax - number of arguments |
| 7266 | // edi - constructor? |
| 7267 | // esp[0] - return address |
| 7268 | // esp[4] - last argument |
| 7269 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 7270 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 7271 | ASSERT(FAST_ELEMENTS == 2); |
| 7272 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 7273 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 7274 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 7275 | |
| 7276 | Handle<Object> undefined_sentinel( |
| 7277 | masm->isolate()->heap()->undefined_value(), |
| 7278 | masm->isolate()); |
| 7279 | |
| 7280 | // is the low bit set? If so, we are holey and that is good. |
| 7281 | __ test_b(edx, 1); |
| 7282 | Label normal_sequence; |
| 7283 | __ j(not_zero, &normal_sequence); |
| 7284 | |
| 7285 | // look at the first argument |
| 7286 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7287 | __ test(ecx, ecx); |
| 7288 | __ j(zero, &normal_sequence); |
| 7289 | |
| 7290 | // 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] | 7291 | // 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] | 7292 | __ inc(edx); |
| 7293 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7294 | __ j(equal, &normal_sequence); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7295 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
| 7296 | Handle<Map> allocation_site_map( |
| 7297 | masm->isolate()->heap()->allocation_site_map(), |
| 7298 | masm->isolate()); |
| 7299 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 7300 | __ j(not_equal, &normal_sequence); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7301 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7302 | // Save the resulting elements kind in type info |
| 7303 | __ SmiTag(edx); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7304 | __ mov(FieldOperand(ecx, AllocationSite::kTransitionInfoOffset), edx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7305 | __ SmiUntag(edx); |
| 7306 | |
| 7307 | __ bind(&normal_sequence); |
| 7308 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7309 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7310 | for (int i = 0; i <= last_index; ++i) { |
| 7311 | Label next; |
| 7312 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7313 | __ cmp(edx, kind); |
| 7314 | __ j(not_equal, &next); |
| 7315 | ArraySingleArgumentConstructorStub stub(kind); |
| 7316 | __ TailCallStub(&stub); |
| 7317 | __ bind(&next); |
| 7318 | } |
| 7319 | |
| 7320 | // If we reached this point there is a problem. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7321 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7322 | } |
| 7323 | |
| 7324 | |
| 7325 | template<class T> |
| 7326 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 7327 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 7328 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7329 | for (int i = 0; i <= to_index; ++i) { |
| 7330 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7331 | T stub(kind); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7332 | stub.GetCode(isolate)->set_is_pregenerated(true); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7333 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7334 | T stub1(kind, CONTEXT_CHECK_REQUIRED, DISABLE_ALLOCATION_SITES); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7335 | stub1.GetCode(isolate)->set_is_pregenerated(true); |
| 7336 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7337 | } |
| 7338 | } |
| 7339 | |
| 7340 | |
| 7341 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 7342 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 7343 | isolate); |
| 7344 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 7345 | isolate); |
| 7346 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 7347 | isolate); |
| 7348 | } |
| 7349 | |
| 7350 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7351 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 7352 | Isolate* isolate) { |
| 7353 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 7354 | for (int i = 0; i < 2; i++) { |
| 7355 | // For internal arrays we only need a few things |
| 7356 | InternalArrayNoArgumentConstructorStub stubh1(kinds[i]); |
| 7357 | stubh1.GetCode(isolate)->set_is_pregenerated(true); |
| 7358 | InternalArraySingleArgumentConstructorStub stubh2(kinds[i]); |
| 7359 | stubh2.GetCode(isolate)->set_is_pregenerated(true); |
| 7360 | InternalArrayNArgumentsConstructorStub stubh3(kinds[i]); |
| 7361 | stubh3.GetCode(isolate)->set_is_pregenerated(true); |
| 7362 | } |
| 7363 | } |
| 7364 | |
| 7365 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7366 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7367 | // ----------- S t a t e ------------- |
| 7368 | // -- eax : argc (only if argument_count_ == ANY) |
| 7369 | // -- ebx : type info cell |
| 7370 | // -- edi : constructor |
| 7371 | // -- esp[0] : return address |
| 7372 | // -- esp[4] : last argument |
| 7373 | // ----------------------------------- |
| 7374 | Handle<Object> undefined_sentinel( |
| 7375 | masm->isolate()->heap()->undefined_value(), |
| 7376 | masm->isolate()); |
| 7377 | |
| 7378 | if (FLAG_debug_code) { |
| 7379 | // The array construct code is only set for the global and natives |
| 7380 | // builtin Array functions which always have maps. |
| 7381 | |
| 7382 | // Initial map for the builtin Array function should be a map. |
| 7383 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7384 | // Will both indicate a NULL and a Smi. |
| 7385 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7386 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7387 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7388 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7389 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7390 | // We should either have undefined in ebx or a valid cell |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7391 | Label okay_here; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7392 | Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7393 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7394 | __ j(equal, &okay_here); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7395 | __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7396 | __ Assert(equal, kExpectedPropertyCellInRegisterEbx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7397 | __ bind(&okay_here); |
| 7398 | } |
| 7399 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7400 | Label no_info, switch_ready; |
| 7401 | // Get the elements kind and case on that. |
| 7402 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7403 | __ j(equal, &no_info); |
| 7404 | __ mov(edx, FieldOperand(ebx, Cell::kValueOffset)); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7405 | |
| 7406 | // The type cell may have undefined in its value. |
| 7407 | __ cmp(edx, Immediate(undefined_sentinel)); |
| 7408 | __ j(equal, &no_info); |
| 7409 | |
| 7410 | // The type cell has either an AllocationSite or a JSFunction |
| 7411 | __ cmp(FieldOperand(edx, 0), Immediate(Handle<Map>( |
| 7412 | masm->isolate()->heap()->allocation_site_map()))); |
| 7413 | __ j(not_equal, &no_info); |
| 7414 | |
| 7415 | __ mov(edx, FieldOperand(edx, AllocationSite::kTransitionInfoOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7416 | __ SmiUntag(edx); |
| 7417 | __ jmp(&switch_ready); |
| 7418 | __ bind(&no_info); |
| 7419 | __ mov(edx, Immediate(GetInitialFastElementsKind())); |
| 7420 | __ bind(&switch_ready); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7421 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7422 | if (argument_count_ == ANY) { |
| 7423 | Label not_zero_case, not_one_case; |
| 7424 | __ test(eax, eax); |
| 7425 | __ j(not_zero, ¬_zero_case); |
| 7426 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7427 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7428 | __ bind(¬_zero_case); |
| 7429 | __ cmp(eax, 1); |
| 7430 | __ j(greater, ¬_one_case); |
| 7431 | CreateArrayDispatchOneArgument(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7432 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7433 | __ bind(¬_one_case); |
| 7434 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
| 7435 | } else if (argument_count_ == NONE) { |
| 7436 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
| 7437 | } else if (argument_count_ == ONE) { |
| 7438 | CreateArrayDispatchOneArgument(masm); |
| 7439 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 7440 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7441 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7442 | UNREACHABLE(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7443 | } |
| 7444 | } |
| 7445 | |
| 7446 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7447 | void InternalArrayConstructorStub::GenerateCase( |
| 7448 | MacroAssembler* masm, ElementsKind kind) { |
| 7449 | Label not_zero_case, not_one_case; |
| 7450 | Label normal_sequence; |
| 7451 | |
| 7452 | __ test(eax, eax); |
| 7453 | __ j(not_zero, ¬_zero_case); |
| 7454 | InternalArrayNoArgumentConstructorStub stub0(kind); |
| 7455 | __ TailCallStub(&stub0); |
| 7456 | |
| 7457 | __ bind(¬_zero_case); |
| 7458 | __ cmp(eax, 1); |
| 7459 | __ j(greater, ¬_one_case); |
| 7460 | |
| 7461 | if (IsFastPackedElementsKind(kind)) { |
| 7462 | // We might need to create a holey array |
| 7463 | // look at the first argument |
| 7464 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7465 | __ test(ecx, ecx); |
| 7466 | __ j(zero, &normal_sequence); |
| 7467 | |
| 7468 | InternalArraySingleArgumentConstructorStub |
| 7469 | stub1_holey(GetHoleyElementsKind(kind)); |
| 7470 | __ TailCallStub(&stub1_holey); |
| 7471 | } |
| 7472 | |
| 7473 | __ bind(&normal_sequence); |
| 7474 | InternalArraySingleArgumentConstructorStub stub1(kind); |
| 7475 | __ TailCallStub(&stub1); |
| 7476 | |
| 7477 | __ bind(¬_one_case); |
| 7478 | InternalArrayNArgumentsConstructorStub stubN(kind); |
| 7479 | __ TailCallStub(&stubN); |
| 7480 | } |
| 7481 | |
| 7482 | |
| 7483 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7484 | // ----------- S t a t e ------------- |
| 7485 | // -- eax : argc |
| 7486 | // -- ebx : type info cell |
| 7487 | // -- edi : constructor |
| 7488 | // -- esp[0] : return address |
| 7489 | // -- esp[4] : last argument |
| 7490 | // ----------------------------------- |
| 7491 | |
| 7492 | if (FLAG_debug_code) { |
| 7493 | // The array construct code is only set for the global and natives |
| 7494 | // builtin Array functions which always have maps. |
| 7495 | |
| 7496 | // Initial map for the builtin Array function should be a map. |
| 7497 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7498 | // Will both indicate a NULL and a Smi. |
| 7499 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7500 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7501 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7502 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7503 | } |
| 7504 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7505 | // Figure out the right elements kind |
| 7506 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7507 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7508 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 7509 | // but the following masking takes care of that anyway. |
| 7510 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 7511 | // Retrieve elements_kind from bit field 2. |
| 7512 | __ and_(ecx, Map::kElementsKindMask); |
| 7513 | __ shr(ecx, Map::kElementsKindShift); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7514 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7515 | if (FLAG_debug_code) { |
| 7516 | Label done; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7517 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7518 | __ j(equal, &done); |
| 7519 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 7520 | __ Assert(equal, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7521 | kInvalidElementsKindForInternalArrayOrInternalPackedArray); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7522 | __ bind(&done); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7523 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7524 | |
| 7525 | Label fast_elements_case; |
| 7526 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 7527 | __ j(equal, &fast_elements_case); |
| 7528 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 7529 | |
| 7530 | __ bind(&fast_elements_case); |
| 7531 | GenerateCase(masm, FAST_ELEMENTS); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7532 | } |
| 7533 | |
| 7534 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7535 | #undef __ |
| 7536 | |
| 7537 | } } // namespace v8::internal |
| 7538 | |
| 7539 | #endif // V8_TARGET_ARCH_IA32 |