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 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 46 | void ToNumberStub::InitializeInterfaceDescriptor( |
| 47 | Isolate* isolate, |
| 48 | CodeStubInterfaceDescriptor* descriptor) { |
| 49 | static Register registers[] = { eax }; |
| 50 | descriptor->register_param_count_ = 1; |
| 51 | descriptor->register_params_ = registers; |
| 52 | descriptor->deoptimization_handler_ = NULL; |
| 53 | } |
| 54 | |
| 55 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 56 | void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( |
| 57 | Isolate* isolate, |
| 58 | CodeStubInterfaceDescriptor* descriptor) { |
| 59 | static Register registers[] = { eax, ebx, ecx }; |
| 60 | descriptor->register_param_count_ = 3; |
| 61 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 62 | descriptor->deoptimization_handler_ = |
| 63 | Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; |
| 64 | } |
| 65 | |
| 66 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 67 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 68 | Isolate* isolate, |
| 69 | CodeStubInterfaceDescriptor* descriptor) { |
| 70 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 71 | descriptor->register_param_count_ = 4; |
| 72 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 73 | descriptor->deoptimization_handler_ = |
| 74 | Runtime::FunctionForId(Runtime::kCreateObjectLiteralShallow)->entry; |
| 75 | } |
| 76 | |
| 77 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 78 | void CreateAllocationSiteStub::InitializeInterfaceDescriptor( |
| 79 | Isolate* isolate, |
| 80 | CodeStubInterfaceDescriptor* descriptor) { |
| 81 | static Register registers[] = { ebx }; |
| 82 | descriptor->register_param_count_ = 1; |
| 83 | descriptor->register_params_ = registers; |
| 84 | descriptor->deoptimization_handler_ = NULL; |
| 85 | } |
| 86 | |
| 87 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 88 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 89 | Isolate* isolate, |
| 90 | CodeStubInterfaceDescriptor* descriptor) { |
| 91 | static Register registers[] = { edx, ecx }; |
| 92 | descriptor->register_param_count_ = 2; |
| 93 | descriptor->register_params_ = registers; |
| 94 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 95 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 99 | void LoadFieldStub::InitializeInterfaceDescriptor( |
| 100 | Isolate* isolate, |
| 101 | CodeStubInterfaceDescriptor* descriptor) { |
| 102 | static Register registers[] = { edx }; |
| 103 | descriptor->register_param_count_ = 1; |
| 104 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 105 | descriptor->deoptimization_handler_ = NULL; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void KeyedLoadFieldStub::InitializeInterfaceDescriptor( |
| 110 | Isolate* isolate, |
| 111 | CodeStubInterfaceDescriptor* descriptor) { |
| 112 | static Register registers[] = { edx }; |
| 113 | descriptor->register_param_count_ = 1; |
| 114 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 115 | descriptor->deoptimization_handler_ = NULL; |
| 116 | } |
| 117 | |
| 118 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 119 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 120 | Isolate* isolate, |
| 121 | CodeStubInterfaceDescriptor* descriptor) { |
| 122 | static Register registers[] = { edx, ecx, eax }; |
| 123 | descriptor->register_param_count_ = 3; |
| 124 | descriptor->register_params_ = registers; |
| 125 | descriptor->deoptimization_handler_ = |
| 126 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 127 | } |
| 128 | |
| 129 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 130 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 131 | Isolate* isolate, |
| 132 | CodeStubInterfaceDescriptor* descriptor) { |
| 133 | static Register registers[] = { eax, ebx }; |
| 134 | descriptor->register_param_count_ = 2; |
| 135 | descriptor->register_params_ = registers; |
| 136 | descriptor->deoptimization_handler_ = |
| 137 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 138 | } |
| 139 | |
| 140 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 141 | static void InitializeArrayConstructorDescriptor( |
| 142 | Isolate* isolate, |
| 143 | CodeStubInterfaceDescriptor* descriptor, |
| 144 | int constant_stack_parameter_count) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 145 | // register state |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 146 | // eax -- number of arguments |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 147 | // edi -- function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 148 | // ebx -- type info cell with elements kind |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 149 | static Register registers[] = { edi, ebx }; |
| 150 | descriptor->register_param_count_ = 2; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 151 | |
| 152 | if (constant_stack_parameter_count != 0) { |
| 153 | // stack param count needs (constructor pointer, and single argument) |
| 154 | descriptor->stack_parameter_count_ = &eax; |
| 155 | } |
| 156 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 157 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 158 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 159 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 160 | Runtime::FunctionForId(Runtime::kArrayConstructor)->entry; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 164 | static void InitializeInternalArrayConstructorDescriptor( |
| 165 | Isolate* isolate, |
| 166 | CodeStubInterfaceDescriptor* descriptor, |
| 167 | int constant_stack_parameter_count) { |
| 168 | // register state |
| 169 | // eax -- number of arguments |
| 170 | // edi -- constructor function |
| 171 | static Register registers[] = { edi }; |
| 172 | descriptor->register_param_count_ = 1; |
| 173 | |
| 174 | if (constant_stack_parameter_count != 0) { |
| 175 | // stack param count needs (constructor pointer, and single argument) |
| 176 | descriptor->stack_parameter_count_ = &eax; |
| 177 | } |
| 178 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
| 179 | descriptor->register_params_ = registers; |
| 180 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
| 181 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 182 | Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 186 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 187 | Isolate* isolate, |
| 188 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 189 | InitializeArrayConstructorDescriptor(isolate, descriptor, 0); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | |
| 193 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 194 | Isolate* isolate, |
| 195 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 196 | InitializeArrayConstructorDescriptor(isolate, descriptor, 1); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | |
| 200 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 201 | Isolate* isolate, |
| 202 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 203 | InitializeArrayConstructorDescriptor(isolate, descriptor, -1); |
| 204 | } |
| 205 | |
| 206 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 207 | void InternalArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 208 | Isolate* isolate, |
| 209 | CodeStubInterfaceDescriptor* descriptor) { |
| 210 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 0); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | void InternalArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 215 | Isolate* isolate, |
| 216 | CodeStubInterfaceDescriptor* descriptor) { |
| 217 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 1); |
| 218 | } |
| 219 | |
| 220 | |
| 221 | void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 222 | Isolate* isolate, |
| 223 | CodeStubInterfaceDescriptor* descriptor) { |
| 224 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, -1); |
| 225 | } |
| 226 | |
| 227 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 228 | void CompareNilICStub::InitializeInterfaceDescriptor( |
| 229 | Isolate* isolate, |
| 230 | CodeStubInterfaceDescriptor* descriptor) { |
| 231 | static Register registers[] = { eax }; |
| 232 | descriptor->register_param_count_ = 1; |
| 233 | descriptor->register_params_ = registers; |
| 234 | descriptor->deoptimization_handler_ = |
| 235 | FUNCTION_ADDR(CompareNilIC_Miss); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 236 | descriptor->SetMissHandler( |
| 237 | ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 238 | } |
| 239 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 240 | void ToBooleanStub::InitializeInterfaceDescriptor( |
| 241 | Isolate* isolate, |
| 242 | CodeStubInterfaceDescriptor* descriptor) { |
| 243 | static Register registers[] = { eax }; |
| 244 | descriptor->register_param_count_ = 1; |
| 245 | descriptor->register_params_ = registers; |
| 246 | descriptor->deoptimization_handler_ = |
| 247 | FUNCTION_ADDR(ToBooleanIC_Miss); |
| 248 | descriptor->SetMissHandler( |
| 249 | ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate)); |
| 250 | } |
| 251 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 252 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 253 | void StoreGlobalStub::InitializeInterfaceDescriptor( |
| 254 | Isolate* isolate, |
| 255 | CodeStubInterfaceDescriptor* descriptor) { |
| 256 | static Register registers[] = { edx, ecx, eax }; |
| 257 | descriptor->register_param_count_ = 3; |
| 258 | descriptor->register_params_ = registers; |
| 259 | descriptor->deoptimization_handler_ = |
| 260 | FUNCTION_ADDR(StoreIC_MissFromStubFailure); |
| 261 | } |
| 262 | |
| 263 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 264 | void ElementsTransitionAndStoreStub::InitializeInterfaceDescriptor( |
| 265 | Isolate* isolate, |
| 266 | CodeStubInterfaceDescriptor* descriptor) { |
| 267 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 268 | descriptor->register_param_count_ = 4; |
| 269 | descriptor->register_params_ = registers; |
| 270 | descriptor->deoptimization_handler_ = |
| 271 | FUNCTION_ADDR(ElementsTransitionAndStoreIC_Miss); |
| 272 | } |
| 273 | |
| 274 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 275 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 276 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 277 | |
| 278 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
| 279 | // Update the static counter each time a new code stub is generated. |
| 280 | Isolate* isolate = masm->isolate(); |
| 281 | isolate->counters()->code_stubs()->Increment(); |
| 282 | |
| 283 | CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
| 284 | int param_count = descriptor->register_param_count_; |
| 285 | { |
| 286 | // Call the runtime system in a fresh internal frame. |
| 287 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 288 | ASSERT(descriptor->register_param_count_ == 0 || |
| 289 | eax.is(descriptor->register_params_[param_count - 1])); |
| 290 | // Push arguments |
| 291 | for (int i = 0; i < param_count; ++i) { |
| 292 | __ push(descriptor->register_params_[i]); |
| 293 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 294 | ExternalReference miss = descriptor->miss_handler(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 295 | __ CallExternalReference(miss, descriptor->register_param_count_); |
| 296 | } |
| 297 | |
| 298 | __ ret(0); |
| 299 | } |
| 300 | |
| 301 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 302 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 303 | // Create a new closure from the given function info in new |
| 304 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 305 | Counters* counters = masm->isolate()->counters(); |
| 306 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 307 | Label gc; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 308 | __ Allocate(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 309 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 310 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 311 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 312 | // Get the function info from the stack. |
| 313 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 314 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 315 | int map_index = Context::FunctionMapIndex(language_mode_, is_generator_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 316 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 317 | // Compute the function map in the current native context and set that |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 318 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 319 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 320 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 321 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 322 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 323 | |
| 324 | // Initialize the rest of the function. We don't have to update the |
| 325 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 326 | Factory* factory = masm->isolate()->factory(); |
| 327 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 328 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 329 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 330 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 331 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 332 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 333 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 334 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 335 | |
| 336 | // Initialize the code pointer in the function to be the one |
| 337 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 338 | // But first check if there is an optimized version for our context. |
| 339 | Label check_optimized; |
| 340 | Label install_unoptimized; |
| 341 | if (FLAG_cache_optimized_code) { |
| 342 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 343 | __ test(ebx, ebx); |
| 344 | __ j(not_zero, &check_optimized, Label::kNear); |
| 345 | } |
| 346 | __ bind(&install_unoptimized); |
| 347 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 348 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 349 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 350 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 351 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 352 | |
| 353 | // Return and remove the on-stack parameter. |
| 354 | __ ret(1 * kPointerSize); |
| 355 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 356 | __ bind(&check_optimized); |
| 357 | |
| 358 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 359 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 360 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 361 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 362 | // Map must never be empty, so check the first elements. |
| 363 | Label install_optimized; |
| 364 | // Speculatively move code object into edx. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 365 | __ mov(edx, FieldOperand(ebx, SharedFunctionInfo::kFirstCodeSlot)); |
| 366 | __ cmp(ecx, FieldOperand(ebx, SharedFunctionInfo::kFirstContextSlot)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 367 | __ j(equal, &install_optimized); |
| 368 | |
| 369 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 370 | Label loop; |
| 371 | Label restore; |
| 372 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 373 | __ bind(&loop); |
| 374 | // Do not double check first entry. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 375 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kSecondEntryIndex))); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 376 | __ j(equal, &restore); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 377 | __ sub(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 378 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 379 | __ j(not_equal, &loop, Label::kNear); |
| 380 | // Hit: fetch the optimized code. |
| 381 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 382 | |
| 383 | __ bind(&install_optimized); |
| 384 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 385 | |
| 386 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 387 | // map and either unmangle them on marking or do nothing as the whole map is |
| 388 | // discarded on major GC anyway. |
| 389 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 390 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 391 | |
| 392 | // Now link a function into a list of optimized functions. |
| 393 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 394 | |
| 395 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 396 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 397 | |
| 398 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 399 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 400 | // it clobbers all the registers passed. |
| 401 | __ mov(edx, eax); |
| 402 | __ RecordWriteContextSlot( |
| 403 | ecx, |
| 404 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 405 | edx, |
| 406 | ebx, |
| 407 | kDontSaveFPRegs); |
| 408 | |
| 409 | // Return and remove the on-stack parameter. |
| 410 | __ ret(1 * kPointerSize); |
| 411 | |
| 412 | __ bind(&restore); |
| 413 | // Restore SharedFunctionInfo into edx. |
| 414 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 415 | __ jmp(&install_unoptimized); |
| 416 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 417 | // Create a new closure through the slower runtime call. |
| 418 | __ bind(&gc); |
| 419 | __ pop(ecx); // Temporarily remove return address. |
| 420 | __ pop(edx); |
| 421 | __ push(esi); |
| 422 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 423 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 424 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 425 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | |
| 429 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 430 | // Try to allocate the context in new space. |
| 431 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 432 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 433 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 434 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 435 | |
| 436 | // Get the function from the stack. |
| 437 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 438 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 439 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 440 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 441 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 442 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 443 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 444 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 445 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 446 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 447 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 448 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 449 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 450 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 451 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 452 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 453 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 454 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 455 | |
| 456 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 457 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 458 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 459 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 460 | } |
| 461 | |
| 462 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 463 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 464 | __ ret(1 * kPointerSize); |
| 465 | |
| 466 | // Need to collect. Call into runtime system. |
| 467 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 468 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 472 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 473 | // Stack layout on entry: |
| 474 | // |
| 475 | // [esp + (1 * kPointerSize)]: function |
| 476 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 477 | |
| 478 | // Try to allocate the context in new space. |
| 479 | Label gc; |
| 480 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 481 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 482 | |
| 483 | // Get the function or sentinel from the stack. |
| 484 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 485 | |
| 486 | // Get the serialized scope info from the stack. |
| 487 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 488 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 489 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 490 | Factory* factory = masm->isolate()->factory(); |
| 491 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 492 | factory->block_context_map()); |
| 493 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 494 | Immediate(Smi::FromInt(length))); |
| 495 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 496 | // 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] | 497 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 498 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 499 | // we still have to look up. |
| 500 | Label after_sentinel; |
| 501 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 502 | if (FLAG_debug_code) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 503 | __ cmp(ecx, 0); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 504 | __ Assert(equal, kExpected0AsASmiSentinel); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 505 | } |
| 506 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 507 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 508 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 509 | __ bind(&after_sentinel); |
| 510 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 511 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 512 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 513 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 514 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 515 | |
| 516 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 517 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 518 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 519 | |
| 520 | // Initialize the rest of the slots to the hole value. |
| 521 | if (slots_ == 1) { |
| 522 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 523 | factory->the_hole_value()); |
| 524 | } else { |
| 525 | __ mov(ebx, factory->the_hole_value()); |
| 526 | for (int i = 0; i < slots_; i++) { |
| 527 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | // Return and remove the on-stack parameters. |
| 532 | __ mov(esi, eax); |
| 533 | __ ret(2 * kPointerSize); |
| 534 | |
| 535 | // Need to collect. Call into runtime system. |
| 536 | __ bind(&gc); |
| 537 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 538 | } |
| 539 | |
| 540 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 541 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 542 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 543 | // store the registers in any particular way, but we do have to store and |
| 544 | // restore them. |
| 545 | __ pushad(); |
| 546 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 547 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 548 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 549 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 550 | XMMRegister reg = XMMRegister::from_code(i); |
| 551 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 552 | } |
| 553 | } |
| 554 | const int argument_count = 1; |
| 555 | |
| 556 | AllowExternalCallThatCantCauseGC scope(masm); |
| 557 | __ PrepareCallCFunction(argument_count, ecx); |
| 558 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 559 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 560 | __ CallCFunction( |
| 561 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 562 | argument_count); |
| 563 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 564 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 565 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 566 | XMMRegister reg = XMMRegister::from_code(i); |
| 567 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 568 | } |
| 569 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 570 | } |
| 571 | __ popad(); |
| 572 | __ ret(0); |
| 573 | } |
| 574 | |
| 575 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 576 | class FloatingPointHelper : public AllStatic { |
| 577 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 578 | enum ArgLocation { |
| 579 | ARGS_ON_STACK, |
| 580 | ARGS_IN_REGISTERS |
| 581 | }; |
| 582 | |
| 583 | // Code pattern for loading a floating point value. Input value must |
| 584 | // be either a smi or a heap number object (fp value). Requirements: |
| 585 | // operand in register number. Returns operand as floating point number |
| 586 | // on FPU stack. |
| 587 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 588 | |
| 589 | // Code pattern for loading floating point values. Input values must |
| 590 | // be either smi or heap number objects (fp values). Requirements: |
| 591 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 592 | // Returns operands as floating point numbers on FPU stack. |
| 593 | static void LoadFloatOperands(MacroAssembler* masm, |
| 594 | Register scratch, |
| 595 | ArgLocation arg_location = ARGS_ON_STACK); |
| 596 | |
| 597 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 598 | // Expects operands in edx, eax. |
| 599 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 600 | |
| 601 | // Test if operands are smi or number objects (fp). Requirements: |
| 602 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 603 | // operands, jumps to the non_float label otherwise. |
| 604 | static void CheckFloatOperands(MacroAssembler* masm, |
| 605 | Label* non_float, |
| 606 | Register scratch); |
| 607 | |
| 608 | // Takes the operands in edx and eax and loads them as integers in eax |
| 609 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 610 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 611 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 612 | BinaryOpIC::TypeInfo left_type, |
| 613 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 614 | Label* operand_conversion_failure); |
| 615 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 616 | // Assumes that operands are smis or heap numbers and loads them |
| 617 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 618 | // Leaves operands unchanged. |
| 619 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 620 | |
| 621 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 622 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 623 | // either operand is not a number. Operands are in edx and eax. |
| 624 | // Leaves operands unchanged. |
| 625 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 626 | |
| 627 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 628 | // Expects operands in edx, eax. |
| 629 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 630 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 631 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 632 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 633 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 634 | Label* non_int32, |
| 635 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 636 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 637 | Register scratch, |
| 638 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 639 | }; |
| 640 | |
| 641 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 642 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 643 | Register input_reg = this->source(); |
| 644 | Register final_result_reg = this->destination(); |
| 645 | ASSERT(is_truncating()); |
| 646 | |
| 647 | Label check_negative, process_64_bits, done, done_no_stash; |
| 648 | |
| 649 | int double_offset = offset(); |
| 650 | |
| 651 | // Account for return address and saved regs if input is esp. |
| 652 | if (input_reg.is(esp)) double_offset += 3 * kPointerSize; |
| 653 | |
| 654 | MemOperand mantissa_operand(MemOperand(input_reg, double_offset)); |
| 655 | MemOperand exponent_operand(MemOperand(input_reg, |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 656 | double_offset + kDoubleSize / 2)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 657 | |
| 658 | Register scratch1; |
| 659 | { |
| 660 | Register scratch_candidates[3] = { ebx, edx, edi }; |
| 661 | for (int i = 0; i < 3; i++) { |
| 662 | scratch1 = scratch_candidates[i]; |
| 663 | if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break; |
| 664 | } |
| 665 | } |
| 666 | // Since we must use ecx for shifts below, use some other register (eax) |
| 667 | // to calculate the result if ecx is the requested return register. |
| 668 | Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg; |
| 669 | // Save ecx if it isn't the return register and therefore volatile, or if it |
| 670 | // is the return register, then save the temp register we use in its stead for |
| 671 | // the result. |
| 672 | Register save_reg = final_result_reg.is(ecx) ? eax : ecx; |
| 673 | __ push(scratch1); |
| 674 | __ push(save_reg); |
| 675 | |
| 676 | bool stash_exponent_copy = !input_reg.is(esp); |
| 677 | __ mov(scratch1, mantissa_operand); |
| 678 | if (CpuFeatures::IsSupported(SSE3)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 679 | CpuFeatureScope scope(masm, SSE3); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 680 | // Load x87 register with heap number. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 681 | __ fld_d(mantissa_operand); |
| 682 | } |
| 683 | __ mov(ecx, exponent_operand); |
| 684 | if (stash_exponent_copy) __ push(ecx); |
| 685 | |
| 686 | __ and_(ecx, HeapNumber::kExponentMask); |
| 687 | __ shr(ecx, HeapNumber::kExponentShift); |
| 688 | __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias)); |
| 689 | __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits)); |
| 690 | __ j(below, &process_64_bits); |
| 691 | |
| 692 | // Result is entirely in lower 32-bits of mantissa |
| 693 | int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize; |
| 694 | if (CpuFeatures::IsSupported(SSE3)) { |
| 695 | __ fstp(0); |
| 696 | } |
| 697 | __ sub(ecx, Immediate(delta)); |
| 698 | __ xor_(result_reg, result_reg); |
| 699 | __ cmp(ecx, Immediate(31)); |
| 700 | __ j(above, &done); |
| 701 | __ shl_cl(scratch1); |
| 702 | __ jmp(&check_negative); |
| 703 | |
| 704 | __ bind(&process_64_bits); |
| 705 | if (CpuFeatures::IsSupported(SSE3)) { |
| 706 | CpuFeatureScope scope(masm, SSE3); |
| 707 | if (stash_exponent_copy) { |
| 708 | // Already a copy of the exponent on the stack, overwrite it. |
| 709 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 710 | __ sub(esp, Immediate(kDoubleSize / 2)); |
| 711 | } else { |
| 712 | // Reserve space for 64 bit answer. |
| 713 | __ sub(esp, Immediate(kDoubleSize)); // Nolint. |
| 714 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 715 | // Do conversion, which cannot fail because we checked the exponent. |
| 716 | __ fisttp_d(Operand(esp, 0)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 717 | __ mov(result_reg, Operand(esp, 0)); // Load low word of answer as result |
| 718 | __ add(esp, Immediate(kDoubleSize)); |
| 719 | __ jmp(&done_no_stash); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 720 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 721 | // Result must be extracted from shifted 32-bit mantissa |
| 722 | __ sub(ecx, Immediate(delta)); |
| 723 | __ neg(ecx); |
| 724 | if (stash_exponent_copy) { |
| 725 | __ mov(result_reg, MemOperand(esp, 0)); |
| 726 | } else { |
| 727 | __ mov(result_reg, exponent_operand); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 728 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 729 | __ and_(result_reg, |
| 730 | Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32))); |
| 731 | __ add(result_reg, |
| 732 | Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32))); |
| 733 | __ shrd(result_reg, scratch1); |
| 734 | __ shr_cl(result_reg); |
| 735 | __ test(ecx, Immediate(32)); |
| 736 | if (CpuFeatures::IsSupported(CMOV)) { |
| 737 | CpuFeatureScope use_cmov(masm, CMOV); |
| 738 | __ cmov(not_equal, scratch1, result_reg); |
| 739 | } else { |
| 740 | Label skip_mov; |
| 741 | __ j(equal, &skip_mov, Label::kNear); |
| 742 | __ mov(scratch1, result_reg); |
| 743 | __ bind(&skip_mov); |
| 744 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 745 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 746 | |
| 747 | // If the double was negative, negate the integer result. |
| 748 | __ bind(&check_negative); |
| 749 | __ mov(result_reg, scratch1); |
| 750 | __ neg(result_reg); |
| 751 | if (stash_exponent_copy) { |
| 752 | __ cmp(MemOperand(esp, 0), Immediate(0)); |
| 753 | } else { |
| 754 | __ cmp(exponent_operand, Immediate(0)); |
| 755 | } |
| 756 | if (CpuFeatures::IsSupported(CMOV)) { |
| 757 | CpuFeatureScope use_cmov(masm, CMOV); |
| 758 | __ cmov(greater, result_reg, scratch1); |
| 759 | } else { |
| 760 | Label skip_mov; |
| 761 | __ j(less_equal, &skip_mov, Label::kNear); |
| 762 | __ mov(result_reg, scratch1); |
| 763 | __ bind(&skip_mov); |
| 764 | } |
| 765 | |
| 766 | // Restore registers |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 767 | __ bind(&done); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 768 | if (stash_exponent_copy) { |
| 769 | __ add(esp, Immediate(kDoubleSize / 2)); |
| 770 | } |
| 771 | __ bind(&done_no_stash); |
| 772 | if (!final_result_reg.is(result_reg)) { |
| 773 | ASSERT(final_result_reg.is(ecx)); |
| 774 | __ mov(final_result_reg, result_reg); |
| 775 | } |
| 776 | __ pop(save_reg); |
| 777 | __ pop(scratch1); |
| 778 | __ ret(0); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 782 | // Uses SSE2 to convert the heap number in |source| to an integer. Jumps to |
| 783 | // |conversion_failure| if the heap number did not contain an int32 value. |
| 784 | // Result is in ecx. Trashes ebx, xmm0, and xmm1. |
| 785 | static void ConvertHeapNumberToInt32(MacroAssembler* masm, |
| 786 | Register source, |
| 787 | Label* conversion_failure) { |
| 788 | __ movdbl(xmm0, FieldOperand(source, HeapNumber::kValueOffset)); |
| 789 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 790 | masm, conversion_failure, xmm0, ecx, ebx, xmm1); |
| 791 | } |
| 792 | |
| 793 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 794 | void BinaryOpStub::Initialize() { |
| 795 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 796 | } |
| 797 | |
| 798 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 799 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 800 | __ pop(ecx); // Save return address. |
| 801 | __ push(edx); |
| 802 | __ push(eax); |
| 803 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 804 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 805 | |
| 806 | __ push(ecx); // Push return address. |
| 807 | |
| 808 | // Patch the caller to an appropriate specialized stub and return the |
| 809 | // operation result to the caller of the stub. |
| 810 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 811 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 812 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 813 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 814 | 1); |
| 815 | } |
| 816 | |
| 817 | |
| 818 | // Prepare for a type transition runtime call when the args are already on |
| 819 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 820 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 821 | __ pop(ecx); // Save return address. |
| 822 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 823 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 824 | |
| 825 | __ push(ecx); // Push return address. |
| 826 | |
| 827 | // Patch the caller to an appropriate specialized stub and return the |
| 828 | // operation result to the caller of the stub. |
| 829 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 830 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 831 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 832 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 833 | 1); |
| 834 | } |
| 835 | |
| 836 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 837 | static void BinaryOpStub_GenerateRegisterArgsPop(MacroAssembler* masm) { |
| 838 | __ pop(ecx); |
| 839 | __ pop(eax); |
| 840 | __ pop(edx); |
| 841 | __ push(ecx); |
| 842 | } |
| 843 | |
| 844 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 845 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 846 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 847 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 848 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 849 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 850 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 851 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 852 | Comment load_comment(masm, "-- Load arguments"); |
| 853 | Register left = edx; |
| 854 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 855 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 856 | left = eax; |
| 857 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 858 | __ mov(ebx, eax); |
| 859 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 860 | } |
| 861 | |
| 862 | |
| 863 | // 2. Prepare the smi check of both operands by oring them together. |
| 864 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 865 | Label not_smis; |
| 866 | Register combined = ecx; |
| 867 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 868 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 869 | case Token::BIT_OR: |
| 870 | // Perform the operation into eax and smi check the result. Preserve |
| 871 | // eax in case the result is not a smi. |
| 872 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 873 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 874 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 875 | combined = right; |
| 876 | break; |
| 877 | |
| 878 | case Token::BIT_XOR: |
| 879 | case Token::BIT_AND: |
| 880 | case Token::ADD: |
| 881 | case Token::SUB: |
| 882 | case Token::MUL: |
| 883 | case Token::DIV: |
| 884 | case Token::MOD: |
| 885 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 886 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 887 | break; |
| 888 | |
| 889 | case Token::SHL: |
| 890 | case Token::SAR: |
| 891 | case Token::SHR: |
| 892 | // Move the right operand into ecx for the shift operation, use eax |
| 893 | // for the smi check register. |
| 894 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 895 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 896 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 897 | combined = right; |
| 898 | break; |
| 899 | |
| 900 | default: |
| 901 | break; |
| 902 | } |
| 903 | |
| 904 | // 3. Perform the smi check of the operands. |
| 905 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 906 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 907 | |
| 908 | // 4. Operands are both smis, perform the operation leaving the result in |
| 909 | // eax and check the result if necessary. |
| 910 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 911 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 912 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 913 | case Token::BIT_OR: |
| 914 | // Nothing to do. |
| 915 | break; |
| 916 | |
| 917 | case Token::BIT_XOR: |
| 918 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 919 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 920 | break; |
| 921 | |
| 922 | case Token::BIT_AND: |
| 923 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 924 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 925 | break; |
| 926 | |
| 927 | case Token::SHL: |
| 928 | // Remove tags from operands (but keep sign). |
| 929 | __ SmiUntag(left); |
| 930 | __ SmiUntag(ecx); |
| 931 | // Perform the operation. |
| 932 | __ shl_cl(left); |
| 933 | // Check that the *signed* result fits in a smi. |
| 934 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 935 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 936 | // Tag the result and store it in register eax. |
| 937 | __ SmiTag(left); |
| 938 | __ mov(eax, left); |
| 939 | break; |
| 940 | |
| 941 | case Token::SAR: |
| 942 | // Remove tags from operands (but keep sign). |
| 943 | __ SmiUntag(left); |
| 944 | __ SmiUntag(ecx); |
| 945 | // Perform the operation. |
| 946 | __ sar_cl(left); |
| 947 | // Tag the result and store it in register eax. |
| 948 | __ SmiTag(left); |
| 949 | __ mov(eax, left); |
| 950 | break; |
| 951 | |
| 952 | case Token::SHR: |
| 953 | // Remove tags from operands (but keep sign). |
| 954 | __ SmiUntag(left); |
| 955 | __ SmiUntag(ecx); |
| 956 | // Perform the operation. |
| 957 | __ shr_cl(left); |
| 958 | // Check that the *unsigned* result fits in a smi. |
| 959 | // Neither of the two high-order bits can be set: |
| 960 | // - 0x80000000: high bit would be lost when smi tagging. |
| 961 | // - 0x40000000: this number would convert to negative when |
| 962 | // Smi tagging these two cases can only happen with shifts |
| 963 | // by 0 or 1 when handed a valid smi. |
| 964 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 965 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 966 | // Tag the result and store it in register eax. |
| 967 | __ SmiTag(left); |
| 968 | __ mov(eax, left); |
| 969 | break; |
| 970 | |
| 971 | case Token::ADD: |
| 972 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 973 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 974 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 975 | break; |
| 976 | |
| 977 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 978 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 979 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 980 | __ mov(eax, left); |
| 981 | break; |
| 982 | |
| 983 | case Token::MUL: |
| 984 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 985 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 986 | // We can't revert the multiplication if the result is not a smi |
| 987 | // so save the right operand. |
| 988 | __ mov(ebx, right); |
| 989 | // Remove tag from one of the operands (but keep sign). |
| 990 | __ SmiUntag(right); |
| 991 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 992 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 993 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 994 | // Check for negative zero result. Use combined = left | right. |
| 995 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 996 | break; |
| 997 | |
| 998 | case Token::DIV: |
| 999 | // We can't revert the division if the result is not a smi so |
| 1000 | // save the left operand. |
| 1001 | __ mov(edi, left); |
| 1002 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1003 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1004 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1005 | // Sign extend left into edx:eax. |
| 1006 | ASSERT(left.is(eax)); |
| 1007 | __ cdq(); |
| 1008 | // Divide edx:eax by right. |
| 1009 | __ idiv(right); |
| 1010 | // Check for the corner case of dividing the most negative smi by |
| 1011 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1012 | // instruction. |
| 1013 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1014 | __ cmp(eax, 0x40000000); |
| 1015 | __ j(equal, &use_fp_on_smis); |
| 1016 | // Check for negative zero result. Use combined = left | right. |
| 1017 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1018 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1019 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1020 | __ j(not_zero, &use_fp_on_smis); |
| 1021 | // Tag the result and store it in register eax. |
| 1022 | __ SmiTag(eax); |
| 1023 | break; |
| 1024 | |
| 1025 | case Token::MOD: |
| 1026 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1027 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1028 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1029 | |
| 1030 | // Sign extend left into edx:eax. |
| 1031 | ASSERT(left.is(eax)); |
| 1032 | __ cdq(); |
| 1033 | // Divide edx:eax by right. |
| 1034 | __ idiv(right); |
| 1035 | // Check for negative zero result. Use combined = left | right. |
| 1036 | __ NegativeZeroTest(edx, combined, slow); |
| 1037 | // Move remainder to register eax. |
| 1038 | __ mov(eax, edx); |
| 1039 | break; |
| 1040 | |
| 1041 | default: |
| 1042 | UNREACHABLE(); |
| 1043 | } |
| 1044 | |
| 1045 | // 5. Emit return of result in eax. Some operations have registers pushed. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1046 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1047 | case Token::ADD: |
| 1048 | case Token::SUB: |
| 1049 | case Token::MUL: |
| 1050 | case Token::DIV: |
| 1051 | __ ret(0); |
| 1052 | break; |
| 1053 | case Token::MOD: |
| 1054 | case Token::BIT_OR: |
| 1055 | case Token::BIT_AND: |
| 1056 | case Token::BIT_XOR: |
| 1057 | case Token::SAR: |
| 1058 | case Token::SHL: |
| 1059 | case Token::SHR: |
| 1060 | __ ret(2 * kPointerSize); |
| 1061 | break; |
| 1062 | default: |
| 1063 | UNREACHABLE(); |
| 1064 | } |
| 1065 | |
| 1066 | // 6. For some operations emit inline code to perform floating point |
| 1067 | // operations on known smis (e.g., if the result of the operation |
| 1068 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1069 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1070 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1071 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1072 | // Undo the effects of some operations, and some register moves. |
| 1073 | case Token::SHL: |
| 1074 | // The arguments are saved on the stack, and only used from there. |
| 1075 | break; |
| 1076 | case Token::ADD: |
| 1077 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1078 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1079 | break; |
| 1080 | case Token::SUB: |
| 1081 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1082 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1083 | break; |
| 1084 | case Token::MUL: |
| 1085 | // Right was clobbered but a copy is in ebx. |
| 1086 | __ mov(right, ebx); |
| 1087 | break; |
| 1088 | case Token::DIV: |
| 1089 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1090 | // division. They should be in eax, ebx for jump to not_smi. |
| 1091 | __ mov(eax, edi); |
| 1092 | break; |
| 1093 | default: |
| 1094 | // No other operators jump to use_fp_on_smis. |
| 1095 | break; |
| 1096 | } |
| 1097 | __ jmp(¬_smis); |
| 1098 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1099 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1100 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1101 | case Token::SHL: |
| 1102 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1103 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1104 | __ bind(&use_fp_on_smis); |
| 1105 | // Result we want is in left == edx, so we can put the allocated heap |
| 1106 | // number in eax. |
| 1107 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1108 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1109 | // It's OK to overwrite the arguments on the stack because we |
| 1110 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1111 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1112 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1113 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1114 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1115 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1116 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1117 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1118 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1119 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1120 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1121 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1122 | } else { |
| 1123 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1124 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1125 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1126 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1127 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1128 | __ ret(2 * kPointerSize); |
| 1129 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | case Token::ADD: |
| 1133 | case Token::SUB: |
| 1134 | case Token::MUL: |
| 1135 | case Token::DIV: { |
| 1136 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1137 | __ bind(&use_fp_on_smis); |
| 1138 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1139 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1140 | case Token::ADD: |
| 1141 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1142 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1143 | break; |
| 1144 | case Token::SUB: |
| 1145 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1146 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1147 | break; |
| 1148 | case Token::MUL: |
| 1149 | // Right was clobbered but a copy is in ebx. |
| 1150 | __ mov(right, ebx); |
| 1151 | break; |
| 1152 | case Token::DIV: |
| 1153 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1154 | // division. |
| 1155 | __ mov(edx, edi); |
| 1156 | __ mov(eax, right); |
| 1157 | break; |
| 1158 | default: UNREACHABLE(); |
| 1159 | break; |
| 1160 | } |
| 1161 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1162 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1163 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1164 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1165 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1166 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1167 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1168 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1169 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1170 | default: UNREACHABLE(); |
| 1171 | } |
| 1172 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1173 | } else { // SSE2 not available, use FPU. |
| 1174 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1175 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1176 | case Token::ADD: __ faddp(1); break; |
| 1177 | case Token::SUB: __ fsubp(1); break; |
| 1178 | case Token::MUL: __ fmulp(1); break; |
| 1179 | case Token::DIV: __ fdivp(1); break; |
| 1180 | default: UNREACHABLE(); |
| 1181 | } |
| 1182 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1183 | } |
| 1184 | __ mov(eax, ecx); |
| 1185 | __ ret(0); |
| 1186 | break; |
| 1187 | } |
| 1188 | |
| 1189 | default: |
| 1190 | break; |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1195 | // edx and eax. |
| 1196 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1197 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1198 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1199 | case Token::BIT_OR: |
| 1200 | case Token::SHL: |
| 1201 | case Token::SAR: |
| 1202 | case Token::SHR: |
| 1203 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1204 | // check. |
| 1205 | __ mov(eax, ecx); |
| 1206 | break; |
| 1207 | |
| 1208 | case Token::DIV: |
| 1209 | case Token::MOD: |
| 1210 | // Operands are in eax, ebx at this point. |
| 1211 | __ mov(edx, eax); |
| 1212 | __ mov(eax, ebx); |
| 1213 | break; |
| 1214 | |
| 1215 | default: |
| 1216 | break; |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1221 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1222 | Label right_arg_changed, call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1223 | |
| 1224 | switch (op_) { |
| 1225 | case Token::ADD: |
| 1226 | case Token::SUB: |
| 1227 | case Token::MUL: |
| 1228 | case Token::DIV: |
| 1229 | break; |
| 1230 | case Token::MOD: |
| 1231 | case Token::BIT_OR: |
| 1232 | case Token::BIT_AND: |
| 1233 | case Token::BIT_XOR: |
| 1234 | case Token::SAR: |
| 1235 | case Token::SHL: |
| 1236 | case Token::SHR: |
| 1237 | GenerateRegisterArgsPush(masm); |
| 1238 | break; |
| 1239 | default: |
| 1240 | UNREACHABLE(); |
| 1241 | } |
| 1242 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1243 | if (op_ == Token::MOD && encoded_right_arg_.has_value) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1244 | // It is guaranteed that the value will fit into a Smi, because if it |
| 1245 | // didn't, we wouldn't be here, see BinaryOp_Patch. |
| 1246 | __ cmp(eax, Immediate(Smi::FromInt(fixed_right_arg_value()))); |
| 1247 | __ j(not_equal, &right_arg_changed); |
| 1248 | } |
| 1249 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1250 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1251 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1252 | BinaryOpStub_GenerateSmiCode( |
| 1253 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1254 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1255 | BinaryOpStub_GenerateSmiCode( |
| 1256 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1257 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1258 | |
| 1259 | // Code falls through if the result is not returned as either a smi or heap |
| 1260 | // number. |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1261 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1262 | switch (op_) { |
| 1263 | case Token::ADD: |
| 1264 | case Token::SUB: |
| 1265 | case Token::MUL: |
| 1266 | case Token::DIV: |
| 1267 | GenerateTypeTransition(masm); |
| 1268 | break; |
| 1269 | case Token::MOD: |
| 1270 | case Token::BIT_OR: |
| 1271 | case Token::BIT_AND: |
| 1272 | case Token::BIT_XOR: |
| 1273 | case Token::SAR: |
| 1274 | case Token::SHL: |
| 1275 | case Token::SHR: |
| 1276 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1277 | break; |
| 1278 | default: |
| 1279 | UNREACHABLE(); |
| 1280 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1281 | |
| 1282 | __ bind(&call_runtime); |
| 1283 | switch (op_) { |
| 1284 | case Token::ADD: |
| 1285 | case Token::SUB: |
| 1286 | case Token::MUL: |
| 1287 | case Token::DIV: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1288 | break; |
| 1289 | case Token::MOD: |
| 1290 | case Token::BIT_OR: |
| 1291 | case Token::BIT_AND: |
| 1292 | case Token::BIT_XOR: |
| 1293 | case Token::SAR: |
| 1294 | case Token::SHL: |
| 1295 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1296 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1297 | break; |
| 1298 | default: |
| 1299 | UNREACHABLE(); |
| 1300 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1301 | |
| 1302 | { |
| 1303 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1304 | __ push(edx); |
| 1305 | __ push(eax); |
| 1306 | GenerateCallRuntime(masm); |
| 1307 | } |
| 1308 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1312 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1313 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1314 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1315 | ASSERT(op_ == Token::ADD); |
| 1316 | // If both arguments are strings, call the string add stub. |
| 1317 | // Otherwise, do a transition. |
| 1318 | |
| 1319 | // Registers containing left and right operands respectively. |
| 1320 | Register left = edx; |
| 1321 | Register right = eax; |
| 1322 | |
| 1323 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1324 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1325 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1326 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1327 | |
| 1328 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1329 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1330 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1331 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1332 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1333 | StringAddStub string_add_stub( |
| 1334 | (StringAddFlags)(STRING_ADD_CHECK_NONE | STRING_ADD_ERECT_FRAME)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1335 | GenerateRegisterArgsPush(masm); |
| 1336 | __ TailCallStub(&string_add_stub); |
| 1337 | |
| 1338 | __ bind(&call_runtime); |
| 1339 | GenerateTypeTransition(masm); |
| 1340 | } |
| 1341 | |
| 1342 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1343 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1344 | Label* alloc_failure, |
| 1345 | OverwriteMode mode); |
| 1346 | |
| 1347 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1348 | // Input: |
| 1349 | // edx: left operand (tagged) |
| 1350 | // eax: right operand (tagged) |
| 1351 | // Output: |
| 1352 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1353 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1354 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1355 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1356 | |
| 1357 | // Floating point case. |
| 1358 | switch (op_) { |
| 1359 | case Token::ADD: |
| 1360 | case Token::SUB: |
| 1361 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1362 | case Token::DIV: |
| 1363 | case Token::MOD: { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1364 | Label not_floats, not_int32, right_arg_changed; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1365 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1366 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1367 | // It could be that only SMIs have been seen at either the left |
| 1368 | // or the right operand. For precise type feedback, patch the IC |
| 1369 | // again if this changes. |
| 1370 | // In theory, we would need the same check in the non-SSE2 case, |
| 1371 | // but since we don't support Crankshaft on such hardware we can |
| 1372 | // afford not to care about precise type feedback. |
| 1373 | if (left_type_ == BinaryOpIC::SMI) { |
| 1374 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1375 | } |
| 1376 | if (right_type_ == BinaryOpIC::SMI) { |
| 1377 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1378 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1379 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1380 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1381 | masm, ¬_int32, xmm0, ebx, ecx, xmm2); |
| 1382 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1383 | masm, ¬_int32, xmm1, edi, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1384 | if (op_ == Token::MOD) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1385 | if (encoded_right_arg_.has_value) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1386 | __ cmp(edi, Immediate(fixed_right_arg_value())); |
| 1387 | __ j(not_equal, &right_arg_changed); |
| 1388 | } |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1389 | GenerateRegisterArgsPush(masm); |
| 1390 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1391 | } else { |
| 1392 | switch (op_) { |
| 1393 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1394 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1395 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1396 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1397 | default: UNREACHABLE(); |
| 1398 | } |
| 1399 | // Check result type if it is currently Int32. |
| 1400 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1401 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1402 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1403 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1404 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1405 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1406 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1407 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1408 | } else { // SSE2 not available, use FPU. |
| 1409 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1410 | FloatingPointHelper::LoadFloatOperands( |
| 1411 | masm, |
| 1412 | ecx, |
| 1413 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1414 | if (op_ == Token::MOD) { |
| 1415 | // The operands are now on the FPU stack, but we don't need them. |
| 1416 | __ fstp(0); |
| 1417 | __ fstp(0); |
| 1418 | GenerateRegisterArgsPush(masm); |
| 1419 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1420 | } else { |
| 1421 | switch (op_) { |
| 1422 | case Token::ADD: __ faddp(1); break; |
| 1423 | case Token::SUB: __ fsubp(1); break; |
| 1424 | case Token::MUL: __ fmulp(1); break; |
| 1425 | case Token::DIV: __ fdivp(1); break; |
| 1426 | default: UNREACHABLE(); |
| 1427 | } |
| 1428 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1429 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1430 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1431 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1432 | __ ret(0); |
| 1433 | __ bind(&after_alloc_failure); |
| 1434 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1435 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1436 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | __ bind(¬_floats); |
| 1440 | __ bind(¬_int32); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1441 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1442 | GenerateTypeTransition(masm); |
| 1443 | break; |
| 1444 | } |
| 1445 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1446 | case Token::BIT_OR: |
| 1447 | case Token::BIT_AND: |
| 1448 | case Token::BIT_XOR: |
| 1449 | case Token::SAR: |
| 1450 | case Token::SHL: |
| 1451 | case Token::SHR: { |
| 1452 | GenerateRegisterArgsPush(masm); |
| 1453 | Label not_floats; |
| 1454 | Label not_int32; |
| 1455 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1456 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1457 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1458 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1459 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1460 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1461 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1462 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1463 | case Token::SAR: __ sar_cl(eax); break; |
| 1464 | case Token::SHL: __ shl_cl(eax); break; |
| 1465 | case Token::SHR: __ shr_cl(eax); break; |
| 1466 | default: UNREACHABLE(); |
| 1467 | } |
| 1468 | if (op_ == Token::SHR) { |
| 1469 | // Check if result is non-negative and fits in a smi. |
| 1470 | __ test(eax, Immediate(0xc0000000)); |
| 1471 | __ j(not_zero, &call_runtime); |
| 1472 | } else { |
| 1473 | // Check if result fits in a smi. |
| 1474 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1475 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1476 | } |
| 1477 | // Tag smi result and return. |
| 1478 | __ SmiTag(eax); |
| 1479 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1480 | |
| 1481 | // All ops except SHR return a signed int32 that we load in |
| 1482 | // a HeapNumber. |
| 1483 | if (op_ != Token::SHR) { |
| 1484 | __ bind(&non_smi_result); |
| 1485 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1486 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1487 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1488 | switch (mode_) { |
| 1489 | case OVERWRITE_LEFT: |
| 1490 | case OVERWRITE_RIGHT: |
| 1491 | // If the operand was an object, we skip the |
| 1492 | // allocation of a heap number. |
| 1493 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1494 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1495 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1496 | // Fall through! |
| 1497 | case NO_OVERWRITE: |
| 1498 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1499 | __ bind(&skip_allocation); |
| 1500 | break; |
| 1501 | default: UNREACHABLE(); |
| 1502 | } |
| 1503 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1504 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1505 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1506 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1507 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1508 | } else { |
| 1509 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1510 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1511 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1512 | } |
| 1513 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1514 | } |
| 1515 | |
| 1516 | __ bind(¬_floats); |
| 1517 | __ bind(¬_int32); |
| 1518 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1519 | break; |
| 1520 | } |
| 1521 | default: UNREACHABLE(); break; |
| 1522 | } |
| 1523 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1524 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1525 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1526 | __ bind(&call_runtime); |
| 1527 | |
| 1528 | switch (op_) { |
| 1529 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1530 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1531 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1532 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1533 | break; |
| 1534 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1535 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1536 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1537 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1538 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1539 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1540 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1541 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1542 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1543 | break; |
| 1544 | default: |
| 1545 | UNREACHABLE(); |
| 1546 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1547 | |
| 1548 | { |
| 1549 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1550 | __ push(edx); |
| 1551 | __ push(eax); |
| 1552 | GenerateCallRuntime(masm); |
| 1553 | } |
| 1554 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1558 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1559 | if (op_ == Token::ADD) { |
| 1560 | // Handle string addition here, because it is the only operation |
| 1561 | // that does not do a ToNumber conversion on the operands. |
| 1562 | GenerateAddStrings(masm); |
| 1563 | } |
| 1564 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1565 | Factory* factory = masm->isolate()->factory(); |
| 1566 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1567 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1568 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1569 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1570 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1571 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1572 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1573 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1574 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1575 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1576 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1577 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1578 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1579 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1580 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1581 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1582 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1583 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1584 | } |
| 1585 | __ bind(&done); |
| 1586 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1587 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1591 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1592 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1593 | |
| 1594 | // Floating point case. |
| 1595 | switch (op_) { |
| 1596 | case Token::ADD: |
| 1597 | case Token::SUB: |
| 1598 | case Token::MUL: |
| 1599 | case Token::DIV: { |
| 1600 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1601 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1602 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1603 | |
| 1604 | // It could be that only SMIs have been seen at either the left |
| 1605 | // or the right operand. For precise type feedback, patch the IC |
| 1606 | // again if this changes. |
| 1607 | // In theory, we would need the same check in the non-SSE2 case, |
| 1608 | // but since we don't support Crankshaft on such hardware we can |
| 1609 | // afford not to care about precise type feedback. |
| 1610 | if (left_type_ == BinaryOpIC::SMI) { |
| 1611 | __ JumpIfNotSmi(edx, ¬_floats); |
| 1612 | } |
| 1613 | if (right_type_ == BinaryOpIC::SMI) { |
| 1614 | __ JumpIfNotSmi(eax, ¬_floats); |
| 1615 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1616 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1617 | if (left_type_ == BinaryOpIC::INT32) { |
| 1618 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1619 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1620 | } |
| 1621 | if (right_type_ == BinaryOpIC::INT32) { |
| 1622 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1623 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1624 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1625 | |
| 1626 | switch (op_) { |
| 1627 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1628 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1629 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1630 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1631 | default: UNREACHABLE(); |
| 1632 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1633 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1634 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1635 | __ ret(0); |
| 1636 | } else { // SSE2 not available, use FPU. |
| 1637 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1638 | FloatingPointHelper::LoadFloatOperands( |
| 1639 | masm, |
| 1640 | ecx, |
| 1641 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1642 | switch (op_) { |
| 1643 | case Token::ADD: __ faddp(1); break; |
| 1644 | case Token::SUB: __ fsubp(1); break; |
| 1645 | case Token::MUL: __ fmulp(1); break; |
| 1646 | case Token::DIV: __ fdivp(1); break; |
| 1647 | default: UNREACHABLE(); |
| 1648 | } |
| 1649 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1650 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1651 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1652 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1653 | __ ret(0); |
| 1654 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1655 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1656 | __ jmp(&call_runtime); |
| 1657 | } |
| 1658 | |
| 1659 | __ bind(¬_floats); |
| 1660 | GenerateTypeTransition(masm); |
| 1661 | break; |
| 1662 | } |
| 1663 | |
| 1664 | case Token::MOD: { |
| 1665 | // For MOD we go directly to runtime in the non-smi case. |
| 1666 | break; |
| 1667 | } |
| 1668 | case Token::BIT_OR: |
| 1669 | case Token::BIT_AND: |
| 1670 | case Token::BIT_XOR: |
| 1671 | case Token::SAR: |
| 1672 | case Token::SHL: |
| 1673 | case Token::SHR: { |
| 1674 | GenerateRegisterArgsPush(masm); |
| 1675 | Label not_floats; |
| 1676 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1677 | // We do not check the input arguments here, as any value is |
| 1678 | // unconditionally truncated to an int32 anyway. To get the |
| 1679 | // right optimized code, int32 type feedback is just right. |
| 1680 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1681 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1682 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1683 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1684 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1685 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1686 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1687 | case Token::SAR: __ sar_cl(eax); break; |
| 1688 | case Token::SHL: __ shl_cl(eax); break; |
| 1689 | case Token::SHR: __ shr_cl(eax); break; |
| 1690 | default: UNREACHABLE(); |
| 1691 | } |
| 1692 | if (op_ == Token::SHR) { |
| 1693 | // Check if result is non-negative and fits in a smi. |
| 1694 | __ test(eax, Immediate(0xc0000000)); |
| 1695 | __ j(not_zero, &call_runtime); |
| 1696 | } else { |
| 1697 | // Check if result fits in a smi. |
| 1698 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1699 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1700 | } |
| 1701 | // Tag smi result and return. |
| 1702 | __ SmiTag(eax); |
| 1703 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1704 | |
| 1705 | // All ops except SHR return a signed int32 that we load in |
| 1706 | // a HeapNumber. |
| 1707 | if (op_ != Token::SHR) { |
| 1708 | __ bind(&non_smi_result); |
| 1709 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1710 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1711 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1712 | switch (mode_) { |
| 1713 | case OVERWRITE_LEFT: |
| 1714 | case OVERWRITE_RIGHT: |
| 1715 | // If the operand was an object, we skip the |
| 1716 | // allocation of a heap number. |
| 1717 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1718 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1719 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1720 | // Fall through! |
| 1721 | case NO_OVERWRITE: |
| 1722 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1723 | __ bind(&skip_allocation); |
| 1724 | break; |
| 1725 | default: UNREACHABLE(); |
| 1726 | } |
| 1727 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1728 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1729 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1730 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1731 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1732 | } else { |
| 1733 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1734 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1735 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1736 | } |
| 1737 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1738 | } |
| 1739 | |
| 1740 | __ bind(¬_floats); |
| 1741 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1742 | break; |
| 1743 | } |
| 1744 | default: UNREACHABLE(); break; |
| 1745 | } |
| 1746 | |
| 1747 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 1748 | // use the runtime system to get the correct result. |
| 1749 | __ bind(&call_runtime); |
| 1750 | |
| 1751 | switch (op_) { |
| 1752 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1753 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1754 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1755 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1756 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1757 | break; |
| 1758 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1759 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1760 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1761 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1762 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1763 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1764 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1765 | break; |
| 1766 | default: |
| 1767 | UNREACHABLE(); |
| 1768 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1769 | |
| 1770 | { |
| 1771 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1772 | __ push(edx); |
| 1773 | __ push(eax); |
| 1774 | GenerateCallRuntime(masm); |
| 1775 | } |
| 1776 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1777 | } |
| 1778 | |
| 1779 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1780 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1781 | Label call_runtime; |
| 1782 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1783 | Counters* counters = masm->isolate()->counters(); |
| 1784 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1785 | |
| 1786 | switch (op_) { |
| 1787 | case Token::ADD: |
| 1788 | case Token::SUB: |
| 1789 | case Token::MUL: |
| 1790 | case Token::DIV: |
| 1791 | break; |
| 1792 | case Token::MOD: |
| 1793 | case Token::BIT_OR: |
| 1794 | case Token::BIT_AND: |
| 1795 | case Token::BIT_XOR: |
| 1796 | case Token::SAR: |
| 1797 | case Token::SHL: |
| 1798 | case Token::SHR: |
| 1799 | GenerateRegisterArgsPush(masm); |
| 1800 | break; |
| 1801 | default: |
| 1802 | UNREACHABLE(); |
| 1803 | } |
| 1804 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1805 | BinaryOpStub_GenerateSmiCode( |
| 1806 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1807 | |
| 1808 | // Floating point case. |
| 1809 | switch (op_) { |
| 1810 | case Token::ADD: |
| 1811 | case Token::SUB: |
| 1812 | case Token::MUL: |
| 1813 | case Token::DIV: { |
| 1814 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1815 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1816 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1817 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1818 | |
| 1819 | switch (op_) { |
| 1820 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1821 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1822 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1823 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1824 | default: UNREACHABLE(); |
| 1825 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1826 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1827 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1828 | __ ret(0); |
| 1829 | } else { // SSE2 not available, use FPU. |
| 1830 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1831 | FloatingPointHelper::LoadFloatOperands( |
| 1832 | masm, |
| 1833 | ecx, |
| 1834 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1835 | switch (op_) { |
| 1836 | case Token::ADD: __ faddp(1); break; |
| 1837 | case Token::SUB: __ fsubp(1); break; |
| 1838 | case Token::MUL: __ fmulp(1); break; |
| 1839 | case Token::DIV: __ fdivp(1); break; |
| 1840 | default: UNREACHABLE(); |
| 1841 | } |
| 1842 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1843 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1844 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1845 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1846 | __ ret(0); |
| 1847 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1848 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1849 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1850 | } |
| 1851 | __ bind(¬_floats); |
| 1852 | break; |
| 1853 | } |
| 1854 | case Token::MOD: { |
| 1855 | // For MOD we go directly to runtime in the non-smi case. |
| 1856 | break; |
| 1857 | } |
| 1858 | case Token::BIT_OR: |
| 1859 | case Token::BIT_AND: |
| 1860 | case Token::BIT_XOR: |
| 1861 | case Token::SAR: |
| 1862 | case Token::SHL: |
| 1863 | case Token::SHR: { |
| 1864 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1865 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1866 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1867 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1868 | BinaryOpIC::GENERIC, |
| 1869 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1870 | &call_runtime); |
| 1871 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1872 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1873 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1874 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1875 | case Token::SAR: __ sar_cl(eax); break; |
| 1876 | case Token::SHL: __ shl_cl(eax); break; |
| 1877 | case Token::SHR: __ shr_cl(eax); break; |
| 1878 | default: UNREACHABLE(); |
| 1879 | } |
| 1880 | if (op_ == Token::SHR) { |
| 1881 | // Check if result is non-negative and fits in a smi. |
| 1882 | __ test(eax, Immediate(0xc0000000)); |
| 1883 | __ j(not_zero, &call_runtime); |
| 1884 | } else { |
| 1885 | // Check if result fits in a smi. |
| 1886 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1887 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1888 | } |
| 1889 | // Tag smi result and return. |
| 1890 | __ SmiTag(eax); |
| 1891 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 1892 | |
| 1893 | // All ops except SHR return a signed int32 that we load in |
| 1894 | // a HeapNumber. |
| 1895 | if (op_ != Token::SHR) { |
| 1896 | __ bind(&non_smi_result); |
| 1897 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1898 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1899 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1900 | switch (mode_) { |
| 1901 | case OVERWRITE_LEFT: |
| 1902 | case OVERWRITE_RIGHT: |
| 1903 | // If the operand was an object, we skip the |
| 1904 | // allocation of a heap number. |
| 1905 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1906 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1907 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1908 | // Fall through! |
| 1909 | case NO_OVERWRITE: |
| 1910 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1911 | __ bind(&skip_allocation); |
| 1912 | break; |
| 1913 | default: UNREACHABLE(); |
| 1914 | } |
| 1915 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1916 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1917 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1918 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1919 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1920 | } else { |
| 1921 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1922 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1923 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1924 | } |
| 1925 | __ ret(2 * kPointerSize); |
| 1926 | } |
| 1927 | break; |
| 1928 | } |
| 1929 | default: UNREACHABLE(); break; |
| 1930 | } |
| 1931 | |
| 1932 | // If all else fails, use the runtime system to get the correct |
| 1933 | // result. |
| 1934 | __ bind(&call_runtime); |
| 1935 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1936 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1937 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1938 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1939 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1940 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1941 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1942 | break; |
| 1943 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1944 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1945 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1946 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1947 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1948 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1949 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1950 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1951 | break; |
| 1952 | default: |
| 1953 | UNREACHABLE(); |
| 1954 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1955 | |
| 1956 | { |
| 1957 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1958 | __ push(edx); |
| 1959 | __ push(eax); |
| 1960 | GenerateCallRuntime(masm); |
| 1961 | } |
| 1962 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1966 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1967 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1968 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1969 | |
| 1970 | // Registers containing left and right operands respectively. |
| 1971 | Register left = edx; |
| 1972 | Register right = eax; |
| 1973 | |
| 1974 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1975 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1976 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1977 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1978 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1979 | StringAddStub string_add_left_stub( |
| 1980 | (StringAddFlags)(STRING_ADD_CHECK_RIGHT | STRING_ADD_ERECT_FRAME)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1981 | GenerateRegisterArgsPush(masm); |
| 1982 | __ TailCallStub(&string_add_left_stub); |
| 1983 | |
| 1984 | // Left operand is not a string, test right. |
| 1985 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1986 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1987 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1988 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1989 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1990 | StringAddStub string_add_right_stub( |
| 1991 | (StringAddFlags)(STRING_ADD_CHECK_LEFT | STRING_ADD_ERECT_FRAME)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1992 | GenerateRegisterArgsPush(masm); |
| 1993 | __ TailCallStub(&string_add_right_stub); |
| 1994 | |
| 1995 | // Neither argument is a string. |
| 1996 | __ bind(&call_runtime); |
| 1997 | } |
| 1998 | |
| 1999 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2000 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2001 | Label* alloc_failure, |
| 2002 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2003 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2004 | switch (mode) { |
| 2005 | case OVERWRITE_LEFT: { |
| 2006 | // If the argument in edx is already an object, we skip the |
| 2007 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2008 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2009 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2010 | // for the possible runtime call. |
| 2011 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2012 | // Now edx can be overwritten losing one of the arguments as we are |
| 2013 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2014 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2015 | __ bind(&skip_allocation); |
| 2016 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2017 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2018 | break; |
| 2019 | } |
| 2020 | case OVERWRITE_RIGHT: |
| 2021 | // If the argument in eax is already an object, we skip the |
| 2022 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2023 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2024 | // Fall through! |
| 2025 | case NO_OVERWRITE: |
| 2026 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2027 | // for the possible runtime call. |
| 2028 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2029 | // Now eax can be overwritten losing one of the arguments as we are |
| 2030 | // now done and will not need it any more. |
| 2031 | __ mov(eax, ebx); |
| 2032 | __ bind(&skip_allocation); |
| 2033 | break; |
| 2034 | default: UNREACHABLE(); |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2039 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2040 | __ pop(ecx); |
| 2041 | __ push(edx); |
| 2042 | __ push(eax); |
| 2043 | __ push(ecx); |
| 2044 | } |
| 2045 | |
| 2046 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2047 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2048 | // TAGGED case: |
| 2049 | // Input: |
| 2050 | // esp[4]: tagged number input argument (should be number). |
| 2051 | // esp[0]: return address. |
| 2052 | // Output: |
| 2053 | // eax: tagged double result. |
| 2054 | // UNTAGGED case: |
| 2055 | // Input:: |
| 2056 | // esp[0]: return address. |
| 2057 | // xmm1: untagged double input argument |
| 2058 | // Output: |
| 2059 | // xmm1: untagged double result. |
| 2060 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2061 | Label runtime_call; |
| 2062 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2063 | Label skip_cache; |
| 2064 | const bool tagged = (argument_type_ == TAGGED); |
| 2065 | if (tagged) { |
| 2066 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2067 | Label input_not_smi; |
| 2068 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2069 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2070 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2071 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2072 | // Then load the low and high words of the double into ebx, edx. |
| 2073 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2074 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2075 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2076 | __ mov(Operand(esp, 0), eax); |
| 2077 | __ fild_s(Operand(esp, 0)); |
| 2078 | __ fst_d(Operand(esp, 0)); |
| 2079 | __ pop(edx); |
| 2080 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2081 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2082 | __ bind(&input_not_smi); |
| 2083 | // Check if input is a HeapNumber. |
| 2084 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2085 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2086 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2087 | __ j(not_equal, &runtime_call); |
| 2088 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2089 | // low and high words into ebx, edx. |
| 2090 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2091 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2092 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2093 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2094 | __ bind(&loaded); |
| 2095 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2096 | CpuFeatureScope scope(masm, SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2097 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2098 | CpuFeatureScope sse4_scope(masm, SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2099 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2100 | } else { |
| 2101 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2102 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2103 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2104 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2108 | // ebx = low 32 bits of double value |
| 2109 | // edx = high 32 bits of double value |
| 2110 | // Compute hash (the shifts are arithmetic): |
| 2111 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2112 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2113 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2114 | __ mov(eax, ecx); |
| 2115 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2116 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2117 | __ mov(eax, ecx); |
| 2118 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2119 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2120 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2121 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2122 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2123 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2124 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2125 | // ebx = low 32 bits of double value. |
| 2126 | // edx = high 32 bits of double value. |
| 2127 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2128 | ExternalReference cache_array = |
| 2129 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2130 | __ mov(eax, Immediate(cache_array)); |
| 2131 | int cache_array_index = |
| 2132 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2133 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2134 | // Eax points to the cache for the type type_. |
| 2135 | // If NULL, the cache hasn't been initialized yet, so go through runtime. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2136 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2137 | __ j(zero, &runtime_call_clear_stack); |
| 2138 | #ifdef DEBUG |
| 2139 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2140 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2141 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2142 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2143 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2144 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2145 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2146 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2147 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2148 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2149 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2150 | } |
| 2151 | #endif |
| 2152 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2153 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2154 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2155 | // Check if cache matches: Double value is stored in uint32_t[2] array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2156 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2157 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2158 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2159 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2160 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2161 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2162 | Counters* counters = masm->isolate()->counters(); |
| 2163 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2164 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2165 | if (tagged) { |
| 2166 | __ fstp(0); |
| 2167 | __ ret(kPointerSize); |
| 2168 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2169 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2170 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2171 | __ Ret(); |
| 2172 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2173 | |
| 2174 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2175 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2176 | // Update cache with new value. |
| 2177 | // We are short on registers, so use no_reg as scratch. |
| 2178 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2179 | if (tagged) { |
| 2180 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2181 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2182 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2183 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2184 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2185 | __ movdbl(Operand(esp, 0), xmm1); |
| 2186 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2187 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2188 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2189 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2190 | __ mov(Operand(ecx, 0), ebx); |
| 2191 | __ mov(Operand(ecx, kIntSize), edx); |
| 2192 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2193 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2194 | if (tagged) { |
| 2195 | __ ret(kPointerSize); |
| 2196 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2197 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2198 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2199 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2200 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2201 | // Skip cache and return answer directly, only in untagged case. |
| 2202 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2203 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2204 | __ movdbl(Operand(esp, 0), xmm1); |
| 2205 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2206 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2207 | __ fstp_d(Operand(esp, 0)); |
| 2208 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2209 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2210 | // We return the value in xmm1 without adding it to the cache, but |
| 2211 | // we cause a scavenging GC so that future allocations will succeed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2212 | { |
| 2213 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2214 | // Allocate an unused object bigger than a HeapNumber. |
| 2215 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2216 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2217 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2218 | __ Ret(); |
| 2219 | } |
| 2220 | |
| 2221 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2222 | if (tagged) { |
| 2223 | __ bind(&runtime_call_clear_stack); |
| 2224 | __ fstp(0); |
| 2225 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2226 | ExternalReference runtime = |
| 2227 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2228 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2229 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2230 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2231 | __ bind(&runtime_call_clear_stack); |
| 2232 | __ bind(&runtime_call); |
| 2233 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2234 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2235 | { |
| 2236 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2237 | __ push(eax); |
| 2238 | __ CallRuntime(RuntimeFunction(), 1); |
| 2239 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2240 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2241 | __ Ret(); |
| 2242 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2243 | } |
| 2244 | |
| 2245 | |
| 2246 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2247 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2248 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2249 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2250 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2251 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2252 | default: |
| 2253 | UNIMPLEMENTED(); |
| 2254 | return Runtime::kAbort; |
| 2255 | } |
| 2256 | } |
| 2257 | |
| 2258 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2259 | void TranscendentalCacheStub::GenerateOperation( |
| 2260 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2261 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2262 | // Input value is on FP stack, and also in ebx/edx. |
| 2263 | // Input value is possibly in xmm1. |
| 2264 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2265 | if (type == TranscendentalCache::SIN || |
| 2266 | type == TranscendentalCache::COS || |
| 2267 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2268 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2269 | // return NaN for infinities and NaN. They can share all code except |
| 2270 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2271 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2272 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2273 | // work. We must reduce it to the appropriate range. |
| 2274 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2275 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2276 | int supported_exponent_limit = |
| 2277 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2278 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2279 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2280 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2281 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2282 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2283 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2284 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2285 | __ fstp(0); |
| 2286 | // NaN is represented by 0x7ff8000000000000. |
| 2287 | __ push(Immediate(0x7ff80000)); |
| 2288 | __ push(Immediate(0)); |
| 2289 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2290 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2291 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2292 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2293 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2294 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2295 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2296 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2297 | __ fldpi(); |
| 2298 | __ fadd(0); |
| 2299 | __ fld(1); |
| 2300 | // FPU Stack: input, 2*pi, input. |
| 2301 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2302 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2303 | __ fwait(); |
| 2304 | __ fnstsw_ax(); |
| 2305 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2306 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2307 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2308 | __ fnclex(); |
| 2309 | __ bind(&no_exceptions); |
| 2310 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2311 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2312 | // Compute st(0) % st(1) |
| 2313 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2314 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2315 | __ bind(&partial_remainder_loop); |
| 2316 | __ fprem1(); |
| 2317 | __ fwait(); |
| 2318 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2319 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2320 | // If C2 is set, computation only has partial result. Loop to |
| 2321 | // continue computation. |
| 2322 | __ j(not_zero, &partial_remainder_loop); |
| 2323 | } |
| 2324 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2325 | __ fstp(2); |
| 2326 | __ fstp(0); |
| 2327 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2328 | |
| 2329 | // FPU Stack: input % 2*pi |
| 2330 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2331 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2332 | case TranscendentalCache::SIN: |
| 2333 | __ fsin(); |
| 2334 | break; |
| 2335 | case TranscendentalCache::COS: |
| 2336 | __ fcos(); |
| 2337 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2338 | case TranscendentalCache::TAN: |
| 2339 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2340 | // FP register stack. |
| 2341 | __ fptan(); |
| 2342 | __ fstp(0); // Pop FP register stack. |
| 2343 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2344 | default: |
| 2345 | UNREACHABLE(); |
| 2346 | } |
| 2347 | __ bind(&done); |
| 2348 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2349 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2350 | __ fldln2(); |
| 2351 | __ fxch(); |
| 2352 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2353 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2357 | // Input: edx, eax are the left and right objects of a bit op. |
| 2358 | // Output: eax, ecx are left and right integers for a bit op. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2359 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2360 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2361 | MacroAssembler* masm, |
| 2362 | bool use_sse3, |
| 2363 | BinaryOpIC::TypeInfo left_type, |
| 2364 | BinaryOpIC::TypeInfo right_type, |
| 2365 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2366 | // Check float operands. |
| 2367 | Label arg1_is_object, check_undefined_arg1; |
| 2368 | Label arg2_is_object, check_undefined_arg2; |
| 2369 | Label load_arg2, done; |
| 2370 | |
| 2371 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2372 | if (left_type == BinaryOpIC::SMI) { |
| 2373 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2374 | } else { |
| 2375 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2376 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2377 | |
| 2378 | __ SmiUntag(edx); |
| 2379 | __ jmp(&load_arg2); |
| 2380 | |
| 2381 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2382 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2383 | Factory* factory = masm->isolate()->factory(); |
| 2384 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2385 | __ j(not_equal, conversion_failure); |
| 2386 | __ mov(edx, Immediate(0)); |
| 2387 | __ jmp(&load_arg2); |
| 2388 | |
| 2389 | __ bind(&arg1_is_object); |
| 2390 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2391 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2392 | __ j(not_equal, &check_undefined_arg1); |
| 2393 | |
| 2394 | // Get the untagged integer version of the edx heap number in ecx. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2395 | if (left_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2396 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2397 | ConvertHeapNumberToInt32(masm, edx, conversion_failure); |
| 2398 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2399 | DoubleToIStub stub(edx, ecx, HeapNumber::kValueOffset - kHeapObjectTag, |
| 2400 | true); |
| 2401 | __ call(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2402 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2403 | __ mov(edx, ecx); |
| 2404 | |
| 2405 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2406 | __ bind(&load_arg2); |
| 2407 | |
| 2408 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2409 | if (right_type == BinaryOpIC::SMI) { |
| 2410 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2411 | } else { |
| 2412 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2413 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2414 | |
| 2415 | __ SmiUntag(eax); |
| 2416 | __ mov(ecx, eax); |
| 2417 | __ jmp(&done); |
| 2418 | |
| 2419 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2420 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2421 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2422 | __ j(not_equal, conversion_failure); |
| 2423 | __ mov(ecx, Immediate(0)); |
| 2424 | __ jmp(&done); |
| 2425 | |
| 2426 | __ bind(&arg2_is_object); |
| 2427 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2428 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2429 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2430 | // 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] | 2431 | |
| 2432 | if (right_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2433 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2434 | ConvertHeapNumberToInt32(masm, eax, conversion_failure); |
| 2435 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2436 | DoubleToIStub stub(eax, ecx, HeapNumber::kValueOffset - kHeapObjectTag, |
| 2437 | true); |
| 2438 | __ call(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2439 | } |
| 2440 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2441 | __ bind(&done); |
| 2442 | __ mov(eax, edx); |
| 2443 | } |
| 2444 | |
| 2445 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2446 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2447 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2448 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2449 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2450 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2451 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2452 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2453 | |
| 2454 | __ bind(&load_smi); |
| 2455 | __ SmiUntag(number); |
| 2456 | __ push(number); |
| 2457 | __ fild_s(Operand(esp, 0)); |
| 2458 | __ pop(number); |
| 2459 | |
| 2460 | __ bind(&done); |
| 2461 | } |
| 2462 | |
| 2463 | |
| 2464 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2465 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2466 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2467 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2468 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2469 | |
| 2470 | __ bind(&load_eax); |
| 2471 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2472 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2473 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2474 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2475 | |
| 2476 | __ bind(&load_smi_edx); |
| 2477 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2478 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2479 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2480 | __ jmp(&load_eax); |
| 2481 | |
| 2482 | __ bind(&load_smi_eax); |
| 2483 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2484 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2485 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2486 | |
| 2487 | __ bind(&done); |
| 2488 | } |
| 2489 | |
| 2490 | |
| 2491 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2492 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2493 | 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] | 2494 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2495 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2496 | Factory* factory = masm->isolate()->factory(); |
| 2497 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2498 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2499 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2500 | __ bind(&load_eax); |
| 2501 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2502 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2503 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2504 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2505 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2506 | __ bind(&load_smi_edx); |
| 2507 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2508 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2509 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2510 | __ jmp(&load_eax); |
| 2511 | __ bind(&load_smi_eax); |
| 2512 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2513 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2514 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2515 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2516 | __ bind(&load_float_eax); |
| 2517 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2518 | __ bind(&done); |
| 2519 | } |
| 2520 | |
| 2521 | |
| 2522 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2523 | Register scratch) { |
| 2524 | const Register left = edx; |
| 2525 | const Register right = eax; |
| 2526 | __ mov(scratch, left); |
| 2527 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2528 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2529 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2530 | |
| 2531 | __ mov(scratch, right); |
| 2532 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2533 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2534 | } |
| 2535 | |
| 2536 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2537 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2538 | Label* non_int32, |
| 2539 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2540 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2541 | Register scratch, |
| 2542 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2543 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2544 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2545 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2546 | __ movmskps(scratch, xmm_scratch); |
| 2547 | // Two least significant bits should be both set. |
| 2548 | __ not_(scratch); |
| 2549 | __ test(scratch, Immediate(3)); |
| 2550 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2554 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2555 | Register scratch, |
| 2556 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2557 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2558 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2559 | __ mov(scratch, edx); |
| 2560 | } else { |
| 2561 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2562 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2563 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2564 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2565 | __ bind(&done_load_1); |
| 2566 | |
| 2567 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2568 | __ mov(scratch, eax); |
| 2569 | } else { |
| 2570 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2571 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2572 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2573 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2574 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2575 | |
| 2576 | __ bind(&load_smi_1); |
| 2577 | __ SmiUntag(scratch); |
| 2578 | __ push(scratch); |
| 2579 | __ fild_s(Operand(esp, 0)); |
| 2580 | __ pop(scratch); |
| 2581 | __ jmp(&done_load_1); |
| 2582 | |
| 2583 | __ bind(&load_smi_2); |
| 2584 | __ SmiUntag(scratch); |
| 2585 | __ push(scratch); |
| 2586 | __ fild_s(Operand(esp, 0)); |
| 2587 | __ pop(scratch); |
| 2588 | |
| 2589 | __ bind(&done); |
| 2590 | } |
| 2591 | |
| 2592 | |
| 2593 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2594 | Register scratch) { |
| 2595 | const Register left = edx; |
| 2596 | const Register right = eax; |
| 2597 | __ mov(scratch, left); |
| 2598 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2599 | __ SmiUntag(scratch); |
| 2600 | __ push(scratch); |
| 2601 | __ fild_s(Operand(esp, 0)); |
| 2602 | |
| 2603 | __ mov(scratch, right); |
| 2604 | __ SmiUntag(scratch); |
| 2605 | __ mov(Operand(esp, 0), scratch); |
| 2606 | __ fild_s(Operand(esp, 0)); |
| 2607 | __ pop(scratch); |
| 2608 | } |
| 2609 | |
| 2610 | |
| 2611 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2612 | Label* non_float, |
| 2613 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2614 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2615 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2616 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2617 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2618 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2619 | Factory* factory = masm->isolate()->factory(); |
| 2620 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2621 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2622 | |
| 2623 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2624 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2625 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2626 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2627 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2628 | |
| 2629 | // Fall-through: Both operands are numbers. |
| 2630 | __ bind(&done); |
| 2631 | } |
| 2632 | |
| 2633 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2634 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2635 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2636 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2637 | const Register exponent = eax; |
| 2638 | const Register base = edx; |
| 2639 | const Register scratch = ecx; |
| 2640 | const XMMRegister double_result = xmm3; |
| 2641 | const XMMRegister double_base = xmm2; |
| 2642 | const XMMRegister double_exponent = xmm1; |
| 2643 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2644 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2645 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2646 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2647 | // Save 1 in double_result - we need this several times later on. |
| 2648 | __ mov(scratch, Immediate(1)); |
| 2649 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2650 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2651 | if (exponent_type_ == ON_STACK) { |
| 2652 | Label base_is_smi, unpack_exponent; |
| 2653 | // The exponent and base are supplied as arguments on the stack. |
| 2654 | // This can only happen if the stub is called from non-optimized code. |
| 2655 | // Load input parameters from stack. |
| 2656 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 2657 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 2658 | |
| 2659 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2660 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 2661 | factory->heap_number_map()); |
| 2662 | __ j(not_equal, &call_runtime); |
| 2663 | |
| 2664 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2665 | __ jmp(&unpack_exponent, Label::kNear); |
| 2666 | |
| 2667 | __ bind(&base_is_smi); |
| 2668 | __ SmiUntag(base); |
| 2669 | __ cvtsi2sd(double_base, base); |
| 2670 | |
| 2671 | __ bind(&unpack_exponent); |
| 2672 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2673 | __ SmiUntag(exponent); |
| 2674 | __ jmp(&int_exponent); |
| 2675 | |
| 2676 | __ bind(&exponent_not_smi); |
| 2677 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2678 | factory->heap_number_map()); |
| 2679 | __ j(not_equal, &call_runtime); |
| 2680 | __ movdbl(double_exponent, |
| 2681 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2682 | } else if (exponent_type_ == TAGGED) { |
| 2683 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2684 | __ SmiUntag(exponent); |
| 2685 | __ jmp(&int_exponent); |
| 2686 | |
| 2687 | __ bind(&exponent_not_smi); |
| 2688 | __ movdbl(double_exponent, |
| 2689 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2690 | } |
| 2691 | |
| 2692 | if (exponent_type_ != INTEGER) { |
| 2693 | Label fast_power; |
| 2694 | // Detect integer exponents stored as double. |
| 2695 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 2696 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 2697 | __ cmp(exponent, Immediate(0x80000000u)); |
| 2698 | __ j(equal, &call_runtime); |
| 2699 | __ cvtsi2sd(double_scratch, exponent); |
| 2700 | // Already ruled out NaNs for exponent. |
| 2701 | __ ucomisd(double_exponent, double_scratch); |
| 2702 | __ j(equal, &int_exponent); |
| 2703 | |
| 2704 | if (exponent_type_ == ON_STACK) { |
| 2705 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 2706 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 2707 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 2708 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 2709 | // Test for 0.5. |
| 2710 | // Load double_scratch with 0.5. |
| 2711 | __ mov(scratch, Immediate(0x3F000000u)); |
| 2712 | __ movd(double_scratch, scratch); |
| 2713 | __ cvtss2sd(double_scratch, double_scratch); |
| 2714 | // Already ruled out NaNs for exponent. |
| 2715 | __ ucomisd(double_scratch, double_exponent); |
| 2716 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 2717 | |
| 2718 | // Calculates square root of base. Check for the special case of |
| 2719 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 2720 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2721 | // 9 bits set and the lowest 23 bits cleared. |
| 2722 | __ mov(scratch, 0xFF800000u); |
| 2723 | __ movd(double_scratch, scratch); |
| 2724 | __ cvtss2sd(double_scratch, double_scratch); |
| 2725 | __ ucomisd(double_base, double_scratch); |
| 2726 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2727 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2728 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 2729 | __ j(carry, &continue_sqrt, Label::kNear); |
| 2730 | |
| 2731 | // Set result to Infinity in the special case. |
| 2732 | __ xorps(double_result, double_result); |
| 2733 | __ subsd(double_result, double_scratch); |
| 2734 | __ jmp(&done); |
| 2735 | |
| 2736 | __ bind(&continue_sqrt); |
| 2737 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2738 | __ xorps(double_scratch, double_scratch); |
| 2739 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 2740 | __ sqrtsd(double_result, double_scratch); |
| 2741 | __ jmp(&done); |
| 2742 | |
| 2743 | // Test for -0.5. |
| 2744 | __ bind(¬_plus_half); |
| 2745 | // Load double_exponent with -0.5 by substracting 1. |
| 2746 | __ subsd(double_scratch, double_result); |
| 2747 | // Already ruled out NaNs for exponent. |
| 2748 | __ ucomisd(double_scratch, double_exponent); |
| 2749 | __ j(not_equal, &fast_power, Label::kNear); |
| 2750 | |
| 2751 | // Calculates reciprocal of square root of base. Check for the special |
| 2752 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 2753 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2754 | // 9 bits set and the lowest 23 bits cleared. |
| 2755 | __ mov(scratch, 0xFF800000u); |
| 2756 | __ movd(double_scratch, scratch); |
| 2757 | __ cvtss2sd(double_scratch, double_scratch); |
| 2758 | __ ucomisd(double_base, double_scratch); |
| 2759 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2760 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2761 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 2762 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 2763 | |
| 2764 | // Set result to 0 in the special case. |
| 2765 | __ xorps(double_result, double_result); |
| 2766 | __ jmp(&done); |
| 2767 | |
| 2768 | __ bind(&continue_rsqrt); |
| 2769 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2770 | __ xorps(double_exponent, double_exponent); |
| 2771 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 2772 | __ sqrtsd(double_exponent, double_exponent); |
| 2773 | __ divsd(double_result, double_exponent); |
| 2774 | __ jmp(&done); |
| 2775 | } |
| 2776 | |
| 2777 | // Using FPU instructions to calculate power. |
| 2778 | Label fast_power_failed; |
| 2779 | __ bind(&fast_power); |
| 2780 | __ fnclex(); // Clear flags to catch exceptions later. |
| 2781 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 2782 | __ sub(esp, Immediate(kDoubleSize)); |
| 2783 | __ movdbl(Operand(esp, 0), double_exponent); |
| 2784 | __ fld_d(Operand(esp, 0)); // E |
| 2785 | __ movdbl(Operand(esp, 0), double_base); |
| 2786 | __ fld_d(Operand(esp, 0)); // B, E |
| 2787 | |
| 2788 | // Exponent is in st(1) and base is in st(0) |
| 2789 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 2790 | // FYL2X calculates st(1) * log2(st(0)) |
| 2791 | __ fyl2x(); // X |
| 2792 | __ fld(0); // X, X |
| 2793 | __ frndint(); // rnd(X), X |
| 2794 | __ fsub(1); // rnd(X), X-rnd(X) |
| 2795 | __ fxch(1); // X - rnd(X), rnd(X) |
| 2796 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 2797 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 2798 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2799 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2800 | // FSCALE calculates st(0) * 2^st(1) |
| 2801 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2802 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2803 | // Bail out to runtime in case of exceptions in the status word. |
| 2804 | __ fnstsw_ax(); |
| 2805 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 2806 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 2807 | __ fstp_d(Operand(esp, 0)); |
| 2808 | __ movdbl(double_result, Operand(esp, 0)); |
| 2809 | __ add(esp, Immediate(kDoubleSize)); |
| 2810 | __ jmp(&done); |
| 2811 | |
| 2812 | __ bind(&fast_power_failed); |
| 2813 | __ fninit(); |
| 2814 | __ add(esp, Immediate(kDoubleSize)); |
| 2815 | __ jmp(&call_runtime); |
| 2816 | } |
| 2817 | |
| 2818 | // Calculate power with integer exponent. |
| 2819 | __ bind(&int_exponent); |
| 2820 | const XMMRegister double_scratch2 = double_exponent; |
| 2821 | __ mov(scratch, exponent); // Back up exponent. |
| 2822 | __ movsd(double_scratch, double_base); // Back up base. |
| 2823 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2824 | |
| 2825 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2826 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2827 | __ test(scratch, scratch); |
| 2828 | __ j(positive, &no_neg, Label::kNear); |
| 2829 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2830 | __ bind(&no_neg); |
| 2831 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2832 | __ j(zero, &while_false, Label::kNear); |
| 2833 | __ shr(scratch, 1); |
| 2834 | // Above condition means CF==0 && ZF==0. This means that the |
| 2835 | // bit that has been shifted out is 0 and the result is not 0. |
| 2836 | __ j(above, &while_true, Label::kNear); |
| 2837 | __ movsd(double_result, double_scratch); |
| 2838 | __ j(zero, &while_false, Label::kNear); |
| 2839 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2840 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2841 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2842 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2843 | __ j(above, &while_true, Label::kNear); |
| 2844 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2845 | __ j(not_zero, &while_true); |
| 2846 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2847 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2848 | // scratch has the original value of the exponent - if the exponent is |
| 2849 | // negative, return 1/result. |
| 2850 | __ test(exponent, exponent); |
| 2851 | __ j(positive, &done); |
| 2852 | __ divsd(double_scratch2, double_result); |
| 2853 | __ movsd(double_result, double_scratch2); |
| 2854 | // Test whether result is zero. Bail out to check for subnormal result. |
| 2855 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 2856 | __ xorps(double_scratch2, double_scratch2); |
| 2857 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 2858 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 2859 | // and may not have contained the exponent value in the first place when the |
| 2860 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 2861 | __ j(not_equal, &done); |
| 2862 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2863 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2864 | // Returning or bailing out. |
| 2865 | Counters* counters = masm->isolate()->counters(); |
| 2866 | if (exponent_type_ == ON_STACK) { |
| 2867 | // The arguments are still on the stack. |
| 2868 | __ bind(&call_runtime); |
| 2869 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2870 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2871 | // The stub is called from non-optimized code, which expects the result |
| 2872 | // as heap number in exponent. |
| 2873 | __ bind(&done); |
| 2874 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 2875 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 2876 | __ IncrementCounter(counters->math_pow(), 1); |
| 2877 | __ ret(2 * kPointerSize); |
| 2878 | } else { |
| 2879 | __ bind(&call_runtime); |
| 2880 | { |
| 2881 | AllowExternalCallThatCantCauseGC scope(masm); |
| 2882 | __ PrepareCallCFunction(4, scratch); |
| 2883 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 2884 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 2885 | __ CallCFunction( |
| 2886 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 2887 | } |
| 2888 | // Return value is in st(0) on ia32. |
| 2889 | // Store it into the (fixed) result register. |
| 2890 | __ sub(esp, Immediate(kDoubleSize)); |
| 2891 | __ fstp_d(Operand(esp, 0)); |
| 2892 | __ movdbl(double_result, Operand(esp, 0)); |
| 2893 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2894 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2895 | __ bind(&done); |
| 2896 | __ IncrementCounter(counters->math_pow(), 1); |
| 2897 | __ ret(0); |
| 2898 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2902 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 2903 | // ----------- S t a t e ------------- |
| 2904 | // -- ecx : name |
| 2905 | // -- edx : receiver |
| 2906 | // -- esp[0] : return address |
| 2907 | // ----------------------------------- |
| 2908 | Label miss; |
| 2909 | |
| 2910 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2911 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2912 | __ j(not_equal, &miss); |
| 2913 | } |
| 2914 | |
| 2915 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 2916 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2917 | StubCompiler::TailCallBuiltin( |
| 2918 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | |
| 2922 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 2923 | // ----------- S t a t e ------------- |
| 2924 | // -- ecx : name |
| 2925 | // -- edx : receiver |
| 2926 | // -- esp[0] : return address |
| 2927 | // ----------------------------------- |
| 2928 | Label miss; |
| 2929 | |
| 2930 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2931 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2932 | __ j(not_equal, &miss); |
| 2933 | } |
| 2934 | |
| 2935 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 2936 | support_wrapper_); |
| 2937 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2938 | StubCompiler::TailCallBuiltin( |
| 2939 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2943 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 2944 | // ----------- S t a t e ------------- |
| 2945 | // -- eax : value |
| 2946 | // -- ecx : name |
| 2947 | // -- edx : receiver |
| 2948 | // -- esp[0] : return address |
| 2949 | // ----------------------------------- |
| 2950 | // |
| 2951 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 2952 | // (currently anything except for external arrays which means anything with |
| 2953 | // elements of FixedArray type). Value must be a number, but only smis are |
| 2954 | // accepted as the most common case. |
| 2955 | |
| 2956 | Label miss; |
| 2957 | |
| 2958 | Register receiver = edx; |
| 2959 | Register value = eax; |
| 2960 | Register scratch = ebx; |
| 2961 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2962 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2963 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2964 | __ j(not_equal, &miss); |
| 2965 | } |
| 2966 | |
| 2967 | // Check that the receiver isn't a smi. |
| 2968 | __ JumpIfSmi(receiver, &miss); |
| 2969 | |
| 2970 | // Check that the object is a JS array. |
| 2971 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 2972 | __ j(not_equal, &miss); |
| 2973 | |
| 2974 | // Check that elements are FixedArray. |
| 2975 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 2976 | // fast elements (including COW). |
| 2977 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 2978 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 2979 | __ j(not_equal, &miss); |
| 2980 | |
| 2981 | // Check that the array has fast properties, otherwise the length |
| 2982 | // property might have been redefined. |
| 2983 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 2984 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 2985 | Heap::kHashTableMapRootIndex); |
| 2986 | __ j(equal, &miss); |
| 2987 | |
| 2988 | // Check that value is a smi. |
| 2989 | __ JumpIfNotSmi(value, &miss); |
| 2990 | |
| 2991 | // Prepare tail call to StoreIC_ArrayLength. |
| 2992 | __ pop(scratch); |
| 2993 | __ push(receiver); |
| 2994 | __ push(value); |
| 2995 | __ push(scratch); // return address |
| 2996 | |
| 2997 | ExternalReference ref = |
| 2998 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 2999 | __ TailCallExternalReference(ref, 2, 1); |
| 3000 | |
| 3001 | __ bind(&miss); |
| 3002 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 3003 | StubCompiler::TailCallBuiltin( |
| 3004 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3005 | } |
| 3006 | |
| 3007 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3008 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3009 | // The key is in edx and the parameter count is in eax. |
| 3010 | |
| 3011 | // The displacement is used for skipping the frame pointer on the |
| 3012 | // stack. It is the offset of the last parameter (if any) relative |
| 3013 | // to the frame pointer. |
| 3014 | static const int kDisplacement = 1 * kPointerSize; |
| 3015 | |
| 3016 | // Check that the key is a smi. |
| 3017 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3018 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3019 | |
| 3020 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3021 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3022 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3023 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3024 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3025 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3026 | |
| 3027 | // Check index against formal parameters count limit passed in |
| 3028 | // through register eax. Use unsigned comparison to get negative |
| 3029 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3030 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3031 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3032 | |
| 3033 | // Read the argument from the stack and return it. |
| 3034 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3035 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3036 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3037 | __ neg(edx); |
| 3038 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3039 | __ ret(0); |
| 3040 | |
| 3041 | // Arguments adaptor case: Check index against actual arguments |
| 3042 | // limit found in the arguments adaptor frame. Use unsigned |
| 3043 | // comparison to get negative check for free. |
| 3044 | __ bind(&adaptor); |
| 3045 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3046 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3047 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3048 | |
| 3049 | // Read the argument from the stack and return it. |
| 3050 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3051 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3052 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3053 | __ neg(edx); |
| 3054 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3055 | __ ret(0); |
| 3056 | |
| 3057 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3058 | // by calling the runtime system. |
| 3059 | __ bind(&slow); |
| 3060 | __ pop(ebx); // Return address. |
| 3061 | __ push(edx); |
| 3062 | __ push(ebx); |
| 3063 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3064 | } |
| 3065 | |
| 3066 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3067 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3068 | // esp[0] : return address |
| 3069 | // esp[4] : number of parameters |
| 3070 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3071 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3072 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3073 | // Check if the calling frame is an arguments adaptor frame. |
| 3074 | Label runtime; |
| 3075 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3076 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3077 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3078 | __ j(not_equal, &runtime, Label::kNear); |
| 3079 | |
| 3080 | // Patch the arguments.length and the parameters pointer. |
| 3081 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3082 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3083 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3084 | StandardFrameConstants::kCallerSPOffset)); |
| 3085 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3086 | |
| 3087 | __ bind(&runtime); |
| 3088 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3089 | } |
| 3090 | |
| 3091 | |
| 3092 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3093 | Isolate* isolate = masm->isolate(); |
| 3094 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3095 | // esp[0] : return address |
| 3096 | // esp[4] : number of parameters (tagged) |
| 3097 | // esp[8] : receiver displacement |
| 3098 | // esp[12] : function |
| 3099 | |
| 3100 | // ebx = parameter count (tagged) |
| 3101 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3102 | |
| 3103 | // Check if the calling frame is an arguments adaptor frame. |
| 3104 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3105 | // Generate* functions. |
| 3106 | Label runtime; |
| 3107 | Label adaptor_frame, try_allocate; |
| 3108 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3109 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3110 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3111 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3112 | |
| 3113 | // No adaptor, parameter count = argument count. |
| 3114 | __ mov(ecx, ebx); |
| 3115 | __ jmp(&try_allocate, Label::kNear); |
| 3116 | |
| 3117 | // We have an adaptor frame. Patch the parameters pointer. |
| 3118 | __ bind(&adaptor_frame); |
| 3119 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3120 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3121 | StandardFrameConstants::kCallerSPOffset)); |
| 3122 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3123 | |
| 3124 | // ebx = parameter count (tagged) |
| 3125 | // ecx = argument count (tagged) |
| 3126 | // esp[4] = parameter count (tagged) |
| 3127 | // esp[8] = address of receiver argument |
| 3128 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3129 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3130 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3131 | __ mov(ebx, ecx); |
| 3132 | |
| 3133 | __ bind(&try_allocate); |
| 3134 | |
| 3135 | // Save mapped parameter count. |
| 3136 | __ push(ebx); |
| 3137 | |
| 3138 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3139 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3140 | const int kParameterMapHeaderSize = |
| 3141 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3142 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3143 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3144 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3145 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3146 | __ bind(&no_parameter_map); |
| 3147 | |
| 3148 | // 2. Backing store. |
| 3149 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3150 | |
| 3151 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3152 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3153 | |
| 3154 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3155 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3156 | |
| 3157 | // eax = address of new object(s) (tagged) |
| 3158 | // ecx = argument count (tagged) |
| 3159 | // esp[0] = mapped parameter count (tagged) |
| 3160 | // esp[8] = parameter count (tagged) |
| 3161 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3162 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3163 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3164 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3165 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3166 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3167 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3168 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3169 | __ mov(edi, Operand(edi, |
| 3170 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3171 | __ jmp(©, Label::kNear); |
| 3172 | |
| 3173 | __ bind(&has_mapped_parameters); |
| 3174 | __ mov(edi, Operand(edi, |
| 3175 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3176 | __ bind(©); |
| 3177 | |
| 3178 | // eax = address of new object (tagged) |
| 3179 | // ebx = mapped parameter count (tagged) |
| 3180 | // ecx = argument count (tagged) |
| 3181 | // edi = address of boilerplate object (tagged) |
| 3182 | // esp[0] = mapped parameter count (tagged) |
| 3183 | // esp[8] = parameter count (tagged) |
| 3184 | // esp[12] = address of receiver argument |
| 3185 | // Copy the JS object part. |
| 3186 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3187 | __ mov(edx, FieldOperand(edi, i)); |
| 3188 | __ mov(FieldOperand(eax, i), edx); |
| 3189 | } |
| 3190 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3191 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3192 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3193 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3194 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3195 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3196 | edx); |
| 3197 | |
| 3198 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3199 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3200 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3201 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3202 | ecx); |
| 3203 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3204 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3205 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3206 | // backing store. |
| 3207 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3208 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3209 | |
| 3210 | // eax = address of new object (tagged) |
| 3211 | // ebx = mapped parameter count (tagged) |
| 3212 | // ecx = argument count (tagged) |
| 3213 | // edi = address of parameter map or backing store (tagged) |
| 3214 | // esp[0] = mapped parameter count (tagged) |
| 3215 | // esp[8] = parameter count (tagged) |
| 3216 | // esp[12] = address of receiver argument |
| 3217 | // Free a register. |
| 3218 | __ push(eax); |
| 3219 | |
| 3220 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3221 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3222 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3223 | __ j(zero, &skip_parameter_map); |
| 3224 | |
| 3225 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3226 | Immediate(isolate->factory()->non_strict_arguments_elements_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3227 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3228 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3229 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3230 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3231 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3232 | |
| 3233 | // Copy the parameter slots and the holes in the arguments. |
| 3234 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3235 | // where parameters are stored in reverse order, at |
| 3236 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3237 | // The mapped parameter thus need to get indices |
| 3238 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3239 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3240 | // We loop from right to left. |
| 3241 | Label parameters_loop, parameters_test; |
| 3242 | __ push(ecx); |
| 3243 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3244 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3245 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3246 | __ sub(ebx, eax); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3247 | __ mov(ecx, isolate->factory()->the_hole_value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3248 | __ mov(edx, edi); |
| 3249 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3250 | // eax = loop variable (tagged) |
| 3251 | // ebx = mapping index (tagged) |
| 3252 | // ecx = the hole value |
| 3253 | // edx = address of parameter map (tagged) |
| 3254 | // edi = address of backing store (tagged) |
| 3255 | // esp[0] = argument count (tagged) |
| 3256 | // esp[4] = address of new object (tagged) |
| 3257 | // esp[8] = mapped parameter count (tagged) |
| 3258 | // esp[16] = parameter count (tagged) |
| 3259 | // esp[20] = address of receiver argument |
| 3260 | __ jmp(¶meters_test, Label::kNear); |
| 3261 | |
| 3262 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3263 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3264 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3265 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3266 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3267 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3268 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3269 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3270 | __ pop(ecx); |
| 3271 | |
| 3272 | __ bind(&skip_parameter_map); |
| 3273 | |
| 3274 | // ecx = argument count (tagged) |
| 3275 | // edi = address of backing store (tagged) |
| 3276 | // esp[0] = address of new object (tagged) |
| 3277 | // esp[4] = mapped parameter count (tagged) |
| 3278 | // esp[12] = parameter count (tagged) |
| 3279 | // esp[16] = address of receiver argument |
| 3280 | // Copy arguments header and remaining slots (if there are any). |
| 3281 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3282 | Immediate(isolate->factory()->fixed_array_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3283 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3284 | |
| 3285 | Label arguments_loop, arguments_test; |
| 3286 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3287 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3288 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3289 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3290 | __ jmp(&arguments_test, Label::kNear); |
| 3291 | |
| 3292 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3293 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3294 | __ mov(eax, Operand(edx, 0)); |
| 3295 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3296 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3297 | |
| 3298 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3299 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3300 | __ j(less, &arguments_loop, Label::kNear); |
| 3301 | |
| 3302 | // Restore. |
| 3303 | __ pop(eax); // Address of arguments object. |
| 3304 | __ pop(ebx); // Parameter count. |
| 3305 | |
| 3306 | // Return and remove the on-stack parameters. |
| 3307 | __ ret(3 * kPointerSize); |
| 3308 | |
| 3309 | // Do the runtime call to allocate the arguments object. |
| 3310 | __ bind(&runtime); |
| 3311 | __ pop(eax); // Remove saved parameter count. |
| 3312 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3313 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | |
| 3317 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3318 | Isolate* isolate = masm->isolate(); |
| 3319 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3320 | // esp[0] : return address |
| 3321 | // esp[4] : number of parameters |
| 3322 | // esp[8] : receiver displacement |
| 3323 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3324 | |
| 3325 | // Check if the calling frame is an arguments adaptor frame. |
| 3326 | Label adaptor_frame, try_allocate, runtime; |
| 3327 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3328 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3329 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3330 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3331 | |
| 3332 | // Get the length from the frame. |
| 3333 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3334 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3335 | |
| 3336 | // Patch the arguments.length and the parameters pointer. |
| 3337 | __ bind(&adaptor_frame); |
| 3338 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3339 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3340 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3341 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3342 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3343 | |
| 3344 | // Try the new space allocation. Start out with computing the size of |
| 3345 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3346 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3347 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3348 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3349 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3350 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3351 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3352 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3353 | |
| 3354 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3355 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3356 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3357 | // Get the arguments boilerplate from the current native context. |
| 3358 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3359 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3360 | const int offset = |
| 3361 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3362 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3363 | |
| 3364 | // Copy the JS object part. |
| 3365 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3366 | __ mov(ebx, FieldOperand(edi, i)); |
| 3367 | __ mov(FieldOperand(eax, i), ebx); |
| 3368 | } |
| 3369 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3370 | // 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] | 3371 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3372 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3373 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3374 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3375 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3376 | |
| 3377 | // If there are no actual arguments, we're done. |
| 3378 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3379 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3380 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3381 | |
| 3382 | // Get the parameters pointer from the stack. |
| 3383 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3384 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3385 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3386 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3387 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3388 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3389 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3390 | Immediate(isolate->factory()->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3391 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3392 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3393 | // Untag the length for the loop below. |
| 3394 | __ SmiUntag(ecx); |
| 3395 | |
| 3396 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3397 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3398 | __ bind(&loop); |
| 3399 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3400 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3401 | __ add(edi, Immediate(kPointerSize)); |
| 3402 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3403 | __ dec(ecx); |
| 3404 | __ j(not_zero, &loop); |
| 3405 | |
| 3406 | // Return and remove the on-stack parameters. |
| 3407 | __ bind(&done); |
| 3408 | __ ret(3 * kPointerSize); |
| 3409 | |
| 3410 | // Do the runtime call to allocate the arguments object. |
| 3411 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3412 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | |
| 3416 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3417 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3418 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3419 | // at compilation. |
| 3420 | #ifdef V8_INTERPRETED_REGEXP |
| 3421 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3422 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3423 | |
| 3424 | // Stack frame on entry. |
| 3425 | // esp[0]: return address |
| 3426 | // esp[4]: last_match_info (expected JSArray) |
| 3427 | // esp[8]: previous index |
| 3428 | // esp[12]: subject string |
| 3429 | // esp[16]: JSRegExp object |
| 3430 | |
| 3431 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3432 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3433 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3434 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3435 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3436 | Label runtime; |
| 3437 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3438 | |
| 3439 | // Ensure that a RegExp stack is allocated. |
| 3440 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3441 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3442 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3443 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3444 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3445 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3446 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3447 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3448 | |
| 3449 | // Check that the first argument is a JSRegExp object. |
| 3450 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3451 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3452 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3453 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3454 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3455 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3456 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3457 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3458 | if (FLAG_debug_code) { |
| 3459 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 3460 | __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3461 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 3462 | __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3463 | } |
| 3464 | |
| 3465 | // ecx: RegExp data (FixedArray) |
| 3466 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3467 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3468 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3469 | __ j(not_equal, &runtime); |
| 3470 | |
| 3471 | // ecx: RegExp data (FixedArray) |
| 3472 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3473 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3474 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3475 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3476 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3477 | STATIC_ASSERT(kSmiTag == 0); |
| 3478 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3479 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3480 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3481 | __ j(above, &runtime); |
| 3482 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3483 | // Reset offset for possibly sliced string. |
| 3484 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3485 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3486 | __ JumpIfSmi(eax, &runtime); |
| 3487 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3488 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3489 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3490 | |
| 3491 | // eax: subject string |
| 3492 | // edx: subject string |
| 3493 | // ebx: subject string instance type |
| 3494 | // ecx: RegExp data (FixedArray) |
| 3495 | // Handle subject string according to its encoding and representation: |
| 3496 | // (1) Sequential two byte? If yes, go to (9). |
| 3497 | // (2) Sequential one byte? If yes, go to (6). |
| 3498 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3499 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3500 | // Otherwise bailout. |
| 3501 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3502 | // (5b) Is subject external? If yes, go to (8). |
| 3503 | // (6) One byte sequential. Load regexp code for one byte. |
| 3504 | // (E) Carry on. |
| 3505 | /// [...] |
| 3506 | |
| 3507 | // Deferred code at the end of the stub: |
| 3508 | // (7) Not a long external string? If yes, go to (10). |
| 3509 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3510 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3511 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3512 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3513 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3514 | |
| 3515 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3516 | external_string /* 8 */, check_underlying /* 5a */, |
| 3517 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3518 | not_long_external /* 10 */; |
| 3519 | |
| 3520 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3521 | __ and_(ebx, kIsNotStringMask | |
| 3522 | kStringRepresentationMask | |
| 3523 | kStringEncodingMask | |
| 3524 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3525 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3526 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3527 | |
| 3528 | // (2) Sequential one byte? If yes, go to (6). |
| 3529 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3530 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3531 | kStringRepresentationMask | |
| 3532 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3533 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3534 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3535 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3536 | // We check whether the subject string is a cons, since sequential strings |
| 3537 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3538 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3539 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3540 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3541 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3542 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3543 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3544 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3545 | // (4) Cons string. Check that it's flat. |
| 3546 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3547 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3548 | __ j(not_equal, &runtime); |
| 3549 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3550 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3551 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3552 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3553 | |
| 3554 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3555 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3556 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3557 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3558 | // (5b) Is subject external? If yes, go to (8). |
| 3559 | __ test_b(ebx, kStringRepresentationMask); |
| 3560 | // The underlying external string is never a short external string. |
| 3561 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3562 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3563 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3564 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3565 | // eax: sequential subject string (or look-alike, external string) |
| 3566 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3567 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3568 | // (6) One byte sequential. Load regexp code for one byte. |
| 3569 | __ bind(&seq_one_byte_string); |
| 3570 | // Load previous index and check range before edx is overwritten. We have |
| 3571 | // to use edx instead of eax here because it might have been only made to |
| 3572 | // look like a sequential string when it actually is an external string. |
| 3573 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3574 | __ JumpIfNotSmi(ebx, &runtime); |
| 3575 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3576 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3577 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3578 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3579 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3580 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3581 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3582 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3583 | // Check that the irregexp code has been generated for the actual string |
| 3584 | // 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] | 3585 | // a smi (code flushing support). |
| 3586 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3587 | |
| 3588 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3589 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3590 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3591 | // 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] | 3592 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3593 | Counters* counters = masm->isolate()->counters(); |
| 3594 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3595 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3596 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3597 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3598 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3599 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3600 | // Argument 9: Pass current isolate address. |
| 3601 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3602 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3603 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3604 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3605 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3606 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3607 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3608 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3609 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3610 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3611 | |
| 3612 | // Argument 6: Set the number of capture registers to zero to force global |
| 3613 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3614 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3615 | |
| 3616 | // Argument 5: static offsets vector buffer. |
| 3617 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3618 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3619 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3620 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3621 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3622 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3623 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3624 | |
| 3625 | // Argument 1: Original subject string. |
| 3626 | // The original subject is in the previous stack frame. Therefore we have to |
| 3627 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3628 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3629 | // and thereby moves up esp by one kPointerSize.) |
| 3630 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3631 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3632 | |
| 3633 | // esi: original subject string |
| 3634 | // eax: underlying subject string |
| 3635 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3636 | // 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] | 3637 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3638 | // Argument 4: End of string data |
| 3639 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3640 | // Prepare start and end index of the input. |
| 3641 | // Load the length from the original sliced string if that is the case. |
| 3642 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3643 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3644 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3645 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3646 | |
| 3647 | // ebx: start index of the input string |
| 3648 | // esi: end index of the input string |
| 3649 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3650 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3651 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3652 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3653 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3654 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3655 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3656 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3657 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3658 | |
| 3659 | __ bind(&setup_two_byte); |
| 3660 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3661 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3662 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3663 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3664 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3665 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3666 | |
| 3667 | __ bind(&setup_rest); |
| 3668 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3669 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3670 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3671 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3672 | |
| 3673 | // Drop arguments and come back to JS mode. |
| 3674 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3675 | |
| 3676 | // Check the result. |
| 3677 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3678 | __ cmp(eax, 1); |
| 3679 | // We expect exactly one result since we force the called regexp to behave |
| 3680 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3681 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3682 | Label failure; |
| 3683 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3684 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3685 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3686 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3687 | __ j(not_equal, &runtime); |
| 3688 | // Result must now be exception. If there is no pending exception already a |
| 3689 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3690 | // haven't created the exception yet. Handle that in the runtime system. |
| 3691 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3692 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3693 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3694 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3695 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3696 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3697 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3698 | // For exception, throw the exception again. |
| 3699 | |
| 3700 | // Clear the pending exception variable. |
| 3701 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3702 | |
| 3703 | // Special handling of termination exceptions which are uncatchable |
| 3704 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3705 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3706 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3707 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3708 | |
| 3709 | // Handle normal exception by following handler chain. |
| 3710 | __ Throw(eax); |
| 3711 | |
| 3712 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3713 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3714 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3715 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3716 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3717 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3718 | __ ret(4 * kPointerSize); |
| 3719 | |
| 3720 | // Load RegExp data. |
| 3721 | __ bind(&success); |
| 3722 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3723 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3724 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3725 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3726 | STATIC_ASSERT(kSmiTag == 0); |
| 3727 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3728 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3729 | |
| 3730 | // edx: Number of capture registers |
| 3731 | // 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] | 3732 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3733 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3734 | __ JumpIfSmi(eax, &runtime); |
| 3735 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3736 | __ j(not_equal, &runtime); |
| 3737 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3738 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3739 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 3740 | __ cmp(eax, factory->fixed_array_map()); |
| 3741 | __ j(not_equal, &runtime); |
| 3742 | // Check that the last match info has space for the capture registers and the |
| 3743 | // additional information. |
| 3744 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3745 | __ SmiUntag(eax); |
| 3746 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3747 | __ cmp(edx, eax); |
| 3748 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3749 | |
| 3750 | // ebx: last_match_info backing store (FixedArray) |
| 3751 | // edx: number of capture registers |
| 3752 | // Store the capture count. |
| 3753 | __ SmiTag(edx); // Number of capture registers to smi. |
| 3754 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 3755 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 3756 | // Store last subject and last input. |
| 3757 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3758 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3759 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3760 | __ RecordWriteField(ebx, |
| 3761 | RegExpImpl::kLastSubjectOffset, |
| 3762 | eax, |
| 3763 | edi, |
| 3764 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3765 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3766 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3767 | __ RecordWriteField(ebx, |
| 3768 | RegExpImpl::kLastInputOffset, |
| 3769 | eax, |
| 3770 | edi, |
| 3771 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3772 | |
| 3773 | // Get the static offsets vector filled by the native regexp code. |
| 3774 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3775 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3776 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 3777 | |
| 3778 | // ebx: last_match_info backing store (FixedArray) |
| 3779 | // ecx: offsets vector |
| 3780 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3781 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3782 | // Capture register counter starts from number of capture registers and |
| 3783 | // counts down until wraping after zero. |
| 3784 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3785 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3786 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3787 | // Read the value from the static offsets vector buffer. |
| 3788 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 3789 | __ SmiTag(edi); |
| 3790 | // Store the smi value in the last match info. |
| 3791 | __ mov(FieldOperand(ebx, |
| 3792 | edx, |
| 3793 | times_pointer_size, |
| 3794 | RegExpImpl::kFirstCaptureOffset), |
| 3795 | edi); |
| 3796 | __ jmp(&next_capture); |
| 3797 | __ bind(&done); |
| 3798 | |
| 3799 | // Return last match info. |
| 3800 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 3801 | __ ret(4 * kPointerSize); |
| 3802 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3803 | // Do the runtime call to execute the regexp. |
| 3804 | __ bind(&runtime); |
| 3805 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3806 | |
| 3807 | // Deferred code for string handling. |
| 3808 | // (7) Not a long external string? If yes, go to (10). |
| 3809 | __ bind(¬_seq_nor_cons); |
| 3810 | // Compare flags are still set from (3). |
| 3811 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 3812 | |
| 3813 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3814 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3815 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3816 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3817 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3818 | if (FLAG_debug_code) { |
| 3819 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 3820 | // Sequential strings have already been ruled out. |
| 3821 | __ test_b(ebx, kIsIndirectStringMask); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 3822 | __ Assert(zero, kExternalStringExpectedButNotFound); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3823 | } |
| 3824 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 3825 | // 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] | 3826 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3827 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3828 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3829 | // (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] | 3830 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3831 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3832 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3833 | // eax: sequential subject string (or look-alike, external string) |
| 3834 | // edx: original subject string |
| 3835 | // ecx: RegExp data (FixedArray) |
| 3836 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3837 | __ bind(&seq_two_byte_string); |
| 3838 | // Load previous index and check range before edx is overwritten. We have |
| 3839 | // to use edx instead of eax here because it might have been only made to |
| 3840 | // look like a sequential string when it actually is an external string. |
| 3841 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3842 | __ JumpIfNotSmi(ebx, &runtime); |
| 3843 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3844 | __ j(above_equal, &runtime); |
| 3845 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 3846 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 3847 | __ jmp(&check_code); // Go to (E). |
| 3848 | |
| 3849 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 3850 | __ bind(¬_long_external); |
| 3851 | // Catch non-string subject or short external string. |
| 3852 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3853 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 3854 | __ j(not_zero, &runtime); |
| 3855 | |
| 3856 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3857 | // Load offset into edi and replace subject string with parent. |
| 3858 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3859 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3860 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3861 | #endif // V8_INTERPRETED_REGEXP |
| 3862 | } |
| 3863 | |
| 3864 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3865 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 3866 | const int kMaxInlineLength = 100; |
| 3867 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3868 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3869 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3870 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3871 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3872 | __ j(above, &slowcase); |
| 3873 | // Smi-tagging is equivalent to multiplying by 2. |
| 3874 | STATIC_ASSERT(kSmiTag == 0); |
| 3875 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3876 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 3877 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 3878 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3879 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 3880 | times_pointer_size, |
| 3881 | ebx, // In: Number of elements as a smi |
| 3882 | REGISTER_VALUE_IS_SMI, |
| 3883 | eax, // Out: Start of allocation (tagged). |
| 3884 | ecx, // Out: End of allocation. |
| 3885 | edx, // Scratch register |
| 3886 | &slowcase, |
| 3887 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3888 | // eax: Start of allocated area, object-tagged. |
| 3889 | |
| 3890 | // Set JSArray map to global.regexp_result_map(). |
| 3891 | // Set empty properties FixedArray. |
| 3892 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 3893 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3894 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3895 | Factory* factory = masm->isolate()->factory(); |
| 3896 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3897 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3898 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3899 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 3900 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 3901 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 3902 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 3903 | |
| 3904 | // Set input, index and length fields from arguments. |
| 3905 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 3906 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 3907 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 3908 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 3909 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 3910 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 3911 | |
| 3912 | // Fill out the elements FixedArray. |
| 3913 | // eax: JSArray. |
| 3914 | // ebx: FixedArray. |
| 3915 | // ecx: Number of elements in array, as smi. |
| 3916 | |
| 3917 | // Set map. |
| 3918 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3919 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3920 | // Set length. |
| 3921 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3922 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3923 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3924 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3925 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3926 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3927 | // eax: JSArray. |
| 3928 | // ecx: Number of elements to fill. |
| 3929 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3930 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3931 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3932 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3933 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3934 | __ 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] | 3935 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3936 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 3937 | __ jmp(&loop); |
| 3938 | |
| 3939 | __ bind(&done); |
| 3940 | __ ret(3 * kPointerSize); |
| 3941 | |
| 3942 | __ bind(&slowcase); |
| 3943 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 3944 | } |
| 3945 | |
| 3946 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3947 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 3948 | Register object, |
| 3949 | Register result, |
| 3950 | Register scratch1, |
| 3951 | Register scratch2, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3952 | Label* not_found) { |
| 3953 | // Use of registers. Register result is used as a temporary. |
| 3954 | Register number_string_cache = result; |
| 3955 | Register mask = scratch1; |
| 3956 | Register scratch = scratch2; |
| 3957 | |
| 3958 | // Load the number string cache. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 3959 | __ LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3960 | // Make the hash mask from the length of the number string cache. It |
| 3961 | // contains two elements (number and string) for each cache entry. |
| 3962 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 3963 | __ 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] | 3964 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3965 | |
| 3966 | // Calculate the entry in the number string cache. The hash value in the |
| 3967 | // number string cache for smis is just the smi value, and the hash for |
| 3968 | // doubles is the xor of the upper and lower words. See |
| 3969 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3970 | Label smi_hash_calculated; |
| 3971 | Label load_result_from_cache; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3972 | Label not_smi; |
| 3973 | STATIC_ASSERT(kSmiTag == 0); |
| 3974 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
| 3975 | __ mov(scratch, object); |
| 3976 | __ SmiUntag(scratch); |
| 3977 | __ jmp(&smi_hash_calculated, Label::kNear); |
| 3978 | __ bind(¬_smi); |
| 3979 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
| 3980 | masm->isolate()->factory()->heap_number_map()); |
| 3981 | __ j(not_equal, not_found); |
| 3982 | STATIC_ASSERT(8 == kDoubleSize); |
| 3983 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 3984 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 3985 | // Object is heap number and hash is now in scratch. Calculate cache index. |
| 3986 | __ and_(scratch, mask); |
| 3987 | Register index = scratch; |
| 3988 | Register probe = mask; |
| 3989 | __ mov(probe, |
| 3990 | FieldOperand(number_string_cache, |
| 3991 | index, |
| 3992 | times_twice_pointer_size, |
| 3993 | FixedArray::kHeaderSize)); |
| 3994 | __ JumpIfSmi(probe, not_found); |
| 3995 | if (CpuFeatures::IsSupported(SSE2)) { |
| 3996 | CpuFeatureScope fscope(masm, SSE2); |
| 3997 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 3998 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 3999 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4000 | } else { |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4001 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4002 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4003 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4004 | } |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4005 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4006 | __ j(not_equal, not_found); // The cache did not contain this value. |
| 4007 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4008 | |
| 4009 | __ bind(&smi_hash_calculated); |
| 4010 | // 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] | 4011 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4012 | // Check if the entry is the smi we are looking for. |
| 4013 | __ cmp(object, |
| 4014 | FieldOperand(number_string_cache, |
| 4015 | index, |
| 4016 | times_twice_pointer_size, |
| 4017 | FixedArray::kHeaderSize)); |
| 4018 | __ j(not_equal, not_found); |
| 4019 | |
| 4020 | // Get the result from the cache. |
| 4021 | __ bind(&load_result_from_cache); |
| 4022 | __ mov(result, |
| 4023 | FieldOperand(number_string_cache, |
| 4024 | index, |
| 4025 | times_twice_pointer_size, |
| 4026 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4027 | Counters* counters = masm->isolate()->counters(); |
| 4028 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | |
| 4032 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4033 | Label runtime; |
| 4034 | |
| 4035 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4036 | |
| 4037 | // Generate code to lookup number in the number string cache. |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4038 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4039 | __ ret(1 * kPointerSize); |
| 4040 | |
| 4041 | __ bind(&runtime); |
| 4042 | // Handle number to string in the runtime system if not found in the cache. |
| 4043 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4044 | } |
| 4045 | |
| 4046 | |
| 4047 | static int NegativeComparisonResult(Condition cc) { |
| 4048 | ASSERT(cc != equal); |
| 4049 | ASSERT((cc == less) || (cc == less_equal) |
| 4050 | || (cc == greater) || (cc == greater_equal)); |
| 4051 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4052 | } |
| 4053 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4054 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4055 | static void CheckInputType(MacroAssembler* masm, |
| 4056 | Register input, |
| 4057 | CompareIC::State expected, |
| 4058 | Label* fail) { |
| 4059 | Label ok; |
| 4060 | if (expected == CompareIC::SMI) { |
| 4061 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4062 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4063 | __ JumpIfSmi(input, &ok); |
| 4064 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4065 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4066 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4067 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4068 | // 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] | 4069 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4070 | __ bind(&ok); |
| 4071 | } |
| 4072 | |
| 4073 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4074 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 4075 | Label* label, |
| 4076 | Register object, |
| 4077 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4078 | __ JumpIfSmi(object, label); |
| 4079 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4080 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4081 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 4082 | __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 4083 | __ j(not_zero, label); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | |
| 4087 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4088 | Label check_unequal_objects; |
| 4089 | Condition cc = GetCondition(); |
| 4090 | |
| 4091 | Label miss; |
| 4092 | CheckInputType(masm, edx, left_, &miss); |
| 4093 | CheckInputType(masm, eax, right_, &miss); |
| 4094 | |
| 4095 | // Compare two smis. |
| 4096 | Label non_smi, smi_done; |
| 4097 | __ mov(ecx, edx); |
| 4098 | __ or_(ecx, eax); |
| 4099 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4100 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4101 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4102 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4103 | __ bind(&smi_done); |
| 4104 | __ mov(eax, edx); |
| 4105 | __ ret(0); |
| 4106 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4107 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4108 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4109 | // it is certain that at least one operand isn't a smi. |
| 4110 | |
| 4111 | // Identical objects can be compared fast, but there are some tricky cases |
| 4112 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4113 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4114 | { |
| 4115 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4116 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4117 | __ j(not_equal, ¬_identical); |
| 4118 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4119 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4120 | // Check for undefined. undefined OP undefined is false even though |
| 4121 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4122 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4123 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4124 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4125 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4126 | __ ret(0); |
| 4127 | __ bind(&check_for_nan); |
| 4128 | } |
| 4129 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4130 | // Test for NaN. Compare heap numbers in a general way, |
| 4131 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4132 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4133 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4134 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4135 | if (cc != equal) { |
| 4136 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4137 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4138 | __ j(above_equal, ¬_identical); |
| 4139 | } |
| 4140 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4141 | __ ret(0); |
| 4142 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4143 | |
| 4144 | __ bind(¬_identical); |
| 4145 | } |
| 4146 | |
| 4147 | // Strict equality can quickly decide whether objects are equal. |
| 4148 | // 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] | 4149 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4150 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4151 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4152 | // If we're doing a strict equality comparison, we don't have to do |
| 4153 | // type conversion, so we generate code to do fast comparison for objects |
| 4154 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4155 | // slow-case code. |
| 4156 | // If either is a Smi (we know that not both are), then they can only |
| 4157 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4158 | STATIC_ASSERT(kSmiTag == 0); |
| 4159 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4160 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4161 | __ and_(ecx, eax); |
| 4162 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4163 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4164 | // One operand is a smi. |
| 4165 | |
| 4166 | // Check whether the non-smi is a heap number. |
| 4167 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4168 | // 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] | 4169 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4170 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4171 | __ xor_(ebx, eax); |
| 4172 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4173 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4174 | // if eax was smi, ebx is now edx, else eax. |
| 4175 | |
| 4176 | // Check if the non-smi operand is a heap number. |
| 4177 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4178 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4179 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4180 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4181 | // Return non-equal (ebx is not zero) |
| 4182 | __ mov(eax, ebx); |
| 4183 | __ ret(0); |
| 4184 | |
| 4185 | __ bind(¬_smis); |
| 4186 | // If either operand is a JSObject or an oddball value, then they are not |
| 4187 | // equal since their pointers are different |
| 4188 | // There is no test for undetectability in strict equality. |
| 4189 | |
| 4190 | // Get the type of the first operand. |
| 4191 | // 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] | 4192 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4193 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4194 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4195 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4196 | |
| 4197 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4198 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4199 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4200 | __ bind(&return_not_equal); |
| 4201 | __ ret(0); |
| 4202 | |
| 4203 | __ bind(&first_non_object); |
| 4204 | // Check for oddballs: true, false, null, undefined. |
| 4205 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4206 | __ j(equal, &return_not_equal); |
| 4207 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4208 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4209 | __ j(above_equal, &return_not_equal); |
| 4210 | |
| 4211 | // Check for oddballs: true, false, null, undefined. |
| 4212 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4213 | __ j(equal, &return_not_equal); |
| 4214 | |
| 4215 | // Fall through to the general case. |
| 4216 | __ bind(&slow); |
| 4217 | } |
| 4218 | |
| 4219 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4220 | Label non_number_comparison; |
| 4221 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4222 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4223 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4224 | CpuFeatureScope use_sse2(masm, SSE2); |
| 4225 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4226 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4227 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4228 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4229 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4230 | // Don't base result on EFLAGS when a NaN is involved. |
| 4231 | __ j(parity_even, &unordered, Label::kNear); |
| 4232 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4233 | __ mov(eax, 0); // equal |
| 4234 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4235 | __ cmov(above, eax, ecx); |
| 4236 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4237 | __ cmov(below, eax, ecx); |
| 4238 | __ ret(0); |
| 4239 | } else { |
| 4240 | FloatingPointHelper::CheckFloatOperands( |
| 4241 | masm, &non_number_comparison, ebx); |
| 4242 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4243 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4244 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4245 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4246 | // Don't base result on EFLAGS when a NaN is involved. |
| 4247 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4248 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4249 | Label below_label, above_label; |
| 4250 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4251 | __ j(below, &below_label, Label::kNear); |
| 4252 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4253 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4254 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4255 | __ ret(0); |
| 4256 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4257 | __ bind(&below_label); |
| 4258 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4259 | __ ret(0); |
| 4260 | |
| 4261 | __ bind(&above_label); |
| 4262 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4263 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4264 | } |
| 4265 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4266 | // If one of the numbers was NaN, then the result is always false. |
| 4267 | // The cc is never not-equal. |
| 4268 | __ bind(&unordered); |
| 4269 | ASSERT(cc != not_equal); |
| 4270 | if (cc == less || cc == less_equal) { |
| 4271 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4272 | } else { |
| 4273 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4274 | } |
| 4275 | __ ret(0); |
| 4276 | |
| 4277 | // The number comparison code did not provide a valid result. |
| 4278 | __ bind(&non_number_comparison); |
| 4279 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4280 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4281 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4282 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4283 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 4284 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4285 | |
| 4286 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4287 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4288 | // non-zero value, which indicates not equal, so just return. |
| 4289 | __ ret(0); |
| 4290 | } |
| 4291 | |
| 4292 | __ bind(&check_for_strings); |
| 4293 | |
| 4294 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4295 | &check_unequal_objects); |
| 4296 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4297 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4298 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4299 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4300 | edx, |
| 4301 | eax, |
| 4302 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4303 | ebx); |
| 4304 | } else { |
| 4305 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4306 | edx, |
| 4307 | eax, |
| 4308 | ecx, |
| 4309 | ebx, |
| 4310 | edi); |
| 4311 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4312 | #ifdef DEBUG |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 4313 | __ Abort(kUnexpectedFallThroughFromStringComparison); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4314 | #endif |
| 4315 | |
| 4316 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4317 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4318 | // Non-strict equality. Objects are unequal if |
| 4319 | // they are both JSObjects and not undetectable, |
| 4320 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4321 | Label not_both_objects; |
| 4322 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4323 | // At most one is a smi, so we can test for smi by adding the two. |
| 4324 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4325 | // a heap object has the low bit clear. |
| 4326 | STATIC_ASSERT(kSmiTag == 0); |
| 4327 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4328 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4329 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4330 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4331 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4332 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4333 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4334 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4335 | // We do not bail out after this point. Both are JSObjects, and |
| 4336 | // they are equal if and only if both are undetectable. |
| 4337 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4338 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4339 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4340 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4341 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4342 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4343 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4344 | // The objects are both undetectable, so they both compare as the value |
| 4345 | // undefined, and are equal. |
| 4346 | __ Set(eax, Immediate(EQUAL)); |
| 4347 | __ bind(&return_unequal); |
| 4348 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4349 | // or return equal if we fell through to here. |
| 4350 | __ ret(0); // rax, rdx were pushed |
| 4351 | __ bind(¬_both_objects); |
| 4352 | } |
| 4353 | |
| 4354 | // Push arguments below the return address. |
| 4355 | __ pop(ecx); |
| 4356 | __ push(edx); |
| 4357 | __ push(eax); |
| 4358 | |
| 4359 | // Figure out which native to call and setup the arguments. |
| 4360 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4361 | if (cc == equal) { |
| 4362 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4363 | } else { |
| 4364 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4365 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4366 | } |
| 4367 | |
| 4368 | // Restore return address on the stack. |
| 4369 | __ push(ecx); |
| 4370 | |
| 4371 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4372 | // tagged as a small integer. |
| 4373 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4374 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4375 | __ bind(&miss); |
| 4376 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4377 | } |
| 4378 | |
| 4379 | |
| 4380 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4381 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4385 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4386 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4387 | } |
| 4388 | |
| 4389 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4390 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4391 | // Cache the called function in a global property cell. Cache states |
| 4392 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4393 | // megamorphic. |
| 4394 | // ebx : cache cell for call target |
| 4395 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4396 | Isolate* isolate = masm->isolate(); |
| 4397 | Label initialize, done, miss, megamorphic, not_array_function; |
| 4398 | |
| 4399 | // Load the cache state into ecx. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4400 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4401 | |
| 4402 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4403 | // function without changing the state. |
| 4404 | __ cmp(ecx, edi); |
| 4405 | __ j(equal, &done); |
| 4406 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4407 | __ j(equal, &done); |
| 4408 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4409 | // If we came here, we need to see if we are the array function. |
| 4410 | // If we didn't have a matching function, and we didn't find the megamorph |
| 4411 | // sentinel, then we have in the cell either some other function or an |
| 4412 | // AllocationSite. Do a map check on the object in ecx. |
| 4413 | Handle<Map> allocation_site_map( |
| 4414 | masm->isolate()->heap()->allocation_site_map(), |
| 4415 | masm->isolate()); |
| 4416 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 4417 | __ j(not_equal, &miss); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4418 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4419 | // Load the global or builtins object from the current context |
| 4420 | __ LoadGlobalContext(ecx); |
| 4421 | // Make sure the function is the Array() function |
| 4422 | __ cmp(edi, Operand(ecx, |
| 4423 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4424 | __ j(not_equal, &megamorphic); |
| 4425 | __ jmp(&done); |
| 4426 | |
| 4427 | __ bind(&miss); |
| 4428 | |
| 4429 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4430 | // megamorphic. |
| 4431 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4432 | __ j(equal, &initialize); |
| 4433 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4434 | // write-barrier is needed. |
| 4435 | __ bind(&megamorphic); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4436 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4437 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4438 | __ jmp(&done, Label::kNear); |
| 4439 | |
| 4440 | // An uninitialized cache is patched with the function or sentinel to |
| 4441 | // indicate the ElementsKind if function is the Array constructor. |
| 4442 | __ bind(&initialize); |
| 4443 | __ LoadGlobalContext(ecx); |
| 4444 | // Make sure the function is the Array() function |
| 4445 | __ cmp(edi, Operand(ecx, |
| 4446 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4447 | __ j(not_equal, ¬_array_function); |
| 4448 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4449 | // The target function is the Array constructor, |
| 4450 | // Create an AllocationSite if we don't already have it, store it in the cell |
| 4451 | { |
| 4452 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4453 | |
| 4454 | __ push(eax); |
| 4455 | __ push(edi); |
| 4456 | __ push(ebx); |
| 4457 | |
| 4458 | CreateAllocationSiteStub create_stub; |
| 4459 | __ CallStub(&create_stub); |
| 4460 | |
| 4461 | __ pop(ebx); |
| 4462 | __ pop(edi); |
| 4463 | __ pop(eax); |
| 4464 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4465 | __ jmp(&done); |
| 4466 | |
| 4467 | __ bind(¬_array_function); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4468 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4469 | // No need for a write barrier here - cells are rescanned. |
| 4470 | |
| 4471 | __ bind(&done); |
| 4472 | } |
| 4473 | |
| 4474 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4475 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4476 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4477 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4478 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4479 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4480 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4481 | // The receiver might implicitly be the global object. This is |
| 4482 | // indicated by passing the hole as the receiver to the call |
| 4483 | // function stub. |
| 4484 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4485 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4486 | // Get the receiver from the stack. |
| 4487 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4488 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4489 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4490 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4491 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4492 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4493 | __ mov(ecx, GlobalObjectOperand()); |
| 4494 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4495 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4496 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4497 | } |
| 4498 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4499 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4500 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4501 | // Goto slow case if we do not have a function. |
| 4502 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4503 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4504 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4505 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4506 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4507 | } |
| 4508 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4509 | // Fast-case: Just invoke the function. |
| 4510 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4511 | |
| 4512 | if (ReceiverMightBeImplicit()) { |
| 4513 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4514 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4515 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4516 | __ InvokeFunction(edi, |
| 4517 | actual, |
| 4518 | JUMP_FUNCTION, |
| 4519 | NullCallWrapper(), |
| 4520 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4521 | __ bind(&call_as_function); |
| 4522 | } |
| 4523 | __ InvokeFunction(edi, |
| 4524 | actual, |
| 4525 | JUMP_FUNCTION, |
| 4526 | NullCallWrapper(), |
| 4527 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4528 | |
| 4529 | // Slow-case: Non-function called. |
| 4530 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4531 | if (RecordCallTarget()) { |
| 4532 | // 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] | 4533 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4534 | // object (undefined) so no write barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4535 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4536 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4537 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4538 | // Check for function proxy. |
| 4539 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4540 | __ j(not_equal, &non_function); |
| 4541 | __ pop(ecx); |
| 4542 | __ push(edi); // put proxy as additional argument under return address |
| 4543 | __ push(ecx); |
| 4544 | __ Set(eax, Immediate(argc_ + 1)); |
| 4545 | __ Set(ebx, Immediate(0)); |
| 4546 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4547 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4548 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4549 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4550 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4551 | } |
| 4552 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4553 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4554 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4555 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4556 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4557 | __ Set(eax, Immediate(argc_)); |
| 4558 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4559 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4560 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4561 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4562 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4563 | } |
| 4564 | |
| 4565 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4566 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4567 | // eax : number of arguments |
| 4568 | // ebx : cache cell for call target |
| 4569 | // edi : constructor function |
| 4570 | Label slow, non_function_call; |
| 4571 | |
| 4572 | // Check that function is not a smi. |
| 4573 | __ JumpIfSmi(edi, &non_function_call); |
| 4574 | // Check that function is a JSFunction. |
| 4575 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4576 | __ j(not_equal, &slow); |
| 4577 | |
| 4578 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4579 | GenerateRecordCallTarget(masm); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4580 | } |
| 4581 | |
| 4582 | // Jump to the function-specific construct stub. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4583 | Register jmp_reg = ecx; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4584 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4585 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 4586 | SharedFunctionInfo::kConstructStubOffset)); |
| 4587 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 4588 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4589 | |
| 4590 | // edi: called object |
| 4591 | // eax: number of arguments |
| 4592 | // ecx: object map |
| 4593 | Label do_call; |
| 4594 | __ bind(&slow); |
| 4595 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4596 | __ j(not_equal, &non_function_call); |
| 4597 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4598 | __ jmp(&do_call); |
| 4599 | |
| 4600 | __ bind(&non_function_call); |
| 4601 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4602 | __ bind(&do_call); |
| 4603 | // Set expected number of arguments to zero (not changing eax). |
| 4604 | __ Set(ebx, Immediate(0)); |
| 4605 | Handle<Code> arguments_adaptor = |
| 4606 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4607 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4608 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4609 | } |
| 4610 | |
| 4611 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4612 | bool CEntryStub::NeedsImmovableCode() { |
| 4613 | return false; |
| 4614 | } |
| 4615 | |
| 4616 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4617 | bool CEntryStub::IsPregenerated() { |
| 4618 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4619 | result_size_ == 1; |
| 4620 | } |
| 4621 | |
| 4622 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4623 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4624 | CEntryStub::GenerateAheadOfTime(isolate); |
| 4625 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4626 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4627 | // 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] | 4628 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4629 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4630 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4631 | } |
| 4632 | |
| 4633 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4634 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4635 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4636 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4637 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4638 | // which would lead to code stub initialization state being messed up. |
| 4639 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4640 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 4641 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4642 | } |
| 4643 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4644 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4645 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4649 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4650 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4651 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4652 | code->set_is_pregenerated(true); |
| 4653 | } |
| 4654 | |
| 4655 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4656 | static void JumpIfOOM(MacroAssembler* masm, |
| 4657 | Register value, |
| 4658 | Register scratch, |
| 4659 | Label* oom_label) { |
| 4660 | __ mov(scratch, value); |
| 4661 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 4662 | STATIC_ASSERT(kFailureTag == 3); |
| 4663 | __ and_(scratch, 0xf); |
| 4664 | __ cmp(scratch, 0xf); |
| 4665 | __ j(equal, oom_label); |
| 4666 | } |
| 4667 | |
| 4668 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4669 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4670 | Label* throw_normal_exception, |
| 4671 | Label* throw_termination_exception, |
| 4672 | Label* throw_out_of_memory_exception, |
| 4673 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4674 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4675 | // eax: result parameter for PerformGC, if any |
| 4676 | // ebx: pointer to C function (C callee-saved) |
| 4677 | // ebp: frame pointer (restored after C call) |
| 4678 | // esp: stack pointer (restored after C call) |
| 4679 | // edi: number of arguments including receiver (C callee-saved) |
| 4680 | // esi: pointer to the first argument (C callee-saved) |
| 4681 | |
| 4682 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4683 | |
| 4684 | // Check stack alignment. |
| 4685 | if (FLAG_debug_code) { |
| 4686 | __ CheckStackAlignment(); |
| 4687 | } |
| 4688 | |
| 4689 | if (do_gc) { |
| 4690 | // Pass failure code returned from last attempt as first argument to |
| 4691 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4692 | // stack alignment is known to be correct. This function takes one argument |
| 4693 | // which is passed on the stack, and we know that the stack has been |
| 4694 | // prepared to pass at least one argument. |
| 4695 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4696 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4697 | } |
| 4698 | |
| 4699 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4700 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4701 | if (always_allocate_scope) { |
| 4702 | __ inc(Operand::StaticVariable(scope_depth)); |
| 4703 | } |
| 4704 | |
| 4705 | // Call C function. |
| 4706 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 4707 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4708 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4709 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4710 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4711 | // Result is in eax or edx:eax - do not destroy these registers! |
| 4712 | |
| 4713 | if (always_allocate_scope) { |
| 4714 | __ dec(Operand::StaticVariable(scope_depth)); |
| 4715 | } |
| 4716 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4717 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 4718 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4719 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4720 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4721 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4722 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4723 | __ int3(); |
| 4724 | __ bind(&okay); |
| 4725 | } |
| 4726 | |
| 4727 | // Check for failure result. |
| 4728 | Label failure_returned; |
| 4729 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4730 | __ lea(ecx, Operand(eax, 1)); |
| 4731 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 4732 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4733 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4734 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4735 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4736 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4737 | |
| 4738 | // Check that there is no pending exception, otherwise we |
| 4739 | // should have returned some failure value. |
| 4740 | if (FLAG_debug_code) { |
| 4741 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4742 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4743 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4744 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 4745 | // 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] | 4746 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4747 | __ int3(); |
| 4748 | __ bind(&okay); |
| 4749 | __ pop(edx); |
| 4750 | } |
| 4751 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4752 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4753 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4754 | __ ret(0); |
| 4755 | |
| 4756 | // Handling of failure. |
| 4757 | __ bind(&failure_returned); |
| 4758 | |
| 4759 | Label retry; |
| 4760 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 4761 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4762 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4763 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4764 | |
| 4765 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4766 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4767 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4768 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4769 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4770 | |
| 4771 | // See if we just retrieved an OOM exception. |
| 4772 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 4773 | |
| 4774 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4775 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4776 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 4777 | |
| 4778 | // Special handling of termination exceptions which are uncatchable |
| 4779 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4780 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4781 | __ j(equal, throw_termination_exception); |
| 4782 | |
| 4783 | // Handle normal exception. |
| 4784 | __ jmp(throw_normal_exception); |
| 4785 | |
| 4786 | // Retry. |
| 4787 | __ bind(&retry); |
| 4788 | } |
| 4789 | |
| 4790 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4791 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4792 | // eax: number of arguments including receiver |
| 4793 | // ebx: pointer to C function (C callee-saved) |
| 4794 | // ebp: frame pointer (restored after C call) |
| 4795 | // esp: stack pointer (restored after C call) |
| 4796 | // esi: current context (C callee-saved) |
| 4797 | // edi: JS function of the caller (C callee-saved) |
| 4798 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4799 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 4800 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4801 | // NOTE: Invocations of builtins may return failure objects instead |
| 4802 | // of a proper result. The builtin entry handles this by performing |
| 4803 | // a garbage collection and retrying the builtin (twice). |
| 4804 | |
| 4805 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4806 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4807 | |
| 4808 | // eax: result parameter for PerformGC, if any (setup below) |
| 4809 | // ebx: pointer to builtin function (C callee-saved) |
| 4810 | // ebp: frame pointer (restored after C call) |
| 4811 | // esp: stack pointer (restored after C call) |
| 4812 | // edi: number of arguments including receiver (C callee-saved) |
| 4813 | // esi: argv pointer (C callee-saved) |
| 4814 | |
| 4815 | Label throw_normal_exception; |
| 4816 | Label throw_termination_exception; |
| 4817 | Label throw_out_of_memory_exception; |
| 4818 | |
| 4819 | // Call into the runtime system. |
| 4820 | GenerateCore(masm, |
| 4821 | &throw_normal_exception, |
| 4822 | &throw_termination_exception, |
| 4823 | &throw_out_of_memory_exception, |
| 4824 | false, |
| 4825 | false); |
| 4826 | |
| 4827 | // Do space-specific GC and retry runtime call. |
| 4828 | GenerateCore(masm, |
| 4829 | &throw_normal_exception, |
| 4830 | &throw_termination_exception, |
| 4831 | &throw_out_of_memory_exception, |
| 4832 | true, |
| 4833 | false); |
| 4834 | |
| 4835 | // Do full GC and retry runtime call one final time. |
| 4836 | Failure* failure = Failure::InternalError(); |
| 4837 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 4838 | GenerateCore(masm, |
| 4839 | &throw_normal_exception, |
| 4840 | &throw_termination_exception, |
| 4841 | &throw_out_of_memory_exception, |
| 4842 | true, |
| 4843 | true); |
| 4844 | |
| 4845 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4846 | // Set external caught exception to false. |
| 4847 | Isolate* isolate = masm->isolate(); |
| 4848 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 4849 | isolate); |
| 4850 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 4851 | |
| 4852 | // Set pending exception and eax to out of memory exception. |
| 4853 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 4854 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4855 | Label already_have_failure; |
| 4856 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 4857 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 4858 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4859 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4860 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4861 | |
| 4862 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4863 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4864 | |
| 4865 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4866 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4867 | } |
| 4868 | |
| 4869 | |
| 4870 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4871 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4872 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4873 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4874 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 4875 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4876 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4877 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4878 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4879 | |
| 4880 | // Push marker in two places. |
| 4881 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4882 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 4883 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 4884 | // Save callee-saved registers (C calling conventions). |
| 4885 | __ push(edi); |
| 4886 | __ push(esi); |
| 4887 | __ push(ebx); |
| 4888 | |
| 4889 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4890 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4891 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 4892 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4893 | // 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] | 4894 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4895 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4896 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4897 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4898 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4899 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 4900 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4901 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4902 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4903 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4904 | // Jump to a faked try block that does the invoke, with a faked catch |
| 4905 | // block that sets the pending exception. |
| 4906 | __ jmp(&invoke); |
| 4907 | __ bind(&handler_entry); |
| 4908 | handler_offset_ = handler_entry.pos(); |
| 4909 | // Caught exception: Store result (exception) in the pending exception |
| 4910 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4911 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4912 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4913 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4914 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 4915 | __ jmp(&exit); |
| 4916 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4917 | // Invoke: Link this frame into the handler chain. There's only one |
| 4918 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4919 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4920 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4921 | |
| 4922 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4923 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4924 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4925 | |
| 4926 | // Fake a receiver (NULL). |
| 4927 | __ push(Immediate(0)); // receiver |
| 4928 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4929 | // Invoke the function by calling through JS entry trampoline builtin and |
| 4930 | // pop the faked function when we return. Notice that we cannot store a |
| 4931 | // reference to the trampoline code directly in this stub, because the |
| 4932 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4933 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4934 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 4935 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4936 | __ mov(edx, Immediate(construct_entry)); |
| 4937 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4938 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4939 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4940 | __ mov(edx, Immediate(entry)); |
| 4941 | } |
| 4942 | __ mov(edx, Operand(edx, 0)); // deref address |
| 4943 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4944 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4945 | |
| 4946 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4947 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4948 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4949 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4950 | // Check if the current stack frame is marked as the outermost JS frame. |
| 4951 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4952 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4953 | __ j(not_equal, ¬_outermost_js_2); |
| 4954 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 4955 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4956 | |
| 4957 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4958 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4959 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4960 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4961 | |
| 4962 | // Restore callee-saved registers (C calling conventions). |
| 4963 | __ pop(ebx); |
| 4964 | __ pop(esi); |
| 4965 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4966 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4967 | |
| 4968 | // Restore frame pointer and return. |
| 4969 | __ pop(ebp); |
| 4970 | __ ret(0); |
| 4971 | } |
| 4972 | |
| 4973 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4974 | // Generate stub code for instanceof. |
| 4975 | // This code can patch a call site inlined cache of the instance of check, |
| 4976 | // which looks like this. |
| 4977 | // |
| 4978 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 4979 | // 75 0a jne <some near label> |
| 4980 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 4981 | // |
| 4982 | // If call site patching is requested the stack will have the delta from the |
| 4983 | // return address to the cmp instruction just below the return address. This |
| 4984 | // also means that call site patching can only take place with arguments in |
| 4985 | // registers. TOS looks like this when call site patching is requested |
| 4986 | // |
| 4987 | // esp[0] : return address |
| 4988 | // esp[4] : delta from return address to cmp instruction |
| 4989 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4990 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4991 | // Call site inlining and patching implies arguments in registers. |
| 4992 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 4993 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4994 | // Fixed register usage throughout the stub. |
| 4995 | Register object = eax; // Object (lhs). |
| 4996 | Register map = ebx; // Map of the object. |
| 4997 | Register function = edx; // Function (rhs). |
| 4998 | Register prototype = edi; // Prototype of the function. |
| 4999 | Register scratch = ecx; |
| 5000 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5001 | // Constants describing the call site code to patch. |
| 5002 | static const int kDeltaToCmpImmediate = 2; |
| 5003 | static const int kDeltaToMov = 8; |
| 5004 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5005 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5006 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5007 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5008 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5009 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5010 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5011 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5012 | // Get the object and function - they are always both needed. |
| 5013 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5014 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5015 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5016 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5017 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5018 | |
| 5019 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5020 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5021 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5022 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5023 | // If there is a call site cache don't look in the global cache, but do the |
| 5024 | // real lookup and update the call site cache. |
| 5025 | if (!HasCallSiteInlineCheck()) { |
| 5026 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5027 | Label miss; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5028 | __ CompareRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5029 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5030 | __ CompareRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5031 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5032 | __ LoadRoot(eax, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5033 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5034 | __ bind(&miss); |
| 5035 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5036 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5037 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5038 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5039 | |
| 5040 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5041 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5042 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5043 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5044 | // Update the global instanceof or call site inlined cache with the current |
| 5045 | // map and function. The cached answer will be set when it is known below. |
| 5046 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5047 | __ StoreRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
| 5048 | __ StoreRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5049 | } else { |
| 5050 | // The constants for the code patching are based on no push instructions |
| 5051 | // at the call site. |
| 5052 | ASSERT(HasArgsInRegisters()); |
| 5053 | // Get return address and delta to inlined map check. |
| 5054 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5055 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5056 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5057 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5058 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp1); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5059 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5060 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5061 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5062 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5063 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5064 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5065 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5066 | // Loop through the prototype chain of the object looking for the function |
| 5067 | // prototype. |
| 5068 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5069 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5070 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5071 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5072 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5073 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5074 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5075 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5076 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5077 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5078 | __ jmp(&loop); |
| 5079 | |
| 5080 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5081 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5082 | __ mov(eax, Immediate(0)); |
| 5083 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5084 | } else { |
| 5085 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5086 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5087 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5088 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5089 | if (FLAG_debug_code) { |
| 5090 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5091 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5092 | } |
| 5093 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5094 | if (!ReturnTrueFalseObject()) { |
| 5095 | __ Set(eax, Immediate(0)); |
| 5096 | } |
| 5097 | } |
| 5098 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5099 | |
| 5100 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5101 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5102 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 5103 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5104 | } else { |
| 5105 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5106 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5107 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5108 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5109 | if (FLAG_debug_code) { |
| 5110 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5111 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5112 | } |
| 5113 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5114 | if (!ReturnTrueFalseObject()) { |
| 5115 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5116 | } |
| 5117 | } |
| 5118 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5119 | |
| 5120 | Label object_not_null, object_not_null_or_smi; |
| 5121 | __ bind(¬_js_object); |
| 5122 | // Before null, smi and string value checks, check that the rhs is a function |
| 5123 | // 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] | 5124 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5125 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5126 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5127 | |
| 5128 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5129 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5130 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5131 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5132 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5133 | |
| 5134 | __ bind(&object_not_null); |
| 5135 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5136 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5137 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5138 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5139 | |
| 5140 | __ bind(&object_not_null_or_smi); |
| 5141 | // String values is not instance of anything. |
| 5142 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5143 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5144 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5145 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5146 | |
| 5147 | // Slow-case: Go through the JavaScript implementation. |
| 5148 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5149 | if (!ReturnTrueFalseObject()) { |
| 5150 | // Tail call the builtin which returns 0 or 1. |
| 5151 | if (HasArgsInRegisters()) { |
| 5152 | // Push arguments below return address. |
| 5153 | __ pop(scratch); |
| 5154 | __ push(object); |
| 5155 | __ push(function); |
| 5156 | __ push(scratch); |
| 5157 | } |
| 5158 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5159 | } else { |
| 5160 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5161 | { |
| 5162 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5163 | __ push(object); |
| 5164 | __ push(function); |
| 5165 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5166 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5167 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5168 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5169 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5170 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5171 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5172 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5173 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5174 | __ bind(&done); |
| 5175 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5176 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5177 | } |
| 5178 | |
| 5179 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5180 | Register InstanceofStub::left() { return eax; } |
| 5181 | |
| 5182 | |
| 5183 | Register InstanceofStub::right() { return edx; } |
| 5184 | |
| 5185 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5186 | // ------------------------------------------------------------------------- |
| 5187 | // StringCharCodeAtGenerator |
| 5188 | |
| 5189 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5190 | // If the receiver is a smi trigger the non-string case. |
| 5191 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5192 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5193 | |
| 5194 | // Fetch the instance type of the receiver into result register. |
| 5195 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5196 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5197 | // If the receiver is not a string trigger the non-string case. |
| 5198 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5199 | __ j(not_zero, receiver_not_string_); |
| 5200 | |
| 5201 | // If the index is non-smi trigger the non-smi case. |
| 5202 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5203 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5204 | __ bind(&got_smi_index_); |
| 5205 | |
| 5206 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5207 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5208 | __ j(above_equal, index_out_of_range_); |
| 5209 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5210 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5211 | |
| 5212 | Factory* factory = masm->isolate()->factory(); |
| 5213 | StringCharLoadGenerator::Generate( |
| 5214 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5215 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5216 | __ SmiTag(result_); |
| 5217 | __ bind(&exit_); |
| 5218 | } |
| 5219 | |
| 5220 | |
| 5221 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5222 | MacroAssembler* masm, |
| 5223 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5224 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5225 | |
| 5226 | // Index is not a smi. |
| 5227 | __ bind(&index_not_smi_); |
| 5228 | // 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] | 5229 | __ CheckMap(index_, |
| 5230 | masm->isolate()->factory()->heap_number_map(), |
| 5231 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5232 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5233 | call_helper.BeforeCall(masm); |
| 5234 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5235 | __ push(index_); // Consumed by runtime conversion function. |
| 5236 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5237 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5238 | } else { |
| 5239 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5240 | // NumberToSmi discards numbers that are not exact integers. |
| 5241 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5242 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5243 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5244 | // Save the conversion result before the pop instructions below |
| 5245 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5246 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5247 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5248 | __ pop(object_); |
| 5249 | // Reload the instance type. |
| 5250 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5251 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5252 | call_helper.AfterCall(masm); |
| 5253 | // If index is still not a smi, it must be out of range. |
| 5254 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5255 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5256 | // Otherwise, return to the fast path. |
| 5257 | __ jmp(&got_smi_index_); |
| 5258 | |
| 5259 | // Call runtime. We get here when the receiver is a string and the |
| 5260 | // index is a number, but the code of getting the actual character |
| 5261 | // is too complex (e.g., when the string needs to be flattened). |
| 5262 | __ bind(&call_runtime_); |
| 5263 | call_helper.BeforeCall(masm); |
| 5264 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5265 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5266 | __ push(index_); |
| 5267 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5268 | if (!result_.is(eax)) { |
| 5269 | __ mov(result_, eax); |
| 5270 | } |
| 5271 | call_helper.AfterCall(masm); |
| 5272 | __ jmp(&exit_); |
| 5273 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5274 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5275 | } |
| 5276 | |
| 5277 | |
| 5278 | // ------------------------------------------------------------------------- |
| 5279 | // StringCharFromCodeGenerator |
| 5280 | |
| 5281 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5282 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5283 | STATIC_ASSERT(kSmiTag == 0); |
| 5284 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5285 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5286 | __ test(code_, |
| 5287 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5288 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5289 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5290 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5291 | Factory* factory = masm->isolate()->factory(); |
| 5292 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5293 | STATIC_ASSERT(kSmiTag == 0); |
| 5294 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5295 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5296 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5297 | __ mov(result_, FieldOperand(result_, |
| 5298 | code_, times_half_pointer_size, |
| 5299 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5300 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5301 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5302 | __ bind(&exit_); |
| 5303 | } |
| 5304 | |
| 5305 | |
| 5306 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5307 | MacroAssembler* masm, |
| 5308 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5309 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5310 | |
| 5311 | __ bind(&slow_case_); |
| 5312 | call_helper.BeforeCall(masm); |
| 5313 | __ push(code_); |
| 5314 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5315 | if (!result_.is(eax)) { |
| 5316 | __ mov(result_, eax); |
| 5317 | } |
| 5318 | call_helper.AfterCall(masm); |
| 5319 | __ jmp(&exit_); |
| 5320 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5321 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5322 | } |
| 5323 | |
| 5324 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5325 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5326 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5327 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5328 | |
| 5329 | // Load the two arguments. |
| 5330 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5331 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5332 | |
| 5333 | // 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] | 5334 | // Otherwise, at least one of the arguments is definitely a string, |
| 5335 | // and we convert the one that is not known to be a string. |
| 5336 | if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) { |
| 5337 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT); |
| 5338 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5339 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5340 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5341 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5342 | |
| 5343 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5344 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5345 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5346 | __ j(above_equal, &call_runtime); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5347 | } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) { |
| 5348 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0); |
| 5349 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5350 | &call_builtin); |
| 5351 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5352 | } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) { |
| 5353 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0); |
| 5354 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5355 | &call_builtin); |
| 5356 | builtin_id = Builtins::STRING_ADD_LEFT; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5357 | } |
| 5358 | |
| 5359 | // Both arguments are strings. |
| 5360 | // eax: first string |
| 5361 | // edx: second string |
| 5362 | // 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] | 5363 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5364 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5365 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5366 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5367 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5368 | // 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] | 5369 | Counters* counters = masm->isolate()->counters(); |
| 5370 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5371 | __ ret(2 * kPointerSize); |
| 5372 | __ bind(&second_not_zero_length); |
| 5373 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5374 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5375 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5376 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5377 | // First string is empty, result is second string which is in edx. |
| 5378 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5379 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5380 | __ ret(2 * kPointerSize); |
| 5381 | |
| 5382 | // Both strings are non-empty. |
| 5383 | // eax: first string |
| 5384 | // ebx: length of first string as a smi |
| 5385 | // ecx: length of second string as a smi |
| 5386 | // edx: second string |
| 5387 | // Look at the length of the result of adding the two strings. |
| 5388 | Label string_add_flat_result, longer_than_two; |
| 5389 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5390 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5391 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5392 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5393 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5394 | // Use the string table when adding two one character strings, as it |
| 5395 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5396 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5397 | __ j(not_equal, &longer_than_two); |
| 5398 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5399 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5400 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5401 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5402 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5403 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5404 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5405 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5406 | // 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] | 5407 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5408 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5409 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5410 | masm, ebx, ecx, eax, edx, edi, |
| 5411 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5412 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5413 | __ ret(2 * kPointerSize); |
| 5414 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5415 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5416 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5417 | // Reload the arguments. |
| 5418 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5419 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5420 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5421 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5422 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5423 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5424 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5425 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5426 | // Pack both characters in ebx. |
| 5427 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5428 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5429 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5430 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5431 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5432 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5433 | |
| 5434 | __ bind(&longer_than_two); |
| 5435 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5436 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5437 | __ j(below, &string_add_flat_result); |
| 5438 | |
| 5439 | // 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] | 5440 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5441 | Label non_ascii, allocated, ascii_data; |
| 5442 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5443 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5444 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5445 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5446 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5447 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5448 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5449 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5450 | __ j(zero, &non_ascii); |
| 5451 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5452 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5453 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5454 | __ bind(&allocated); |
| 5455 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5456 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5457 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5458 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5459 | Immediate(String::kEmptyHashField)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5460 | |
| 5461 | Label skip_write_barrier, after_writing; |
| 5462 | ExternalReference high_promotion_mode = ExternalReference:: |
| 5463 | new_space_high_promotion_mode_active_address(masm->isolate()); |
| 5464 | __ test(Operand::StaticVariable(high_promotion_mode), Immediate(1)); |
| 5465 | __ j(zero, &skip_write_barrier); |
| 5466 | |
| 5467 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5468 | __ RecordWriteField(ecx, |
| 5469 | ConsString::kFirstOffset, |
| 5470 | eax, |
| 5471 | ebx, |
| 5472 | kDontSaveFPRegs); |
| 5473 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5474 | __ RecordWriteField(ecx, |
| 5475 | ConsString::kSecondOffset, |
| 5476 | edx, |
| 5477 | ebx, |
| 5478 | kDontSaveFPRegs); |
| 5479 | __ jmp(&after_writing); |
| 5480 | |
| 5481 | __ bind(&skip_write_barrier); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5482 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5483 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5484 | |
| 5485 | __ bind(&after_writing); |
| 5486 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5487 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5488 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5489 | __ ret(2 * kPointerSize); |
| 5490 | __ bind(&non_ascii); |
| 5491 | // 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] | 5492 | // to contain only one byte characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5493 | // ecx: first instance type AND second instance type. |
| 5494 | // edi: second instance type. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5495 | __ test(ecx, Immediate(kOneByteDataHintMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5496 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5497 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5498 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5499 | __ xor_(edi, ecx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5500 | STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0); |
| 5501 | __ and_(edi, kOneByteStringTag | kOneByteDataHintTag); |
| 5502 | __ cmp(edi, kOneByteStringTag | kOneByteDataHintTag); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5503 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5504 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5505 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5506 | __ jmp(&allocated); |
| 5507 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5508 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5509 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5510 | // Handle creating a flat result from either external or sequential strings. |
| 5511 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5512 | // eax: first string |
| 5513 | // ebx: length of resulting flat string as a smi |
| 5514 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5515 | Label first_prepared, second_prepared; |
| 5516 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5517 | __ bind(&string_add_flat_result); |
| 5518 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5519 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5520 | // ecx: instance type of first string |
| 5521 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5522 | __ test_b(ecx, kStringRepresentationMask); |
| 5523 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5524 | // Rule out short external string and load string resource. |
| 5525 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5526 | __ test_b(ecx, kShortExternalStringMask); |
| 5527 | __ j(not_zero, &call_runtime); |
| 5528 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5529 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5530 | __ jmp(&first_prepared, Label::kNear); |
| 5531 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5532 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5533 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5534 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5535 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5536 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5537 | // Check whether both strings have same encoding. |
| 5538 | // edi: instance type of second string |
| 5539 | __ xor_(ecx, edi); |
| 5540 | __ test_b(ecx, kStringEncodingMask); |
| 5541 | __ j(not_zero, &call_runtime); |
| 5542 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5543 | __ test_b(edi, kStringRepresentationMask); |
| 5544 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5545 | // Rule out short external string and load string resource. |
| 5546 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5547 | __ test_b(edi, kShortExternalStringMask); |
| 5548 | __ j(not_zero, &call_runtime); |
| 5549 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5550 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5551 | __ jmp(&second_prepared, Label::kNear); |
| 5552 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5553 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5554 | __ bind(&second_prepared); |
| 5555 | |
| 5556 | // Push the addresses of both strings' first characters onto the stack. |
| 5557 | __ push(edx); |
| 5558 | __ push(eax); |
| 5559 | |
| 5560 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5561 | // edi: instance type of second string |
| 5562 | // First string and second string have the same encoding. |
| 5563 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5564 | __ test_b(edi, kStringEncodingMask); |
| 5565 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5566 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5567 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5568 | // ebx: length of resulting flat string as a smi |
| 5569 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5570 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5571 | // eax: result string |
| 5572 | __ mov(ecx, eax); |
| 5573 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5574 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5575 | // Load first argument's length and first character location. Account for |
| 5576 | // values currently on the stack when fetching arguments from it. |
| 5577 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5578 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5579 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5580 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5581 | // eax: result string |
| 5582 | // ecx: first character of result |
| 5583 | // edx: first char of first argument |
| 5584 | // edi: length of first argument |
| 5585 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5586 | // Load second argument's length and first character location. Account for |
| 5587 | // values currently on the stack when fetching arguments from it. |
| 5588 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5589 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5590 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5591 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5592 | // eax: result string |
| 5593 | // ecx: next character of result |
| 5594 | // edx: first char of second argument |
| 5595 | // edi: length of second argument |
| 5596 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5597 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5598 | __ ret(2 * kPointerSize); |
| 5599 | |
| 5600 | // Handle creating a flat two byte result. |
| 5601 | // eax: first string - known to be two byte |
| 5602 | // ebx: length of resulting flat string as a smi |
| 5603 | // edx: second string |
| 5604 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5605 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5606 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5607 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5608 | // eax: result string |
| 5609 | __ mov(ecx, eax); |
| 5610 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5611 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5612 | // Load second argument's length and first character location. Account for |
| 5613 | // values currently on the stack when fetching arguments from it. |
| 5614 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5615 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5616 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5617 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5618 | // eax: result string |
| 5619 | // ecx: first character of result |
| 5620 | // edx: first char of first argument |
| 5621 | // edi: length of first argument |
| 5622 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5623 | // Load second argument's length and first character location. Account for |
| 5624 | // values currently on the stack when fetching arguments from it. |
| 5625 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5626 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5627 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5628 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5629 | // eax: result string |
| 5630 | // ecx: next character of result |
| 5631 | // edx: first char of second argument |
| 5632 | // edi: length of second argument |
| 5633 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5634 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5635 | __ ret(2 * kPointerSize); |
| 5636 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5637 | // Recover stack pointer before jumping to runtime. |
| 5638 | __ bind(&call_runtime_drop_two); |
| 5639 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5640 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5641 | __ bind(&call_runtime); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5642 | if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) { |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5643 | GenerateRegisterArgsPop(masm, ecx); |
| 5644 | // Build a frame |
| 5645 | { |
| 5646 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5647 | GenerateRegisterArgsPush(masm); |
| 5648 | __ CallRuntime(Runtime::kStringAdd, 2); |
| 5649 | } |
| 5650 | __ ret(0); |
| 5651 | } else { |
| 5652 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
| 5653 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5654 | |
| 5655 | if (call_builtin.is_linked()) { |
| 5656 | __ bind(&call_builtin); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5657 | if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) { |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5658 | GenerateRegisterArgsPop(masm, ecx); |
| 5659 | // Build a frame |
| 5660 | { |
| 5661 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5662 | GenerateRegisterArgsPush(masm); |
| 5663 | __ InvokeBuiltin(builtin_id, CALL_FUNCTION); |
| 5664 | } |
| 5665 | __ ret(0); |
| 5666 | } else { |
| 5667 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5668 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5669 | } |
| 5670 | } |
| 5671 | |
| 5672 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5673 | void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
| 5674 | __ push(eax); |
| 5675 | __ push(edx); |
| 5676 | } |
| 5677 | |
| 5678 | |
| 5679 | void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm, |
| 5680 | Register temp) { |
| 5681 | __ pop(temp); |
| 5682 | __ pop(edx); |
| 5683 | __ pop(eax); |
| 5684 | __ push(temp); |
| 5685 | } |
| 5686 | |
| 5687 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5688 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5689 | int stack_offset, |
| 5690 | Register arg, |
| 5691 | Register scratch1, |
| 5692 | Register scratch2, |
| 5693 | Register scratch3, |
| 5694 | Label* slow) { |
| 5695 | // First check if the argument is already a string. |
| 5696 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5697 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5698 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5699 | __ j(below, &done); |
| 5700 | |
| 5701 | // Check the number to string cache. |
| 5702 | Label not_cached; |
| 5703 | __ bind(¬_string); |
| 5704 | // Puts the cached result into scratch1. |
| 5705 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 5706 | arg, |
| 5707 | scratch1, |
| 5708 | scratch2, |
| 5709 | scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5710 | ¬_cached); |
| 5711 | __ mov(arg, scratch1); |
| 5712 | __ mov(Operand(esp, stack_offset), arg); |
| 5713 | __ jmp(&done); |
| 5714 | |
| 5715 | // Check if the argument is a safe string wrapper. |
| 5716 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5717 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5718 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 5719 | __ j(not_equal, slow); |
| 5720 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 5721 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 5722 | __ j(zero, slow); |
| 5723 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 5724 | __ mov(Operand(esp, stack_offset), arg); |
| 5725 | |
| 5726 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5727 | } |
| 5728 | |
| 5729 | |
| 5730 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5731 | Register dest, |
| 5732 | Register src, |
| 5733 | Register count, |
| 5734 | Register scratch, |
| 5735 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5736 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5737 | __ bind(&loop); |
| 5738 | // This loop just copies one character at a time, as it is only used for very |
| 5739 | // short strings. |
| 5740 | if (ascii) { |
| 5741 | __ mov_b(scratch, Operand(src, 0)); |
| 5742 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5743 | __ add(src, Immediate(1)); |
| 5744 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5745 | } else { |
| 5746 | __ mov_w(scratch, Operand(src, 0)); |
| 5747 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5748 | __ add(src, Immediate(2)); |
| 5749 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5750 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5751 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5752 | __ j(not_zero, &loop); |
| 5753 | } |
| 5754 | |
| 5755 | |
| 5756 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 5757 | Register dest, |
| 5758 | Register src, |
| 5759 | Register count, |
| 5760 | Register scratch, |
| 5761 | bool ascii) { |
| 5762 | // Copy characters using rep movs of doublewords. |
| 5763 | // The destination is aligned on a 4 byte boundary because we are |
| 5764 | // copying to the beginning of a newly allocated string. |
| 5765 | ASSERT(dest.is(edi)); // rep movs destination |
| 5766 | ASSERT(src.is(esi)); // rep movs source |
| 5767 | ASSERT(count.is(ecx)); // rep movs count |
| 5768 | ASSERT(!scratch.is(dest)); |
| 5769 | ASSERT(!scratch.is(src)); |
| 5770 | ASSERT(!scratch.is(count)); |
| 5771 | |
| 5772 | // Nothing to do for zero characters. |
| 5773 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5774 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5775 | __ j(zero, &done); |
| 5776 | |
| 5777 | // Make count the number of bytes to copy. |
| 5778 | if (!ascii) { |
| 5779 | __ shl(count, 1); |
| 5780 | } |
| 5781 | |
| 5782 | // 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] | 5783 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5784 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5785 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5786 | |
| 5787 | // Copy from edi to esi using rep movs instruction. |
| 5788 | __ mov(scratch, count); |
| 5789 | __ sar(count, 2); // Number of doublewords to copy. |
| 5790 | __ cld(); |
| 5791 | __ rep_movs(); |
| 5792 | |
| 5793 | // Find number of bytes left. |
| 5794 | __ mov(count, scratch); |
| 5795 | __ and_(count, 3); |
| 5796 | |
| 5797 | // Check if there are more bytes to copy. |
| 5798 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5799 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5800 | __ j(zero, &done); |
| 5801 | |
| 5802 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5803 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5804 | __ bind(&loop); |
| 5805 | __ mov_b(scratch, Operand(src, 0)); |
| 5806 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5807 | __ add(src, Immediate(1)); |
| 5808 | __ add(dest, Immediate(1)); |
| 5809 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5810 | __ j(not_zero, &loop); |
| 5811 | |
| 5812 | __ bind(&done); |
| 5813 | } |
| 5814 | |
| 5815 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5816 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5817 | Register c1, |
| 5818 | Register c2, |
| 5819 | Register scratch1, |
| 5820 | Register scratch2, |
| 5821 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5822 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5823 | Label* not_found) { |
| 5824 | // Register scratch3 is the general scratch register in this function. |
| 5825 | Register scratch = scratch3; |
| 5826 | |
| 5827 | // 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] | 5828 | // 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] | 5829 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5830 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5831 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5832 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5833 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5834 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5835 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5836 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5837 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5838 | |
| 5839 | __ bind(¬_array_index); |
| 5840 | // Calculate the two character string hash. |
| 5841 | Register hash = scratch1; |
| 5842 | GenerateHashInit(masm, hash, c1, scratch); |
| 5843 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 5844 | GenerateHashGetHash(masm, hash, scratch); |
| 5845 | |
| 5846 | // Collect the two characters in a register. |
| 5847 | Register chars = c1; |
| 5848 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5849 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5850 | |
| 5851 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5852 | // hash: hash of two character string. |
| 5853 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5854 | // Load the string table. |
| 5855 | Register string_table = c2; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5856 | __ LoadRoot(string_table, Heap::kStringTableRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5857 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5858 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5859 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5860 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5861 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5862 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5863 | |
| 5864 | // Registers |
| 5865 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5866 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5867 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5868 | // mask: capacity mask |
| 5869 | // scratch: - |
| 5870 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5871 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5872 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5873 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5874 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5875 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5876 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5877 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5878 | __ mov(scratch, hash); |
| 5879 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5880 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5881 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5882 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5883 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5884 | // Load the entry from the string table. |
| 5885 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5886 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5887 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5888 | scratch, |
| 5889 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5890 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5891 | |
| 5892 | // 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] | 5893 | Factory* factory = masm->isolate()->factory(); |
| 5894 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5895 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5896 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5897 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5898 | |
| 5899 | // If length is not 2 the string is not a candidate. |
| 5900 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 5901 | Immediate(Smi::FromInt(2))); |
| 5902 | __ j(not_equal, &next_probe[i]); |
| 5903 | |
| 5904 | // As we are out of registers save the mask on the stack and use that |
| 5905 | // register as a temporary. |
| 5906 | __ push(mask); |
| 5907 | Register temp = mask; |
| 5908 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5909 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5910 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 5911 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 5912 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 5913 | temp, temp, &next_probe_pop_mask[i]); |
| 5914 | |
| 5915 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5916 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5917 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5918 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5919 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5920 | __ bind(&next_probe_pop_mask[i]); |
| 5921 | __ pop(mask); |
| 5922 | __ bind(&next_probe[i]); |
| 5923 | } |
| 5924 | |
| 5925 | // No matching 2 character string found by probing. |
| 5926 | __ jmp(not_found); |
| 5927 | |
| 5928 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5929 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5930 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5931 | __ pop(mask); // Pop saved mask from the stack. |
| 5932 | if (!result.is(eax)) { |
| 5933 | __ mov(eax, result); |
| 5934 | } |
| 5935 | } |
| 5936 | |
| 5937 | |
| 5938 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 5939 | Register hash, |
| 5940 | Register character, |
| 5941 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5942 | // hash = (seed + character) + ((seed + character) << 10); |
| 5943 | if (Serializer::enabled()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 5944 | __ LoadRoot(scratch, Heap::kHashSeedRootIndex); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5945 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5946 | __ add(scratch, character); |
| 5947 | __ mov(hash, scratch); |
| 5948 | __ shl(scratch, 10); |
| 5949 | __ add(hash, scratch); |
| 5950 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5951 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5952 | __ lea(scratch, Operand(character, seed)); |
| 5953 | __ shl(scratch, 10); |
| 5954 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 5955 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5956 | // hash ^= hash >> 6; |
| 5957 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5958 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5959 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5960 | } |
| 5961 | |
| 5962 | |
| 5963 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 5964 | Register hash, |
| 5965 | Register character, |
| 5966 | Register scratch) { |
| 5967 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5968 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5969 | // hash += hash << 10; |
| 5970 | __ mov(scratch, hash); |
| 5971 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5972 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5973 | // hash ^= hash >> 6; |
| 5974 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5975 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5976 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5977 | } |
| 5978 | |
| 5979 | |
| 5980 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 5981 | Register hash, |
| 5982 | Register scratch) { |
| 5983 | // hash += hash << 3; |
| 5984 | __ mov(scratch, hash); |
| 5985 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5986 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5987 | // hash ^= hash >> 11; |
| 5988 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5989 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5990 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5991 | // hash += hash << 15; |
| 5992 | __ mov(scratch, hash); |
| 5993 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5994 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5995 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5996 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5997 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5998 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5999 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6000 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6001 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6002 | __ bind(&hash_not_zero); |
| 6003 | } |
| 6004 | |
| 6005 | |
| 6006 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6007 | Label runtime; |
| 6008 | |
| 6009 | // Stack frame on entry. |
| 6010 | // esp[0]: return address |
| 6011 | // esp[4]: to |
| 6012 | // esp[8]: from |
| 6013 | // esp[12]: string |
| 6014 | |
| 6015 | // Make sure first argument is a string. |
| 6016 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6017 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6018 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6019 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6020 | __ j(NegateCondition(is_string), &runtime); |
| 6021 | |
| 6022 | // eax: string |
| 6023 | // ebx: instance type |
| 6024 | |
| 6025 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6026 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6027 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6028 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6029 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6030 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6031 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6032 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6033 | // Shorter than original string's length: an actual substring. |
| 6034 | __ j(below, ¬_original_string, Label::kNear); |
| 6035 | // Longer than original string's length or negative: unsafe arguments. |
| 6036 | __ j(above, &runtime); |
| 6037 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6038 | Counters* counters = masm->isolate()->counters(); |
| 6039 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6040 | __ ret(3 * kPointerSize); |
| 6041 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6042 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6043 | Label single_char; |
| 6044 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 6045 | __ j(equal, &single_char); |
| 6046 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6047 | // eax: string |
| 6048 | // ebx: instance type |
| 6049 | // ecx: sub string length (smi) |
| 6050 | // edx: from index (smi) |
| 6051 | // Deal with different string types: update the index if necessary |
| 6052 | // and put the underlying string into edi. |
| 6053 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6054 | // If the string is not indirect, it can only be sequential or external. |
| 6055 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6056 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6057 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6058 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6059 | |
| 6060 | Factory* factory = masm->isolate()->factory(); |
| 6061 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6062 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6063 | // Cons string. Check whether it is flat, then fetch first part. |
| 6064 | // Flat cons strings have an empty second part. |
| 6065 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6066 | factory->empty_string()); |
| 6067 | __ j(not_equal, &runtime); |
| 6068 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6069 | // Update instance type. |
| 6070 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6071 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6072 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6073 | |
| 6074 | __ bind(&sliced_string); |
| 6075 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6076 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6077 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6078 | // Update instance type. |
| 6079 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6080 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6081 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6082 | |
| 6083 | __ bind(&seq_or_external_string); |
| 6084 | // Sequential or external string. Just move string to the expected register. |
| 6085 | __ mov(edi, eax); |
| 6086 | |
| 6087 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6088 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6089 | if (FLAG_string_slices) { |
| 6090 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6091 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6092 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6093 | // edx: adjusted start index (smi) |
| 6094 | // ecx: length (smi) |
| 6095 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6096 | // Short slice. Copy instead of slicing. |
| 6097 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6098 | // Allocate new sliced string. At this point we do not reload the instance |
| 6099 | // type including the string encoding because we simply rely on the info |
| 6100 | // provided by the original string. It does not matter if the original |
| 6101 | // string's encoding is wrong because we always have to recheck encoding of |
| 6102 | // the newly created string's parent anyways due to externalized strings. |
| 6103 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6104 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6105 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6106 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6107 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6108 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6109 | __ jmp(&set_slice_header, Label::kNear); |
| 6110 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6111 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6112 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6113 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6114 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6115 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6116 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6117 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6118 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6119 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6120 | |
| 6121 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6122 | } |
| 6123 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6124 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6125 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6126 | // edx: adjusted start index (smi) |
| 6127 | // ecx: length (smi) |
| 6128 | // The subject string can only be external or sequential string of either |
| 6129 | // encoding at this point. |
| 6130 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6131 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6132 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6133 | __ test_b(ebx, kExternalStringTag); |
| 6134 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6135 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6136 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6137 | // Rule out short external strings. |
| 6138 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6139 | __ test_b(ebx, kShortExternalStringMask); |
| 6140 | __ j(not_zero, &runtime); |
| 6141 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6142 | // 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] | 6143 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6144 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6145 | |
| 6146 | __ bind(&sequential_string); |
| 6147 | // Stash away (adjusted) index and (underlying) string. |
| 6148 | __ push(edx); |
| 6149 | __ push(edi); |
| 6150 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6151 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6152 | __ test_b(ebx, kStringEncodingMask); |
| 6153 | __ j(zero, &two_byte_sequential); |
| 6154 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6155 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6156 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6157 | |
| 6158 | // eax: result string |
| 6159 | // ecx: result string length |
| 6160 | __ mov(edx, esi); // esi used by following code. |
| 6161 | // Locate first character of result. |
| 6162 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6163 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6164 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6165 | __ pop(esi); |
| 6166 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6167 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6168 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6169 | |
| 6170 | // eax: result string |
| 6171 | // ecx: result length |
| 6172 | // edx: original value of esi |
| 6173 | // edi: first character of result |
| 6174 | // esi: character of sub string start |
| 6175 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6176 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6177 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6178 | __ ret(3 * kPointerSize); |
| 6179 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6180 | __ bind(&two_byte_sequential); |
| 6181 | // Sequential two-byte string. Allocate the result. |
| 6182 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6183 | |
| 6184 | // eax: result string |
| 6185 | // ecx: result string length |
| 6186 | __ mov(edx, esi); // esi used by following code. |
| 6187 | // Locate first character of result. |
| 6188 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6189 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6190 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6191 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6192 | __ pop(esi); |
| 6193 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6194 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6195 | // byte character. |
| 6196 | STATIC_ASSERT(kSmiTag == 0); |
| 6197 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6198 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6199 | |
| 6200 | // eax: result string |
| 6201 | // ecx: result length |
| 6202 | // edx: original value of esi |
| 6203 | // edi: first character of result |
| 6204 | // esi: character of sub string start |
| 6205 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6206 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6207 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6208 | __ ret(3 * kPointerSize); |
| 6209 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6210 | // Drop pushed values on the stack before tail call. |
| 6211 | __ bind(&runtime_drop_two); |
| 6212 | __ Drop(2); |
| 6213 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6214 | // Just jump to runtime to create the sub string. |
| 6215 | __ bind(&runtime); |
| 6216 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6217 | |
| 6218 | __ bind(&single_char); |
| 6219 | // eax: string |
| 6220 | // ebx: instance type |
| 6221 | // ecx: sub string length (smi) |
| 6222 | // edx: from index (smi) |
| 6223 | StringCharAtGenerator generator( |
| 6224 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6225 | generator.GenerateFast(masm); |
| 6226 | __ ret(3 * kPointerSize); |
| 6227 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6231 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6232 | Register left, |
| 6233 | Register right, |
| 6234 | Register scratch1, |
| 6235 | Register scratch2) { |
| 6236 | Register length = scratch1; |
| 6237 | |
| 6238 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6239 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6240 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6241 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6242 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6243 | __ bind(&strings_not_equal); |
| 6244 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6245 | __ ret(0); |
| 6246 | |
| 6247 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6248 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6249 | __ bind(&check_zero_length); |
| 6250 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6251 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6252 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6253 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6254 | __ ret(0); |
| 6255 | |
| 6256 | // Compare characters. |
| 6257 | __ bind(&compare_chars); |
| 6258 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6259 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6260 | |
| 6261 | // Characters are equal. |
| 6262 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6263 | __ ret(0); |
| 6264 | } |
| 6265 | |
| 6266 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6267 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6268 | Register left, |
| 6269 | Register right, |
| 6270 | Register scratch1, |
| 6271 | Register scratch2, |
| 6272 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6273 | Counters* counters = masm->isolate()->counters(); |
| 6274 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6275 | |
| 6276 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6277 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6278 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6279 | __ mov(scratch3, scratch1); |
| 6280 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6281 | |
| 6282 | Register length_delta = scratch3; |
| 6283 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6284 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6285 | // 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] | 6286 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6287 | __ bind(&left_shorter); |
| 6288 | |
| 6289 | Register min_length = scratch1; |
| 6290 | |
| 6291 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6292 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6293 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6294 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6295 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6296 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6297 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6298 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6299 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6300 | |
| 6301 | // Compare lengths - strings up to min-length are equal. |
| 6302 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6303 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6304 | Label length_not_equal; |
| 6305 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6306 | |
| 6307 | // Result is EQUAL. |
| 6308 | STATIC_ASSERT(EQUAL == 0); |
| 6309 | STATIC_ASSERT(kSmiTag == 0); |
| 6310 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6311 | __ ret(0); |
| 6312 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6313 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6314 | Label result_less; |
| 6315 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6316 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6317 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6318 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6319 | __ j(above, &result_greater, Label::kNear); |
| 6320 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6321 | |
| 6322 | // Result is LESS. |
| 6323 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6324 | __ ret(0); |
| 6325 | |
| 6326 | // Result is GREATER. |
| 6327 | __ bind(&result_greater); |
| 6328 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6329 | __ ret(0); |
| 6330 | } |
| 6331 | |
| 6332 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6333 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6334 | MacroAssembler* masm, |
| 6335 | Register left, |
| 6336 | Register right, |
| 6337 | Register length, |
| 6338 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6339 | Label* chars_not_equal, |
| 6340 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6341 | // Change index to run from -length to -1 by adding length to string |
| 6342 | // start. This means that loop ends when index reaches zero, which |
| 6343 | // doesn't need an additional compare. |
| 6344 | __ SmiUntag(length); |
| 6345 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6346 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6347 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6348 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6349 | __ neg(length); |
| 6350 | Register index = length; // index = -length; |
| 6351 | |
| 6352 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6353 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6354 | __ bind(&loop); |
| 6355 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6356 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6357 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6358 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6359 | __ j(not_zero, &loop); |
| 6360 | } |
| 6361 | |
| 6362 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6363 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6364 | Label runtime; |
| 6365 | |
| 6366 | // Stack frame on entry. |
| 6367 | // esp[0]: return address |
| 6368 | // esp[4]: right string |
| 6369 | // esp[8]: left string |
| 6370 | |
| 6371 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6372 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6373 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6374 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6375 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6376 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6377 | STATIC_ASSERT(EQUAL == 0); |
| 6378 | STATIC_ASSERT(kSmiTag == 0); |
| 6379 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6380 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6381 | __ ret(2 * kPointerSize); |
| 6382 | |
| 6383 | __ bind(¬_same); |
| 6384 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6385 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6386 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6387 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6388 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6389 | // Drop arguments from the stack. |
| 6390 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6391 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6392 | __ push(ecx); |
| 6393 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6394 | |
| 6395 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6396 | // tagged as a small integer. |
| 6397 | __ bind(&runtime); |
| 6398 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6399 | } |
| 6400 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6401 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6402 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6403 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6404 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6405 | __ mov(ecx, edx); |
| 6406 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6407 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6408 | |
| 6409 | if (GetCondition() == equal) { |
| 6410 | // 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] | 6411 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6412 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6413 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6414 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6415 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6416 | // Correct sign of result in case of overflow. |
| 6417 | __ not_(edx); |
| 6418 | __ bind(&done); |
| 6419 | __ mov(eax, edx); |
| 6420 | } |
| 6421 | __ ret(0); |
| 6422 | |
| 6423 | __ bind(&miss); |
| 6424 | GenerateMiss(masm); |
| 6425 | } |
| 6426 | |
| 6427 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6428 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6429 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6430 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6431 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6432 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6433 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6434 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6435 | if (left_ == CompareIC::SMI) { |
| 6436 | __ JumpIfNotSmi(edx, &miss); |
| 6437 | } |
| 6438 | if (right_ == CompareIC::SMI) { |
| 6439 | __ JumpIfNotSmi(eax, &miss); |
| 6440 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6441 | |
| 6442 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6443 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6444 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6445 | CpuFeatureScope scope1(masm, SSE2); |
| 6446 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6447 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6448 | // Load left and right operand. |
| 6449 | Label done, left, left_smi, right_smi; |
| 6450 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6451 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6452 | masm->isolate()->factory()->heap_number_map()); |
| 6453 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6454 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6455 | __ jmp(&left, Label::kNear); |
| 6456 | __ bind(&right_smi); |
| 6457 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6458 | __ SmiUntag(ecx); |
| 6459 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6460 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6461 | __ bind(&left); |
| 6462 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6463 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6464 | masm->isolate()->factory()->heap_number_map()); |
| 6465 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6466 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6467 | __ jmp(&done); |
| 6468 | __ bind(&left_smi); |
| 6469 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6470 | __ SmiUntag(ecx); |
| 6471 | __ cvtsi2sd(xmm0, ecx); |
| 6472 | |
| 6473 | __ bind(&done); |
| 6474 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6475 | __ ucomisd(xmm0, xmm1); |
| 6476 | |
| 6477 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6478 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6479 | |
| 6480 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6481 | // Performing mov, because xor would destroy the flag register. |
| 6482 | __ mov(eax, 0); // equal |
| 6483 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6484 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6485 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6486 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6487 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6488 | } else { |
| 6489 | __ mov(ecx, edx); |
| 6490 | __ and_(ecx, eax); |
| 6491 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6492 | |
| 6493 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6494 | masm->isolate()->factory()->heap_number_map()); |
| 6495 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6496 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6497 | masm->isolate()->factory()->heap_number_map()); |
| 6498 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6499 | } |
| 6500 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6501 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6502 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6503 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6504 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6505 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6506 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6507 | __ bind(&maybe_undefined1); |
| 6508 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6509 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6510 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6511 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6512 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6513 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6514 | __ jmp(&unordered); |
| 6515 | } |
| 6516 | |
| 6517 | __ bind(&maybe_undefined2); |
| 6518 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6519 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6520 | __ j(equal, &unordered); |
| 6521 | } |
| 6522 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6523 | __ bind(&miss); |
| 6524 | GenerateMiss(masm); |
| 6525 | } |
| 6526 | |
| 6527 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6528 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 6529 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6530 | ASSERT(GetCondition() == equal); |
| 6531 | |
| 6532 | // Registers containing left and right operands respectively. |
| 6533 | Register left = edx; |
| 6534 | Register right = eax; |
| 6535 | Register tmp1 = ecx; |
| 6536 | Register tmp2 = ebx; |
| 6537 | |
| 6538 | // Check that both operands are heap objects. |
| 6539 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6540 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6541 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6542 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6543 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6544 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6545 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6546 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6547 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6548 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6549 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 6550 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 6551 | __ or_(tmp1, tmp2); |
| 6552 | __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 6553 | __ j(not_zero, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6554 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6555 | // Internalized strings are compared by identity. |
| 6556 | Label done; |
| 6557 | __ cmp(left, right); |
| 6558 | // Make sure eax is non-zero. At this point input operands are |
| 6559 | // guaranteed to be non-zero. |
| 6560 | ASSERT(right.is(eax)); |
| 6561 | __ j(not_equal, &done, Label::kNear); |
| 6562 | STATIC_ASSERT(EQUAL == 0); |
| 6563 | STATIC_ASSERT(kSmiTag == 0); |
| 6564 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6565 | __ bind(&done); |
| 6566 | __ ret(0); |
| 6567 | |
| 6568 | __ bind(&miss); |
| 6569 | GenerateMiss(masm); |
| 6570 | } |
| 6571 | |
| 6572 | |
| 6573 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 6574 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 6575 | ASSERT(GetCondition() == equal); |
| 6576 | |
| 6577 | // Registers containing left and right operands respectively. |
| 6578 | Register left = edx; |
| 6579 | Register right = eax; |
| 6580 | Register tmp1 = ecx; |
| 6581 | Register tmp2 = ebx; |
| 6582 | |
| 6583 | // Check that both operands are heap objects. |
| 6584 | Label miss; |
| 6585 | __ mov(tmp1, left); |
| 6586 | STATIC_ASSERT(kSmiTag == 0); |
| 6587 | __ and_(tmp1, right); |
| 6588 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 6589 | |
| 6590 | // Check that both operands are unique names. This leaves the instance |
| 6591 | // types loaded in tmp1 and tmp2. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6592 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6593 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6594 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6595 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6596 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6597 | __ JumpIfNotUniqueName(tmp1, &miss, Label::kNear); |
| 6598 | __ JumpIfNotUniqueName(tmp2, &miss, Label::kNear); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6599 | |
| 6600 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6601 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6602 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6603 | // Make sure eax is non-zero. At this point input operands are |
| 6604 | // guaranteed to be non-zero. |
| 6605 | ASSERT(right.is(eax)); |
| 6606 | __ j(not_equal, &done, Label::kNear); |
| 6607 | STATIC_ASSERT(EQUAL == 0); |
| 6608 | STATIC_ASSERT(kSmiTag == 0); |
| 6609 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6610 | __ bind(&done); |
| 6611 | __ ret(0); |
| 6612 | |
| 6613 | __ bind(&miss); |
| 6614 | GenerateMiss(masm); |
| 6615 | } |
| 6616 | |
| 6617 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6618 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6619 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6620 | Label miss; |
| 6621 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6622 | bool equality = Token::IsEqualityOp(op_); |
| 6623 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6624 | // Registers containing left and right operands respectively. |
| 6625 | Register left = edx; |
| 6626 | Register right = eax; |
| 6627 | Register tmp1 = ecx; |
| 6628 | Register tmp2 = ebx; |
| 6629 | Register tmp3 = edi; |
| 6630 | |
| 6631 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6632 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6633 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6634 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6635 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6636 | |
| 6637 | // Check that both operands are strings. This leaves the instance |
| 6638 | // types loaded in tmp1 and tmp2. |
| 6639 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6640 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6641 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6642 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6643 | __ mov(tmp3, tmp1); |
| 6644 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6645 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6646 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6647 | __ j(not_zero, &miss); |
| 6648 | |
| 6649 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6650 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6651 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6652 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6653 | STATIC_ASSERT(EQUAL == 0); |
| 6654 | STATIC_ASSERT(kSmiTag == 0); |
| 6655 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6656 | __ ret(0); |
| 6657 | |
| 6658 | // Handle not identical strings. |
| 6659 | __ bind(¬_same); |
| 6660 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6661 | // 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] | 6662 | // 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] | 6663 | // non-equality compare, we still need to determine the order. We |
| 6664 | // also know they are both strings. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6665 | if (equality) { |
| 6666 | Label do_compare; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 6667 | STATIC_ASSERT(kInternalizedTag == 0); |
| 6668 | __ or_(tmp1, tmp2); |
| 6669 | __ test(tmp1, Immediate(kIsNotInternalizedMask)); |
| 6670 | __ j(not_zero, &do_compare, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6671 | // Make sure eax is non-zero. At this point input operands are |
| 6672 | // guaranteed to be non-zero. |
| 6673 | ASSERT(right.is(eax)); |
| 6674 | __ ret(0); |
| 6675 | __ bind(&do_compare); |
| 6676 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6677 | |
| 6678 | // Check that both strings are sequential ASCII. |
| 6679 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6680 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6681 | |
| 6682 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6683 | if (equality) { |
| 6684 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6685 | masm, left, right, tmp1, tmp2); |
| 6686 | } else { |
| 6687 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6688 | masm, left, right, tmp1, tmp2, tmp3); |
| 6689 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6690 | |
| 6691 | // Handle more complex cases in runtime. |
| 6692 | __ bind(&runtime); |
| 6693 | __ pop(tmp1); // Return address. |
| 6694 | __ push(left); |
| 6695 | __ push(right); |
| 6696 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6697 | if (equality) { |
| 6698 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6699 | } else { |
| 6700 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6701 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6702 | |
| 6703 | __ bind(&miss); |
| 6704 | GenerateMiss(masm); |
| 6705 | } |
| 6706 | |
| 6707 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6708 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6709 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6710 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6711 | __ mov(ecx, edx); |
| 6712 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6713 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6714 | |
| 6715 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6716 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6717 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6718 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6719 | |
| 6720 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6721 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6722 | __ ret(0); |
| 6723 | |
| 6724 | __ bind(&miss); |
| 6725 | GenerateMiss(masm); |
| 6726 | } |
| 6727 | |
| 6728 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6729 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6730 | Label miss; |
| 6731 | __ mov(ecx, edx); |
| 6732 | __ and_(ecx, eax); |
| 6733 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6734 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6735 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 6736 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 6737 | __ cmp(ecx, known_map_); |
| 6738 | __ j(not_equal, &miss, Label::kNear); |
| 6739 | __ cmp(ebx, known_map_); |
| 6740 | __ j(not_equal, &miss, Label::kNear); |
| 6741 | |
| 6742 | __ sub(eax, edx); |
| 6743 | __ ret(0); |
| 6744 | |
| 6745 | __ bind(&miss); |
| 6746 | GenerateMiss(masm); |
| 6747 | } |
| 6748 | |
| 6749 | |
| 6750 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6751 | { |
| 6752 | // Call the runtime system in a fresh internal frame. |
| 6753 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 6754 | masm->isolate()); |
| 6755 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6756 | __ push(edx); // Preserve edx and eax. |
| 6757 | __ push(eax); |
| 6758 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6759 | __ push(eax); |
| 6760 | __ push(Immediate(Smi::FromInt(op_))); |
| 6761 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6762 | // Compute the entry point of the rewritten stub. |
| 6763 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 6764 | __ pop(eax); |
| 6765 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6766 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6767 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6768 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6769 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6770 | } |
| 6771 | |
| 6772 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6773 | // Helper function used to check that the dictionary doesn't contain |
| 6774 | // the property. This function may return false negatives, so miss_label |
| 6775 | // must always call a backup property check that is complete. |
| 6776 | // 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] | 6777 | // Name must be a unique name and receiver must be a heap object. |
| 6778 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6779 | Label* miss, |
| 6780 | Label* done, |
| 6781 | Register properties, |
| 6782 | Handle<Name> name, |
| 6783 | Register r0) { |
| 6784 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6785 | |
| 6786 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6787 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6788 | // undefined value), it guarantees the hash table doesn't contain the |
| 6789 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6790 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6791 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6792 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6793 | Register index = r0; |
| 6794 | // Capacity is smi 2^n. |
| 6795 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 6796 | __ dec(index); |
| 6797 | __ and_(index, |
| 6798 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6799 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6800 | |
| 6801 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6802 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6803 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6804 | Register entity_name = r0; |
| 6805 | // Having undefined at this place means the name is not contained. |
| 6806 | ASSERT_EQ(kSmiTagSize, 1); |
| 6807 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 6808 | kElementsStartOffset - kHeapObjectTag)); |
| 6809 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 6810 | __ j(equal, done); |
| 6811 | |
| 6812 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6813 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6814 | __ j(equal, miss); |
| 6815 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6816 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6817 | // Check for the hole and skip. |
| 6818 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6819 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6820 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6821 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6822 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6823 | __ JumpIfNotUniqueName(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6824 | miss); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6825 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6826 | } |
| 6827 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6828 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6829 | __ push(Immediate(Handle<Object>(name))); |
| 6830 | __ push(Immediate(name->Hash())); |
| 6831 | __ CallStub(&stub); |
| 6832 | __ test(r0, r0); |
| 6833 | __ j(not_zero, miss); |
| 6834 | __ jmp(done); |
| 6835 | } |
| 6836 | |
| 6837 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6838 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6839 | // |done| label if a property with the given name is found leaving the |
| 6840 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 6841 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6842 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6843 | Label* miss, |
| 6844 | Label* done, |
| 6845 | Register elements, |
| 6846 | Register name, |
| 6847 | Register r0, |
| 6848 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6849 | ASSERT(!elements.is(r0)); |
| 6850 | ASSERT(!elements.is(r1)); |
| 6851 | ASSERT(!name.is(r0)); |
| 6852 | ASSERT(!name.is(r1)); |
| 6853 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6854 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6855 | |
| 6856 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 6857 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 6858 | __ dec(r1); |
| 6859 | |
| 6860 | // Generate an unrolled loop that performs a few probes before |
| 6861 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6862 | // cover ~93% of loads from dictionaries. |
| 6863 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6864 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6865 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 6866 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6867 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6868 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6869 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6870 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6871 | |
| 6872 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6873 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6874 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 6875 | |
| 6876 | // Check if the key is identical to the name. |
| 6877 | __ cmp(name, Operand(elements, |
| 6878 | r0, |
| 6879 | times_4, |
| 6880 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6881 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6882 | } |
| 6883 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6884 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6885 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6886 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 6887 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6888 | __ push(r0); |
| 6889 | __ CallStub(&stub); |
| 6890 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6891 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6892 | __ j(zero, miss); |
| 6893 | __ jmp(done); |
| 6894 | } |
| 6895 | |
| 6896 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6897 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6898 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 6899 | // 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] | 6900 | // Stack frame on entry: |
| 6901 | // esp[0 * kPointerSize]: return address. |
| 6902 | // esp[1 * kPointerSize]: key's hash. |
| 6903 | // esp[2 * kPointerSize]: key. |
| 6904 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6905 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6906 | // result_: used as scratch. |
| 6907 | // index_: will hold an index of entry if lookup is successful. |
| 6908 | // might alias with result_. |
| 6909 | // Returns: |
| 6910 | // result_ is zero if lookup failed, non zero otherwise. |
| 6911 | |
| 6912 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 6913 | |
| 6914 | Register scratch = result_; |
| 6915 | |
| 6916 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 6917 | __ dec(scratch); |
| 6918 | __ SmiUntag(scratch); |
| 6919 | __ push(scratch); |
| 6920 | |
| 6921 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6922 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6923 | // undefined value), it guarantees the hash table doesn't contain the |
| 6924 | // property. It's true even if some slots represent deleted properties |
| 6925 | // (their names are the null value). |
| 6926 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 6927 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6928 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 6929 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6930 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6931 | } |
| 6932 | __ and_(scratch, Operand(esp, 0)); |
| 6933 | |
| 6934 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6935 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6936 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 6937 | |
| 6938 | // Having undefined at this place means the name is not contained. |
| 6939 | ASSERT_EQ(kSmiTagSize, 1); |
| 6940 | __ mov(scratch, Operand(dictionary_, |
| 6941 | index_, |
| 6942 | times_pointer_size, |
| 6943 | kElementsStartOffset - kHeapObjectTag)); |
| 6944 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 6945 | __ j(equal, ¬_in_dictionary); |
| 6946 | |
| 6947 | // Stop if found the property. |
| 6948 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 6949 | __ j(equal, &in_dictionary); |
| 6950 | |
| 6951 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6952 | // 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] | 6953 | // 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] | 6954 | // key we are looking for. |
| 6955 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6956 | // Check if the entry name is not a unique name. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6957 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6958 | __ JumpIfNotUniqueName(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 6959 | &maybe_in_dictionary); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6960 | } |
| 6961 | } |
| 6962 | |
| 6963 | __ bind(&maybe_in_dictionary); |
| 6964 | // If we are doing negative lookup then probing failure should be |
| 6965 | // treated as a lookup success. For positive lookup probing failure |
| 6966 | // should be treated as lookup failure. |
| 6967 | if (mode_ == POSITIVE_LOOKUP) { |
| 6968 | __ mov(result_, Immediate(0)); |
| 6969 | __ Drop(1); |
| 6970 | __ ret(2 * kPointerSize); |
| 6971 | } |
| 6972 | |
| 6973 | __ bind(&in_dictionary); |
| 6974 | __ mov(result_, Immediate(1)); |
| 6975 | __ Drop(1); |
| 6976 | __ ret(2 * kPointerSize); |
| 6977 | |
| 6978 | __ bind(¬_in_dictionary); |
| 6979 | __ mov(result_, Immediate(0)); |
| 6980 | __ Drop(1); |
| 6981 | __ ret(2 * kPointerSize); |
| 6982 | } |
| 6983 | |
| 6984 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6985 | struct AheadOfTimeWriteBarrierStubList { |
| 6986 | Register object, value, address; |
| 6987 | RememberedSetAction action; |
| 6988 | }; |
| 6989 | |
| 6990 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6991 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 6992 | |
| 6993 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6994 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6995 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6996 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6997 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 6998 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6999 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7000 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7001 | // Used in StoreStubCompiler::CompileStoreField and |
| 7002 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7003 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7004 | // GenerateStoreField calls the stub with two different permutations of |
| 7005 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7006 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7007 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7008 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7009 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7010 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7011 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7012 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7013 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7014 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7015 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7016 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7017 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7018 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7019 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7020 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7021 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7022 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7023 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7024 | // FastNewClosureStub and StringAddStub::Generate |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7025 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7026 | // StringAddStub::Generate |
| 7027 | { REG(ecx), REG(eax), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7028 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7029 | { 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] | 7030 | }; |
| 7031 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7032 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7033 | |
| 7034 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7035 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7036 | !entry->object.is(no_reg); |
| 7037 | entry++) { |
| 7038 | if (object_.is(entry->object) && |
| 7039 | value_.is(entry->value) && |
| 7040 | address_.is(entry->address) && |
| 7041 | remembered_set_action_ == entry->action && |
| 7042 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7043 | return true; |
| 7044 | } |
| 7045 | } |
| 7046 | return false; |
| 7047 | } |
| 7048 | |
| 7049 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7050 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 7051 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7052 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
| 7053 | stub.GetCode(isolate)->set_is_pregenerated(true); |
| 7054 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7055 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7056 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7057 | } |
| 7058 | } |
| 7059 | |
| 7060 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7061 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7062 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7063 | !entry->object.is(no_reg); |
| 7064 | entry++) { |
| 7065 | RecordWriteStub stub(entry->object, |
| 7066 | entry->value, |
| 7067 | entry->address, |
| 7068 | entry->action, |
| 7069 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7070 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7071 | } |
| 7072 | } |
| 7073 | |
| 7074 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7075 | bool CodeStub::CanUseFPRegisters() { |
| 7076 | return CpuFeatures::IsSupported(SSE2); |
| 7077 | } |
| 7078 | |
| 7079 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7080 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7081 | // the value has just been written into the object, now this stub makes sure |
| 7082 | // we keep the GC informed. The word in the object where the value has been |
| 7083 | // written is in the address register. |
| 7084 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7085 | Label skip_to_incremental_noncompacting; |
| 7086 | Label skip_to_incremental_compacting; |
| 7087 | |
| 7088 | // The first two instructions are generated with labels so as to get the |
| 7089 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7090 | // forth between a compare instructions (a nop in this position) and the |
| 7091 | // real branch when we start and stop incremental heap marking. |
| 7092 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7093 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7094 | |
| 7095 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7096 | __ RememberedSetHelper(object_, |
| 7097 | address_, |
| 7098 | value_, |
| 7099 | save_fp_regs_mode_, |
| 7100 | MacroAssembler::kReturnAtEnd); |
| 7101 | } else { |
| 7102 | __ ret(0); |
| 7103 | } |
| 7104 | |
| 7105 | __ bind(&skip_to_incremental_noncompacting); |
| 7106 | GenerateIncremental(masm, INCREMENTAL); |
| 7107 | |
| 7108 | __ bind(&skip_to_incremental_compacting); |
| 7109 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7110 | |
| 7111 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7112 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7113 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7114 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7115 | } |
| 7116 | |
| 7117 | |
| 7118 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7119 | regs_.Save(masm); |
| 7120 | |
| 7121 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7122 | Label dont_need_remembered_set; |
| 7123 | |
| 7124 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7125 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7126 | regs_.scratch0(), |
| 7127 | &dont_need_remembered_set); |
| 7128 | |
| 7129 | __ CheckPageFlag(regs_.object(), |
| 7130 | regs_.scratch0(), |
| 7131 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7132 | not_zero, |
| 7133 | &dont_need_remembered_set); |
| 7134 | |
| 7135 | // First notify the incremental marker if necessary, then update the |
| 7136 | // remembered set. |
| 7137 | CheckNeedsToInformIncrementalMarker( |
| 7138 | masm, |
| 7139 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7140 | mode); |
| 7141 | InformIncrementalMarker(masm, mode); |
| 7142 | regs_.Restore(masm); |
| 7143 | __ RememberedSetHelper(object_, |
| 7144 | address_, |
| 7145 | value_, |
| 7146 | save_fp_regs_mode_, |
| 7147 | MacroAssembler::kReturnAtEnd); |
| 7148 | |
| 7149 | __ bind(&dont_need_remembered_set); |
| 7150 | } |
| 7151 | |
| 7152 | CheckNeedsToInformIncrementalMarker( |
| 7153 | masm, |
| 7154 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7155 | mode); |
| 7156 | InformIncrementalMarker(masm, mode); |
| 7157 | regs_.Restore(masm); |
| 7158 | __ ret(0); |
| 7159 | } |
| 7160 | |
| 7161 | |
| 7162 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7163 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7164 | int argument_count = 3; |
| 7165 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7166 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7167 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7168 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 7169 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7170 | |
| 7171 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7172 | if (mode == INCREMENTAL_COMPACTION) { |
| 7173 | __ CallCFunction( |
| 7174 | ExternalReference::incremental_evacuation_record_write_function( |
| 7175 | masm->isolate()), |
| 7176 | argument_count); |
| 7177 | } else { |
| 7178 | ASSERT(mode == INCREMENTAL); |
| 7179 | __ CallCFunction( |
| 7180 | ExternalReference::incremental_marking_record_write_function( |
| 7181 | masm->isolate()), |
| 7182 | argument_count); |
| 7183 | } |
| 7184 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7185 | } |
| 7186 | |
| 7187 | |
| 7188 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7189 | MacroAssembler* masm, |
| 7190 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7191 | Mode mode) { |
| 7192 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7193 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7194 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7195 | __ and_(regs_.scratch0(), regs_.object()); |
| 7196 | __ mov(regs_.scratch1(), |
| 7197 | Operand(regs_.scratch0(), |
| 7198 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7199 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7200 | __ mov(Operand(regs_.scratch0(), |
| 7201 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7202 | regs_.scratch1()); |
| 7203 | __ j(negative, &need_incremental); |
| 7204 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7205 | // Let's look at the color of the object: If it is not black we don't have |
| 7206 | // to inform the incremental marker. |
| 7207 | __ JumpIfBlack(regs_.object(), |
| 7208 | regs_.scratch0(), |
| 7209 | regs_.scratch1(), |
| 7210 | &object_is_black, |
| 7211 | Label::kNear); |
| 7212 | |
| 7213 | regs_.Restore(masm); |
| 7214 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7215 | __ RememberedSetHelper(object_, |
| 7216 | address_, |
| 7217 | value_, |
| 7218 | save_fp_regs_mode_, |
| 7219 | MacroAssembler::kReturnAtEnd); |
| 7220 | } else { |
| 7221 | __ ret(0); |
| 7222 | } |
| 7223 | |
| 7224 | __ bind(&object_is_black); |
| 7225 | |
| 7226 | // Get the value from the slot. |
| 7227 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7228 | |
| 7229 | if (mode == INCREMENTAL_COMPACTION) { |
| 7230 | Label ensure_not_white; |
| 7231 | |
| 7232 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7233 | regs_.scratch1(), // Scratch. |
| 7234 | MemoryChunk::kEvacuationCandidateMask, |
| 7235 | zero, |
| 7236 | &ensure_not_white, |
| 7237 | Label::kNear); |
| 7238 | |
| 7239 | __ CheckPageFlag(regs_.object(), |
| 7240 | regs_.scratch1(), // Scratch. |
| 7241 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7242 | not_zero, |
| 7243 | &ensure_not_white, |
| 7244 | Label::kNear); |
| 7245 | |
| 7246 | __ jmp(&need_incremental); |
| 7247 | |
| 7248 | __ bind(&ensure_not_white); |
| 7249 | } |
| 7250 | |
| 7251 | // We need an extra register for this, so we push the object register |
| 7252 | // temporarily. |
| 7253 | __ push(regs_.object()); |
| 7254 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7255 | regs_.scratch1(), // Scratch. |
| 7256 | regs_.object(), // Scratch. |
| 7257 | &need_incremental_pop_object, |
| 7258 | Label::kNear); |
| 7259 | __ pop(regs_.object()); |
| 7260 | |
| 7261 | regs_.Restore(masm); |
| 7262 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7263 | __ RememberedSetHelper(object_, |
| 7264 | address_, |
| 7265 | value_, |
| 7266 | save_fp_regs_mode_, |
| 7267 | MacroAssembler::kReturnAtEnd); |
| 7268 | } else { |
| 7269 | __ ret(0); |
| 7270 | } |
| 7271 | |
| 7272 | __ bind(&need_incremental_pop_object); |
| 7273 | __ pop(regs_.object()); |
| 7274 | |
| 7275 | __ bind(&need_incremental); |
| 7276 | |
| 7277 | // Fall through when we need to inform the incremental marker. |
| 7278 | } |
| 7279 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7280 | |
| 7281 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7282 | // ----------- S t a t e ------------- |
| 7283 | // -- eax : element value to store |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7284 | // -- ecx : element index as smi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7285 | // -- esp[0] : return address |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7286 | // -- esp[4] : array literal index in function |
| 7287 | // -- esp[8] : array literal |
| 7288 | // clobbers ebx, edx, edi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7289 | // ----------------------------------- |
| 7290 | |
| 7291 | Label element_done; |
| 7292 | Label double_elements; |
| 7293 | Label smi_element; |
| 7294 | Label slow_elements; |
| 7295 | Label slow_elements_from_double; |
| 7296 | Label fast_elements; |
| 7297 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7298 | // Get array literal index, array literal and its map. |
| 7299 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 7300 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 7301 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 7302 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7303 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7304 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7305 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7306 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7307 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7308 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7309 | // Store into the array literal requires a elements transition. Call into |
| 7310 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7311 | |
| 7312 | __ bind(&slow_elements); |
| 7313 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7314 | // call. |
| 7315 | __ push(ebx); |
| 7316 | __ push(ecx); |
| 7317 | __ push(eax); |
| 7318 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7319 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7320 | __ push(edx); |
| 7321 | __ push(edi); // Return return address so that tail call returns to right |
| 7322 | // place. |
| 7323 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7324 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7325 | __ bind(&slow_elements_from_double); |
| 7326 | __ pop(edx); |
| 7327 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7328 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7329 | // 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] | 7330 | __ bind(&fast_elements); |
| 7331 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7332 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7333 | FixedArrayBase::kHeaderSize)); |
| 7334 | __ mov(Operand(ecx, 0), eax); |
| 7335 | // Update the write barrier for the array store. |
| 7336 | __ RecordWrite(ebx, ecx, eax, |
| 7337 | kDontSaveFPRegs, |
| 7338 | EMIT_REMEMBERED_SET, |
| 7339 | OMIT_SMI_CHECK); |
| 7340 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7341 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7342 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7343 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7344 | __ bind(&smi_element); |
| 7345 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7346 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7347 | FixedArrayBase::kHeaderSize), eax); |
| 7348 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7349 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7350 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7351 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7352 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7353 | __ push(edx); |
| 7354 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7355 | __ StoreNumberToDoubleElements(eax, |
| 7356 | edx, |
| 7357 | ecx, |
| 7358 | edi, |
| 7359 | xmm0, |
| 7360 | &slow_elements_from_double, |
| 7361 | false); |
| 7362 | __ pop(edx); |
| 7363 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7364 | } |
| 7365 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7366 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7367 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7368 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7369 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7370 | int parameter_count_offset = |
| 7371 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7372 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7373 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7374 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7375 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 7376 | ? kPointerSize |
| 7377 | : 0; |
| 7378 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7379 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7380 | } |
| 7381 | |
| 7382 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7383 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7384 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 7385 | // It's always safe to call the entry hook stub, as the hook itself |
| 7386 | // is not allowed to call back to V8. |
| 7387 | AllowStubCallsScope allow_stub_calls(masm, true); |
| 7388 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7389 | ProfileEntryHookStub stub; |
| 7390 | masm->CallStub(&stub); |
| 7391 | } |
| 7392 | } |
| 7393 | |
| 7394 | |
| 7395 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7396 | // Save volatile registers. |
| 7397 | const int kNumSavedRegisters = 3; |
| 7398 | __ push(eax); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7399 | __ push(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7400 | __ push(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7401 | |
| 7402 | // Calculate and push the original stack pointer. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7403 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7404 | __ push(eax); |
| 7405 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7406 | // Retrieve our return address and use it to calculate the calling |
| 7407 | // function's address. |
| 7408 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7409 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7410 | __ push(eax); |
| 7411 | |
| 7412 | // Call the entry hook. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7413 | ASSERT(masm->isolate()->function_entry_hook() != NULL); |
| 7414 | __ call(FUNCTION_ADDR(masm->isolate()->function_entry_hook()), |
| 7415 | RelocInfo::RUNTIME_ENTRY); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7416 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7417 | |
| 7418 | // Restore ecx. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7419 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7420 | __ pop(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7421 | __ pop(eax); |
| 7422 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7423 | __ ret(0); |
| 7424 | } |
| 7425 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7426 | |
| 7427 | template<class T> |
| 7428 | static void CreateArrayDispatch(MacroAssembler* masm) { |
| 7429 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7430 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7431 | for (int i = 0; i <= last_index; ++i) { |
| 7432 | Label next; |
| 7433 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7434 | __ cmp(edx, kind); |
| 7435 | __ j(not_equal, &next); |
| 7436 | T stub(kind); |
| 7437 | __ TailCallStub(&stub); |
| 7438 | __ bind(&next); |
| 7439 | } |
| 7440 | |
| 7441 | // If we reached this point there is a problem. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 7442 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7443 | } |
| 7444 | |
| 7445 | |
| 7446 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm) { |
| 7447 | // ebx - type info cell |
| 7448 | // edx - kind |
| 7449 | // eax - number of arguments |
| 7450 | // edi - constructor? |
| 7451 | // esp[0] - return address |
| 7452 | // esp[4] - last argument |
| 7453 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 7454 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 7455 | ASSERT(FAST_ELEMENTS == 2); |
| 7456 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 7457 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 7458 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 7459 | |
| 7460 | Handle<Object> undefined_sentinel( |
| 7461 | masm->isolate()->heap()->undefined_value(), |
| 7462 | masm->isolate()); |
| 7463 | |
| 7464 | // is the low bit set? If so, we are holey and that is good. |
| 7465 | __ test_b(edx, 1); |
| 7466 | Label normal_sequence; |
| 7467 | __ j(not_zero, &normal_sequence); |
| 7468 | |
| 7469 | // look at the first argument |
| 7470 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7471 | __ test(ecx, ecx); |
| 7472 | __ j(zero, &normal_sequence); |
| 7473 | |
| 7474 | // 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] | 7475 | // 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] | 7476 | __ inc(edx); |
| 7477 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7478 | __ j(equal, &normal_sequence); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7479 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
| 7480 | Handle<Map> allocation_site_map( |
| 7481 | masm->isolate()->heap()->allocation_site_map(), |
| 7482 | masm->isolate()); |
| 7483 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 7484 | __ j(not_equal, &normal_sequence); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7485 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7486 | // Save the resulting elements kind in type info |
| 7487 | __ SmiTag(edx); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7488 | __ mov(FieldOperand(ecx, AllocationSite::kTransitionInfoOffset), edx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7489 | __ SmiUntag(edx); |
| 7490 | |
| 7491 | __ bind(&normal_sequence); |
| 7492 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7493 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7494 | for (int i = 0; i <= last_index; ++i) { |
| 7495 | Label next; |
| 7496 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7497 | __ cmp(edx, kind); |
| 7498 | __ j(not_equal, &next); |
| 7499 | ArraySingleArgumentConstructorStub stub(kind); |
| 7500 | __ TailCallStub(&stub); |
| 7501 | __ bind(&next); |
| 7502 | } |
| 7503 | |
| 7504 | // If we reached this point there is a problem. |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 7505 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7506 | } |
| 7507 | |
| 7508 | |
| 7509 | template<class T> |
| 7510 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 7511 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 7512 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7513 | for (int i = 0; i <= to_index; ++i) { |
| 7514 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7515 | T stub(kind); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7516 | stub.GetCode(isolate)->set_is_pregenerated(true); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7517 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7518 | T stub1(kind, CONTEXT_CHECK_REQUIRED, DISABLE_ALLOCATION_SITES); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7519 | stub1.GetCode(isolate)->set_is_pregenerated(true); |
| 7520 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7521 | } |
| 7522 | } |
| 7523 | |
| 7524 | |
| 7525 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 7526 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 7527 | isolate); |
| 7528 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 7529 | isolate); |
| 7530 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 7531 | isolate); |
| 7532 | } |
| 7533 | |
| 7534 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7535 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 7536 | Isolate* isolate) { |
| 7537 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 7538 | for (int i = 0; i < 2; i++) { |
| 7539 | // For internal arrays we only need a few things |
| 7540 | InternalArrayNoArgumentConstructorStub stubh1(kinds[i]); |
| 7541 | stubh1.GetCode(isolate)->set_is_pregenerated(true); |
| 7542 | InternalArraySingleArgumentConstructorStub stubh2(kinds[i]); |
| 7543 | stubh2.GetCode(isolate)->set_is_pregenerated(true); |
| 7544 | InternalArrayNArgumentsConstructorStub stubh3(kinds[i]); |
| 7545 | stubh3.GetCode(isolate)->set_is_pregenerated(true); |
| 7546 | } |
| 7547 | } |
| 7548 | |
| 7549 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7550 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7551 | // ----------- S t a t e ------------- |
| 7552 | // -- eax : argc (only if argument_count_ == ANY) |
| 7553 | // -- ebx : type info cell |
| 7554 | // -- edi : constructor |
| 7555 | // -- esp[0] : return address |
| 7556 | // -- esp[4] : last argument |
| 7557 | // ----------------------------------- |
| 7558 | Handle<Object> undefined_sentinel( |
| 7559 | masm->isolate()->heap()->undefined_value(), |
| 7560 | masm->isolate()); |
| 7561 | |
| 7562 | if (FLAG_debug_code) { |
| 7563 | // The array construct code is only set for the global and natives |
| 7564 | // builtin Array functions which always have maps. |
| 7565 | |
| 7566 | // Initial map for the builtin Array function should be a map. |
| 7567 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7568 | // Will both indicate a NULL and a Smi. |
| 7569 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 7570 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7571 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 7572 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7573 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7574 | // We should either have undefined in ebx or a valid cell |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7575 | Label okay_here; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7576 | Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7577 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7578 | __ j(equal, &okay_here); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7579 | __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 7580 | __ Assert(equal, kExpectedPropertyCellInRegisterEbx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7581 | __ bind(&okay_here); |
| 7582 | } |
| 7583 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7584 | Label no_info, switch_ready; |
| 7585 | // Get the elements kind and case on that. |
| 7586 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7587 | __ j(equal, &no_info); |
| 7588 | __ mov(edx, FieldOperand(ebx, Cell::kValueOffset)); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7589 | |
| 7590 | // The type cell may have undefined in its value. |
| 7591 | __ cmp(edx, Immediate(undefined_sentinel)); |
| 7592 | __ j(equal, &no_info); |
| 7593 | |
| 7594 | // The type cell has either an AllocationSite or a JSFunction |
| 7595 | __ cmp(FieldOperand(edx, 0), Immediate(Handle<Map>( |
| 7596 | masm->isolate()->heap()->allocation_site_map()))); |
| 7597 | __ j(not_equal, &no_info); |
| 7598 | |
| 7599 | __ mov(edx, FieldOperand(edx, AllocationSite::kTransitionInfoOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7600 | __ SmiUntag(edx); |
| 7601 | __ jmp(&switch_ready); |
| 7602 | __ bind(&no_info); |
| 7603 | __ mov(edx, Immediate(GetInitialFastElementsKind())); |
| 7604 | __ bind(&switch_ready); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7605 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7606 | if (argument_count_ == ANY) { |
| 7607 | Label not_zero_case, not_one_case; |
| 7608 | __ test(eax, eax); |
| 7609 | __ j(not_zero, ¬_zero_case); |
| 7610 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7611 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7612 | __ bind(¬_zero_case); |
| 7613 | __ cmp(eax, 1); |
| 7614 | __ j(greater, ¬_one_case); |
| 7615 | CreateArrayDispatchOneArgument(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7616 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7617 | __ bind(¬_one_case); |
| 7618 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
| 7619 | } else if (argument_count_ == NONE) { |
| 7620 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
| 7621 | } else if (argument_count_ == ONE) { |
| 7622 | CreateArrayDispatchOneArgument(masm); |
| 7623 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 7624 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7625 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7626 | UNREACHABLE(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7627 | } |
| 7628 | } |
| 7629 | |
| 7630 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7631 | void InternalArrayConstructorStub::GenerateCase( |
| 7632 | MacroAssembler* masm, ElementsKind kind) { |
| 7633 | Label not_zero_case, not_one_case; |
| 7634 | Label normal_sequence; |
| 7635 | |
| 7636 | __ test(eax, eax); |
| 7637 | __ j(not_zero, ¬_zero_case); |
| 7638 | InternalArrayNoArgumentConstructorStub stub0(kind); |
| 7639 | __ TailCallStub(&stub0); |
| 7640 | |
| 7641 | __ bind(¬_zero_case); |
| 7642 | __ cmp(eax, 1); |
| 7643 | __ j(greater, ¬_one_case); |
| 7644 | |
| 7645 | if (IsFastPackedElementsKind(kind)) { |
| 7646 | // We might need to create a holey array |
| 7647 | // look at the first argument |
| 7648 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7649 | __ test(ecx, ecx); |
| 7650 | __ j(zero, &normal_sequence); |
| 7651 | |
| 7652 | InternalArraySingleArgumentConstructorStub |
| 7653 | stub1_holey(GetHoleyElementsKind(kind)); |
| 7654 | __ TailCallStub(&stub1_holey); |
| 7655 | } |
| 7656 | |
| 7657 | __ bind(&normal_sequence); |
| 7658 | InternalArraySingleArgumentConstructorStub stub1(kind); |
| 7659 | __ TailCallStub(&stub1); |
| 7660 | |
| 7661 | __ bind(¬_one_case); |
| 7662 | InternalArrayNArgumentsConstructorStub stubN(kind); |
| 7663 | __ TailCallStub(&stubN); |
| 7664 | } |
| 7665 | |
| 7666 | |
| 7667 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7668 | // ----------- S t a t e ------------- |
| 7669 | // -- eax : argc |
| 7670 | // -- ebx : type info cell |
| 7671 | // -- edi : constructor |
| 7672 | // -- esp[0] : return address |
| 7673 | // -- esp[4] : last argument |
| 7674 | // ----------------------------------- |
| 7675 | |
| 7676 | if (FLAG_debug_code) { |
| 7677 | // The array construct code is only set for the global and natives |
| 7678 | // builtin Array functions which always have maps. |
| 7679 | |
| 7680 | // Initial map for the builtin Array function should be a map. |
| 7681 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7682 | // Will both indicate a NULL and a Smi. |
| 7683 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 7684 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7685 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 7686 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7687 | } |
| 7688 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7689 | // Figure out the right elements kind |
| 7690 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7691 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7692 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 7693 | // but the following masking takes care of that anyway. |
| 7694 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 7695 | // Retrieve elements_kind from bit field 2. |
| 7696 | __ and_(ecx, Map::kElementsKindMask); |
| 7697 | __ shr(ecx, Map::kElementsKindShift); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7698 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7699 | if (FLAG_debug_code) { |
| 7700 | Label done; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7701 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7702 | __ j(equal, &done); |
| 7703 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 7704 | __ Assert(equal, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame^] | 7705 | kInvalidElementsKindForInternalArrayOrInternalPackedArray); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7706 | __ bind(&done); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7707 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7708 | |
| 7709 | Label fast_elements_case; |
| 7710 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 7711 | __ j(equal, &fast_elements_case); |
| 7712 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 7713 | |
| 7714 | __ bind(&fast_elements_case); |
| 7715 | GenerateCase(masm, FAST_ELEMENTS); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7716 | } |
| 7717 | |
| 7718 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7719 | #undef __ |
| 7720 | |
| 7721 | } } // namespace v8::internal |
| 7722 | |
| 7723 | #endif // V8_TARGET_ARCH_IA32 |