yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 30 | #if V8_TARGET_ARCH_IA32 |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 31 | |
| 32 | #include "bootstrapper.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 33 | #include "code-stubs.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 34 | #include "isolate.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 35 | #include "jsregexp.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 36 | #include "regexp-macro-assembler.h" |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 37 | #include "runtime.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 38 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 39 | #include "codegen.h" |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 40 | #include "runtime.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 41 | |
| 42 | namespace v8 { |
| 43 | namespace internal { |
| 44 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 45 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 46 | void FastNewClosureStub::InitializeInterfaceDescriptor( |
| 47 | Isolate* isolate, |
| 48 | CodeStubInterfaceDescriptor* descriptor) { |
| 49 | static Register registers[] = { ebx }; |
| 50 | descriptor->register_param_count_ = 1; |
| 51 | descriptor->register_params_ = registers; |
| 52 | descriptor->deoptimization_handler_ = |
| 53 | Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry; |
| 54 | } |
| 55 | |
| 56 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 57 | void ToNumberStub::InitializeInterfaceDescriptor( |
| 58 | Isolate* isolate, |
| 59 | CodeStubInterfaceDescriptor* descriptor) { |
| 60 | static Register registers[] = { eax }; |
| 61 | descriptor->register_param_count_ = 1; |
| 62 | descriptor->register_params_ = registers; |
| 63 | descriptor->deoptimization_handler_ = NULL; |
| 64 | } |
| 65 | |
| 66 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame^] | 67 | void NumberToStringStub::InitializeInterfaceDescriptor( |
| 68 | Isolate* isolate, |
| 69 | CodeStubInterfaceDescriptor* descriptor) { |
| 70 | static Register registers[] = { eax }; |
| 71 | descriptor->register_param_count_ = 1; |
| 72 | descriptor->register_params_ = registers; |
| 73 | descriptor->deoptimization_handler_ = NULL; |
| 74 | } |
| 75 | |
| 76 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 77 | void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( |
| 78 | Isolate* isolate, |
| 79 | CodeStubInterfaceDescriptor* descriptor) { |
| 80 | static Register registers[] = { eax, ebx, ecx }; |
| 81 | descriptor->register_param_count_ = 3; |
| 82 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 83 | descriptor->deoptimization_handler_ = |
| 84 | Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; |
| 85 | } |
| 86 | |
| 87 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 88 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 89 | Isolate* isolate, |
| 90 | CodeStubInterfaceDescriptor* descriptor) { |
| 91 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 92 | descriptor->register_param_count_ = 4; |
| 93 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 94 | descriptor->deoptimization_handler_ = |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 95 | Runtime::FunctionForId(Runtime::kCreateObjectLiteral)->entry; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 99 | void CreateAllocationSiteStub::InitializeInterfaceDescriptor( |
| 100 | Isolate* isolate, |
| 101 | CodeStubInterfaceDescriptor* descriptor) { |
| 102 | static Register registers[] = { ebx }; |
| 103 | descriptor->register_param_count_ = 1; |
| 104 | descriptor->register_params_ = registers; |
| 105 | descriptor->deoptimization_handler_ = NULL; |
| 106 | } |
| 107 | |
| 108 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 109 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 110 | Isolate* isolate, |
| 111 | CodeStubInterfaceDescriptor* descriptor) { |
| 112 | static Register registers[] = { edx, ecx }; |
| 113 | descriptor->register_param_count_ = 2; |
| 114 | descriptor->register_params_ = registers; |
| 115 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 116 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 120 | void LoadFieldStub::InitializeInterfaceDescriptor( |
| 121 | Isolate* isolate, |
| 122 | CodeStubInterfaceDescriptor* descriptor) { |
| 123 | static Register registers[] = { edx }; |
| 124 | descriptor->register_param_count_ = 1; |
| 125 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 126 | descriptor->deoptimization_handler_ = NULL; |
| 127 | } |
| 128 | |
| 129 | |
| 130 | void KeyedLoadFieldStub::InitializeInterfaceDescriptor( |
| 131 | Isolate* isolate, |
| 132 | CodeStubInterfaceDescriptor* descriptor) { |
| 133 | static Register registers[] = { edx }; |
| 134 | descriptor->register_param_count_ = 1; |
| 135 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 136 | descriptor->deoptimization_handler_ = NULL; |
| 137 | } |
| 138 | |
| 139 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 140 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 141 | Isolate* isolate, |
| 142 | CodeStubInterfaceDescriptor* descriptor) { |
| 143 | static Register registers[] = { edx, ecx, eax }; |
| 144 | descriptor->register_param_count_ = 3; |
| 145 | descriptor->register_params_ = registers; |
| 146 | descriptor->deoptimization_handler_ = |
| 147 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 148 | } |
| 149 | |
| 150 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 151 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 152 | Isolate* isolate, |
| 153 | CodeStubInterfaceDescriptor* descriptor) { |
| 154 | static Register registers[] = { eax, ebx }; |
| 155 | descriptor->register_param_count_ = 2; |
| 156 | descriptor->register_params_ = registers; |
| 157 | descriptor->deoptimization_handler_ = |
| 158 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 159 | } |
| 160 | |
| 161 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 162 | static void InitializeArrayConstructorDescriptor( |
| 163 | Isolate* isolate, |
| 164 | CodeStubInterfaceDescriptor* descriptor, |
| 165 | int constant_stack_parameter_count) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 166 | // register state |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 167 | // eax -- number of arguments |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 168 | // edi -- function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 169 | // ebx -- type info cell with elements kind |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 170 | static Register registers[] = { edi, ebx }; |
| 171 | descriptor->register_param_count_ = 2; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 172 | |
| 173 | if (constant_stack_parameter_count != 0) { |
| 174 | // stack param count needs (constructor pointer, and single argument) |
| 175 | descriptor->stack_parameter_count_ = &eax; |
| 176 | } |
| 177 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 178 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 179 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 180 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 181 | Runtime::FunctionForId(Runtime::kArrayConstructor)->entry; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 185 | static void InitializeInternalArrayConstructorDescriptor( |
| 186 | Isolate* isolate, |
| 187 | CodeStubInterfaceDescriptor* descriptor, |
| 188 | int constant_stack_parameter_count) { |
| 189 | // register state |
| 190 | // eax -- number of arguments |
| 191 | // edi -- constructor function |
| 192 | static Register registers[] = { edi }; |
| 193 | descriptor->register_param_count_ = 1; |
| 194 | |
| 195 | if (constant_stack_parameter_count != 0) { |
| 196 | // stack param count needs (constructor pointer, and single argument) |
| 197 | descriptor->stack_parameter_count_ = &eax; |
| 198 | } |
| 199 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
| 200 | descriptor->register_params_ = registers; |
| 201 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
| 202 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 203 | Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 207 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 208 | Isolate* isolate, |
| 209 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 210 | InitializeArrayConstructorDescriptor(isolate, descriptor, 0); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | |
| 214 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 215 | Isolate* isolate, |
| 216 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 217 | InitializeArrayConstructorDescriptor(isolate, descriptor, 1); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | |
| 221 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 222 | Isolate* isolate, |
| 223 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 224 | InitializeArrayConstructorDescriptor(isolate, descriptor, -1); |
| 225 | } |
| 226 | |
| 227 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 228 | void InternalArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 229 | Isolate* isolate, |
| 230 | CodeStubInterfaceDescriptor* descriptor) { |
| 231 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 0); |
| 232 | } |
| 233 | |
| 234 | |
| 235 | void InternalArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 236 | Isolate* isolate, |
| 237 | CodeStubInterfaceDescriptor* descriptor) { |
| 238 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 1); |
| 239 | } |
| 240 | |
| 241 | |
| 242 | void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 243 | Isolate* isolate, |
| 244 | CodeStubInterfaceDescriptor* descriptor) { |
| 245 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, -1); |
| 246 | } |
| 247 | |
| 248 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 249 | void CompareNilICStub::InitializeInterfaceDescriptor( |
| 250 | Isolate* isolate, |
| 251 | CodeStubInterfaceDescriptor* descriptor) { |
| 252 | static Register registers[] = { eax }; |
| 253 | descriptor->register_param_count_ = 1; |
| 254 | descriptor->register_params_ = registers; |
| 255 | descriptor->deoptimization_handler_ = |
| 256 | FUNCTION_ADDR(CompareNilIC_Miss); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 257 | descriptor->SetMissHandler( |
| 258 | ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 259 | } |
| 260 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 261 | void ToBooleanStub::InitializeInterfaceDescriptor( |
| 262 | Isolate* isolate, |
| 263 | CodeStubInterfaceDescriptor* descriptor) { |
| 264 | static Register registers[] = { eax }; |
| 265 | descriptor->register_param_count_ = 1; |
| 266 | descriptor->register_params_ = registers; |
| 267 | descriptor->deoptimization_handler_ = |
| 268 | FUNCTION_ADDR(ToBooleanIC_Miss); |
| 269 | descriptor->SetMissHandler( |
| 270 | ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate)); |
| 271 | } |
| 272 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 273 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 274 | void StoreGlobalStub::InitializeInterfaceDescriptor( |
| 275 | Isolate* isolate, |
| 276 | CodeStubInterfaceDescriptor* descriptor) { |
| 277 | static Register registers[] = { edx, ecx, eax }; |
| 278 | descriptor->register_param_count_ = 3; |
| 279 | descriptor->register_params_ = registers; |
| 280 | descriptor->deoptimization_handler_ = |
| 281 | FUNCTION_ADDR(StoreIC_MissFromStubFailure); |
| 282 | } |
| 283 | |
| 284 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 285 | void ElementsTransitionAndStoreStub::InitializeInterfaceDescriptor( |
| 286 | Isolate* isolate, |
| 287 | CodeStubInterfaceDescriptor* descriptor) { |
| 288 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 289 | descriptor->register_param_count_ = 4; |
| 290 | descriptor->register_params_ = registers; |
| 291 | descriptor->deoptimization_handler_ = |
| 292 | FUNCTION_ADDR(ElementsTransitionAndStoreIC_Miss); |
| 293 | } |
| 294 | |
| 295 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 296 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 297 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 298 | |
| 299 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
| 300 | // Update the static counter each time a new code stub is generated. |
| 301 | Isolate* isolate = masm->isolate(); |
| 302 | isolate->counters()->code_stubs()->Increment(); |
| 303 | |
| 304 | CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
| 305 | int param_count = descriptor->register_param_count_; |
| 306 | { |
| 307 | // Call the runtime system in a fresh internal frame. |
| 308 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 309 | ASSERT(descriptor->register_param_count_ == 0 || |
| 310 | eax.is(descriptor->register_params_[param_count - 1])); |
| 311 | // Push arguments |
| 312 | for (int i = 0; i < param_count; ++i) { |
| 313 | __ push(descriptor->register_params_[i]); |
| 314 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 315 | ExternalReference miss = descriptor->miss_handler(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 316 | __ CallExternalReference(miss, descriptor->register_param_count_); |
| 317 | } |
| 318 | |
| 319 | __ ret(0); |
| 320 | } |
| 321 | |
| 322 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 323 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 324 | // Try to allocate the context in new space. |
| 325 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 326 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 327 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 328 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 329 | |
| 330 | // Get the function from the stack. |
| 331 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 332 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 333 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 334 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 335 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 336 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 337 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 338 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 339 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 340 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 341 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 342 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 343 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 344 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 345 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 346 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 347 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 348 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 349 | |
| 350 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 351 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 352 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 353 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 354 | } |
| 355 | |
| 356 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 357 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 358 | __ ret(1 * kPointerSize); |
| 359 | |
| 360 | // Need to collect. Call into runtime system. |
| 361 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 362 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 366 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 367 | // Stack layout on entry: |
| 368 | // |
| 369 | // [esp + (1 * kPointerSize)]: function |
| 370 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 371 | |
| 372 | // Try to allocate the context in new space. |
| 373 | Label gc; |
| 374 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 375 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 376 | |
| 377 | // Get the function or sentinel from the stack. |
| 378 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 379 | |
| 380 | // Get the serialized scope info from the stack. |
| 381 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 382 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 383 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 384 | Factory* factory = masm->isolate()->factory(); |
| 385 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 386 | factory->block_context_map()); |
| 387 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 388 | Immediate(Smi::FromInt(length))); |
| 389 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 390 | // 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] | 391 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 392 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 393 | // we still have to look up. |
| 394 | Label after_sentinel; |
| 395 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 396 | if (FLAG_debug_code) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 397 | __ cmp(ecx, 0); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 398 | __ Assert(equal, kExpected0AsASmiSentinel); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 399 | } |
| 400 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 401 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 402 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 403 | __ bind(&after_sentinel); |
| 404 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 405 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 406 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 407 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 408 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 409 | |
| 410 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 411 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 412 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 413 | |
| 414 | // Initialize the rest of the slots to the hole value. |
| 415 | if (slots_ == 1) { |
| 416 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 417 | factory->the_hole_value()); |
| 418 | } else { |
| 419 | __ mov(ebx, factory->the_hole_value()); |
| 420 | for (int i = 0; i < slots_; i++) { |
| 421 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | // Return and remove the on-stack parameters. |
| 426 | __ mov(esi, eax); |
| 427 | __ ret(2 * kPointerSize); |
| 428 | |
| 429 | // Need to collect. Call into runtime system. |
| 430 | __ bind(&gc); |
| 431 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 432 | } |
| 433 | |
| 434 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 435 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 436 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 437 | // store the registers in any particular way, but we do have to store and |
| 438 | // restore them. |
| 439 | __ pushad(); |
| 440 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 441 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 442 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 443 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 444 | XMMRegister reg = XMMRegister::from_code(i); |
| 445 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 446 | } |
| 447 | } |
| 448 | const int argument_count = 1; |
| 449 | |
| 450 | AllowExternalCallThatCantCauseGC scope(masm); |
| 451 | __ PrepareCallCFunction(argument_count, ecx); |
| 452 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 453 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 454 | __ CallCFunction( |
| 455 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 456 | argument_count); |
| 457 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 458 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 459 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 460 | XMMRegister reg = XMMRegister::from_code(i); |
| 461 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 462 | } |
| 463 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 464 | } |
| 465 | __ popad(); |
| 466 | __ ret(0); |
| 467 | } |
| 468 | |
| 469 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 470 | class FloatingPointHelper : public AllStatic { |
| 471 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 472 | enum ArgLocation { |
| 473 | ARGS_ON_STACK, |
| 474 | ARGS_IN_REGISTERS |
| 475 | }; |
| 476 | |
| 477 | // Code pattern for loading a floating point value. Input value must |
| 478 | // be either a smi or a heap number object (fp value). Requirements: |
| 479 | // operand in register number. Returns operand as floating point number |
| 480 | // on FPU stack. |
| 481 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 482 | |
| 483 | // Code pattern for loading floating point values. Input values must |
| 484 | // be either smi or heap number objects (fp values). Requirements: |
| 485 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 486 | // Returns operands as floating point numbers on FPU stack. |
| 487 | static void LoadFloatOperands(MacroAssembler* masm, |
| 488 | Register scratch, |
| 489 | ArgLocation arg_location = ARGS_ON_STACK); |
| 490 | |
| 491 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 492 | // Expects operands in edx, eax. |
| 493 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 494 | |
| 495 | // Test if operands are smi or number objects (fp). Requirements: |
| 496 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 497 | // operands, jumps to the non_float label otherwise. |
| 498 | static void CheckFloatOperands(MacroAssembler* masm, |
| 499 | Label* non_float, |
| 500 | Register scratch); |
| 501 | |
| 502 | // Takes the operands in edx and eax and loads them as integers in eax |
| 503 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 504 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 505 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 506 | BinaryOpIC::TypeInfo left_type, |
| 507 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 508 | Label* operand_conversion_failure); |
| 509 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 510 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 511 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 512 | // either operand is not a number. Operands are in edx and eax. |
| 513 | // Leaves operands unchanged. |
| 514 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 515 | |
| 516 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 517 | // Expects operands in edx, eax. |
| 518 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 519 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 520 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 521 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 522 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 523 | Label* non_int32, |
| 524 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 525 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 526 | Register scratch, |
| 527 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 528 | }; |
| 529 | |
| 530 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 531 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 532 | Register input_reg = this->source(); |
| 533 | Register final_result_reg = this->destination(); |
| 534 | ASSERT(is_truncating()); |
| 535 | |
| 536 | Label check_negative, process_64_bits, done, done_no_stash; |
| 537 | |
| 538 | int double_offset = offset(); |
| 539 | |
| 540 | // Account for return address and saved regs if input is esp. |
| 541 | if (input_reg.is(esp)) double_offset += 3 * kPointerSize; |
| 542 | |
| 543 | MemOperand mantissa_operand(MemOperand(input_reg, double_offset)); |
| 544 | MemOperand exponent_operand(MemOperand(input_reg, |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 545 | double_offset + kDoubleSize / 2)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 546 | |
| 547 | Register scratch1; |
| 548 | { |
| 549 | Register scratch_candidates[3] = { ebx, edx, edi }; |
| 550 | for (int i = 0; i < 3; i++) { |
| 551 | scratch1 = scratch_candidates[i]; |
| 552 | if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break; |
| 553 | } |
| 554 | } |
| 555 | // Since we must use ecx for shifts below, use some other register (eax) |
| 556 | // to calculate the result if ecx is the requested return register. |
| 557 | Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg; |
| 558 | // Save ecx if it isn't the return register and therefore volatile, or if it |
| 559 | // is the return register, then save the temp register we use in its stead for |
| 560 | // the result. |
| 561 | Register save_reg = final_result_reg.is(ecx) ? eax : ecx; |
| 562 | __ push(scratch1); |
| 563 | __ push(save_reg); |
| 564 | |
| 565 | bool stash_exponent_copy = !input_reg.is(esp); |
| 566 | __ mov(scratch1, mantissa_operand); |
| 567 | if (CpuFeatures::IsSupported(SSE3)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 568 | CpuFeatureScope scope(masm, SSE3); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 569 | // Load x87 register with heap number. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 570 | __ fld_d(mantissa_operand); |
| 571 | } |
| 572 | __ mov(ecx, exponent_operand); |
| 573 | if (stash_exponent_copy) __ push(ecx); |
| 574 | |
| 575 | __ and_(ecx, HeapNumber::kExponentMask); |
| 576 | __ shr(ecx, HeapNumber::kExponentShift); |
| 577 | __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias)); |
| 578 | __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits)); |
| 579 | __ j(below, &process_64_bits); |
| 580 | |
| 581 | // Result is entirely in lower 32-bits of mantissa |
| 582 | int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize; |
| 583 | if (CpuFeatures::IsSupported(SSE3)) { |
| 584 | __ fstp(0); |
| 585 | } |
| 586 | __ sub(ecx, Immediate(delta)); |
| 587 | __ xor_(result_reg, result_reg); |
| 588 | __ cmp(ecx, Immediate(31)); |
| 589 | __ j(above, &done); |
| 590 | __ shl_cl(scratch1); |
| 591 | __ jmp(&check_negative); |
| 592 | |
| 593 | __ bind(&process_64_bits); |
| 594 | if (CpuFeatures::IsSupported(SSE3)) { |
| 595 | CpuFeatureScope scope(masm, SSE3); |
| 596 | if (stash_exponent_copy) { |
| 597 | // Already a copy of the exponent on the stack, overwrite it. |
| 598 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 599 | __ sub(esp, Immediate(kDoubleSize / 2)); |
| 600 | } else { |
| 601 | // Reserve space for 64 bit answer. |
| 602 | __ sub(esp, Immediate(kDoubleSize)); // Nolint. |
| 603 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 604 | // Do conversion, which cannot fail because we checked the exponent. |
| 605 | __ fisttp_d(Operand(esp, 0)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 606 | __ mov(result_reg, Operand(esp, 0)); // Load low word of answer as result |
| 607 | __ add(esp, Immediate(kDoubleSize)); |
| 608 | __ jmp(&done_no_stash); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 609 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 610 | // Result must be extracted from shifted 32-bit mantissa |
| 611 | __ sub(ecx, Immediate(delta)); |
| 612 | __ neg(ecx); |
| 613 | if (stash_exponent_copy) { |
| 614 | __ mov(result_reg, MemOperand(esp, 0)); |
| 615 | } else { |
| 616 | __ mov(result_reg, exponent_operand); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 617 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 618 | __ and_(result_reg, |
| 619 | Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32))); |
| 620 | __ add(result_reg, |
| 621 | Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32))); |
| 622 | __ shrd(result_reg, scratch1); |
| 623 | __ shr_cl(result_reg); |
| 624 | __ test(ecx, Immediate(32)); |
| 625 | if (CpuFeatures::IsSupported(CMOV)) { |
| 626 | CpuFeatureScope use_cmov(masm, CMOV); |
| 627 | __ cmov(not_equal, scratch1, result_reg); |
| 628 | } else { |
| 629 | Label skip_mov; |
| 630 | __ j(equal, &skip_mov, Label::kNear); |
| 631 | __ mov(scratch1, result_reg); |
| 632 | __ bind(&skip_mov); |
| 633 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 634 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 635 | |
| 636 | // If the double was negative, negate the integer result. |
| 637 | __ bind(&check_negative); |
| 638 | __ mov(result_reg, scratch1); |
| 639 | __ neg(result_reg); |
| 640 | if (stash_exponent_copy) { |
| 641 | __ cmp(MemOperand(esp, 0), Immediate(0)); |
| 642 | } else { |
| 643 | __ cmp(exponent_operand, Immediate(0)); |
| 644 | } |
| 645 | if (CpuFeatures::IsSupported(CMOV)) { |
| 646 | CpuFeatureScope use_cmov(masm, CMOV); |
| 647 | __ cmov(greater, result_reg, scratch1); |
| 648 | } else { |
| 649 | Label skip_mov; |
| 650 | __ j(less_equal, &skip_mov, Label::kNear); |
| 651 | __ mov(result_reg, scratch1); |
| 652 | __ bind(&skip_mov); |
| 653 | } |
| 654 | |
| 655 | // Restore registers |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 656 | __ bind(&done); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 657 | if (stash_exponent_copy) { |
| 658 | __ add(esp, Immediate(kDoubleSize / 2)); |
| 659 | } |
| 660 | __ bind(&done_no_stash); |
| 661 | if (!final_result_reg.is(result_reg)) { |
| 662 | ASSERT(final_result_reg.is(ecx)); |
| 663 | __ mov(final_result_reg, result_reg); |
| 664 | } |
| 665 | __ pop(save_reg); |
| 666 | __ pop(scratch1); |
| 667 | __ ret(0); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 671 | void BinaryOpStub::Initialize() { |
| 672 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 673 | } |
| 674 | |
| 675 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 676 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 677 | __ pop(ecx); // Save return address. |
| 678 | __ push(edx); |
| 679 | __ push(eax); |
| 680 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 681 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 682 | |
| 683 | __ push(ecx); // Push return address. |
| 684 | |
| 685 | // Patch the caller to an appropriate specialized stub and return the |
| 686 | // operation result to the caller of the stub. |
| 687 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 688 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 689 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 690 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 691 | 1); |
| 692 | } |
| 693 | |
| 694 | |
| 695 | // Prepare for a type transition runtime call when the args are already on |
| 696 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 697 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 698 | __ pop(ecx); // Save return address. |
| 699 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 700 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 701 | |
| 702 | __ push(ecx); // Push return address. |
| 703 | |
| 704 | // Patch the caller to an appropriate specialized stub and return the |
| 705 | // operation result to the caller of the stub. |
| 706 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 707 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 708 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 709 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 710 | 1); |
| 711 | } |
| 712 | |
| 713 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 714 | static void BinaryOpStub_GenerateRegisterArgsPop(MacroAssembler* masm) { |
| 715 | __ pop(ecx); |
| 716 | __ pop(eax); |
| 717 | __ pop(edx); |
| 718 | __ push(ecx); |
| 719 | } |
| 720 | |
| 721 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 722 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 723 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 724 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 725 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 726 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 727 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 728 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 729 | Comment load_comment(masm, "-- Load arguments"); |
| 730 | Register left = edx; |
| 731 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 732 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 733 | left = eax; |
| 734 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 735 | __ mov(ebx, eax); |
| 736 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | |
| 740 | // 2. Prepare the smi check of both operands by oring them together. |
| 741 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 742 | Label not_smis; |
| 743 | Register combined = ecx; |
| 744 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 745 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 746 | case Token::BIT_OR: |
| 747 | // Perform the operation into eax and smi check the result. Preserve |
| 748 | // eax in case the result is not a smi. |
| 749 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 750 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 751 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 752 | combined = right; |
| 753 | break; |
| 754 | |
| 755 | case Token::BIT_XOR: |
| 756 | case Token::BIT_AND: |
| 757 | case Token::ADD: |
| 758 | case Token::SUB: |
| 759 | case Token::MUL: |
| 760 | case Token::DIV: |
| 761 | case Token::MOD: |
| 762 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 763 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 764 | break; |
| 765 | |
| 766 | case Token::SHL: |
| 767 | case Token::SAR: |
| 768 | case Token::SHR: |
| 769 | // Move the right operand into ecx for the shift operation, use eax |
| 770 | // for the smi check register. |
| 771 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 772 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 773 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 774 | combined = right; |
| 775 | break; |
| 776 | |
| 777 | default: |
| 778 | break; |
| 779 | } |
| 780 | |
| 781 | // 3. Perform the smi check of the operands. |
| 782 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 783 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 784 | |
| 785 | // 4. Operands are both smis, perform the operation leaving the result in |
| 786 | // eax and check the result if necessary. |
| 787 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 788 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 789 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 790 | case Token::BIT_OR: |
| 791 | // Nothing to do. |
| 792 | break; |
| 793 | |
| 794 | case Token::BIT_XOR: |
| 795 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 796 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 797 | break; |
| 798 | |
| 799 | case Token::BIT_AND: |
| 800 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 801 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 802 | break; |
| 803 | |
| 804 | case Token::SHL: |
| 805 | // Remove tags from operands (but keep sign). |
| 806 | __ SmiUntag(left); |
| 807 | __ SmiUntag(ecx); |
| 808 | // Perform the operation. |
| 809 | __ shl_cl(left); |
| 810 | // Check that the *signed* result fits in a smi. |
| 811 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 812 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 813 | // Tag the result and store it in register eax. |
| 814 | __ SmiTag(left); |
| 815 | __ mov(eax, left); |
| 816 | break; |
| 817 | |
| 818 | case Token::SAR: |
| 819 | // Remove tags from operands (but keep sign). |
| 820 | __ SmiUntag(left); |
| 821 | __ SmiUntag(ecx); |
| 822 | // Perform the operation. |
| 823 | __ sar_cl(left); |
| 824 | // Tag the result and store it in register eax. |
| 825 | __ SmiTag(left); |
| 826 | __ mov(eax, left); |
| 827 | break; |
| 828 | |
| 829 | case Token::SHR: |
| 830 | // Remove tags from operands (but keep sign). |
| 831 | __ SmiUntag(left); |
| 832 | __ SmiUntag(ecx); |
| 833 | // Perform the operation. |
| 834 | __ shr_cl(left); |
| 835 | // Check that the *unsigned* result fits in a smi. |
| 836 | // Neither of the two high-order bits can be set: |
| 837 | // - 0x80000000: high bit would be lost when smi tagging. |
| 838 | // - 0x40000000: this number would convert to negative when |
| 839 | // Smi tagging these two cases can only happen with shifts |
| 840 | // by 0 or 1 when handed a valid smi. |
| 841 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 842 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 843 | // Tag the result and store it in register eax. |
| 844 | __ SmiTag(left); |
| 845 | __ mov(eax, left); |
| 846 | break; |
| 847 | |
| 848 | case Token::ADD: |
| 849 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 850 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 851 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 852 | break; |
| 853 | |
| 854 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 855 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 856 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 857 | __ mov(eax, left); |
| 858 | break; |
| 859 | |
| 860 | case Token::MUL: |
| 861 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 862 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 863 | // We can't revert the multiplication if the result is not a smi |
| 864 | // so save the right operand. |
| 865 | __ mov(ebx, right); |
| 866 | // Remove tag from one of the operands (but keep sign). |
| 867 | __ SmiUntag(right); |
| 868 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 869 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 870 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 871 | // Check for negative zero result. Use combined = left | right. |
| 872 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 873 | break; |
| 874 | |
| 875 | case Token::DIV: |
| 876 | // We can't revert the division if the result is not a smi so |
| 877 | // save the left operand. |
| 878 | __ mov(edi, left); |
| 879 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 880 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 881 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 882 | // Sign extend left into edx:eax. |
| 883 | ASSERT(left.is(eax)); |
| 884 | __ cdq(); |
| 885 | // Divide edx:eax by right. |
| 886 | __ idiv(right); |
| 887 | // Check for the corner case of dividing the most negative smi by |
| 888 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 889 | // instruction. |
| 890 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 891 | __ cmp(eax, 0x40000000); |
| 892 | __ j(equal, &use_fp_on_smis); |
| 893 | // Check for negative zero result. Use combined = left | right. |
| 894 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 895 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 896 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 897 | __ j(not_zero, &use_fp_on_smis); |
| 898 | // Tag the result and store it in register eax. |
| 899 | __ SmiTag(eax); |
| 900 | break; |
| 901 | |
| 902 | case Token::MOD: |
| 903 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 904 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 905 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 906 | |
| 907 | // Sign extend left into edx:eax. |
| 908 | ASSERT(left.is(eax)); |
| 909 | __ cdq(); |
| 910 | // Divide edx:eax by right. |
| 911 | __ idiv(right); |
| 912 | // Check for negative zero result. Use combined = left | right. |
| 913 | __ NegativeZeroTest(edx, combined, slow); |
| 914 | // Move remainder to register eax. |
| 915 | __ mov(eax, edx); |
| 916 | break; |
| 917 | |
| 918 | default: |
| 919 | UNREACHABLE(); |
| 920 | } |
| 921 | |
| 922 | // 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] | 923 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 924 | case Token::ADD: |
| 925 | case Token::SUB: |
| 926 | case Token::MUL: |
| 927 | case Token::DIV: |
| 928 | __ ret(0); |
| 929 | break; |
| 930 | case Token::MOD: |
| 931 | case Token::BIT_OR: |
| 932 | case Token::BIT_AND: |
| 933 | case Token::BIT_XOR: |
| 934 | case Token::SAR: |
| 935 | case Token::SHL: |
| 936 | case Token::SHR: |
| 937 | __ ret(2 * kPointerSize); |
| 938 | break; |
| 939 | default: |
| 940 | UNREACHABLE(); |
| 941 | } |
| 942 | |
| 943 | // 6. For some operations emit inline code to perform floating point |
| 944 | // operations on known smis (e.g., if the result of the operation |
| 945 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 946 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 947 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 948 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 949 | // Undo the effects of some operations, and some register moves. |
| 950 | case Token::SHL: |
| 951 | // The arguments are saved on the stack, and only used from there. |
| 952 | break; |
| 953 | case Token::ADD: |
| 954 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 955 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 956 | break; |
| 957 | case Token::SUB: |
| 958 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 959 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 960 | break; |
| 961 | case Token::MUL: |
| 962 | // Right was clobbered but a copy is in ebx. |
| 963 | __ mov(right, ebx); |
| 964 | break; |
| 965 | case Token::DIV: |
| 966 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 967 | // division. They should be in eax, ebx for jump to not_smi. |
| 968 | __ mov(eax, edi); |
| 969 | break; |
| 970 | default: |
| 971 | // No other operators jump to use_fp_on_smis. |
| 972 | break; |
| 973 | } |
| 974 | __ jmp(¬_smis); |
| 975 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 976 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 977 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 978 | case Token::SHL: |
| 979 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 980 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 981 | __ bind(&use_fp_on_smis); |
| 982 | // Result we want is in left == edx, so we can put the allocated heap |
| 983 | // number in eax. |
| 984 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 985 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 986 | // It's OK to overwrite the arguments on the stack because we |
| 987 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 988 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 989 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 990 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 991 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 992 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 993 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 994 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 995 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 996 | CpuFeatureScope use_sse2(masm, SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 997 | __ Cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 998 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 999 | } else { |
| 1000 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1001 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1002 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1003 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1004 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1005 | __ ret(2 * kPointerSize); |
| 1006 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
| 1009 | case Token::ADD: |
| 1010 | case Token::SUB: |
| 1011 | case Token::MUL: |
| 1012 | case Token::DIV: { |
| 1013 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1014 | __ bind(&use_fp_on_smis); |
| 1015 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1016 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1017 | case Token::ADD: |
| 1018 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1019 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1020 | break; |
| 1021 | case Token::SUB: |
| 1022 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1023 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1024 | break; |
| 1025 | case Token::MUL: |
| 1026 | // Right was clobbered but a copy is in ebx. |
| 1027 | __ mov(right, ebx); |
| 1028 | break; |
| 1029 | case Token::DIV: |
| 1030 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1031 | // division. |
| 1032 | __ mov(edx, edi); |
| 1033 | __ mov(eax, right); |
| 1034 | break; |
| 1035 | default: UNREACHABLE(); |
| 1036 | break; |
| 1037 | } |
| 1038 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1039 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1040 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1041 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1042 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1043 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1044 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1045 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1046 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1047 | default: UNREACHABLE(); |
| 1048 | } |
| 1049 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1050 | } else { // SSE2 not available, use FPU. |
| 1051 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1052 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1053 | case Token::ADD: __ faddp(1); break; |
| 1054 | case Token::SUB: __ fsubp(1); break; |
| 1055 | case Token::MUL: __ fmulp(1); break; |
| 1056 | case Token::DIV: __ fdivp(1); break; |
| 1057 | default: UNREACHABLE(); |
| 1058 | } |
| 1059 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1060 | } |
| 1061 | __ mov(eax, ecx); |
| 1062 | __ ret(0); |
| 1063 | break; |
| 1064 | } |
| 1065 | |
| 1066 | default: |
| 1067 | break; |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1072 | // edx and eax. |
| 1073 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1074 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1075 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1076 | case Token::BIT_OR: |
| 1077 | case Token::SHL: |
| 1078 | case Token::SAR: |
| 1079 | case Token::SHR: |
| 1080 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1081 | // check. |
| 1082 | __ mov(eax, ecx); |
| 1083 | break; |
| 1084 | |
| 1085 | case Token::DIV: |
| 1086 | case Token::MOD: |
| 1087 | // Operands are in eax, ebx at this point. |
| 1088 | __ mov(edx, eax); |
| 1089 | __ mov(eax, ebx); |
| 1090 | break; |
| 1091 | |
| 1092 | default: |
| 1093 | break; |
| 1094 | } |
| 1095 | } |
| 1096 | |
| 1097 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1098 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1099 | Label right_arg_changed, call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1100 | |
| 1101 | switch (op_) { |
| 1102 | case Token::ADD: |
| 1103 | case Token::SUB: |
| 1104 | case Token::MUL: |
| 1105 | case Token::DIV: |
| 1106 | break; |
| 1107 | case Token::MOD: |
| 1108 | case Token::BIT_OR: |
| 1109 | case Token::BIT_AND: |
| 1110 | case Token::BIT_XOR: |
| 1111 | case Token::SAR: |
| 1112 | case Token::SHL: |
| 1113 | case Token::SHR: |
| 1114 | GenerateRegisterArgsPush(masm); |
| 1115 | break; |
| 1116 | default: |
| 1117 | UNREACHABLE(); |
| 1118 | } |
| 1119 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1120 | if (op_ == Token::MOD && encoded_right_arg_.has_value) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1121 | // It is guaranteed that the value will fit into a Smi, because if it |
| 1122 | // didn't, we wouldn't be here, see BinaryOp_Patch. |
| 1123 | __ cmp(eax, Immediate(Smi::FromInt(fixed_right_arg_value()))); |
| 1124 | __ j(not_equal, &right_arg_changed); |
| 1125 | } |
| 1126 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1127 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1128 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1129 | BinaryOpStub_GenerateSmiCode( |
| 1130 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1131 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1132 | BinaryOpStub_GenerateSmiCode( |
| 1133 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1134 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1135 | |
| 1136 | // Code falls through if the result is not returned as either a smi or heap |
| 1137 | // number. |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1138 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1139 | switch (op_) { |
| 1140 | case Token::ADD: |
| 1141 | case Token::SUB: |
| 1142 | case Token::MUL: |
| 1143 | case Token::DIV: |
| 1144 | GenerateTypeTransition(masm); |
| 1145 | break; |
| 1146 | case Token::MOD: |
| 1147 | case Token::BIT_OR: |
| 1148 | case Token::BIT_AND: |
| 1149 | case Token::BIT_XOR: |
| 1150 | case Token::SAR: |
| 1151 | case Token::SHL: |
| 1152 | case Token::SHR: |
| 1153 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1154 | break; |
| 1155 | default: |
| 1156 | UNREACHABLE(); |
| 1157 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1158 | |
| 1159 | __ bind(&call_runtime); |
| 1160 | switch (op_) { |
| 1161 | case Token::ADD: |
| 1162 | case Token::SUB: |
| 1163 | case Token::MUL: |
| 1164 | case Token::DIV: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1165 | break; |
| 1166 | case Token::MOD: |
| 1167 | case Token::BIT_OR: |
| 1168 | case Token::BIT_AND: |
| 1169 | case Token::BIT_XOR: |
| 1170 | case Token::SAR: |
| 1171 | case Token::SHL: |
| 1172 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1173 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1174 | break; |
| 1175 | default: |
| 1176 | UNREACHABLE(); |
| 1177 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1178 | |
| 1179 | { |
| 1180 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1181 | __ push(edx); |
| 1182 | __ push(eax); |
| 1183 | GenerateCallRuntime(masm); |
| 1184 | } |
| 1185 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1189 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1190 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1191 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1192 | ASSERT(op_ == Token::ADD); |
| 1193 | // If both arguments are strings, call the string add stub. |
| 1194 | // Otherwise, do a transition. |
| 1195 | |
| 1196 | // Registers containing left and right operands respectively. |
| 1197 | Register left = edx; |
| 1198 | Register right = eax; |
| 1199 | |
| 1200 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1201 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1202 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1203 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1204 | |
| 1205 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1206 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1207 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1208 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1209 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1210 | StringAddStub string_add_stub( |
| 1211 | (StringAddFlags)(STRING_ADD_CHECK_NONE | STRING_ADD_ERECT_FRAME)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1212 | GenerateRegisterArgsPush(masm); |
| 1213 | __ TailCallStub(&string_add_stub); |
| 1214 | |
| 1215 | __ bind(&call_runtime); |
| 1216 | GenerateTypeTransition(masm); |
| 1217 | } |
| 1218 | |
| 1219 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1220 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1221 | Label* alloc_failure, |
| 1222 | OverwriteMode mode); |
| 1223 | |
| 1224 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1225 | // Input: |
| 1226 | // edx: left operand (tagged) |
| 1227 | // eax: right operand (tagged) |
| 1228 | // Output: |
| 1229 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1230 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1231 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1232 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1233 | |
| 1234 | // Floating point case. |
| 1235 | switch (op_) { |
| 1236 | case Token::ADD: |
| 1237 | case Token::SUB: |
| 1238 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1239 | case Token::DIV: |
| 1240 | case Token::MOD: { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1241 | Label not_floats, not_int32, right_arg_changed; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1242 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1243 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1244 | // It could be that only SMIs have been seen at either the left |
| 1245 | // or the right operand. For precise type feedback, patch the IC |
| 1246 | // again if this changes. |
| 1247 | // In theory, we would need the same check in the non-SSE2 case, |
| 1248 | // but since we don't support Crankshaft on such hardware we can |
| 1249 | // afford not to care about precise type feedback. |
| 1250 | if (left_type_ == BinaryOpIC::SMI) { |
| 1251 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1252 | } |
| 1253 | if (right_type_ == BinaryOpIC::SMI) { |
| 1254 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1255 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1256 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1257 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1258 | masm, ¬_int32, xmm0, ebx, ecx, xmm2); |
| 1259 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1260 | masm, ¬_int32, xmm1, edi, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1261 | if (op_ == Token::MOD) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1262 | if (encoded_right_arg_.has_value) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1263 | __ cmp(edi, Immediate(fixed_right_arg_value())); |
| 1264 | __ j(not_equal, &right_arg_changed); |
| 1265 | } |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1266 | GenerateRegisterArgsPush(masm); |
| 1267 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1268 | } else { |
| 1269 | switch (op_) { |
| 1270 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1271 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1272 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1273 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1274 | default: UNREACHABLE(); |
| 1275 | } |
| 1276 | // Check result type if it is currently Int32. |
| 1277 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1278 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1279 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1280 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1281 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1282 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1283 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1284 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1285 | } else { // SSE2 not available, use FPU. |
| 1286 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1287 | FloatingPointHelper::LoadFloatOperands( |
| 1288 | masm, |
| 1289 | ecx, |
| 1290 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1291 | if (op_ == Token::MOD) { |
| 1292 | // The operands are now on the FPU stack, but we don't need them. |
| 1293 | __ fstp(0); |
| 1294 | __ fstp(0); |
| 1295 | GenerateRegisterArgsPush(masm); |
| 1296 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1297 | } else { |
| 1298 | switch (op_) { |
| 1299 | case Token::ADD: __ faddp(1); break; |
| 1300 | case Token::SUB: __ fsubp(1); break; |
| 1301 | case Token::MUL: __ fmulp(1); break; |
| 1302 | case Token::DIV: __ fdivp(1); break; |
| 1303 | default: UNREACHABLE(); |
| 1304 | } |
| 1305 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1306 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1307 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1308 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1309 | __ ret(0); |
| 1310 | __ bind(&after_alloc_failure); |
| 1311 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1312 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1313 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1314 | } |
| 1315 | |
| 1316 | __ bind(¬_floats); |
| 1317 | __ bind(¬_int32); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1318 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1319 | GenerateTypeTransition(masm); |
| 1320 | break; |
| 1321 | } |
| 1322 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1323 | case Token::BIT_OR: |
| 1324 | case Token::BIT_AND: |
| 1325 | case Token::BIT_XOR: |
| 1326 | case Token::SAR: |
| 1327 | case Token::SHL: |
| 1328 | case Token::SHR: { |
| 1329 | GenerateRegisterArgsPush(masm); |
| 1330 | Label not_floats; |
| 1331 | Label not_int32; |
| 1332 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1333 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1334 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1335 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1336 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1337 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1338 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1339 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1340 | case Token::SAR: __ sar_cl(eax); break; |
| 1341 | case Token::SHL: __ shl_cl(eax); break; |
| 1342 | case Token::SHR: __ shr_cl(eax); break; |
| 1343 | default: UNREACHABLE(); |
| 1344 | } |
| 1345 | if (op_ == Token::SHR) { |
| 1346 | // Check if result is non-negative and fits in a smi. |
| 1347 | __ test(eax, Immediate(0xc0000000)); |
| 1348 | __ j(not_zero, &call_runtime); |
| 1349 | } else { |
| 1350 | // Check if result fits in a smi. |
| 1351 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1352 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1353 | } |
| 1354 | // Tag smi result and return. |
| 1355 | __ SmiTag(eax); |
| 1356 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1357 | |
| 1358 | // All ops except SHR return a signed int32 that we load in |
| 1359 | // a HeapNumber. |
| 1360 | if (op_ != Token::SHR) { |
| 1361 | __ bind(&non_smi_result); |
| 1362 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1363 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1364 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1365 | switch (mode_) { |
| 1366 | case OVERWRITE_LEFT: |
| 1367 | case OVERWRITE_RIGHT: |
| 1368 | // If the operand was an object, we skip the |
| 1369 | // allocation of a heap number. |
| 1370 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1371 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1372 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1373 | // Fall through! |
| 1374 | case NO_OVERWRITE: |
| 1375 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1376 | __ bind(&skip_allocation); |
| 1377 | break; |
| 1378 | default: UNREACHABLE(); |
| 1379 | } |
| 1380 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1381 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1382 | CpuFeatureScope use_sse2(masm, SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1383 | __ Cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1384 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1385 | } else { |
| 1386 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1387 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1388 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1389 | } |
| 1390 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1391 | } |
| 1392 | |
| 1393 | __ bind(¬_floats); |
| 1394 | __ bind(¬_int32); |
| 1395 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1396 | break; |
| 1397 | } |
| 1398 | default: UNREACHABLE(); break; |
| 1399 | } |
| 1400 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1401 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1402 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1403 | __ bind(&call_runtime); |
| 1404 | |
| 1405 | switch (op_) { |
| 1406 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1407 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1408 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1409 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1410 | break; |
| 1411 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1412 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1413 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1414 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1415 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1416 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1417 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1418 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1419 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1420 | break; |
| 1421 | default: |
| 1422 | UNREACHABLE(); |
| 1423 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1424 | |
| 1425 | { |
| 1426 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1427 | __ push(edx); |
| 1428 | __ push(eax); |
| 1429 | GenerateCallRuntime(masm); |
| 1430 | } |
| 1431 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1435 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1436 | if (op_ == Token::ADD) { |
| 1437 | // Handle string addition here, because it is the only operation |
| 1438 | // that does not do a ToNumber conversion on the operands. |
| 1439 | GenerateAddStrings(masm); |
| 1440 | } |
| 1441 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1442 | Factory* factory = masm->isolate()->factory(); |
| 1443 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1444 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1445 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1446 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1447 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1448 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1449 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1450 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1451 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1452 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1453 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1454 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1455 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1456 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1457 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1458 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1459 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1460 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1461 | } |
| 1462 | __ bind(&done); |
| 1463 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1464 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
| 1467 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1468 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1469 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1470 | |
| 1471 | // Floating point case. |
| 1472 | switch (op_) { |
| 1473 | case Token::ADD: |
| 1474 | case Token::SUB: |
| 1475 | case Token::MUL: |
| 1476 | case Token::DIV: { |
| 1477 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1478 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1479 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1480 | |
| 1481 | // It could be that only SMIs have been seen at either the left |
| 1482 | // or the right operand. For precise type feedback, patch the IC |
| 1483 | // again if this changes. |
| 1484 | // In theory, we would need the same check in the non-SSE2 case, |
| 1485 | // but since we don't support Crankshaft on such hardware we can |
| 1486 | // afford not to care about precise type feedback. |
| 1487 | if (left_type_ == BinaryOpIC::SMI) { |
| 1488 | __ JumpIfNotSmi(edx, ¬_floats); |
| 1489 | } |
| 1490 | if (right_type_ == BinaryOpIC::SMI) { |
| 1491 | __ JumpIfNotSmi(eax, ¬_floats); |
| 1492 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1493 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1494 | if (left_type_ == BinaryOpIC::INT32) { |
| 1495 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1496 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1497 | } |
| 1498 | if (right_type_ == BinaryOpIC::INT32) { |
| 1499 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1500 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1501 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1502 | |
| 1503 | switch (op_) { |
| 1504 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1505 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1506 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1507 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1508 | default: UNREACHABLE(); |
| 1509 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1510 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1511 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1512 | __ ret(0); |
| 1513 | } else { // SSE2 not available, use FPU. |
| 1514 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1515 | FloatingPointHelper::LoadFloatOperands( |
| 1516 | masm, |
| 1517 | ecx, |
| 1518 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1519 | switch (op_) { |
| 1520 | case Token::ADD: __ faddp(1); break; |
| 1521 | case Token::SUB: __ fsubp(1); break; |
| 1522 | case Token::MUL: __ fmulp(1); break; |
| 1523 | case Token::DIV: __ fdivp(1); break; |
| 1524 | default: UNREACHABLE(); |
| 1525 | } |
| 1526 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1527 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1528 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1529 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1530 | __ ret(0); |
| 1531 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1532 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1533 | __ jmp(&call_runtime); |
| 1534 | } |
| 1535 | |
| 1536 | __ bind(¬_floats); |
| 1537 | GenerateTypeTransition(masm); |
| 1538 | break; |
| 1539 | } |
| 1540 | |
| 1541 | case Token::MOD: { |
| 1542 | // For MOD we go directly to runtime in the non-smi case. |
| 1543 | break; |
| 1544 | } |
| 1545 | case Token::BIT_OR: |
| 1546 | case Token::BIT_AND: |
| 1547 | case Token::BIT_XOR: |
| 1548 | case Token::SAR: |
| 1549 | case Token::SHL: |
| 1550 | case Token::SHR: { |
| 1551 | GenerateRegisterArgsPush(masm); |
| 1552 | Label not_floats; |
| 1553 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1554 | // We do not check the input arguments here, as any value is |
| 1555 | // unconditionally truncated to an int32 anyway. To get the |
| 1556 | // right optimized code, int32 type feedback is just right. |
| 1557 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1558 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1559 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1560 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1561 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1562 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1563 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1564 | case Token::SAR: __ sar_cl(eax); break; |
| 1565 | case Token::SHL: __ shl_cl(eax); break; |
| 1566 | case Token::SHR: __ shr_cl(eax); break; |
| 1567 | default: UNREACHABLE(); |
| 1568 | } |
| 1569 | if (op_ == Token::SHR) { |
| 1570 | // Check if result is non-negative and fits in a smi. |
| 1571 | __ test(eax, Immediate(0xc0000000)); |
| 1572 | __ j(not_zero, &call_runtime); |
| 1573 | } else { |
| 1574 | // Check if result fits in a smi. |
| 1575 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1576 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1577 | } |
| 1578 | // Tag smi result and return. |
| 1579 | __ SmiTag(eax); |
| 1580 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1581 | |
| 1582 | // All ops except SHR return a signed int32 that we load in |
| 1583 | // a HeapNumber. |
| 1584 | if (op_ != Token::SHR) { |
| 1585 | __ bind(&non_smi_result); |
| 1586 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1587 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1588 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1589 | switch (mode_) { |
| 1590 | case OVERWRITE_LEFT: |
| 1591 | case OVERWRITE_RIGHT: |
| 1592 | // If the operand was an object, we skip the |
| 1593 | // allocation of a heap number. |
| 1594 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1595 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1596 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1597 | // Fall through! |
| 1598 | case NO_OVERWRITE: |
| 1599 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1600 | __ bind(&skip_allocation); |
| 1601 | break; |
| 1602 | default: UNREACHABLE(); |
| 1603 | } |
| 1604 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1605 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1606 | CpuFeatureScope use_sse2(masm, SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1607 | __ Cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1608 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1609 | } else { |
| 1610 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1611 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1612 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1613 | } |
| 1614 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1615 | } |
| 1616 | |
| 1617 | __ bind(¬_floats); |
| 1618 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1619 | break; |
| 1620 | } |
| 1621 | default: UNREACHABLE(); break; |
| 1622 | } |
| 1623 | |
| 1624 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 1625 | // use the runtime system to get the correct result. |
| 1626 | __ bind(&call_runtime); |
| 1627 | |
| 1628 | switch (op_) { |
| 1629 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1630 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1631 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1632 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1633 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1634 | break; |
| 1635 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1636 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1637 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1638 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1639 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1640 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1641 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1642 | break; |
| 1643 | default: |
| 1644 | UNREACHABLE(); |
| 1645 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1646 | |
| 1647 | { |
| 1648 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1649 | __ push(edx); |
| 1650 | __ push(eax); |
| 1651 | GenerateCallRuntime(masm); |
| 1652 | } |
| 1653 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1657 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1658 | Label call_runtime; |
| 1659 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1660 | Counters* counters = masm->isolate()->counters(); |
| 1661 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1662 | |
| 1663 | switch (op_) { |
| 1664 | case Token::ADD: |
| 1665 | case Token::SUB: |
| 1666 | case Token::MUL: |
| 1667 | case Token::DIV: |
| 1668 | break; |
| 1669 | case Token::MOD: |
| 1670 | case Token::BIT_OR: |
| 1671 | case Token::BIT_AND: |
| 1672 | case Token::BIT_XOR: |
| 1673 | case Token::SAR: |
| 1674 | case Token::SHL: |
| 1675 | case Token::SHR: |
| 1676 | GenerateRegisterArgsPush(masm); |
| 1677 | break; |
| 1678 | default: |
| 1679 | UNREACHABLE(); |
| 1680 | } |
| 1681 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1682 | BinaryOpStub_GenerateSmiCode( |
| 1683 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1684 | |
| 1685 | // Floating point case. |
| 1686 | switch (op_) { |
| 1687 | case Token::ADD: |
| 1688 | case Token::SUB: |
| 1689 | case Token::MUL: |
| 1690 | case Token::DIV: { |
| 1691 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1692 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1693 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1694 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1695 | |
| 1696 | switch (op_) { |
| 1697 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1698 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1699 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1700 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1701 | default: UNREACHABLE(); |
| 1702 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1703 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1704 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1705 | __ ret(0); |
| 1706 | } else { // SSE2 not available, use FPU. |
| 1707 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1708 | FloatingPointHelper::LoadFloatOperands( |
| 1709 | masm, |
| 1710 | ecx, |
| 1711 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1712 | switch (op_) { |
| 1713 | case Token::ADD: __ faddp(1); break; |
| 1714 | case Token::SUB: __ fsubp(1); break; |
| 1715 | case Token::MUL: __ fmulp(1); break; |
| 1716 | case Token::DIV: __ fdivp(1); break; |
| 1717 | default: UNREACHABLE(); |
| 1718 | } |
| 1719 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1720 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1721 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1722 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1723 | __ ret(0); |
| 1724 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1725 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1726 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1727 | } |
| 1728 | __ bind(¬_floats); |
| 1729 | break; |
| 1730 | } |
| 1731 | case Token::MOD: { |
| 1732 | // For MOD we go directly to runtime in the non-smi case. |
| 1733 | break; |
| 1734 | } |
| 1735 | case Token::BIT_OR: |
| 1736 | case Token::BIT_AND: |
| 1737 | case Token::BIT_XOR: |
| 1738 | case Token::SAR: |
| 1739 | case Token::SHL: |
| 1740 | case Token::SHR: { |
| 1741 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1742 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1743 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1744 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1745 | BinaryOpIC::GENERIC, |
| 1746 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1747 | &call_runtime); |
| 1748 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1749 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1750 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1751 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1752 | case Token::SAR: __ sar_cl(eax); break; |
| 1753 | case Token::SHL: __ shl_cl(eax); break; |
| 1754 | case Token::SHR: __ shr_cl(eax); break; |
| 1755 | default: UNREACHABLE(); |
| 1756 | } |
| 1757 | if (op_ == Token::SHR) { |
| 1758 | // Check if result is non-negative and fits in a smi. |
| 1759 | __ test(eax, Immediate(0xc0000000)); |
| 1760 | __ j(not_zero, &call_runtime); |
| 1761 | } else { |
| 1762 | // Check if result fits in a smi. |
| 1763 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1764 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1765 | } |
| 1766 | // Tag smi result and return. |
| 1767 | __ SmiTag(eax); |
| 1768 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 1769 | |
| 1770 | // All ops except SHR return a signed int32 that we load in |
| 1771 | // a HeapNumber. |
| 1772 | if (op_ != Token::SHR) { |
| 1773 | __ bind(&non_smi_result); |
| 1774 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1775 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1776 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1777 | switch (mode_) { |
| 1778 | case OVERWRITE_LEFT: |
| 1779 | case OVERWRITE_RIGHT: |
| 1780 | // If the operand was an object, we skip the |
| 1781 | // allocation of a heap number. |
| 1782 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1783 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1784 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1785 | // Fall through! |
| 1786 | case NO_OVERWRITE: |
| 1787 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1788 | __ bind(&skip_allocation); |
| 1789 | break; |
| 1790 | default: UNREACHABLE(); |
| 1791 | } |
| 1792 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1793 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1794 | CpuFeatureScope use_sse2(masm, SSE2); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1795 | __ Cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1796 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1797 | } else { |
| 1798 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1799 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1800 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1801 | } |
| 1802 | __ ret(2 * kPointerSize); |
| 1803 | } |
| 1804 | break; |
| 1805 | } |
| 1806 | default: UNREACHABLE(); break; |
| 1807 | } |
| 1808 | |
| 1809 | // If all else fails, use the runtime system to get the correct |
| 1810 | // result. |
| 1811 | __ bind(&call_runtime); |
| 1812 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1813 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1814 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1815 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1816 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1817 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1818 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1819 | break; |
| 1820 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1821 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1822 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1823 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1824 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1825 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1826 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1827 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1828 | break; |
| 1829 | default: |
| 1830 | UNREACHABLE(); |
| 1831 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1832 | |
| 1833 | { |
| 1834 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1835 | __ push(edx); |
| 1836 | __ push(eax); |
| 1837 | GenerateCallRuntime(masm); |
| 1838 | } |
| 1839 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1840 | } |
| 1841 | |
| 1842 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1843 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1844 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1845 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1846 | |
| 1847 | // Registers containing left and right operands respectively. |
| 1848 | Register left = edx; |
| 1849 | Register right = eax; |
| 1850 | |
| 1851 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1852 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1853 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1854 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1855 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1856 | StringAddStub string_add_left_stub( |
| 1857 | (StringAddFlags)(STRING_ADD_CHECK_RIGHT | STRING_ADD_ERECT_FRAME)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1858 | GenerateRegisterArgsPush(masm); |
| 1859 | __ TailCallStub(&string_add_left_stub); |
| 1860 | |
| 1861 | // Left operand is not a string, test right. |
| 1862 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1863 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1864 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1865 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1866 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1867 | StringAddStub string_add_right_stub( |
| 1868 | (StringAddFlags)(STRING_ADD_CHECK_LEFT | STRING_ADD_ERECT_FRAME)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1869 | GenerateRegisterArgsPush(masm); |
| 1870 | __ TailCallStub(&string_add_right_stub); |
| 1871 | |
| 1872 | // Neither argument is a string. |
| 1873 | __ bind(&call_runtime); |
| 1874 | } |
| 1875 | |
| 1876 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1877 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1878 | Label* alloc_failure, |
| 1879 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1880 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1881 | switch (mode) { |
| 1882 | case OVERWRITE_LEFT: { |
| 1883 | // If the argument in edx is already an object, we skip the |
| 1884 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1885 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1886 | // Allocate a heap number for the result. Keep eax and edx intact |
| 1887 | // for the possible runtime call. |
| 1888 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 1889 | // Now edx can be overwritten losing one of the arguments as we are |
| 1890 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1891 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1892 | __ bind(&skip_allocation); |
| 1893 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1894 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1895 | break; |
| 1896 | } |
| 1897 | case OVERWRITE_RIGHT: |
| 1898 | // If the argument in eax is already an object, we skip the |
| 1899 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1900 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1901 | // Fall through! |
| 1902 | case NO_OVERWRITE: |
| 1903 | // Allocate a heap number for the result. Keep eax and edx intact |
| 1904 | // for the possible runtime call. |
| 1905 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 1906 | // Now eax can be overwritten losing one of the arguments as we are |
| 1907 | // now done and will not need it any more. |
| 1908 | __ mov(eax, ebx); |
| 1909 | __ bind(&skip_allocation); |
| 1910 | break; |
| 1911 | default: UNREACHABLE(); |
| 1912 | } |
| 1913 | } |
| 1914 | |
| 1915 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1916 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1917 | __ pop(ecx); |
| 1918 | __ push(edx); |
| 1919 | __ push(eax); |
| 1920 | __ push(ecx); |
| 1921 | } |
| 1922 | |
| 1923 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1924 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1925 | // TAGGED case: |
| 1926 | // Input: |
| 1927 | // esp[4]: tagged number input argument (should be number). |
| 1928 | // esp[0]: return address. |
| 1929 | // Output: |
| 1930 | // eax: tagged double result. |
| 1931 | // UNTAGGED case: |
| 1932 | // Input:: |
| 1933 | // esp[0]: return address. |
| 1934 | // xmm1: untagged double input argument |
| 1935 | // Output: |
| 1936 | // xmm1: untagged double result. |
| 1937 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1938 | Label runtime_call; |
| 1939 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1940 | Label skip_cache; |
| 1941 | const bool tagged = (argument_type_ == TAGGED); |
| 1942 | if (tagged) { |
| 1943 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1944 | Label input_not_smi; |
| 1945 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1946 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1947 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1948 | // Input is a smi. Untag and load it onto the FPU stack. |
| 1949 | // Then load the low and high words of the double into ebx, edx. |
| 1950 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1951 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1952 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1953 | __ mov(Operand(esp, 0), eax); |
| 1954 | __ fild_s(Operand(esp, 0)); |
| 1955 | __ fst_d(Operand(esp, 0)); |
| 1956 | __ pop(edx); |
| 1957 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1958 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1959 | __ bind(&input_not_smi); |
| 1960 | // Check if input is a HeapNumber. |
| 1961 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1962 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1963 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1964 | __ j(not_equal, &runtime_call); |
| 1965 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 1966 | // low and high words into ebx, edx. |
| 1967 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1968 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 1969 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1970 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1971 | __ bind(&loaded); |
| 1972 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1973 | CpuFeatureScope scope(masm, SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1974 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1975 | CpuFeatureScope sse4_scope(masm, SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1976 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1977 | } else { |
| 1978 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1979 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1980 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1981 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 1982 | } |
| 1983 | |
| 1984 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1985 | // ebx = low 32 bits of double value |
| 1986 | // edx = high 32 bits of double value |
| 1987 | // Compute hash (the shifts are arithmetic): |
| 1988 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 1989 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1990 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1991 | __ mov(eax, ecx); |
| 1992 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1993 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1994 | __ mov(eax, ecx); |
| 1995 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1996 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1997 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1998 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1999 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2000 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2001 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2002 | // ebx = low 32 bits of double value. |
| 2003 | // edx = high 32 bits of double value. |
| 2004 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2005 | ExternalReference cache_array = |
| 2006 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2007 | __ mov(eax, Immediate(cache_array)); |
| 2008 | int cache_array_index = |
| 2009 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2010 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2011 | // Eax points to the cache for the type type_. |
| 2012 | // 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] | 2013 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2014 | __ j(zero, &runtime_call_clear_stack); |
| 2015 | #ifdef DEBUG |
| 2016 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2017 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2018 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2019 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2020 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2021 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2022 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2023 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2024 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2025 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2026 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2027 | } |
| 2028 | #endif |
| 2029 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2030 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2031 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2032 | // 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] | 2033 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2034 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2035 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2036 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2037 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2038 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2039 | Counters* counters = masm->isolate()->counters(); |
| 2040 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2041 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2042 | if (tagged) { |
| 2043 | __ fstp(0); |
| 2044 | __ ret(kPointerSize); |
| 2045 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2046 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2047 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2048 | __ Ret(); |
| 2049 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2050 | |
| 2051 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2052 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2053 | // Update cache with new value. |
| 2054 | // We are short on registers, so use no_reg as scratch. |
| 2055 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2056 | if (tagged) { |
| 2057 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2058 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2059 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2060 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2061 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2062 | __ movdbl(Operand(esp, 0), xmm1); |
| 2063 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2064 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2065 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2066 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2067 | __ mov(Operand(ecx, 0), ebx); |
| 2068 | __ mov(Operand(ecx, kIntSize), edx); |
| 2069 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2070 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2071 | if (tagged) { |
| 2072 | __ ret(kPointerSize); |
| 2073 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2074 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2075 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2076 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2077 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2078 | // Skip cache and return answer directly, only in untagged case. |
| 2079 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2080 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2081 | __ movdbl(Operand(esp, 0), xmm1); |
| 2082 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2083 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2084 | __ fstp_d(Operand(esp, 0)); |
| 2085 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2086 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2087 | // We return the value in xmm1 without adding it to the cache, but |
| 2088 | // 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] | 2089 | { |
| 2090 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2091 | // Allocate an unused object bigger than a HeapNumber. |
| 2092 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2093 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2094 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2095 | __ Ret(); |
| 2096 | } |
| 2097 | |
| 2098 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2099 | if (tagged) { |
| 2100 | __ bind(&runtime_call_clear_stack); |
| 2101 | __ fstp(0); |
| 2102 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2103 | ExternalReference runtime = |
| 2104 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2105 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2106 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2107 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2108 | __ bind(&runtime_call_clear_stack); |
| 2109 | __ bind(&runtime_call); |
| 2110 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2111 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2112 | { |
| 2113 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2114 | __ push(eax); |
| 2115 | __ CallRuntime(RuntimeFunction(), 1); |
| 2116 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2117 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2118 | __ Ret(); |
| 2119 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2120 | } |
| 2121 | |
| 2122 | |
| 2123 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2124 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2125 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2126 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2127 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2128 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2129 | default: |
| 2130 | UNIMPLEMENTED(); |
| 2131 | return Runtime::kAbort; |
| 2132 | } |
| 2133 | } |
| 2134 | |
| 2135 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2136 | void TranscendentalCacheStub::GenerateOperation( |
| 2137 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2138 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2139 | // Input value is on FP stack, and also in ebx/edx. |
| 2140 | // Input value is possibly in xmm1. |
| 2141 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2142 | if (type == TranscendentalCache::SIN || |
| 2143 | type == TranscendentalCache::COS || |
| 2144 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2145 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2146 | // return NaN for infinities and NaN. They can share all code except |
| 2147 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2148 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2149 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2150 | // work. We must reduce it to the appropriate range. |
| 2151 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2152 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2153 | int supported_exponent_limit = |
| 2154 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2155 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2156 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2157 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2158 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2159 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2160 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2161 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2162 | __ fstp(0); |
| 2163 | // NaN is represented by 0x7ff8000000000000. |
| 2164 | __ push(Immediate(0x7ff80000)); |
| 2165 | __ push(Immediate(0)); |
| 2166 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2167 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2168 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2169 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2170 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2171 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2172 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2173 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2174 | __ fldpi(); |
| 2175 | __ fadd(0); |
| 2176 | __ fld(1); |
| 2177 | // FPU Stack: input, 2*pi, input. |
| 2178 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2179 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2180 | __ fwait(); |
| 2181 | __ fnstsw_ax(); |
| 2182 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2183 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2184 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2185 | __ fnclex(); |
| 2186 | __ bind(&no_exceptions); |
| 2187 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2188 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2189 | // Compute st(0) % st(1) |
| 2190 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2191 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2192 | __ bind(&partial_remainder_loop); |
| 2193 | __ fprem1(); |
| 2194 | __ fwait(); |
| 2195 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2196 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2197 | // If C2 is set, computation only has partial result. Loop to |
| 2198 | // continue computation. |
| 2199 | __ j(not_zero, &partial_remainder_loop); |
| 2200 | } |
| 2201 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2202 | __ fstp(2); |
| 2203 | __ fstp(0); |
| 2204 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2205 | |
| 2206 | // FPU Stack: input % 2*pi |
| 2207 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2208 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2209 | case TranscendentalCache::SIN: |
| 2210 | __ fsin(); |
| 2211 | break; |
| 2212 | case TranscendentalCache::COS: |
| 2213 | __ fcos(); |
| 2214 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2215 | case TranscendentalCache::TAN: |
| 2216 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2217 | // FP register stack. |
| 2218 | __ fptan(); |
| 2219 | __ fstp(0); // Pop FP register stack. |
| 2220 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2221 | default: |
| 2222 | UNREACHABLE(); |
| 2223 | } |
| 2224 | __ bind(&done); |
| 2225 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2226 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2227 | __ fldln2(); |
| 2228 | __ fxch(); |
| 2229 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2230 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2234 | // Input: edx, eax are the left and right objects of a bit op. |
| 2235 | // 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] | 2236 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2237 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2238 | MacroAssembler* masm, |
| 2239 | bool use_sse3, |
| 2240 | BinaryOpIC::TypeInfo left_type, |
| 2241 | BinaryOpIC::TypeInfo right_type, |
| 2242 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2243 | // Check float operands. |
| 2244 | Label arg1_is_object, check_undefined_arg1; |
| 2245 | Label arg2_is_object, check_undefined_arg2; |
| 2246 | Label load_arg2, done; |
| 2247 | |
| 2248 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2249 | if (left_type == BinaryOpIC::SMI) { |
| 2250 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2251 | } else { |
| 2252 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2253 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2254 | |
| 2255 | __ SmiUntag(edx); |
| 2256 | __ jmp(&load_arg2); |
| 2257 | |
| 2258 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2259 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2260 | Factory* factory = masm->isolate()->factory(); |
| 2261 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2262 | __ j(not_equal, conversion_failure); |
| 2263 | __ mov(edx, Immediate(0)); |
| 2264 | __ jmp(&load_arg2); |
| 2265 | |
| 2266 | __ bind(&arg1_is_object); |
| 2267 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2268 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2269 | __ j(not_equal, &check_undefined_arg1); |
| 2270 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 2271 | __ TruncateHeapNumberToI(edx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2272 | |
| 2273 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2274 | __ bind(&load_arg2); |
| 2275 | |
| 2276 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2277 | if (right_type == BinaryOpIC::SMI) { |
| 2278 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2279 | } else { |
| 2280 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2281 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2282 | |
| 2283 | __ SmiUntag(eax); |
| 2284 | __ mov(ecx, eax); |
| 2285 | __ jmp(&done); |
| 2286 | |
| 2287 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2288 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2289 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2290 | __ j(not_equal, conversion_failure); |
| 2291 | __ mov(ecx, Immediate(0)); |
| 2292 | __ jmp(&done); |
| 2293 | |
| 2294 | __ bind(&arg2_is_object); |
| 2295 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2296 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2297 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2298 | // 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] | 2299 | |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 2300 | __ TruncateHeapNumberToI(ecx, eax); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2301 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2302 | __ bind(&done); |
| 2303 | __ mov(eax, edx); |
| 2304 | } |
| 2305 | |
| 2306 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2307 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2308 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2309 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2310 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2311 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2312 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2313 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2314 | |
| 2315 | __ bind(&load_smi); |
| 2316 | __ SmiUntag(number); |
| 2317 | __ push(number); |
| 2318 | __ fild_s(Operand(esp, 0)); |
| 2319 | __ pop(number); |
| 2320 | |
| 2321 | __ bind(&done); |
| 2322 | } |
| 2323 | |
| 2324 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2325 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2326 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2327 | 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] | 2328 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2329 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2330 | Factory* factory = masm->isolate()->factory(); |
| 2331 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2332 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2333 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2334 | __ bind(&load_eax); |
| 2335 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2336 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2337 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2338 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2339 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2340 | __ bind(&load_smi_edx); |
| 2341 | __ SmiUntag(edx); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2342 | __ Cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2343 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2344 | __ jmp(&load_eax); |
| 2345 | __ bind(&load_smi_eax); |
| 2346 | __ SmiUntag(eax); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2347 | __ Cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2348 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2349 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2350 | __ bind(&load_float_eax); |
| 2351 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2352 | __ bind(&done); |
| 2353 | } |
| 2354 | |
| 2355 | |
| 2356 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2357 | Register scratch) { |
| 2358 | const Register left = edx; |
| 2359 | const Register right = eax; |
| 2360 | __ mov(scratch, left); |
| 2361 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2362 | __ SmiUntag(scratch); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2363 | __ Cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2364 | |
| 2365 | __ mov(scratch, right); |
| 2366 | __ SmiUntag(scratch); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2367 | __ Cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2371 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2372 | Label* non_int32, |
| 2373 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2374 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2375 | Register scratch, |
| 2376 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2377 | __ cvttsd2si(int32_result, Operand(operand)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2378 | __ Cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2379 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2380 | __ movmskps(scratch, xmm_scratch); |
| 2381 | // Two least significant bits should be both set. |
| 2382 | __ not_(scratch); |
| 2383 | __ test(scratch, Immediate(3)); |
| 2384 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2388 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2389 | Register scratch, |
| 2390 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2391 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2392 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2393 | __ mov(scratch, edx); |
| 2394 | } else { |
| 2395 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2396 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2397 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2398 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2399 | __ bind(&done_load_1); |
| 2400 | |
| 2401 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2402 | __ mov(scratch, eax); |
| 2403 | } else { |
| 2404 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2405 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2406 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2407 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2408 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2409 | |
| 2410 | __ bind(&load_smi_1); |
| 2411 | __ SmiUntag(scratch); |
| 2412 | __ push(scratch); |
| 2413 | __ fild_s(Operand(esp, 0)); |
| 2414 | __ pop(scratch); |
| 2415 | __ jmp(&done_load_1); |
| 2416 | |
| 2417 | __ bind(&load_smi_2); |
| 2418 | __ SmiUntag(scratch); |
| 2419 | __ push(scratch); |
| 2420 | __ fild_s(Operand(esp, 0)); |
| 2421 | __ pop(scratch); |
| 2422 | |
| 2423 | __ bind(&done); |
| 2424 | } |
| 2425 | |
| 2426 | |
| 2427 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2428 | Register scratch) { |
| 2429 | const Register left = edx; |
| 2430 | const Register right = eax; |
| 2431 | __ mov(scratch, left); |
| 2432 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2433 | __ SmiUntag(scratch); |
| 2434 | __ push(scratch); |
| 2435 | __ fild_s(Operand(esp, 0)); |
| 2436 | |
| 2437 | __ mov(scratch, right); |
| 2438 | __ SmiUntag(scratch); |
| 2439 | __ mov(Operand(esp, 0), scratch); |
| 2440 | __ fild_s(Operand(esp, 0)); |
| 2441 | __ pop(scratch); |
| 2442 | } |
| 2443 | |
| 2444 | |
| 2445 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2446 | Label* non_float, |
| 2447 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2448 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2449 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2450 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2451 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2452 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2453 | Factory* factory = masm->isolate()->factory(); |
| 2454 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2455 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2456 | |
| 2457 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2458 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2459 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2460 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2461 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2462 | |
| 2463 | // Fall-through: Both operands are numbers. |
| 2464 | __ bind(&done); |
| 2465 | } |
| 2466 | |
| 2467 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2468 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2469 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2470 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2471 | const Register exponent = eax; |
| 2472 | const Register base = edx; |
| 2473 | const Register scratch = ecx; |
| 2474 | const XMMRegister double_result = xmm3; |
| 2475 | const XMMRegister double_base = xmm2; |
| 2476 | const XMMRegister double_exponent = xmm1; |
| 2477 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2478 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2479 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2480 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2481 | // Save 1 in double_result - we need this several times later on. |
| 2482 | __ mov(scratch, Immediate(1)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2483 | __ Cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2484 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2485 | if (exponent_type_ == ON_STACK) { |
| 2486 | Label base_is_smi, unpack_exponent; |
| 2487 | // The exponent and base are supplied as arguments on the stack. |
| 2488 | // This can only happen if the stub is called from non-optimized code. |
| 2489 | // Load input parameters from stack. |
| 2490 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 2491 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 2492 | |
| 2493 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2494 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 2495 | factory->heap_number_map()); |
| 2496 | __ j(not_equal, &call_runtime); |
| 2497 | |
| 2498 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2499 | __ jmp(&unpack_exponent, Label::kNear); |
| 2500 | |
| 2501 | __ bind(&base_is_smi); |
| 2502 | __ SmiUntag(base); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2503 | __ Cvtsi2sd(double_base, base); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2504 | |
| 2505 | __ bind(&unpack_exponent); |
| 2506 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2507 | __ SmiUntag(exponent); |
| 2508 | __ jmp(&int_exponent); |
| 2509 | |
| 2510 | __ bind(&exponent_not_smi); |
| 2511 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2512 | factory->heap_number_map()); |
| 2513 | __ j(not_equal, &call_runtime); |
| 2514 | __ movdbl(double_exponent, |
| 2515 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2516 | } else if (exponent_type_ == TAGGED) { |
| 2517 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2518 | __ SmiUntag(exponent); |
| 2519 | __ jmp(&int_exponent); |
| 2520 | |
| 2521 | __ bind(&exponent_not_smi); |
| 2522 | __ movdbl(double_exponent, |
| 2523 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2524 | } |
| 2525 | |
| 2526 | if (exponent_type_ != INTEGER) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 2527 | Label fast_power, try_arithmetic_simplification; |
| 2528 | __ DoubleToI(exponent, double_exponent, double_scratch, |
| 2529 | TREAT_MINUS_ZERO_AS_ZERO, &try_arithmetic_simplification); |
| 2530 | __ jmp(&int_exponent); |
| 2531 | |
| 2532 | __ bind(&try_arithmetic_simplification); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2533 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 2534 | __ cvttsd2si(exponent, Operand(double_exponent)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2535 | __ cmp(exponent, Immediate(0x80000000u)); |
| 2536 | __ j(equal, &call_runtime); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2537 | |
| 2538 | if (exponent_type_ == ON_STACK) { |
| 2539 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 2540 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 2541 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 2542 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 2543 | // Test for 0.5. |
| 2544 | // Load double_scratch with 0.5. |
| 2545 | __ mov(scratch, Immediate(0x3F000000u)); |
| 2546 | __ movd(double_scratch, scratch); |
| 2547 | __ cvtss2sd(double_scratch, double_scratch); |
| 2548 | // Already ruled out NaNs for exponent. |
| 2549 | __ ucomisd(double_scratch, double_exponent); |
| 2550 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 2551 | |
| 2552 | // Calculates square root of base. Check for the special case of |
| 2553 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 2554 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2555 | // 9 bits set and the lowest 23 bits cleared. |
| 2556 | __ mov(scratch, 0xFF800000u); |
| 2557 | __ movd(double_scratch, scratch); |
| 2558 | __ cvtss2sd(double_scratch, double_scratch); |
| 2559 | __ ucomisd(double_base, double_scratch); |
| 2560 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2561 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2562 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 2563 | __ j(carry, &continue_sqrt, Label::kNear); |
| 2564 | |
| 2565 | // Set result to Infinity in the special case. |
| 2566 | __ xorps(double_result, double_result); |
| 2567 | __ subsd(double_result, double_scratch); |
| 2568 | __ jmp(&done); |
| 2569 | |
| 2570 | __ bind(&continue_sqrt); |
| 2571 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2572 | __ xorps(double_scratch, double_scratch); |
| 2573 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 2574 | __ sqrtsd(double_result, double_scratch); |
| 2575 | __ jmp(&done); |
| 2576 | |
| 2577 | // Test for -0.5. |
| 2578 | __ bind(¬_plus_half); |
| 2579 | // Load double_exponent with -0.5 by substracting 1. |
| 2580 | __ subsd(double_scratch, double_result); |
| 2581 | // Already ruled out NaNs for exponent. |
| 2582 | __ ucomisd(double_scratch, double_exponent); |
| 2583 | __ j(not_equal, &fast_power, Label::kNear); |
| 2584 | |
| 2585 | // Calculates reciprocal of square root of base. Check for the special |
| 2586 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 2587 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2588 | // 9 bits set and the lowest 23 bits cleared. |
| 2589 | __ mov(scratch, 0xFF800000u); |
| 2590 | __ movd(double_scratch, scratch); |
| 2591 | __ cvtss2sd(double_scratch, double_scratch); |
| 2592 | __ ucomisd(double_base, double_scratch); |
| 2593 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2594 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2595 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 2596 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 2597 | |
| 2598 | // Set result to 0 in the special case. |
| 2599 | __ xorps(double_result, double_result); |
| 2600 | __ jmp(&done); |
| 2601 | |
| 2602 | __ bind(&continue_rsqrt); |
| 2603 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2604 | __ xorps(double_exponent, double_exponent); |
| 2605 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 2606 | __ sqrtsd(double_exponent, double_exponent); |
| 2607 | __ divsd(double_result, double_exponent); |
| 2608 | __ jmp(&done); |
| 2609 | } |
| 2610 | |
| 2611 | // Using FPU instructions to calculate power. |
| 2612 | Label fast_power_failed; |
| 2613 | __ bind(&fast_power); |
| 2614 | __ fnclex(); // Clear flags to catch exceptions later. |
| 2615 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 2616 | __ sub(esp, Immediate(kDoubleSize)); |
| 2617 | __ movdbl(Operand(esp, 0), double_exponent); |
| 2618 | __ fld_d(Operand(esp, 0)); // E |
| 2619 | __ movdbl(Operand(esp, 0), double_base); |
| 2620 | __ fld_d(Operand(esp, 0)); // B, E |
| 2621 | |
| 2622 | // Exponent is in st(1) and base is in st(0) |
| 2623 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 2624 | // FYL2X calculates st(1) * log2(st(0)) |
| 2625 | __ fyl2x(); // X |
| 2626 | __ fld(0); // X, X |
| 2627 | __ frndint(); // rnd(X), X |
| 2628 | __ fsub(1); // rnd(X), X-rnd(X) |
| 2629 | __ fxch(1); // X - rnd(X), rnd(X) |
| 2630 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 2631 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 2632 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2633 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2634 | // FSCALE calculates st(0) * 2^st(1) |
| 2635 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2636 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2637 | // Bail out to runtime in case of exceptions in the status word. |
| 2638 | __ fnstsw_ax(); |
| 2639 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 2640 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 2641 | __ fstp_d(Operand(esp, 0)); |
| 2642 | __ movdbl(double_result, Operand(esp, 0)); |
| 2643 | __ add(esp, Immediate(kDoubleSize)); |
| 2644 | __ jmp(&done); |
| 2645 | |
| 2646 | __ bind(&fast_power_failed); |
| 2647 | __ fninit(); |
| 2648 | __ add(esp, Immediate(kDoubleSize)); |
| 2649 | __ jmp(&call_runtime); |
| 2650 | } |
| 2651 | |
| 2652 | // Calculate power with integer exponent. |
| 2653 | __ bind(&int_exponent); |
| 2654 | const XMMRegister double_scratch2 = double_exponent; |
| 2655 | __ mov(scratch, exponent); // Back up exponent. |
| 2656 | __ movsd(double_scratch, double_base); // Back up base. |
| 2657 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2658 | |
| 2659 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2660 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2661 | __ test(scratch, scratch); |
| 2662 | __ j(positive, &no_neg, Label::kNear); |
| 2663 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2664 | __ bind(&no_neg); |
| 2665 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2666 | __ j(zero, &while_false, Label::kNear); |
| 2667 | __ shr(scratch, 1); |
| 2668 | // Above condition means CF==0 && ZF==0. This means that the |
| 2669 | // bit that has been shifted out is 0 and the result is not 0. |
| 2670 | __ j(above, &while_true, Label::kNear); |
| 2671 | __ movsd(double_result, double_scratch); |
| 2672 | __ j(zero, &while_false, Label::kNear); |
| 2673 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2674 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2675 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2676 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2677 | __ j(above, &while_true, Label::kNear); |
| 2678 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2679 | __ j(not_zero, &while_true); |
| 2680 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2681 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2682 | // scratch has the original value of the exponent - if the exponent is |
| 2683 | // negative, return 1/result. |
| 2684 | __ test(exponent, exponent); |
| 2685 | __ j(positive, &done); |
| 2686 | __ divsd(double_scratch2, double_result); |
| 2687 | __ movsd(double_result, double_scratch2); |
| 2688 | // Test whether result is zero. Bail out to check for subnormal result. |
| 2689 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 2690 | __ xorps(double_scratch2, double_scratch2); |
| 2691 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 2692 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 2693 | // and may not have contained the exponent value in the first place when the |
| 2694 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 2695 | __ j(not_equal, &done); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2696 | __ Cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2697 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2698 | // Returning or bailing out. |
| 2699 | Counters* counters = masm->isolate()->counters(); |
| 2700 | if (exponent_type_ == ON_STACK) { |
| 2701 | // The arguments are still on the stack. |
| 2702 | __ bind(&call_runtime); |
| 2703 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2704 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2705 | // The stub is called from non-optimized code, which expects the result |
| 2706 | // as heap number in exponent. |
| 2707 | __ bind(&done); |
| 2708 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 2709 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 2710 | __ IncrementCounter(counters->math_pow(), 1); |
| 2711 | __ ret(2 * kPointerSize); |
| 2712 | } else { |
| 2713 | __ bind(&call_runtime); |
| 2714 | { |
| 2715 | AllowExternalCallThatCantCauseGC scope(masm); |
| 2716 | __ PrepareCallCFunction(4, scratch); |
| 2717 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 2718 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 2719 | __ CallCFunction( |
| 2720 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 2721 | } |
| 2722 | // Return value is in st(0) on ia32. |
| 2723 | // Store it into the (fixed) result register. |
| 2724 | __ sub(esp, Immediate(kDoubleSize)); |
| 2725 | __ fstp_d(Operand(esp, 0)); |
| 2726 | __ movdbl(double_result, Operand(esp, 0)); |
| 2727 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2728 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2729 | __ bind(&done); |
| 2730 | __ IncrementCounter(counters->math_pow(), 1); |
| 2731 | __ ret(0); |
| 2732 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2736 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 2737 | // ----------- S t a t e ------------- |
| 2738 | // -- ecx : name |
| 2739 | // -- edx : receiver |
| 2740 | // -- esp[0] : return address |
| 2741 | // ----------------------------------- |
| 2742 | Label miss; |
| 2743 | |
| 2744 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2745 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2746 | __ j(not_equal, &miss); |
| 2747 | } |
| 2748 | |
| 2749 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 2750 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2751 | StubCompiler::TailCallBuiltin( |
| 2752 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | |
| 2756 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 2757 | // ----------- S t a t e ------------- |
| 2758 | // -- ecx : name |
| 2759 | // -- edx : receiver |
| 2760 | // -- esp[0] : return address |
| 2761 | // ----------------------------------- |
| 2762 | Label miss; |
| 2763 | |
| 2764 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2765 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2766 | __ j(not_equal, &miss); |
| 2767 | } |
| 2768 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2769 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2770 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2771 | StubCompiler::TailCallBuiltin( |
| 2772 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2773 | } |
| 2774 | |
| 2775 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2776 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 2777 | // ----------- S t a t e ------------- |
| 2778 | // -- eax : value |
| 2779 | // -- ecx : name |
| 2780 | // -- edx : receiver |
| 2781 | // -- esp[0] : return address |
| 2782 | // ----------------------------------- |
| 2783 | // |
| 2784 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 2785 | // (currently anything except for external arrays which means anything with |
| 2786 | // elements of FixedArray type). Value must be a number, but only smis are |
| 2787 | // accepted as the most common case. |
| 2788 | |
| 2789 | Label miss; |
| 2790 | |
| 2791 | Register receiver = edx; |
| 2792 | Register value = eax; |
| 2793 | Register scratch = ebx; |
| 2794 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2795 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2796 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2797 | __ j(not_equal, &miss); |
| 2798 | } |
| 2799 | |
| 2800 | // Check that the receiver isn't a smi. |
| 2801 | __ JumpIfSmi(receiver, &miss); |
| 2802 | |
| 2803 | // Check that the object is a JS array. |
| 2804 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 2805 | __ j(not_equal, &miss); |
| 2806 | |
| 2807 | // Check that elements are FixedArray. |
| 2808 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 2809 | // fast elements (including COW). |
| 2810 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 2811 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 2812 | __ j(not_equal, &miss); |
| 2813 | |
| 2814 | // Check that the array has fast properties, otherwise the length |
| 2815 | // property might have been redefined. |
| 2816 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 2817 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 2818 | Heap::kHashTableMapRootIndex); |
| 2819 | __ j(equal, &miss); |
| 2820 | |
| 2821 | // Check that value is a smi. |
| 2822 | __ JumpIfNotSmi(value, &miss); |
| 2823 | |
| 2824 | // Prepare tail call to StoreIC_ArrayLength. |
| 2825 | __ pop(scratch); |
| 2826 | __ push(receiver); |
| 2827 | __ push(value); |
| 2828 | __ push(scratch); // return address |
| 2829 | |
| 2830 | ExternalReference ref = |
| 2831 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 2832 | __ TailCallExternalReference(ref, 2, 1); |
| 2833 | |
| 2834 | __ bind(&miss); |
| 2835 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2836 | StubCompiler::TailCallBuiltin( |
| 2837 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2841 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 2842 | // The key is in edx and the parameter count is in eax. |
| 2843 | |
| 2844 | // The displacement is used for skipping the frame pointer on the |
| 2845 | // stack. It is the offset of the last parameter (if any) relative |
| 2846 | // to the frame pointer. |
| 2847 | static const int kDisplacement = 1 * kPointerSize; |
| 2848 | |
| 2849 | // Check that the key is a smi. |
| 2850 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2851 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2852 | |
| 2853 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2854 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2855 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2856 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2857 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2858 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2859 | |
| 2860 | // Check index against formal parameters count limit passed in |
| 2861 | // through register eax. Use unsigned comparison to get negative |
| 2862 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2863 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2864 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2865 | |
| 2866 | // Read the argument from the stack and return it. |
| 2867 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2868 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 2869 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 2870 | __ neg(edx); |
| 2871 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 2872 | __ ret(0); |
| 2873 | |
| 2874 | // Arguments adaptor case: Check index against actual arguments |
| 2875 | // limit found in the arguments adaptor frame. Use unsigned |
| 2876 | // comparison to get negative check for free. |
| 2877 | __ bind(&adaptor); |
| 2878 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2879 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2880 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2881 | |
| 2882 | // Read the argument from the stack and return it. |
| 2883 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2884 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 2885 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 2886 | __ neg(edx); |
| 2887 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 2888 | __ ret(0); |
| 2889 | |
| 2890 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 2891 | // by calling the runtime system. |
| 2892 | __ bind(&slow); |
| 2893 | __ pop(ebx); // Return address. |
| 2894 | __ push(edx); |
| 2895 | __ push(ebx); |
| 2896 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 2897 | } |
| 2898 | |
| 2899 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2900 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2901 | // esp[0] : return address |
| 2902 | // esp[4] : number of parameters |
| 2903 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2904 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2905 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2906 | // Check if the calling frame is an arguments adaptor frame. |
| 2907 | Label runtime; |
| 2908 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2909 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2910 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2911 | __ j(not_equal, &runtime, Label::kNear); |
| 2912 | |
| 2913 | // Patch the arguments.length and the parameters pointer. |
| 2914 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2915 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 2916 | __ lea(edx, Operand(edx, ecx, times_2, |
| 2917 | StandardFrameConstants::kCallerSPOffset)); |
| 2918 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 2919 | |
| 2920 | __ bind(&runtime); |
| 2921 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 2922 | } |
| 2923 | |
| 2924 | |
| 2925 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 2926 | Isolate* isolate = masm->isolate(); |
| 2927 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2928 | // esp[0] : return address |
| 2929 | // esp[4] : number of parameters (tagged) |
| 2930 | // esp[8] : receiver displacement |
| 2931 | // esp[12] : function |
| 2932 | |
| 2933 | // ebx = parameter count (tagged) |
| 2934 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 2935 | |
| 2936 | // Check if the calling frame is an arguments adaptor frame. |
| 2937 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 2938 | // Generate* functions. |
| 2939 | Label runtime; |
| 2940 | Label adaptor_frame, try_allocate; |
| 2941 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 2942 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2943 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2944 | __ j(equal, &adaptor_frame, Label::kNear); |
| 2945 | |
| 2946 | // No adaptor, parameter count = argument count. |
| 2947 | __ mov(ecx, ebx); |
| 2948 | __ jmp(&try_allocate, Label::kNear); |
| 2949 | |
| 2950 | // We have an adaptor frame. Patch the parameters pointer. |
| 2951 | __ bind(&adaptor_frame); |
| 2952 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 2953 | __ lea(edx, Operand(edx, ecx, times_2, |
| 2954 | StandardFrameConstants::kCallerSPOffset)); |
| 2955 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 2956 | |
| 2957 | // ebx = parameter count (tagged) |
| 2958 | // ecx = argument count (tagged) |
| 2959 | // esp[4] = parameter count (tagged) |
| 2960 | // esp[8] = address of receiver argument |
| 2961 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2962 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2963 | __ j(less_equal, &try_allocate, Label::kNear); |
| 2964 | __ mov(ebx, ecx); |
| 2965 | |
| 2966 | __ bind(&try_allocate); |
| 2967 | |
| 2968 | // Save mapped parameter count. |
| 2969 | __ push(ebx); |
| 2970 | |
| 2971 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 2972 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 2973 | const int kParameterMapHeaderSize = |
| 2974 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 2975 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2976 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2977 | __ j(zero, &no_parameter_map, Label::kNear); |
| 2978 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 2979 | __ bind(&no_parameter_map); |
| 2980 | |
| 2981 | // 2. Backing store. |
| 2982 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 2983 | |
| 2984 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2985 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2986 | |
| 2987 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2988 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2989 | |
| 2990 | // eax = address of new object(s) (tagged) |
| 2991 | // ecx = argument count (tagged) |
| 2992 | // esp[0] = mapped parameter count (tagged) |
| 2993 | // esp[8] = parameter count (tagged) |
| 2994 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2995 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2996 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2997 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 2998 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2999 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3000 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3001 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3002 | __ mov(edi, Operand(edi, |
| 3003 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3004 | __ jmp(©, Label::kNear); |
| 3005 | |
| 3006 | __ bind(&has_mapped_parameters); |
| 3007 | __ mov(edi, Operand(edi, |
| 3008 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3009 | __ bind(©); |
| 3010 | |
| 3011 | // eax = address of new object (tagged) |
| 3012 | // ebx = mapped parameter count (tagged) |
| 3013 | // ecx = argument count (tagged) |
| 3014 | // edi = address of boilerplate object (tagged) |
| 3015 | // esp[0] = mapped parameter count (tagged) |
| 3016 | // esp[8] = parameter count (tagged) |
| 3017 | // esp[12] = address of receiver argument |
| 3018 | // Copy the JS object part. |
| 3019 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3020 | __ mov(edx, FieldOperand(edi, i)); |
| 3021 | __ mov(FieldOperand(eax, i), edx); |
| 3022 | } |
| 3023 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3024 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3025 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3026 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3027 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3028 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3029 | edx); |
| 3030 | |
| 3031 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3032 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3033 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3034 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3035 | ecx); |
| 3036 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3037 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3038 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3039 | // backing store. |
| 3040 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3041 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3042 | |
| 3043 | // eax = address of new object (tagged) |
| 3044 | // ebx = mapped parameter count (tagged) |
| 3045 | // ecx = argument count (tagged) |
| 3046 | // edi = address of parameter map or backing store (tagged) |
| 3047 | // esp[0] = mapped parameter count (tagged) |
| 3048 | // esp[8] = parameter count (tagged) |
| 3049 | // esp[12] = address of receiver argument |
| 3050 | // Free a register. |
| 3051 | __ push(eax); |
| 3052 | |
| 3053 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3054 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3055 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3056 | __ j(zero, &skip_parameter_map); |
| 3057 | |
| 3058 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3059 | Immediate(isolate->factory()->non_strict_arguments_elements_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3060 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3061 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3062 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3063 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3064 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3065 | |
| 3066 | // Copy the parameter slots and the holes in the arguments. |
| 3067 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3068 | // where parameters are stored in reverse order, at |
| 3069 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3070 | // The mapped parameter thus need to get indices |
| 3071 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3072 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3073 | // We loop from right to left. |
| 3074 | Label parameters_loop, parameters_test; |
| 3075 | __ push(ecx); |
| 3076 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3077 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3078 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3079 | __ sub(ebx, eax); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3080 | __ mov(ecx, isolate->factory()->the_hole_value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3081 | __ mov(edx, edi); |
| 3082 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3083 | // eax = loop variable (tagged) |
| 3084 | // ebx = mapping index (tagged) |
| 3085 | // ecx = the hole value |
| 3086 | // edx = address of parameter map (tagged) |
| 3087 | // edi = address of backing store (tagged) |
| 3088 | // esp[0] = argument count (tagged) |
| 3089 | // esp[4] = address of new object (tagged) |
| 3090 | // esp[8] = mapped parameter count (tagged) |
| 3091 | // esp[16] = parameter count (tagged) |
| 3092 | // esp[20] = address of receiver argument |
| 3093 | __ jmp(¶meters_test, Label::kNear); |
| 3094 | |
| 3095 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3096 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3097 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3098 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3099 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3100 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3101 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3102 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3103 | __ pop(ecx); |
| 3104 | |
| 3105 | __ bind(&skip_parameter_map); |
| 3106 | |
| 3107 | // ecx = argument count (tagged) |
| 3108 | // edi = address of backing store (tagged) |
| 3109 | // esp[0] = address of new object (tagged) |
| 3110 | // esp[4] = mapped parameter count (tagged) |
| 3111 | // esp[12] = parameter count (tagged) |
| 3112 | // esp[16] = address of receiver argument |
| 3113 | // Copy arguments header and remaining slots (if there are any). |
| 3114 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3115 | Immediate(isolate->factory()->fixed_array_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3116 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3117 | |
| 3118 | Label arguments_loop, arguments_test; |
| 3119 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3120 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3121 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3122 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3123 | __ jmp(&arguments_test, Label::kNear); |
| 3124 | |
| 3125 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3126 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3127 | __ mov(eax, Operand(edx, 0)); |
| 3128 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3129 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3130 | |
| 3131 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3132 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3133 | __ j(less, &arguments_loop, Label::kNear); |
| 3134 | |
| 3135 | // Restore. |
| 3136 | __ pop(eax); // Address of arguments object. |
| 3137 | __ pop(ebx); // Parameter count. |
| 3138 | |
| 3139 | // Return and remove the on-stack parameters. |
| 3140 | __ ret(3 * kPointerSize); |
| 3141 | |
| 3142 | // Do the runtime call to allocate the arguments object. |
| 3143 | __ bind(&runtime); |
| 3144 | __ pop(eax); // Remove saved parameter count. |
| 3145 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3146 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3147 | } |
| 3148 | |
| 3149 | |
| 3150 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3151 | Isolate* isolate = masm->isolate(); |
| 3152 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3153 | // esp[0] : return address |
| 3154 | // esp[4] : number of parameters |
| 3155 | // esp[8] : receiver displacement |
| 3156 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3157 | |
| 3158 | // Check if the calling frame is an arguments adaptor frame. |
| 3159 | Label adaptor_frame, try_allocate, runtime; |
| 3160 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3161 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3162 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3163 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3164 | |
| 3165 | // Get the length from the frame. |
| 3166 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3167 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3168 | |
| 3169 | // Patch the arguments.length and the parameters pointer. |
| 3170 | __ bind(&adaptor_frame); |
| 3171 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3172 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3173 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3174 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3175 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3176 | |
| 3177 | // Try the new space allocation. Start out with computing the size of |
| 3178 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3179 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3180 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3181 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3182 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3183 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3184 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3185 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3186 | |
| 3187 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3188 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3189 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3190 | // Get the arguments boilerplate from the current native context. |
| 3191 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3192 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3193 | const int offset = |
| 3194 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3195 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3196 | |
| 3197 | // Copy the JS object part. |
| 3198 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3199 | __ mov(ebx, FieldOperand(edi, i)); |
| 3200 | __ mov(FieldOperand(eax, i), ebx); |
| 3201 | } |
| 3202 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3203 | // 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] | 3204 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3205 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3206 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3207 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3208 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3209 | |
| 3210 | // If there are no actual arguments, we're done. |
| 3211 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3212 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3213 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3214 | |
| 3215 | // Get the parameters pointer from the stack. |
| 3216 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3217 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3218 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3219 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3220 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3221 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3222 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3223 | Immediate(isolate->factory()->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3224 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3225 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3226 | // Untag the length for the loop below. |
| 3227 | __ SmiUntag(ecx); |
| 3228 | |
| 3229 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3230 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3231 | __ bind(&loop); |
| 3232 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3233 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3234 | __ add(edi, Immediate(kPointerSize)); |
| 3235 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3236 | __ dec(ecx); |
| 3237 | __ j(not_zero, &loop); |
| 3238 | |
| 3239 | // Return and remove the on-stack parameters. |
| 3240 | __ bind(&done); |
| 3241 | __ ret(3 * kPointerSize); |
| 3242 | |
| 3243 | // Do the runtime call to allocate the arguments object. |
| 3244 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3245 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3246 | } |
| 3247 | |
| 3248 | |
| 3249 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3250 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3251 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3252 | // at compilation. |
| 3253 | #ifdef V8_INTERPRETED_REGEXP |
| 3254 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3255 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3256 | |
| 3257 | // Stack frame on entry. |
| 3258 | // esp[0]: return address |
| 3259 | // esp[4]: last_match_info (expected JSArray) |
| 3260 | // esp[8]: previous index |
| 3261 | // esp[12]: subject string |
| 3262 | // esp[16]: JSRegExp object |
| 3263 | |
| 3264 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3265 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3266 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3267 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3268 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3269 | Label runtime; |
| 3270 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3271 | |
| 3272 | // Ensure that a RegExp stack is allocated. |
| 3273 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3274 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3275 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3276 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3277 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3278 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3279 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3280 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3281 | |
| 3282 | // Check that the first argument is a JSRegExp object. |
| 3283 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3284 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3285 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3286 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3287 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3288 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3289 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3290 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3291 | if (FLAG_debug_code) { |
| 3292 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3293 | __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3294 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3295 | __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | // ecx: RegExp data (FixedArray) |
| 3299 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3300 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3301 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3302 | __ j(not_equal, &runtime); |
| 3303 | |
| 3304 | // ecx: RegExp data (FixedArray) |
| 3305 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3306 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3307 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3308 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3309 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3310 | STATIC_ASSERT(kSmiTag == 0); |
| 3311 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3312 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3313 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3314 | __ j(above, &runtime); |
| 3315 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3316 | // Reset offset for possibly sliced string. |
| 3317 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3318 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3319 | __ JumpIfSmi(eax, &runtime); |
| 3320 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3321 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3322 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3323 | |
| 3324 | // eax: subject string |
| 3325 | // edx: subject string |
| 3326 | // ebx: subject string instance type |
| 3327 | // ecx: RegExp data (FixedArray) |
| 3328 | // Handle subject string according to its encoding and representation: |
| 3329 | // (1) Sequential two byte? If yes, go to (9). |
| 3330 | // (2) Sequential one byte? If yes, go to (6). |
| 3331 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3332 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3333 | // Otherwise bailout. |
| 3334 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3335 | // (5b) Is subject external? If yes, go to (8). |
| 3336 | // (6) One byte sequential. Load regexp code for one byte. |
| 3337 | // (E) Carry on. |
| 3338 | /// [...] |
| 3339 | |
| 3340 | // Deferred code at the end of the stub: |
| 3341 | // (7) Not a long external string? If yes, go to (10). |
| 3342 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3343 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3344 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3345 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3346 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3347 | |
| 3348 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3349 | external_string /* 8 */, check_underlying /* 5a */, |
| 3350 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3351 | not_long_external /* 10 */; |
| 3352 | |
| 3353 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3354 | __ and_(ebx, kIsNotStringMask | |
| 3355 | kStringRepresentationMask | |
| 3356 | kStringEncodingMask | |
| 3357 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3358 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3359 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3360 | |
| 3361 | // (2) Sequential one byte? If yes, go to (6). |
| 3362 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3363 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3364 | kStringRepresentationMask | |
| 3365 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3366 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3367 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3368 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3369 | // We check whether the subject string is a cons, since sequential strings |
| 3370 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3371 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3372 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3373 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3374 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3375 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3376 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3377 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3378 | // (4) Cons string. Check that it's flat. |
| 3379 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3380 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3381 | __ j(not_equal, &runtime); |
| 3382 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3383 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3384 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3385 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3386 | |
| 3387 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3388 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3389 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3390 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3391 | // (5b) Is subject external? If yes, go to (8). |
| 3392 | __ test_b(ebx, kStringRepresentationMask); |
| 3393 | // The underlying external string is never a short external string. |
| 3394 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3395 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3396 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3397 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3398 | // eax: sequential subject string (or look-alike, external string) |
| 3399 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3400 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3401 | // (6) One byte sequential. Load regexp code for one byte. |
| 3402 | __ bind(&seq_one_byte_string); |
| 3403 | // Load previous index and check range before edx is overwritten. We have |
| 3404 | // to use edx instead of eax here because it might have been only made to |
| 3405 | // look like a sequential string when it actually is an external string. |
| 3406 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3407 | __ JumpIfNotSmi(ebx, &runtime); |
| 3408 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3409 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3410 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3411 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3412 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3413 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3414 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3415 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3416 | // Check that the irregexp code has been generated for the actual string |
| 3417 | // 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] | 3418 | // a smi (code flushing support). |
| 3419 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3420 | |
| 3421 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3422 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3423 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3424 | // 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] | 3425 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3426 | Counters* counters = masm->isolate()->counters(); |
| 3427 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3428 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3429 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3430 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3431 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3432 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3433 | // Argument 9: Pass current isolate address. |
| 3434 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3435 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3436 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3437 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3438 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3439 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3440 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3441 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3442 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3443 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3444 | |
| 3445 | // Argument 6: Set the number of capture registers to zero to force global |
| 3446 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3447 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3448 | |
| 3449 | // Argument 5: static offsets vector buffer. |
| 3450 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3451 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3452 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3453 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3454 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3455 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3456 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3457 | |
| 3458 | // Argument 1: Original subject string. |
| 3459 | // The original subject is in the previous stack frame. Therefore we have to |
| 3460 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3461 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3462 | // and thereby moves up esp by one kPointerSize.) |
| 3463 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3464 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3465 | |
| 3466 | // esi: original subject string |
| 3467 | // eax: underlying subject string |
| 3468 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3469 | // 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] | 3470 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3471 | // Argument 4: End of string data |
| 3472 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3473 | // Prepare start and end index of the input. |
| 3474 | // Load the length from the original sliced string if that is the case. |
| 3475 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3476 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3477 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3478 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3479 | |
| 3480 | // ebx: start index of the input string |
| 3481 | // esi: end index of the input string |
| 3482 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3483 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3484 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3485 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3486 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3487 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3488 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3489 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3490 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3491 | |
| 3492 | __ bind(&setup_two_byte); |
| 3493 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3494 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3495 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3496 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3497 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3498 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3499 | |
| 3500 | __ bind(&setup_rest); |
| 3501 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3502 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3503 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3504 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3505 | |
| 3506 | // Drop arguments and come back to JS mode. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3507 | __ LeaveApiExitFrame(true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3508 | |
| 3509 | // Check the result. |
| 3510 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3511 | __ cmp(eax, 1); |
| 3512 | // We expect exactly one result since we force the called regexp to behave |
| 3513 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3514 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3515 | Label failure; |
| 3516 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3517 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3518 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3519 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3520 | __ j(not_equal, &runtime); |
| 3521 | // Result must now be exception. If there is no pending exception already a |
| 3522 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3523 | // haven't created the exception yet. Handle that in the runtime system. |
| 3524 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3525 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3526 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3527 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3528 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3529 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3530 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3531 | // For exception, throw the exception again. |
| 3532 | |
| 3533 | // Clear the pending exception variable. |
| 3534 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3535 | |
| 3536 | // Special handling of termination exceptions which are uncatchable |
| 3537 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3538 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3539 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3540 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3541 | |
| 3542 | // Handle normal exception by following handler chain. |
| 3543 | __ Throw(eax); |
| 3544 | |
| 3545 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3546 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3547 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3548 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3549 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3550 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3551 | __ ret(4 * kPointerSize); |
| 3552 | |
| 3553 | // Load RegExp data. |
| 3554 | __ bind(&success); |
| 3555 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3556 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3557 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3558 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3559 | STATIC_ASSERT(kSmiTag == 0); |
| 3560 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3561 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3562 | |
| 3563 | // edx: Number of capture registers |
| 3564 | // 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] | 3565 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3566 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3567 | __ JumpIfSmi(eax, &runtime); |
| 3568 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3569 | __ j(not_equal, &runtime); |
| 3570 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3571 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3572 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 3573 | __ cmp(eax, factory->fixed_array_map()); |
| 3574 | __ j(not_equal, &runtime); |
| 3575 | // Check that the last match info has space for the capture registers and the |
| 3576 | // additional information. |
| 3577 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3578 | __ SmiUntag(eax); |
| 3579 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3580 | __ cmp(edx, eax); |
| 3581 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3582 | |
| 3583 | // ebx: last_match_info backing store (FixedArray) |
| 3584 | // edx: number of capture registers |
| 3585 | // Store the capture count. |
| 3586 | __ SmiTag(edx); // Number of capture registers to smi. |
| 3587 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 3588 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 3589 | // Store last subject and last input. |
| 3590 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3591 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3592 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3593 | __ RecordWriteField(ebx, |
| 3594 | RegExpImpl::kLastSubjectOffset, |
| 3595 | eax, |
| 3596 | edi, |
| 3597 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3598 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3599 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3600 | __ RecordWriteField(ebx, |
| 3601 | RegExpImpl::kLastInputOffset, |
| 3602 | eax, |
| 3603 | edi, |
| 3604 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3605 | |
| 3606 | // Get the static offsets vector filled by the native regexp code. |
| 3607 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3608 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3609 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 3610 | |
| 3611 | // ebx: last_match_info backing store (FixedArray) |
| 3612 | // ecx: offsets vector |
| 3613 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3614 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3615 | // Capture register counter starts from number of capture registers and |
| 3616 | // counts down until wraping after zero. |
| 3617 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3618 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3619 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3620 | // Read the value from the static offsets vector buffer. |
| 3621 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 3622 | __ SmiTag(edi); |
| 3623 | // Store the smi value in the last match info. |
| 3624 | __ mov(FieldOperand(ebx, |
| 3625 | edx, |
| 3626 | times_pointer_size, |
| 3627 | RegExpImpl::kFirstCaptureOffset), |
| 3628 | edi); |
| 3629 | __ jmp(&next_capture); |
| 3630 | __ bind(&done); |
| 3631 | |
| 3632 | // Return last match info. |
| 3633 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 3634 | __ ret(4 * kPointerSize); |
| 3635 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3636 | // Do the runtime call to execute the regexp. |
| 3637 | __ bind(&runtime); |
| 3638 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3639 | |
| 3640 | // Deferred code for string handling. |
| 3641 | // (7) Not a long external string? If yes, go to (10). |
| 3642 | __ bind(¬_seq_nor_cons); |
| 3643 | // Compare flags are still set from (3). |
| 3644 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 3645 | |
| 3646 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3647 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3648 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3649 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3650 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3651 | if (FLAG_debug_code) { |
| 3652 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 3653 | // Sequential strings have already been ruled out. |
| 3654 | __ test_b(ebx, kIsIndirectStringMask); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3655 | __ Assert(zero, kExternalStringExpectedButNotFound); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3656 | } |
| 3657 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 3658 | // 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] | 3659 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3660 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3661 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3662 | // (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] | 3663 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3664 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3665 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3666 | // eax: sequential subject string (or look-alike, external string) |
| 3667 | // edx: original subject string |
| 3668 | // ecx: RegExp data (FixedArray) |
| 3669 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3670 | __ bind(&seq_two_byte_string); |
| 3671 | // Load previous index and check range before edx is overwritten. We have |
| 3672 | // to use edx instead of eax here because it might have been only made to |
| 3673 | // look like a sequential string when it actually is an external string. |
| 3674 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3675 | __ JumpIfNotSmi(ebx, &runtime); |
| 3676 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3677 | __ j(above_equal, &runtime); |
| 3678 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 3679 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 3680 | __ jmp(&check_code); // Go to (E). |
| 3681 | |
| 3682 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 3683 | __ bind(¬_long_external); |
| 3684 | // Catch non-string subject or short external string. |
| 3685 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3686 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 3687 | __ j(not_zero, &runtime); |
| 3688 | |
| 3689 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3690 | // Load offset into edi and replace subject string with parent. |
| 3691 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3692 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3693 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3694 | #endif // V8_INTERPRETED_REGEXP |
| 3695 | } |
| 3696 | |
| 3697 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3698 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 3699 | const int kMaxInlineLength = 100; |
| 3700 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3701 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3702 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3703 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3704 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3705 | __ j(above, &slowcase); |
| 3706 | // Smi-tagging is equivalent to multiplying by 2. |
| 3707 | STATIC_ASSERT(kSmiTag == 0); |
| 3708 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3709 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 3710 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 3711 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3712 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 3713 | times_pointer_size, |
| 3714 | ebx, // In: Number of elements as a smi |
| 3715 | REGISTER_VALUE_IS_SMI, |
| 3716 | eax, // Out: Start of allocation (tagged). |
| 3717 | ecx, // Out: End of allocation. |
| 3718 | edx, // Scratch register |
| 3719 | &slowcase, |
| 3720 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3721 | // eax: Start of allocated area, object-tagged. |
| 3722 | |
| 3723 | // Set JSArray map to global.regexp_result_map(). |
| 3724 | // Set empty properties FixedArray. |
| 3725 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 3726 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3727 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3728 | Factory* factory = masm->isolate()->factory(); |
| 3729 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3730 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3731 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3732 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 3733 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 3734 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 3735 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 3736 | |
| 3737 | // Set input, index and length fields from arguments. |
| 3738 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 3739 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 3740 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 3741 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 3742 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 3743 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 3744 | |
| 3745 | // Fill out the elements FixedArray. |
| 3746 | // eax: JSArray. |
| 3747 | // ebx: FixedArray. |
| 3748 | // ecx: Number of elements in array, as smi. |
| 3749 | |
| 3750 | // Set map. |
| 3751 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3752 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3753 | // Set length. |
| 3754 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3755 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3756 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3757 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3758 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3759 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3760 | // eax: JSArray. |
| 3761 | // ecx: Number of elements to fill. |
| 3762 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3763 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3764 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3765 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3766 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3767 | __ 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] | 3768 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3769 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 3770 | __ jmp(&loop); |
| 3771 | |
| 3772 | __ bind(&done); |
| 3773 | __ ret(3 * kPointerSize); |
| 3774 | |
| 3775 | __ bind(&slowcase); |
| 3776 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 3777 | } |
| 3778 | |
| 3779 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3780 | static int NegativeComparisonResult(Condition cc) { |
| 3781 | ASSERT(cc != equal); |
| 3782 | ASSERT((cc == less) || (cc == less_equal) |
| 3783 | || (cc == greater) || (cc == greater_equal)); |
| 3784 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 3785 | } |
| 3786 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3787 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3788 | static void CheckInputType(MacroAssembler* masm, |
| 3789 | Register input, |
| 3790 | CompareIC::State expected, |
| 3791 | Label* fail) { |
| 3792 | Label ok; |
| 3793 | if (expected == CompareIC::SMI) { |
| 3794 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 3795 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3796 | __ JumpIfSmi(input, &ok); |
| 3797 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 3798 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 3799 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3800 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3801 | // 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] | 3802 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 3803 | __ bind(&ok); |
| 3804 | } |
| 3805 | |
| 3806 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3807 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 3808 | Label* label, |
| 3809 | Register object, |
| 3810 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3811 | __ JumpIfSmi(object, label); |
| 3812 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 3813 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3814 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 3815 | __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 3816 | __ j(not_zero, label); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
| 3819 | |
| 3820 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 3821 | Label check_unequal_objects; |
| 3822 | Condition cc = GetCondition(); |
| 3823 | |
| 3824 | Label miss; |
| 3825 | CheckInputType(masm, edx, left_, &miss); |
| 3826 | CheckInputType(masm, eax, right_, &miss); |
| 3827 | |
| 3828 | // Compare two smis. |
| 3829 | Label non_smi, smi_done; |
| 3830 | __ mov(ecx, edx); |
| 3831 | __ or_(ecx, eax); |
| 3832 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 3833 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 3834 | __ j(no_overflow, &smi_done, Label::kNear); |
| 3835 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 3836 | __ bind(&smi_done); |
| 3837 | __ mov(eax, edx); |
| 3838 | __ ret(0); |
| 3839 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 3840 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3841 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 3842 | // it is certain that at least one operand isn't a smi. |
| 3843 | |
| 3844 | // Identical objects can be compared fast, but there are some tricky cases |
| 3845 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3846 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3847 | { |
| 3848 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3849 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3850 | __ j(not_equal, ¬_identical); |
| 3851 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3852 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3853 | // Check for undefined. undefined OP undefined is false even though |
| 3854 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3855 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3856 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3857 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3858 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3859 | __ ret(0); |
| 3860 | __ bind(&check_for_nan); |
| 3861 | } |
| 3862 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3863 | // Test for NaN. Compare heap numbers in a general way, |
| 3864 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3865 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 3866 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3867 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3868 | if (cc != equal) { |
| 3869 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 3870 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 3871 | __ j(above_equal, ¬_identical); |
| 3872 | } |
| 3873 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3874 | __ ret(0); |
| 3875 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3876 | |
| 3877 | __ bind(¬_identical); |
| 3878 | } |
| 3879 | |
| 3880 | // Strict equality can quickly decide whether objects are equal. |
| 3881 | // 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] | 3882 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3883 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3884 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3885 | // If we're doing a strict equality comparison, we don't have to do |
| 3886 | // type conversion, so we generate code to do fast comparison for objects |
| 3887 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 3888 | // slow-case code. |
| 3889 | // If either is a Smi (we know that not both are), then they can only |
| 3890 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 3891 | STATIC_ASSERT(kSmiTag == 0); |
| 3892 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 3893 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3894 | __ and_(ecx, eax); |
| 3895 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3896 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3897 | // One operand is a smi. |
| 3898 | |
| 3899 | // Check whether the non-smi is a heap number. |
| 3900 | STATIC_ASSERT(kSmiTagMask == 1); |
| 3901 | // 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] | 3902 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3903 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3904 | __ xor_(ebx, eax); |
| 3905 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 3906 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3907 | // if eax was smi, ebx is now edx, else eax. |
| 3908 | |
| 3909 | // Check if the non-smi operand is a heap number. |
| 3910 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3911 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3912 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3913 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3914 | // Return non-equal (ebx is not zero) |
| 3915 | __ mov(eax, ebx); |
| 3916 | __ ret(0); |
| 3917 | |
| 3918 | __ bind(¬_smis); |
| 3919 | // If either operand is a JSObject or an oddball value, then they are not |
| 3920 | // equal since their pointers are different |
| 3921 | // There is no test for undetectability in strict equality. |
| 3922 | |
| 3923 | // Get the type of the first operand. |
| 3924 | // 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] | 3925 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3926 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 3927 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3928 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3929 | |
| 3930 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3931 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3932 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 3933 | __ bind(&return_not_equal); |
| 3934 | __ ret(0); |
| 3935 | |
| 3936 | __ bind(&first_non_object); |
| 3937 | // Check for oddballs: true, false, null, undefined. |
| 3938 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 3939 | __ j(equal, &return_not_equal); |
| 3940 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 3941 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3942 | __ j(above_equal, &return_not_equal); |
| 3943 | |
| 3944 | // Check for oddballs: true, false, null, undefined. |
| 3945 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 3946 | __ j(equal, &return_not_equal); |
| 3947 | |
| 3948 | // Fall through to the general case. |
| 3949 | __ bind(&slow); |
| 3950 | } |
| 3951 | |
| 3952 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3953 | Label non_number_comparison; |
| 3954 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3955 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3956 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 3957 | CpuFeatureScope use_sse2(masm, SSE2); |
| 3958 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3959 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3960 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 3961 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3962 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3963 | // Don't base result on EFLAGS when a NaN is involved. |
| 3964 | __ j(parity_even, &unordered, Label::kNear); |
| 3965 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 3966 | __ mov(eax, 0); // equal |
| 3967 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 3968 | __ cmov(above, eax, ecx); |
| 3969 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 3970 | __ cmov(below, eax, ecx); |
| 3971 | __ ret(0); |
| 3972 | } else { |
| 3973 | FloatingPointHelper::CheckFloatOperands( |
| 3974 | masm, &non_number_comparison, ebx); |
| 3975 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 3976 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 3977 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3978 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3979 | // Don't base result on EFLAGS when a NaN is involved. |
| 3980 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3981 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3982 | Label below_label, above_label; |
| 3983 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 3984 | __ j(below, &below_label, Label::kNear); |
| 3985 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3986 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3987 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3988 | __ ret(0); |
| 3989 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3990 | __ bind(&below_label); |
| 3991 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 3992 | __ ret(0); |
| 3993 | |
| 3994 | __ bind(&above_label); |
| 3995 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 3996 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3997 | } |
| 3998 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3999 | // If one of the numbers was NaN, then the result is always false. |
| 4000 | // The cc is never not-equal. |
| 4001 | __ bind(&unordered); |
| 4002 | ASSERT(cc != not_equal); |
| 4003 | if (cc == less || cc == less_equal) { |
| 4004 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4005 | } else { |
| 4006 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4007 | } |
| 4008 | __ ret(0); |
| 4009 | |
| 4010 | // The number comparison code did not provide a valid result. |
| 4011 | __ bind(&non_number_comparison); |
| 4012 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4013 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4014 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4015 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4016 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 4017 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4018 | |
| 4019 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4020 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4021 | // non-zero value, which indicates not equal, so just return. |
| 4022 | __ ret(0); |
| 4023 | } |
| 4024 | |
| 4025 | __ bind(&check_for_strings); |
| 4026 | |
| 4027 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4028 | &check_unequal_objects); |
| 4029 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4030 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4031 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4032 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4033 | edx, |
| 4034 | eax, |
| 4035 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4036 | ebx); |
| 4037 | } else { |
| 4038 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4039 | edx, |
| 4040 | eax, |
| 4041 | ecx, |
| 4042 | ebx, |
| 4043 | edi); |
| 4044 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4045 | #ifdef DEBUG |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4046 | __ Abort(kUnexpectedFallThroughFromStringComparison); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4047 | #endif |
| 4048 | |
| 4049 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4050 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4051 | // Non-strict equality. Objects are unequal if |
| 4052 | // they are both JSObjects and not undetectable, |
| 4053 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4054 | Label not_both_objects; |
| 4055 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4056 | // At most one is a smi, so we can test for smi by adding the two. |
| 4057 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4058 | // a heap object has the low bit clear. |
| 4059 | STATIC_ASSERT(kSmiTag == 0); |
| 4060 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4061 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4062 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4063 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4064 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4065 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4066 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4067 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4068 | // We do not bail out after this point. Both are JSObjects, and |
| 4069 | // they are equal if and only if both are undetectable. |
| 4070 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4071 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4072 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4073 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4074 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4075 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4076 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4077 | // The objects are both undetectable, so they both compare as the value |
| 4078 | // undefined, and are equal. |
| 4079 | __ Set(eax, Immediate(EQUAL)); |
| 4080 | __ bind(&return_unequal); |
| 4081 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4082 | // or return equal if we fell through to here. |
| 4083 | __ ret(0); // rax, rdx were pushed |
| 4084 | __ bind(¬_both_objects); |
| 4085 | } |
| 4086 | |
| 4087 | // Push arguments below the return address. |
| 4088 | __ pop(ecx); |
| 4089 | __ push(edx); |
| 4090 | __ push(eax); |
| 4091 | |
| 4092 | // Figure out which native to call and setup the arguments. |
| 4093 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4094 | if (cc == equal) { |
| 4095 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4096 | } else { |
| 4097 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4098 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4099 | } |
| 4100 | |
| 4101 | // Restore return address on the stack. |
| 4102 | __ push(ecx); |
| 4103 | |
| 4104 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4105 | // tagged as a small integer. |
| 4106 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4107 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4108 | __ bind(&miss); |
| 4109 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4110 | } |
| 4111 | |
| 4112 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4113 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4114 | // Cache the called function in a global property cell. Cache states |
| 4115 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4116 | // megamorphic. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4117 | // eax : number of arguments to the construct function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4118 | // ebx : cache cell for call target |
| 4119 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4120 | Isolate* isolate = masm->isolate(); |
| 4121 | Label initialize, done, miss, megamorphic, not_array_function; |
| 4122 | |
| 4123 | // Load the cache state into ecx. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4124 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4125 | |
| 4126 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4127 | // function without changing the state. |
| 4128 | __ cmp(ecx, edi); |
| 4129 | __ j(equal, &done); |
| 4130 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4131 | __ j(equal, &done); |
| 4132 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4133 | // If we came here, we need to see if we are the array function. |
| 4134 | // If we didn't have a matching function, and we didn't find the megamorph |
| 4135 | // sentinel, then we have in the cell either some other function or an |
| 4136 | // AllocationSite. Do a map check on the object in ecx. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4137 | Handle<Map> allocation_site_map = |
| 4138 | masm->isolate()->factory()->allocation_site_map(); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4139 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 4140 | __ j(not_equal, &miss); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4141 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4142 | // Load the global or builtins object from the current context |
| 4143 | __ LoadGlobalContext(ecx); |
| 4144 | // Make sure the function is the Array() function |
| 4145 | __ cmp(edi, Operand(ecx, |
| 4146 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4147 | __ j(not_equal, &megamorphic); |
| 4148 | __ jmp(&done); |
| 4149 | |
| 4150 | __ bind(&miss); |
| 4151 | |
| 4152 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4153 | // megamorphic. |
| 4154 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4155 | __ j(equal, &initialize); |
| 4156 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4157 | // write-barrier is needed. |
| 4158 | __ bind(&megamorphic); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4159 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4160 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4161 | __ jmp(&done, Label::kNear); |
| 4162 | |
| 4163 | // An uninitialized cache is patched with the function or sentinel to |
| 4164 | // indicate the ElementsKind if function is the Array constructor. |
| 4165 | __ bind(&initialize); |
| 4166 | __ LoadGlobalContext(ecx); |
| 4167 | // Make sure the function is the Array() function |
| 4168 | __ cmp(edi, Operand(ecx, |
| 4169 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4170 | __ j(not_equal, ¬_array_function); |
| 4171 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4172 | // The target function is the Array constructor, |
| 4173 | // Create an AllocationSite if we don't already have it, store it in the cell |
| 4174 | { |
| 4175 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4176 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4177 | // Arguments register must be smi-tagged to call out. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 4178 | __ SmiTag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4179 | __ push(eax); |
| 4180 | __ push(edi); |
| 4181 | __ push(ebx); |
| 4182 | |
| 4183 | CreateAllocationSiteStub create_stub; |
| 4184 | __ CallStub(&create_stub); |
| 4185 | |
| 4186 | __ pop(ebx); |
| 4187 | __ pop(edi); |
| 4188 | __ pop(eax); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 4189 | __ SmiUntag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4190 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4191 | __ jmp(&done); |
| 4192 | |
| 4193 | __ bind(¬_array_function); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4194 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4195 | // No need for a write barrier here - cells are rescanned. |
| 4196 | |
| 4197 | __ bind(&done); |
| 4198 | } |
| 4199 | |
| 4200 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4201 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4202 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4203 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4204 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4205 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4206 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4207 | // The receiver might implicitly be the global object. This is |
| 4208 | // indicated by passing the hole as the receiver to the call |
| 4209 | // function stub. |
| 4210 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4211 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4212 | // Get the receiver from the stack. |
| 4213 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4214 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4215 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4216 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4217 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4218 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4219 | __ mov(ecx, GlobalObjectOperand()); |
| 4220 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4221 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4222 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4223 | } |
| 4224 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4225 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4226 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4227 | // Goto slow case if we do not have a function. |
| 4228 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4229 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4230 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4231 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4232 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4233 | } |
| 4234 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4235 | // Fast-case: Just invoke the function. |
| 4236 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4237 | |
| 4238 | if (ReceiverMightBeImplicit()) { |
| 4239 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4240 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4241 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4242 | __ InvokeFunction(edi, |
| 4243 | actual, |
| 4244 | JUMP_FUNCTION, |
| 4245 | NullCallWrapper(), |
| 4246 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4247 | __ bind(&call_as_function); |
| 4248 | } |
| 4249 | __ InvokeFunction(edi, |
| 4250 | actual, |
| 4251 | JUMP_FUNCTION, |
| 4252 | NullCallWrapper(), |
| 4253 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4254 | |
| 4255 | // Slow-case: Non-function called. |
| 4256 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4257 | if (RecordCallTarget()) { |
| 4258 | // 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] | 4259 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4260 | // object (undefined) so no write barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4261 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4262 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4263 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4264 | // Check for function proxy. |
| 4265 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4266 | __ j(not_equal, &non_function); |
| 4267 | __ pop(ecx); |
| 4268 | __ push(edi); // put proxy as additional argument under return address |
| 4269 | __ push(ecx); |
| 4270 | __ Set(eax, Immediate(argc_ + 1)); |
| 4271 | __ Set(ebx, Immediate(0)); |
| 4272 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4273 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4274 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4275 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4276 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4277 | } |
| 4278 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4279 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4280 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4281 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4282 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4283 | __ Set(eax, Immediate(argc_)); |
| 4284 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4285 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4286 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4287 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4288 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4289 | } |
| 4290 | |
| 4291 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4292 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4293 | // eax : number of arguments |
| 4294 | // ebx : cache cell for call target |
| 4295 | // edi : constructor function |
| 4296 | Label slow, non_function_call; |
| 4297 | |
| 4298 | // Check that function is not a smi. |
| 4299 | __ JumpIfSmi(edi, &non_function_call); |
| 4300 | // Check that function is a JSFunction. |
| 4301 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4302 | __ j(not_equal, &slow); |
| 4303 | |
| 4304 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4305 | GenerateRecordCallTarget(masm); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4306 | } |
| 4307 | |
| 4308 | // Jump to the function-specific construct stub. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4309 | Register jmp_reg = ecx; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4310 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4311 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 4312 | SharedFunctionInfo::kConstructStubOffset)); |
| 4313 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 4314 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4315 | |
| 4316 | // edi: called object |
| 4317 | // eax: number of arguments |
| 4318 | // ecx: object map |
| 4319 | Label do_call; |
| 4320 | __ bind(&slow); |
| 4321 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4322 | __ j(not_equal, &non_function_call); |
| 4323 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4324 | __ jmp(&do_call); |
| 4325 | |
| 4326 | __ bind(&non_function_call); |
| 4327 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4328 | __ bind(&do_call); |
| 4329 | // Set expected number of arguments to zero (not changing eax). |
| 4330 | __ Set(ebx, Immediate(0)); |
| 4331 | Handle<Code> arguments_adaptor = |
| 4332 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4333 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4334 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4335 | } |
| 4336 | |
| 4337 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4338 | bool CEntryStub::NeedsImmovableCode() { |
| 4339 | return false; |
| 4340 | } |
| 4341 | |
| 4342 | |
dslomov@chromium.org | e97852d | 2013-09-12 09:02:59 +0000 | [diff] [blame] | 4343 | bool CEntryStub::IsPregenerated(Isolate* isolate) { |
| 4344 | return (!save_doubles_ || isolate->fp_stubs_generated()) && |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4345 | result_size_ == 1; |
| 4346 | } |
| 4347 | |
| 4348 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4349 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4350 | CEntryStub::GenerateAheadOfTime(isolate); |
| 4351 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4352 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4353 | // 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] | 4354 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4355 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4356 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4360 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4361 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4362 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4363 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4364 | // which would lead to code stub initialization state being messed up. |
| 4365 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4366 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 4367 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4368 | } |
| 4369 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4370 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4371 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4372 | } |
| 4373 | |
| 4374 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4375 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4376 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4377 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4378 | code->set_is_pregenerated(true); |
| 4379 | } |
| 4380 | |
| 4381 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4382 | static void JumpIfOOM(MacroAssembler* masm, |
| 4383 | Register value, |
| 4384 | Register scratch, |
| 4385 | Label* oom_label) { |
| 4386 | __ mov(scratch, value); |
| 4387 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 4388 | STATIC_ASSERT(kFailureTag == 3); |
| 4389 | __ and_(scratch, 0xf); |
| 4390 | __ cmp(scratch, 0xf); |
| 4391 | __ j(equal, oom_label); |
| 4392 | } |
| 4393 | |
| 4394 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4395 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4396 | Label* throw_normal_exception, |
| 4397 | Label* throw_termination_exception, |
| 4398 | Label* throw_out_of_memory_exception, |
| 4399 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4400 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4401 | // eax: result parameter for PerformGC, if any |
| 4402 | // ebx: pointer to C function (C callee-saved) |
| 4403 | // ebp: frame pointer (restored after C call) |
| 4404 | // esp: stack pointer (restored after C call) |
| 4405 | // edi: number of arguments including receiver (C callee-saved) |
| 4406 | // esi: pointer to the first argument (C callee-saved) |
| 4407 | |
| 4408 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4409 | |
| 4410 | // Check stack alignment. |
| 4411 | if (FLAG_debug_code) { |
| 4412 | __ CheckStackAlignment(); |
| 4413 | } |
| 4414 | |
| 4415 | if (do_gc) { |
| 4416 | // Pass failure code returned from last attempt as first argument to |
| 4417 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4418 | // stack alignment is known to be correct. This function takes one argument |
| 4419 | // which is passed on the stack, and we know that the stack has been |
| 4420 | // prepared to pass at least one argument. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4421 | __ mov(Operand(esp, 1 * kPointerSize), |
| 4422 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4423 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4424 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4425 | } |
| 4426 | |
| 4427 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4428 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4429 | if (always_allocate_scope) { |
| 4430 | __ inc(Operand::StaticVariable(scope_depth)); |
| 4431 | } |
| 4432 | |
| 4433 | // Call C function. |
| 4434 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 4435 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4436 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4437 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4438 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4439 | // Result is in eax or edx:eax - do not destroy these registers! |
| 4440 | |
| 4441 | if (always_allocate_scope) { |
| 4442 | __ dec(Operand::StaticVariable(scope_depth)); |
| 4443 | } |
| 4444 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4445 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 4446 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4447 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4448 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4449 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4450 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4451 | __ int3(); |
| 4452 | __ bind(&okay); |
| 4453 | } |
| 4454 | |
| 4455 | // Check for failure result. |
| 4456 | Label failure_returned; |
| 4457 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4458 | __ lea(ecx, Operand(eax, 1)); |
| 4459 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 4460 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4461 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4462 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4463 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4464 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4465 | |
| 4466 | // Check that there is no pending exception, otherwise we |
| 4467 | // should have returned some failure value. |
| 4468 | if (FLAG_debug_code) { |
| 4469 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4470 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4471 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4472 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 4473 | // 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] | 4474 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4475 | __ int3(); |
| 4476 | __ bind(&okay); |
| 4477 | __ pop(edx); |
| 4478 | } |
| 4479 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4480 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4481 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4482 | __ ret(0); |
| 4483 | |
| 4484 | // Handling of failure. |
| 4485 | __ bind(&failure_returned); |
| 4486 | |
| 4487 | Label retry; |
| 4488 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 4489 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4490 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4491 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4492 | |
| 4493 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4494 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4495 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4496 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4497 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4498 | |
| 4499 | // See if we just retrieved an OOM exception. |
| 4500 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 4501 | |
| 4502 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4503 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4504 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 4505 | |
| 4506 | // Special handling of termination exceptions which are uncatchable |
| 4507 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4508 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4509 | __ j(equal, throw_termination_exception); |
| 4510 | |
| 4511 | // Handle normal exception. |
| 4512 | __ jmp(throw_normal_exception); |
| 4513 | |
| 4514 | // Retry. |
| 4515 | __ bind(&retry); |
| 4516 | } |
| 4517 | |
| 4518 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4519 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4520 | // eax: number of arguments including receiver |
| 4521 | // ebx: pointer to C function (C callee-saved) |
| 4522 | // ebp: frame pointer (restored after C call) |
| 4523 | // esp: stack pointer (restored after C call) |
| 4524 | // esi: current context (C callee-saved) |
| 4525 | // edi: JS function of the caller (C callee-saved) |
| 4526 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4527 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 4528 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4529 | // NOTE: Invocations of builtins may return failure objects instead |
| 4530 | // of a proper result. The builtin entry handles this by performing |
| 4531 | // a garbage collection and retrying the builtin (twice). |
| 4532 | |
| 4533 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4534 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4535 | |
| 4536 | // eax: result parameter for PerformGC, if any (setup below) |
| 4537 | // ebx: pointer to builtin function (C callee-saved) |
| 4538 | // ebp: frame pointer (restored after C call) |
| 4539 | // esp: stack pointer (restored after C call) |
| 4540 | // edi: number of arguments including receiver (C callee-saved) |
| 4541 | // esi: argv pointer (C callee-saved) |
| 4542 | |
| 4543 | Label throw_normal_exception; |
| 4544 | Label throw_termination_exception; |
| 4545 | Label throw_out_of_memory_exception; |
| 4546 | |
| 4547 | // Call into the runtime system. |
| 4548 | GenerateCore(masm, |
| 4549 | &throw_normal_exception, |
| 4550 | &throw_termination_exception, |
| 4551 | &throw_out_of_memory_exception, |
| 4552 | false, |
| 4553 | false); |
| 4554 | |
| 4555 | // Do space-specific GC and retry runtime call. |
| 4556 | GenerateCore(masm, |
| 4557 | &throw_normal_exception, |
| 4558 | &throw_termination_exception, |
| 4559 | &throw_out_of_memory_exception, |
| 4560 | true, |
| 4561 | false); |
| 4562 | |
| 4563 | // Do full GC and retry runtime call one final time. |
| 4564 | Failure* failure = Failure::InternalError(); |
| 4565 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 4566 | GenerateCore(masm, |
| 4567 | &throw_normal_exception, |
| 4568 | &throw_termination_exception, |
| 4569 | &throw_out_of_memory_exception, |
| 4570 | true, |
| 4571 | true); |
| 4572 | |
| 4573 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4574 | // Set external caught exception to false. |
| 4575 | Isolate* isolate = masm->isolate(); |
| 4576 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 4577 | isolate); |
| 4578 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 4579 | |
| 4580 | // Set pending exception and eax to out of memory exception. |
| 4581 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 4582 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4583 | Label already_have_failure; |
| 4584 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 4585 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 4586 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4587 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4588 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4589 | |
| 4590 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4591 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4592 | |
| 4593 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4594 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | |
| 4598 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4599 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4600 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4601 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4602 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 4603 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4604 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4605 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4606 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4607 | |
| 4608 | // Push marker in two places. |
| 4609 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4610 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 4611 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 4612 | // Save callee-saved registers (C calling conventions). |
| 4613 | __ push(edi); |
| 4614 | __ push(esi); |
| 4615 | __ push(ebx); |
| 4616 | |
| 4617 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4618 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4619 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 4620 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4621 | // 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] | 4622 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4623 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4624 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4625 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4626 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4627 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 4628 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4629 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4630 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4631 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4632 | // Jump to a faked try block that does the invoke, with a faked catch |
| 4633 | // block that sets the pending exception. |
| 4634 | __ jmp(&invoke); |
| 4635 | __ bind(&handler_entry); |
| 4636 | handler_offset_ = handler_entry.pos(); |
| 4637 | // Caught exception: Store result (exception) in the pending exception |
| 4638 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4639 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4640 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4641 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4642 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 4643 | __ jmp(&exit); |
| 4644 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4645 | // Invoke: Link this frame into the handler chain. There's only one |
| 4646 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4647 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4648 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4649 | |
| 4650 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4651 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4652 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4653 | |
| 4654 | // Fake a receiver (NULL). |
| 4655 | __ push(Immediate(0)); // receiver |
| 4656 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4657 | // Invoke the function by calling through JS entry trampoline builtin and |
| 4658 | // pop the faked function when we return. Notice that we cannot store a |
| 4659 | // reference to the trampoline code directly in this stub, because the |
| 4660 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4661 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4662 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 4663 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4664 | __ mov(edx, Immediate(construct_entry)); |
| 4665 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4666 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4667 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4668 | __ mov(edx, Immediate(entry)); |
| 4669 | } |
| 4670 | __ mov(edx, Operand(edx, 0)); // deref address |
| 4671 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4672 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4673 | |
| 4674 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4675 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4676 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4677 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4678 | // Check if the current stack frame is marked as the outermost JS frame. |
| 4679 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4680 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4681 | __ j(not_equal, ¬_outermost_js_2); |
| 4682 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 4683 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4684 | |
| 4685 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4686 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4687 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4688 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4689 | |
| 4690 | // Restore callee-saved registers (C calling conventions). |
| 4691 | __ pop(ebx); |
| 4692 | __ pop(esi); |
| 4693 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4694 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4695 | |
| 4696 | // Restore frame pointer and return. |
| 4697 | __ pop(ebp); |
| 4698 | __ ret(0); |
| 4699 | } |
| 4700 | |
| 4701 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4702 | // Generate stub code for instanceof. |
| 4703 | // This code can patch a call site inlined cache of the instance of check, |
| 4704 | // which looks like this. |
| 4705 | // |
| 4706 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 4707 | // 75 0a jne <some near label> |
| 4708 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 4709 | // |
| 4710 | // If call site patching is requested the stack will have the delta from the |
| 4711 | // return address to the cmp instruction just below the return address. This |
| 4712 | // also means that call site patching can only take place with arguments in |
| 4713 | // registers. TOS looks like this when call site patching is requested |
| 4714 | // |
| 4715 | // esp[0] : return address |
| 4716 | // esp[4] : delta from return address to cmp instruction |
| 4717 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4718 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4719 | // Call site inlining and patching implies arguments in registers. |
| 4720 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 4721 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4722 | // Fixed register usage throughout the stub. |
| 4723 | Register object = eax; // Object (lhs). |
| 4724 | Register map = ebx; // Map of the object. |
| 4725 | Register function = edx; // Function (rhs). |
| 4726 | Register prototype = edi; // Prototype of the function. |
| 4727 | Register scratch = ecx; |
| 4728 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4729 | // Constants describing the call site code to patch. |
| 4730 | static const int kDeltaToCmpImmediate = 2; |
| 4731 | static const int kDeltaToMov = 8; |
| 4732 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4733 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 4734 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4735 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 4736 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4737 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 4738 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 4739 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4740 | // Get the object and function - they are always both needed. |
| 4741 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4742 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4743 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 4744 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 4745 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4746 | |
| 4747 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4748 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4749 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4750 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4751 | // If there is a call site cache don't look in the global cache, but do the |
| 4752 | // real lookup and update the call site cache. |
| 4753 | if (!HasCallSiteInlineCheck()) { |
| 4754 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4755 | Label miss; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4756 | __ CompareRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4757 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4758 | __ CompareRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4759 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4760 | __ LoadRoot(eax, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4761 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 4762 | __ bind(&miss); |
| 4763 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4764 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4765 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4766 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4767 | |
| 4768 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4769 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4770 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4771 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4772 | // Update the global instanceof or call site inlined cache with the current |
| 4773 | // map and function. The cached answer will be set when it is known below. |
| 4774 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4775 | __ StoreRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
| 4776 | __ StoreRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4777 | } else { |
| 4778 | // The constants for the code patching are based on no push instructions |
| 4779 | // at the call site. |
| 4780 | ASSERT(HasArgsInRegisters()); |
| 4781 | // Get return address and delta to inlined map check. |
| 4782 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 4783 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 4784 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4785 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4786 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp1); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4787 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4788 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4789 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4790 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 4791 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4792 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4793 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4794 | // Loop through the prototype chain of the object looking for the function |
| 4795 | // prototype. |
| 4796 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4797 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4798 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4799 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4800 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4801 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4802 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4803 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4804 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 4805 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4806 | __ jmp(&loop); |
| 4807 | |
| 4808 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4809 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4810 | __ mov(eax, Immediate(0)); |
| 4811 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4812 | } else { |
| 4813 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4814 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4815 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 4816 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 4817 | if (FLAG_debug_code) { |
| 4818 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4819 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4820 | } |
| 4821 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 4822 | if (!ReturnTrueFalseObject()) { |
| 4823 | __ Set(eax, Immediate(0)); |
| 4824 | } |
| 4825 | } |
| 4826 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4827 | |
| 4828 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4829 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4830 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4831 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4832 | } else { |
| 4833 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4834 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4835 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 4836 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 4837 | if (FLAG_debug_code) { |
| 4838 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4839 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4840 | } |
| 4841 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 4842 | if (!ReturnTrueFalseObject()) { |
| 4843 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 4844 | } |
| 4845 | } |
| 4846 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4847 | |
| 4848 | Label object_not_null, object_not_null_or_smi; |
| 4849 | __ bind(¬_js_object); |
| 4850 | // Before null, smi and string value checks, check that the rhs is a function |
| 4851 | // 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] | 4852 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4853 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4854 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4855 | |
| 4856 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4857 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4858 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4859 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4860 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4861 | |
| 4862 | __ bind(&object_not_null); |
| 4863 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4864 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4865 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4866 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4867 | |
| 4868 | __ bind(&object_not_null_or_smi); |
| 4869 | // String values is not instance of anything. |
| 4870 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4871 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4872 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4873 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4874 | |
| 4875 | // Slow-case: Go through the JavaScript implementation. |
| 4876 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4877 | if (!ReturnTrueFalseObject()) { |
| 4878 | // Tail call the builtin which returns 0 or 1. |
| 4879 | if (HasArgsInRegisters()) { |
| 4880 | // Push arguments below return address. |
| 4881 | __ pop(scratch); |
| 4882 | __ push(object); |
| 4883 | __ push(function); |
| 4884 | __ push(scratch); |
| 4885 | } |
| 4886 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 4887 | } else { |
| 4888 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4889 | { |
| 4890 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4891 | __ push(object); |
| 4892 | __ push(function); |
| 4893 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 4894 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4895 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4896 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4897 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4898 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4899 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4900 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4901 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4902 | __ bind(&done); |
| 4903 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 4904 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4905 | } |
| 4906 | |
| 4907 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4908 | Register InstanceofStub::left() { return eax; } |
| 4909 | |
| 4910 | |
| 4911 | Register InstanceofStub::right() { return edx; } |
| 4912 | |
| 4913 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4914 | // ------------------------------------------------------------------------- |
| 4915 | // StringCharCodeAtGenerator |
| 4916 | |
| 4917 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4918 | // If the receiver is a smi trigger the non-string case. |
| 4919 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4920 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4921 | |
| 4922 | // Fetch the instance type of the receiver into result register. |
| 4923 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 4924 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 4925 | // If the receiver is not a string trigger the non-string case. |
| 4926 | __ test(result_, Immediate(kIsNotStringMask)); |
| 4927 | __ j(not_zero, receiver_not_string_); |
| 4928 | |
| 4929 | // If the index is non-smi trigger the non-smi case. |
| 4930 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4931 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4932 | __ bind(&got_smi_index_); |
| 4933 | |
| 4934 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4935 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4936 | __ j(above_equal, index_out_of_range_); |
| 4937 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4938 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 4939 | |
| 4940 | Factory* factory = masm->isolate()->factory(); |
| 4941 | StringCharLoadGenerator::Generate( |
| 4942 | masm, factory, object_, index_, result_, &call_runtime_); |
| 4943 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4944 | __ SmiTag(result_); |
| 4945 | __ bind(&exit_); |
| 4946 | } |
| 4947 | |
| 4948 | |
| 4949 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4950 | MacroAssembler* masm, |
| 4951 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 4952 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4953 | |
| 4954 | // Index is not a smi. |
| 4955 | __ bind(&index_not_smi_); |
| 4956 | // 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] | 4957 | __ CheckMap(index_, |
| 4958 | masm->isolate()->factory()->heap_number_map(), |
| 4959 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4960 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4961 | call_helper.BeforeCall(masm); |
| 4962 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4963 | __ push(index_); // Consumed by runtime conversion function. |
| 4964 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 4965 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 4966 | } else { |
| 4967 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 4968 | // NumberToSmi discards numbers that are not exact integers. |
| 4969 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 4970 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4971 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4972 | // Save the conversion result before the pop instructions below |
| 4973 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4974 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4975 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4976 | __ pop(object_); |
| 4977 | // Reload the instance type. |
| 4978 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 4979 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 4980 | call_helper.AfterCall(masm); |
| 4981 | // If index is still not a smi, it must be out of range. |
| 4982 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4983 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4984 | // Otherwise, return to the fast path. |
| 4985 | __ jmp(&got_smi_index_); |
| 4986 | |
| 4987 | // Call runtime. We get here when the receiver is a string and the |
| 4988 | // index is a number, but the code of getting the actual character |
| 4989 | // is too complex (e.g., when the string needs to be flattened). |
| 4990 | __ bind(&call_runtime_); |
| 4991 | call_helper.BeforeCall(masm); |
| 4992 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 4993 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4994 | __ push(index_); |
| 4995 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 4996 | if (!result_.is(eax)) { |
| 4997 | __ mov(result_, eax); |
| 4998 | } |
| 4999 | call_helper.AfterCall(masm); |
| 5000 | __ jmp(&exit_); |
| 5001 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5002 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5003 | } |
| 5004 | |
| 5005 | |
| 5006 | // ------------------------------------------------------------------------- |
| 5007 | // StringCharFromCodeGenerator |
| 5008 | |
| 5009 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5010 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5011 | STATIC_ASSERT(kSmiTag == 0); |
| 5012 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5013 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5014 | __ test(code_, |
| 5015 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5016 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5017 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5018 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5019 | Factory* factory = masm->isolate()->factory(); |
| 5020 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5021 | STATIC_ASSERT(kSmiTag == 0); |
| 5022 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5023 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5024 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5025 | __ mov(result_, FieldOperand(result_, |
| 5026 | code_, times_half_pointer_size, |
| 5027 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5028 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5029 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5030 | __ bind(&exit_); |
| 5031 | } |
| 5032 | |
| 5033 | |
| 5034 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5035 | MacroAssembler* masm, |
| 5036 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5037 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5038 | |
| 5039 | __ bind(&slow_case_); |
| 5040 | call_helper.BeforeCall(masm); |
| 5041 | __ push(code_); |
| 5042 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5043 | if (!result_.is(eax)) { |
| 5044 | __ mov(result_, eax); |
| 5045 | } |
| 5046 | call_helper.AfterCall(masm); |
| 5047 | __ jmp(&exit_); |
| 5048 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5049 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5050 | } |
| 5051 | |
| 5052 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5053 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5054 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5055 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5056 | |
| 5057 | // Load the two arguments. |
| 5058 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5059 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5060 | |
| 5061 | // 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] | 5062 | // Otherwise, at least one of the arguments is definitely a string, |
| 5063 | // and we convert the one that is not known to be a string. |
| 5064 | if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) { |
| 5065 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT); |
| 5066 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5067 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5068 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5069 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5070 | |
| 5071 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5072 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5073 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5074 | __ j(above_equal, &call_runtime); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5075 | } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) { |
| 5076 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0); |
| 5077 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5078 | &call_builtin); |
| 5079 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5080 | } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) { |
| 5081 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0); |
| 5082 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5083 | &call_builtin); |
| 5084 | builtin_id = Builtins::STRING_ADD_LEFT; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5085 | } |
| 5086 | |
| 5087 | // Both arguments are strings. |
| 5088 | // eax: first string |
| 5089 | // edx: second string |
| 5090 | // 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] | 5091 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5092 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5093 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5094 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5095 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5096 | // 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] | 5097 | Counters* counters = masm->isolate()->counters(); |
| 5098 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5099 | __ ret(2 * kPointerSize); |
| 5100 | __ bind(&second_not_zero_length); |
| 5101 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5102 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5103 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5104 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5105 | // First string is empty, result is second string which is in edx. |
| 5106 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5107 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5108 | __ ret(2 * kPointerSize); |
| 5109 | |
| 5110 | // Both strings are non-empty. |
| 5111 | // eax: first string |
| 5112 | // ebx: length of first string as a smi |
| 5113 | // ecx: length of second string as a smi |
| 5114 | // edx: second string |
| 5115 | // Look at the length of the result of adding the two strings. |
| 5116 | Label string_add_flat_result, longer_than_two; |
| 5117 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5118 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5119 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5120 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5121 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5122 | // Use the string table when adding two one character strings, as it |
| 5123 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5124 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5125 | __ j(not_equal, &longer_than_two); |
| 5126 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5127 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5128 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5129 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5130 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5131 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5132 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5133 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5134 | // 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] | 5135 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5136 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5137 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5138 | masm, ebx, ecx, eax, edx, edi, |
| 5139 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5140 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5141 | __ ret(2 * kPointerSize); |
| 5142 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5143 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5144 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5145 | // Reload the arguments. |
| 5146 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5147 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5148 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5149 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5150 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5151 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5152 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5153 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5154 | // Pack both characters in ebx. |
| 5155 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5156 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5157 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5158 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5159 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5160 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5161 | |
| 5162 | __ bind(&longer_than_two); |
| 5163 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5164 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5165 | __ j(below, &string_add_flat_result); |
| 5166 | |
| 5167 | // 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] | 5168 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5169 | Label non_ascii, allocated, ascii_data; |
| 5170 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5171 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5172 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5173 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5174 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5175 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5176 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5177 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5178 | __ j(zero, &non_ascii); |
| 5179 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5180 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5181 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5182 | __ bind(&allocated); |
| 5183 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5184 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5185 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5186 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5187 | Immediate(String::kEmptyHashField)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5188 | |
| 5189 | Label skip_write_barrier, after_writing; |
| 5190 | ExternalReference high_promotion_mode = ExternalReference:: |
| 5191 | new_space_high_promotion_mode_active_address(masm->isolate()); |
| 5192 | __ test(Operand::StaticVariable(high_promotion_mode), Immediate(1)); |
| 5193 | __ j(zero, &skip_write_barrier); |
| 5194 | |
| 5195 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5196 | __ RecordWriteField(ecx, |
| 5197 | ConsString::kFirstOffset, |
| 5198 | eax, |
| 5199 | ebx, |
| 5200 | kDontSaveFPRegs); |
| 5201 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5202 | __ RecordWriteField(ecx, |
| 5203 | ConsString::kSecondOffset, |
| 5204 | edx, |
| 5205 | ebx, |
| 5206 | kDontSaveFPRegs); |
| 5207 | __ jmp(&after_writing); |
| 5208 | |
| 5209 | __ bind(&skip_write_barrier); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5210 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5211 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5212 | |
| 5213 | __ bind(&after_writing); |
| 5214 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5215 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5216 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5217 | __ ret(2 * kPointerSize); |
| 5218 | __ bind(&non_ascii); |
| 5219 | // 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] | 5220 | // to contain only one byte characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5221 | // ecx: first instance type AND second instance type. |
| 5222 | // edi: second instance type. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5223 | __ test(ecx, Immediate(kOneByteDataHintMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5224 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5225 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5226 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5227 | __ xor_(edi, ecx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5228 | STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0); |
| 5229 | __ and_(edi, kOneByteStringTag | kOneByteDataHintTag); |
| 5230 | __ cmp(edi, kOneByteStringTag | kOneByteDataHintTag); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5231 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5232 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5233 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5234 | __ jmp(&allocated); |
| 5235 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5236 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5237 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5238 | // Handle creating a flat result from either external or sequential strings. |
| 5239 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5240 | // eax: first string |
| 5241 | // ebx: length of resulting flat string as a smi |
| 5242 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5243 | Label first_prepared, second_prepared; |
| 5244 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5245 | __ bind(&string_add_flat_result); |
| 5246 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5247 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5248 | // ecx: instance type of first string |
| 5249 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5250 | __ test_b(ecx, kStringRepresentationMask); |
| 5251 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5252 | // Rule out short external string and load string resource. |
| 5253 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5254 | __ test_b(ecx, kShortExternalStringMask); |
| 5255 | __ j(not_zero, &call_runtime); |
| 5256 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5257 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5258 | __ jmp(&first_prepared, Label::kNear); |
| 5259 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5260 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5261 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5262 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5263 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5264 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5265 | // Check whether both strings have same encoding. |
| 5266 | // edi: instance type of second string |
| 5267 | __ xor_(ecx, edi); |
| 5268 | __ test_b(ecx, kStringEncodingMask); |
| 5269 | __ j(not_zero, &call_runtime); |
| 5270 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5271 | __ test_b(edi, kStringRepresentationMask); |
| 5272 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5273 | // Rule out short external string and load string resource. |
| 5274 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5275 | __ test_b(edi, kShortExternalStringMask); |
| 5276 | __ j(not_zero, &call_runtime); |
| 5277 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5278 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5279 | __ jmp(&second_prepared, Label::kNear); |
| 5280 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5281 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5282 | __ bind(&second_prepared); |
| 5283 | |
| 5284 | // Push the addresses of both strings' first characters onto the stack. |
| 5285 | __ push(edx); |
| 5286 | __ push(eax); |
| 5287 | |
| 5288 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5289 | // edi: instance type of second string |
| 5290 | // First string and second string have the same encoding. |
| 5291 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5292 | __ test_b(edi, kStringEncodingMask); |
| 5293 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5294 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5295 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5296 | // ebx: length of resulting flat string as a smi |
| 5297 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5298 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5299 | // eax: result string |
| 5300 | __ mov(ecx, eax); |
| 5301 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5302 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5303 | // Load first argument's length and first character location. Account for |
| 5304 | // values currently on the stack when fetching arguments from it. |
| 5305 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5306 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5307 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5308 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5309 | // eax: result string |
| 5310 | // ecx: first character of result |
| 5311 | // edx: first char of first argument |
| 5312 | // edi: length of first argument |
| 5313 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5314 | // Load second argument's length and first character location. Account for |
| 5315 | // values currently on the stack when fetching arguments from it. |
| 5316 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5317 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5318 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5319 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5320 | // eax: result string |
| 5321 | // ecx: next character of result |
| 5322 | // edx: first char of second argument |
| 5323 | // edi: length of second argument |
| 5324 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5325 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5326 | __ ret(2 * kPointerSize); |
| 5327 | |
| 5328 | // Handle creating a flat two byte result. |
| 5329 | // eax: first string - known to be two byte |
| 5330 | // ebx: length of resulting flat string as a smi |
| 5331 | // edx: second string |
| 5332 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5333 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5334 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5335 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5336 | // eax: result string |
| 5337 | __ mov(ecx, eax); |
| 5338 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5339 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5340 | // Load second argument's length and first character location. Account for |
| 5341 | // values currently on the stack when fetching arguments from it. |
| 5342 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5343 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5344 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5345 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5346 | // eax: result string |
| 5347 | // ecx: first character of result |
| 5348 | // edx: first char of first argument |
| 5349 | // edi: length of first argument |
| 5350 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5351 | // Load second argument's length and first character location. Account for |
| 5352 | // values currently on the stack when fetching arguments from it. |
| 5353 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5354 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5355 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5356 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5357 | // eax: result string |
| 5358 | // ecx: next character of result |
| 5359 | // edx: first char of second argument |
| 5360 | // edi: length of second argument |
| 5361 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5362 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5363 | __ ret(2 * kPointerSize); |
| 5364 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5365 | // Recover stack pointer before jumping to runtime. |
| 5366 | __ bind(&call_runtime_drop_two); |
| 5367 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5368 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5369 | __ bind(&call_runtime); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5370 | if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) { |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5371 | GenerateRegisterArgsPop(masm, ecx); |
| 5372 | // Build a frame |
| 5373 | { |
| 5374 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5375 | GenerateRegisterArgsPush(masm); |
| 5376 | __ CallRuntime(Runtime::kStringAdd, 2); |
| 5377 | } |
| 5378 | __ ret(0); |
| 5379 | } else { |
| 5380 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
| 5381 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5382 | |
| 5383 | if (call_builtin.is_linked()) { |
| 5384 | __ bind(&call_builtin); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5385 | if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) { |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5386 | GenerateRegisterArgsPop(masm, ecx); |
| 5387 | // Build a frame |
| 5388 | { |
| 5389 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5390 | GenerateRegisterArgsPush(masm); |
| 5391 | __ InvokeBuiltin(builtin_id, CALL_FUNCTION); |
| 5392 | } |
| 5393 | __ ret(0); |
| 5394 | } else { |
| 5395 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5396 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5397 | } |
| 5398 | } |
| 5399 | |
| 5400 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5401 | void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
| 5402 | __ push(eax); |
| 5403 | __ push(edx); |
| 5404 | } |
| 5405 | |
| 5406 | |
| 5407 | void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm, |
| 5408 | Register temp) { |
| 5409 | __ pop(temp); |
| 5410 | __ pop(edx); |
| 5411 | __ pop(eax); |
| 5412 | __ push(temp); |
| 5413 | } |
| 5414 | |
| 5415 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5416 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5417 | int stack_offset, |
| 5418 | Register arg, |
| 5419 | Register scratch1, |
| 5420 | Register scratch2, |
| 5421 | Register scratch3, |
| 5422 | Label* slow) { |
| 5423 | // First check if the argument is already a string. |
| 5424 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5425 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5426 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5427 | __ j(below, &done); |
| 5428 | |
| 5429 | // Check the number to string cache. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5430 | __ bind(¬_string); |
| 5431 | // Puts the cached result into scratch1. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5432 | __ LookupNumberStringCache(arg, scratch1, scratch2, scratch3, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5433 | __ mov(arg, scratch1); |
| 5434 | __ mov(Operand(esp, stack_offset), arg); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5435 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5436 | } |
| 5437 | |
| 5438 | |
| 5439 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5440 | Register dest, |
| 5441 | Register src, |
| 5442 | Register count, |
| 5443 | Register scratch, |
| 5444 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5445 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5446 | __ bind(&loop); |
| 5447 | // This loop just copies one character at a time, as it is only used for very |
| 5448 | // short strings. |
| 5449 | if (ascii) { |
| 5450 | __ mov_b(scratch, Operand(src, 0)); |
| 5451 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5452 | __ add(src, Immediate(1)); |
| 5453 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5454 | } else { |
| 5455 | __ mov_w(scratch, Operand(src, 0)); |
| 5456 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5457 | __ add(src, Immediate(2)); |
| 5458 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5459 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5460 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5461 | __ j(not_zero, &loop); |
| 5462 | } |
| 5463 | |
| 5464 | |
| 5465 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 5466 | Register dest, |
| 5467 | Register src, |
| 5468 | Register count, |
| 5469 | Register scratch, |
| 5470 | bool ascii) { |
| 5471 | // Copy characters using rep movs of doublewords. |
| 5472 | // The destination is aligned on a 4 byte boundary because we are |
| 5473 | // copying to the beginning of a newly allocated string. |
| 5474 | ASSERT(dest.is(edi)); // rep movs destination |
| 5475 | ASSERT(src.is(esi)); // rep movs source |
| 5476 | ASSERT(count.is(ecx)); // rep movs count |
| 5477 | ASSERT(!scratch.is(dest)); |
| 5478 | ASSERT(!scratch.is(src)); |
| 5479 | ASSERT(!scratch.is(count)); |
| 5480 | |
| 5481 | // Nothing to do for zero characters. |
| 5482 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5483 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5484 | __ j(zero, &done); |
| 5485 | |
| 5486 | // Make count the number of bytes to copy. |
| 5487 | if (!ascii) { |
| 5488 | __ shl(count, 1); |
| 5489 | } |
| 5490 | |
| 5491 | // 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] | 5492 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5493 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5494 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5495 | |
| 5496 | // Copy from edi to esi using rep movs instruction. |
| 5497 | __ mov(scratch, count); |
| 5498 | __ sar(count, 2); // Number of doublewords to copy. |
| 5499 | __ cld(); |
| 5500 | __ rep_movs(); |
| 5501 | |
| 5502 | // Find number of bytes left. |
| 5503 | __ mov(count, scratch); |
| 5504 | __ and_(count, 3); |
| 5505 | |
| 5506 | // Check if there are more bytes to copy. |
| 5507 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5508 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5509 | __ j(zero, &done); |
| 5510 | |
| 5511 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5512 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5513 | __ bind(&loop); |
| 5514 | __ mov_b(scratch, Operand(src, 0)); |
| 5515 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5516 | __ add(src, Immediate(1)); |
| 5517 | __ add(dest, Immediate(1)); |
| 5518 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5519 | __ j(not_zero, &loop); |
| 5520 | |
| 5521 | __ bind(&done); |
| 5522 | } |
| 5523 | |
| 5524 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5525 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5526 | Register c1, |
| 5527 | Register c2, |
| 5528 | Register scratch1, |
| 5529 | Register scratch2, |
| 5530 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5531 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5532 | Label* not_found) { |
| 5533 | // Register scratch3 is the general scratch register in this function. |
| 5534 | Register scratch = scratch3; |
| 5535 | |
| 5536 | // 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] | 5537 | // 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] | 5538 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5539 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5540 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5541 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5542 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5543 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5544 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5545 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5546 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5547 | |
| 5548 | __ bind(¬_array_index); |
| 5549 | // Calculate the two character string hash. |
| 5550 | Register hash = scratch1; |
| 5551 | GenerateHashInit(masm, hash, c1, scratch); |
| 5552 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 5553 | GenerateHashGetHash(masm, hash, scratch); |
| 5554 | |
| 5555 | // Collect the two characters in a register. |
| 5556 | Register chars = c1; |
| 5557 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5558 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5559 | |
| 5560 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5561 | // hash: hash of two character string. |
| 5562 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5563 | // Load the string table. |
| 5564 | Register string_table = c2; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5565 | __ LoadRoot(string_table, Heap::kStringTableRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5566 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5567 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5568 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5569 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5570 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5571 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5572 | |
| 5573 | // Registers |
| 5574 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5575 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5576 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5577 | // mask: capacity mask |
| 5578 | // scratch: - |
| 5579 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5580 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5581 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5582 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5583 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5584 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5585 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5586 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5587 | __ mov(scratch, hash); |
| 5588 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5589 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5590 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5591 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5592 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5593 | // Load the entry from the string table. |
| 5594 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5595 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5596 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5597 | scratch, |
| 5598 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5599 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5600 | |
| 5601 | // 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] | 5602 | Factory* factory = masm->isolate()->factory(); |
| 5603 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5604 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5605 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5606 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5607 | |
| 5608 | // If length is not 2 the string is not a candidate. |
| 5609 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 5610 | Immediate(Smi::FromInt(2))); |
| 5611 | __ j(not_equal, &next_probe[i]); |
| 5612 | |
| 5613 | // As we are out of registers save the mask on the stack and use that |
| 5614 | // register as a temporary. |
| 5615 | __ push(mask); |
| 5616 | Register temp = mask; |
| 5617 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5618 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5619 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 5620 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 5621 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 5622 | temp, temp, &next_probe_pop_mask[i]); |
| 5623 | |
| 5624 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5625 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5626 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5627 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5628 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5629 | __ bind(&next_probe_pop_mask[i]); |
| 5630 | __ pop(mask); |
| 5631 | __ bind(&next_probe[i]); |
| 5632 | } |
| 5633 | |
| 5634 | // No matching 2 character string found by probing. |
| 5635 | __ jmp(not_found); |
| 5636 | |
| 5637 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5638 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5639 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5640 | __ pop(mask); // Pop saved mask from the stack. |
| 5641 | if (!result.is(eax)) { |
| 5642 | __ mov(eax, result); |
| 5643 | } |
| 5644 | } |
| 5645 | |
| 5646 | |
| 5647 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 5648 | Register hash, |
| 5649 | Register character, |
| 5650 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5651 | // hash = (seed + character) + ((seed + character) << 10); |
| 5652 | if (Serializer::enabled()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5653 | __ LoadRoot(scratch, Heap::kHashSeedRootIndex); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5654 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5655 | __ add(scratch, character); |
| 5656 | __ mov(hash, scratch); |
| 5657 | __ shl(scratch, 10); |
| 5658 | __ add(hash, scratch); |
| 5659 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5660 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5661 | __ lea(scratch, Operand(character, seed)); |
| 5662 | __ shl(scratch, 10); |
| 5663 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 5664 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5665 | // hash ^= hash >> 6; |
| 5666 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5667 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5668 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5669 | } |
| 5670 | |
| 5671 | |
| 5672 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 5673 | Register hash, |
| 5674 | Register character, |
| 5675 | Register scratch) { |
| 5676 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5677 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5678 | // hash += hash << 10; |
| 5679 | __ mov(scratch, hash); |
| 5680 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5681 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5682 | // hash ^= hash >> 6; |
| 5683 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5684 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5685 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5686 | } |
| 5687 | |
| 5688 | |
| 5689 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 5690 | Register hash, |
| 5691 | Register scratch) { |
| 5692 | // hash += hash << 3; |
| 5693 | __ mov(scratch, hash); |
| 5694 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5695 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5696 | // hash ^= hash >> 11; |
| 5697 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5698 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5699 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5700 | // hash += hash << 15; |
| 5701 | __ mov(scratch, hash); |
| 5702 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5703 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5704 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5705 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5706 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5707 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5708 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5709 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5710 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5711 | __ bind(&hash_not_zero); |
| 5712 | } |
| 5713 | |
| 5714 | |
| 5715 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 5716 | Label runtime; |
| 5717 | |
| 5718 | // Stack frame on entry. |
| 5719 | // esp[0]: return address |
| 5720 | // esp[4]: to |
| 5721 | // esp[8]: from |
| 5722 | // esp[12]: string |
| 5723 | |
| 5724 | // Make sure first argument is a string. |
| 5725 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 5726 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5727 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5728 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 5729 | __ j(NegateCondition(is_string), &runtime); |
| 5730 | |
| 5731 | // eax: string |
| 5732 | // ebx: instance type |
| 5733 | |
| 5734 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5735 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5736 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5737 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5738 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5739 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5740 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5741 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 5742 | // Shorter than original string's length: an actual substring. |
| 5743 | __ j(below, ¬_original_string, Label::kNear); |
| 5744 | // Longer than original string's length or negative: unsafe arguments. |
| 5745 | __ j(above, &runtime); |
| 5746 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5747 | Counters* counters = masm->isolate()->counters(); |
| 5748 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 5749 | __ ret(3 * kPointerSize); |
| 5750 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5751 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 5752 | Label single_char; |
| 5753 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 5754 | __ j(equal, &single_char); |
| 5755 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5756 | // eax: string |
| 5757 | // ebx: instance type |
| 5758 | // ecx: sub string length (smi) |
| 5759 | // edx: from index (smi) |
| 5760 | // Deal with different string types: update the index if necessary |
| 5761 | // and put the underlying string into edi. |
| 5762 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 5763 | // If the string is not indirect, it can only be sequential or external. |
| 5764 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 5765 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 5766 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 5767 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 5768 | |
| 5769 | Factory* factory = masm->isolate()->factory(); |
| 5770 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 5771 | __ j(not_zero, &sliced_string, Label::kNear); |
| 5772 | // Cons string. Check whether it is flat, then fetch first part. |
| 5773 | // Flat cons strings have an empty second part. |
| 5774 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 5775 | factory->empty_string()); |
| 5776 | __ j(not_equal, &runtime); |
| 5777 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 5778 | // Update instance type. |
| 5779 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 5780 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 5781 | __ jmp(&underlying_unpacked, Label::kNear); |
| 5782 | |
| 5783 | __ bind(&sliced_string); |
| 5784 | // Sliced string. Fetch parent and adjust start index by offset. |
| 5785 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 5786 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 5787 | // Update instance type. |
| 5788 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 5789 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 5790 | __ jmp(&underlying_unpacked, Label::kNear); |
| 5791 | |
| 5792 | __ bind(&seq_or_external_string); |
| 5793 | // Sequential or external string. Just move string to the expected register. |
| 5794 | __ mov(edi, eax); |
| 5795 | |
| 5796 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5797 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5798 | if (FLAG_string_slices) { |
| 5799 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5800 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5801 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5802 | // edx: adjusted start index (smi) |
| 5803 | // ecx: length (smi) |
| 5804 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 5805 | // Short slice. Copy instead of slicing. |
| 5806 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5807 | // Allocate new sliced string. At this point we do not reload the instance |
| 5808 | // type including the string encoding because we simply rely on the info |
| 5809 | // provided by the original string. It does not matter if the original |
| 5810 | // string's encoding is wrong because we always have to recheck encoding of |
| 5811 | // the newly created string's parent anyways due to externalized strings. |
| 5812 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5813 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5814 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5815 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5816 | __ j(zero, &two_byte_slice, Label::kNear); |
| 5817 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 5818 | __ jmp(&set_slice_header, Label::kNear); |
| 5819 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5820 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5821 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5822 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5823 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 5824 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 5825 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 5826 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5827 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 5828 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5829 | |
| 5830 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 5831 | } |
| 5832 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5833 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5834 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5835 | // edx: adjusted start index (smi) |
| 5836 | // ecx: length (smi) |
| 5837 | // The subject string can only be external or sequential string of either |
| 5838 | // encoding at this point. |
| 5839 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 5840 | STATIC_ASSERT(kExternalStringTag != 0); |
| 5841 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5842 | __ test_b(ebx, kExternalStringTag); |
| 5843 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5844 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5845 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5846 | // Rule out short external strings. |
| 5847 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 5848 | __ test_b(ebx, kShortExternalStringMask); |
| 5849 | __ j(not_zero, &runtime); |
| 5850 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 5851 | // 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] | 5852 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5853 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5854 | |
| 5855 | __ bind(&sequential_string); |
| 5856 | // Stash away (adjusted) index and (underlying) string. |
| 5857 | __ push(edx); |
| 5858 | __ push(edi); |
| 5859 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5860 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5861 | __ test_b(ebx, kStringEncodingMask); |
| 5862 | __ j(zero, &two_byte_sequential); |
| 5863 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5864 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5865 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5866 | |
| 5867 | // eax: result string |
| 5868 | // ecx: result string length |
| 5869 | __ mov(edx, esi); // esi used by following code. |
| 5870 | // Locate first character of result. |
| 5871 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5872 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5873 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5874 | __ pop(esi); |
| 5875 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5876 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5877 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5878 | |
| 5879 | // eax: result string |
| 5880 | // ecx: result length |
| 5881 | // edx: original value of esi |
| 5882 | // edi: first character of result |
| 5883 | // esi: character of sub string start |
| 5884 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 5885 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5886 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5887 | __ ret(3 * kPointerSize); |
| 5888 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5889 | __ bind(&two_byte_sequential); |
| 5890 | // Sequential two-byte string. Allocate the result. |
| 5891 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5892 | |
| 5893 | // eax: result string |
| 5894 | // ecx: result string length |
| 5895 | __ mov(edx, esi); // esi used by following code. |
| 5896 | // Locate first character of result. |
| 5897 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5898 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5899 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5900 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5901 | __ pop(esi); |
| 5902 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5903 | // As from is a smi it is 2 times the value which matches the size of a two |
| 5904 | // byte character. |
| 5905 | STATIC_ASSERT(kSmiTag == 0); |
| 5906 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5907 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5908 | |
| 5909 | // eax: result string |
| 5910 | // ecx: result length |
| 5911 | // edx: original value of esi |
| 5912 | // edi: first character of result |
| 5913 | // esi: character of sub string start |
| 5914 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 5915 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5916 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5917 | __ ret(3 * kPointerSize); |
| 5918 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 5919 | // Drop pushed values on the stack before tail call. |
| 5920 | __ bind(&runtime_drop_two); |
| 5921 | __ Drop(2); |
| 5922 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5923 | // Just jump to runtime to create the sub string. |
| 5924 | __ bind(&runtime); |
| 5925 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 5926 | |
| 5927 | __ bind(&single_char); |
| 5928 | // eax: string |
| 5929 | // ebx: instance type |
| 5930 | // ecx: sub string length (smi) |
| 5931 | // edx: from index (smi) |
| 5932 | StringCharAtGenerator generator( |
| 5933 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 5934 | generator.GenerateFast(masm); |
| 5935 | __ ret(3 * kPointerSize); |
| 5936 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5937 | } |
| 5938 | |
| 5939 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5940 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 5941 | Register left, |
| 5942 | Register right, |
| 5943 | Register scratch1, |
| 5944 | Register scratch2) { |
| 5945 | Register length = scratch1; |
| 5946 | |
| 5947 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5948 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5949 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 5950 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5951 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5952 | __ bind(&strings_not_equal); |
| 5953 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 5954 | __ ret(0); |
| 5955 | |
| 5956 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5957 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5958 | __ bind(&check_zero_length); |
| 5959 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5960 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5961 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5962 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 5963 | __ ret(0); |
| 5964 | |
| 5965 | // Compare characters. |
| 5966 | __ bind(&compare_chars); |
| 5967 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5968 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5969 | |
| 5970 | // Characters are equal. |
| 5971 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 5972 | __ ret(0); |
| 5973 | } |
| 5974 | |
| 5975 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5976 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 5977 | Register left, |
| 5978 | Register right, |
| 5979 | Register scratch1, |
| 5980 | Register scratch2, |
| 5981 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5982 | Counters* counters = masm->isolate()->counters(); |
| 5983 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5984 | |
| 5985 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5986 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5987 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 5988 | __ mov(scratch3, scratch1); |
| 5989 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 5990 | |
| 5991 | Register length_delta = scratch3; |
| 5992 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5993 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5994 | // 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] | 5995 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5996 | __ bind(&left_shorter); |
| 5997 | |
| 5998 | Register min_length = scratch1; |
| 5999 | |
| 6000 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6001 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6002 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6003 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6004 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6005 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6006 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6007 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6008 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6009 | |
| 6010 | // Compare lengths - strings up to min-length are equal. |
| 6011 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6012 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6013 | Label length_not_equal; |
| 6014 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6015 | |
| 6016 | // Result is EQUAL. |
| 6017 | STATIC_ASSERT(EQUAL == 0); |
| 6018 | STATIC_ASSERT(kSmiTag == 0); |
| 6019 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6020 | __ ret(0); |
| 6021 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6022 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6023 | Label result_less; |
| 6024 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6025 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6026 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6027 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6028 | __ j(above, &result_greater, Label::kNear); |
| 6029 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6030 | |
| 6031 | // Result is LESS. |
| 6032 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6033 | __ ret(0); |
| 6034 | |
| 6035 | // Result is GREATER. |
| 6036 | __ bind(&result_greater); |
| 6037 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6038 | __ ret(0); |
| 6039 | } |
| 6040 | |
| 6041 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6042 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6043 | MacroAssembler* masm, |
| 6044 | Register left, |
| 6045 | Register right, |
| 6046 | Register length, |
| 6047 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6048 | Label* chars_not_equal, |
| 6049 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6050 | // Change index to run from -length to -1 by adding length to string |
| 6051 | // start. This means that loop ends when index reaches zero, which |
| 6052 | // doesn't need an additional compare. |
| 6053 | __ SmiUntag(length); |
| 6054 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6055 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6056 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6057 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6058 | __ neg(length); |
| 6059 | Register index = length; // index = -length; |
| 6060 | |
| 6061 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6062 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6063 | __ bind(&loop); |
| 6064 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6065 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6066 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6067 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6068 | __ j(not_zero, &loop); |
| 6069 | } |
| 6070 | |
| 6071 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6072 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6073 | Label runtime; |
| 6074 | |
| 6075 | // Stack frame on entry. |
| 6076 | // esp[0]: return address |
| 6077 | // esp[4]: right string |
| 6078 | // esp[8]: left string |
| 6079 | |
| 6080 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6081 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6082 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6083 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6084 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6085 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6086 | STATIC_ASSERT(EQUAL == 0); |
| 6087 | STATIC_ASSERT(kSmiTag == 0); |
| 6088 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6089 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6090 | __ ret(2 * kPointerSize); |
| 6091 | |
| 6092 | __ bind(¬_same); |
| 6093 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6094 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6095 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6096 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6097 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6098 | // Drop arguments from the stack. |
| 6099 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6100 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6101 | __ push(ecx); |
| 6102 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6103 | |
| 6104 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6105 | // tagged as a small integer. |
| 6106 | __ bind(&runtime); |
| 6107 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6108 | } |
| 6109 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6110 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6111 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6112 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6113 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6114 | __ mov(ecx, edx); |
| 6115 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6116 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6117 | |
| 6118 | if (GetCondition() == equal) { |
| 6119 | // 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] | 6120 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6121 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6122 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6123 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6124 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6125 | // Correct sign of result in case of overflow. |
| 6126 | __ not_(edx); |
| 6127 | __ bind(&done); |
| 6128 | __ mov(eax, edx); |
| 6129 | } |
| 6130 | __ ret(0); |
| 6131 | |
| 6132 | __ bind(&miss); |
| 6133 | GenerateMiss(masm); |
| 6134 | } |
| 6135 | |
| 6136 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6137 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6138 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6139 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6140 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6141 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6142 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6143 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6144 | if (left_ == CompareIC::SMI) { |
| 6145 | __ JumpIfNotSmi(edx, &miss); |
| 6146 | } |
| 6147 | if (right_ == CompareIC::SMI) { |
| 6148 | __ JumpIfNotSmi(eax, &miss); |
| 6149 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6150 | |
| 6151 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6152 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6153 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6154 | CpuFeatureScope scope1(masm, SSE2); |
| 6155 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6156 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6157 | // Load left and right operand. |
| 6158 | Label done, left, left_smi, right_smi; |
| 6159 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6160 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6161 | masm->isolate()->factory()->heap_number_map()); |
| 6162 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6163 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6164 | __ jmp(&left, Label::kNear); |
| 6165 | __ bind(&right_smi); |
| 6166 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6167 | __ SmiUntag(ecx); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6168 | __ Cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6169 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6170 | __ bind(&left); |
| 6171 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6172 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6173 | masm->isolate()->factory()->heap_number_map()); |
| 6174 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6175 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6176 | __ jmp(&done); |
| 6177 | __ bind(&left_smi); |
| 6178 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6179 | __ SmiUntag(ecx); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 6180 | __ Cvtsi2sd(xmm0, ecx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6181 | |
| 6182 | __ bind(&done); |
| 6183 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6184 | __ ucomisd(xmm0, xmm1); |
| 6185 | |
| 6186 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6187 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6188 | |
| 6189 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6190 | // Performing mov, because xor would destroy the flag register. |
| 6191 | __ mov(eax, 0); // equal |
| 6192 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6193 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6194 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6195 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6196 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6197 | } else { |
| 6198 | __ mov(ecx, edx); |
| 6199 | __ and_(ecx, eax); |
| 6200 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6201 | |
| 6202 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6203 | masm->isolate()->factory()->heap_number_map()); |
| 6204 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6205 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6206 | masm->isolate()->factory()->heap_number_map()); |
| 6207 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6208 | } |
| 6209 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6210 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6211 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6212 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6213 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6214 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6215 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6216 | __ bind(&maybe_undefined1); |
| 6217 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6218 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6219 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6220 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6221 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6222 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6223 | __ jmp(&unordered); |
| 6224 | } |
| 6225 | |
| 6226 | __ bind(&maybe_undefined2); |
| 6227 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6228 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6229 | __ j(equal, &unordered); |
| 6230 | } |
| 6231 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6232 | __ bind(&miss); |
| 6233 | GenerateMiss(masm); |
| 6234 | } |
| 6235 | |
| 6236 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6237 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 6238 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6239 | ASSERT(GetCondition() == equal); |
| 6240 | |
| 6241 | // Registers containing left and right operands respectively. |
| 6242 | Register left = edx; |
| 6243 | Register right = eax; |
| 6244 | Register tmp1 = ecx; |
| 6245 | Register tmp2 = ebx; |
| 6246 | |
| 6247 | // Check that both operands are heap objects. |
| 6248 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6249 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6250 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6251 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6252 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6253 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6254 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6255 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6256 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6257 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6258 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 6259 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 6260 | __ or_(tmp1, tmp2); |
| 6261 | __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 6262 | __ j(not_zero, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6263 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6264 | // Internalized strings are compared by identity. |
| 6265 | Label done; |
| 6266 | __ cmp(left, right); |
| 6267 | // Make sure eax is non-zero. At this point input operands are |
| 6268 | // guaranteed to be non-zero. |
| 6269 | ASSERT(right.is(eax)); |
| 6270 | __ j(not_equal, &done, Label::kNear); |
| 6271 | STATIC_ASSERT(EQUAL == 0); |
| 6272 | STATIC_ASSERT(kSmiTag == 0); |
| 6273 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6274 | __ bind(&done); |
| 6275 | __ ret(0); |
| 6276 | |
| 6277 | __ bind(&miss); |
| 6278 | GenerateMiss(masm); |
| 6279 | } |
| 6280 | |
| 6281 | |
| 6282 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 6283 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 6284 | ASSERT(GetCondition() == equal); |
| 6285 | |
| 6286 | // Registers containing left and right operands respectively. |
| 6287 | Register left = edx; |
| 6288 | Register right = eax; |
| 6289 | Register tmp1 = ecx; |
| 6290 | Register tmp2 = ebx; |
| 6291 | |
| 6292 | // Check that both operands are heap objects. |
| 6293 | Label miss; |
| 6294 | __ mov(tmp1, left); |
| 6295 | STATIC_ASSERT(kSmiTag == 0); |
| 6296 | __ and_(tmp1, right); |
| 6297 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 6298 | |
| 6299 | // Check that both operands are unique names. This leaves the instance |
| 6300 | // types loaded in tmp1 and tmp2. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6301 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6302 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6303 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6304 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6305 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6306 | __ JumpIfNotUniqueName(tmp1, &miss, Label::kNear); |
| 6307 | __ JumpIfNotUniqueName(tmp2, &miss, Label::kNear); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6308 | |
| 6309 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6310 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6311 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6312 | // Make sure eax is non-zero. At this point input operands are |
| 6313 | // guaranteed to be non-zero. |
| 6314 | ASSERT(right.is(eax)); |
| 6315 | __ j(not_equal, &done, Label::kNear); |
| 6316 | STATIC_ASSERT(EQUAL == 0); |
| 6317 | STATIC_ASSERT(kSmiTag == 0); |
| 6318 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6319 | __ bind(&done); |
| 6320 | __ ret(0); |
| 6321 | |
| 6322 | __ bind(&miss); |
| 6323 | GenerateMiss(masm); |
| 6324 | } |
| 6325 | |
| 6326 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6327 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6328 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6329 | Label miss; |
| 6330 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6331 | bool equality = Token::IsEqualityOp(op_); |
| 6332 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6333 | // Registers containing left and right operands respectively. |
| 6334 | Register left = edx; |
| 6335 | Register right = eax; |
| 6336 | Register tmp1 = ecx; |
| 6337 | Register tmp2 = ebx; |
| 6338 | Register tmp3 = edi; |
| 6339 | |
| 6340 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6341 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6342 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6343 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6344 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6345 | |
| 6346 | // Check that both operands are strings. This leaves the instance |
| 6347 | // types loaded in tmp1 and tmp2. |
| 6348 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6349 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6350 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6351 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6352 | __ mov(tmp3, tmp1); |
| 6353 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6354 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6355 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6356 | __ j(not_zero, &miss); |
| 6357 | |
| 6358 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6359 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6360 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6361 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6362 | STATIC_ASSERT(EQUAL == 0); |
| 6363 | STATIC_ASSERT(kSmiTag == 0); |
| 6364 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6365 | __ ret(0); |
| 6366 | |
| 6367 | // Handle not identical strings. |
| 6368 | __ bind(¬_same); |
| 6369 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6370 | // 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] | 6371 | // 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] | 6372 | // non-equality compare, we still need to determine the order. We |
| 6373 | // also know they are both strings. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6374 | if (equality) { |
| 6375 | Label do_compare; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 6376 | STATIC_ASSERT(kInternalizedTag == 0); |
| 6377 | __ or_(tmp1, tmp2); |
| 6378 | __ test(tmp1, Immediate(kIsNotInternalizedMask)); |
| 6379 | __ j(not_zero, &do_compare, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6380 | // Make sure eax is non-zero. At this point input operands are |
| 6381 | // guaranteed to be non-zero. |
| 6382 | ASSERT(right.is(eax)); |
| 6383 | __ ret(0); |
| 6384 | __ bind(&do_compare); |
| 6385 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6386 | |
| 6387 | // Check that both strings are sequential ASCII. |
| 6388 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6389 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6390 | |
| 6391 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6392 | if (equality) { |
| 6393 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6394 | masm, left, right, tmp1, tmp2); |
| 6395 | } else { |
| 6396 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6397 | masm, left, right, tmp1, tmp2, tmp3); |
| 6398 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6399 | |
| 6400 | // Handle more complex cases in runtime. |
| 6401 | __ bind(&runtime); |
| 6402 | __ pop(tmp1); // Return address. |
| 6403 | __ push(left); |
| 6404 | __ push(right); |
| 6405 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6406 | if (equality) { |
| 6407 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6408 | } else { |
| 6409 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6410 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6411 | |
| 6412 | __ bind(&miss); |
| 6413 | GenerateMiss(masm); |
| 6414 | } |
| 6415 | |
| 6416 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6417 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6418 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6419 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6420 | __ mov(ecx, edx); |
| 6421 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6422 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6423 | |
| 6424 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6425 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6426 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6427 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6428 | |
| 6429 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6430 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6431 | __ ret(0); |
| 6432 | |
| 6433 | __ bind(&miss); |
| 6434 | GenerateMiss(masm); |
| 6435 | } |
| 6436 | |
| 6437 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6438 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6439 | Label miss; |
| 6440 | __ mov(ecx, edx); |
| 6441 | __ and_(ecx, eax); |
| 6442 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6443 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6444 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 6445 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 6446 | __ cmp(ecx, known_map_); |
| 6447 | __ j(not_equal, &miss, Label::kNear); |
| 6448 | __ cmp(ebx, known_map_); |
| 6449 | __ j(not_equal, &miss, Label::kNear); |
| 6450 | |
| 6451 | __ sub(eax, edx); |
| 6452 | __ ret(0); |
| 6453 | |
| 6454 | __ bind(&miss); |
| 6455 | GenerateMiss(masm); |
| 6456 | } |
| 6457 | |
| 6458 | |
| 6459 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6460 | { |
| 6461 | // Call the runtime system in a fresh internal frame. |
| 6462 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 6463 | masm->isolate()); |
| 6464 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6465 | __ push(edx); // Preserve edx and eax. |
| 6466 | __ push(eax); |
| 6467 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6468 | __ push(eax); |
| 6469 | __ push(Immediate(Smi::FromInt(op_))); |
| 6470 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6471 | // Compute the entry point of the rewritten stub. |
| 6472 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 6473 | __ pop(eax); |
| 6474 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6475 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6476 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6477 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6478 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6479 | } |
| 6480 | |
| 6481 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6482 | // Helper function used to check that the dictionary doesn't contain |
| 6483 | // the property. This function may return false negatives, so miss_label |
| 6484 | // must always call a backup property check that is complete. |
| 6485 | // 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] | 6486 | // Name must be a unique name and receiver must be a heap object. |
| 6487 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6488 | Label* miss, |
| 6489 | Label* done, |
| 6490 | Register properties, |
| 6491 | Handle<Name> name, |
| 6492 | Register r0) { |
| 6493 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6494 | |
| 6495 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6496 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6497 | // undefined value), it guarantees the hash table doesn't contain the |
| 6498 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6499 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6500 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6501 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6502 | Register index = r0; |
| 6503 | // Capacity is smi 2^n. |
| 6504 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 6505 | __ dec(index); |
| 6506 | __ and_(index, |
| 6507 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6508 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6509 | |
| 6510 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6511 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6512 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6513 | Register entity_name = r0; |
| 6514 | // Having undefined at this place means the name is not contained. |
| 6515 | ASSERT_EQ(kSmiTagSize, 1); |
| 6516 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 6517 | kElementsStartOffset - kHeapObjectTag)); |
| 6518 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 6519 | __ j(equal, done); |
| 6520 | |
| 6521 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6522 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6523 | __ j(equal, miss); |
| 6524 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6525 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6526 | // Check for the hole and skip. |
| 6527 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6528 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6529 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6530 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6531 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6532 | __ JumpIfNotUniqueName(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6533 | miss); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6534 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6535 | } |
| 6536 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6537 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6538 | __ push(Immediate(Handle<Object>(name))); |
| 6539 | __ push(Immediate(name->Hash())); |
| 6540 | __ CallStub(&stub); |
| 6541 | __ test(r0, r0); |
| 6542 | __ j(not_zero, miss); |
| 6543 | __ jmp(done); |
| 6544 | } |
| 6545 | |
| 6546 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6547 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6548 | // |done| label if a property with the given name is found leaving the |
| 6549 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 6550 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6551 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6552 | Label* miss, |
| 6553 | Label* done, |
| 6554 | Register elements, |
| 6555 | Register name, |
| 6556 | Register r0, |
| 6557 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6558 | ASSERT(!elements.is(r0)); |
| 6559 | ASSERT(!elements.is(r1)); |
| 6560 | ASSERT(!name.is(r0)); |
| 6561 | ASSERT(!name.is(r1)); |
| 6562 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6563 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6564 | |
| 6565 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 6566 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 6567 | __ dec(r1); |
| 6568 | |
| 6569 | // Generate an unrolled loop that performs a few probes before |
| 6570 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6571 | // cover ~93% of loads from dictionaries. |
| 6572 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6573 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6574 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 6575 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6576 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6577 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6578 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6579 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6580 | |
| 6581 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6582 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6583 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 6584 | |
| 6585 | // Check if the key is identical to the name. |
| 6586 | __ cmp(name, Operand(elements, |
| 6587 | r0, |
| 6588 | times_4, |
| 6589 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6590 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6591 | } |
| 6592 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6593 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6594 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6595 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 6596 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6597 | __ push(r0); |
| 6598 | __ CallStub(&stub); |
| 6599 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6600 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6601 | __ j(zero, miss); |
| 6602 | __ jmp(done); |
| 6603 | } |
| 6604 | |
| 6605 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6606 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6607 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 6608 | // 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] | 6609 | // Stack frame on entry: |
| 6610 | // esp[0 * kPointerSize]: return address. |
| 6611 | // esp[1 * kPointerSize]: key's hash. |
| 6612 | // esp[2 * kPointerSize]: key. |
| 6613 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6614 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6615 | // result_: used as scratch. |
| 6616 | // index_: will hold an index of entry if lookup is successful. |
| 6617 | // might alias with result_. |
| 6618 | // Returns: |
| 6619 | // result_ is zero if lookup failed, non zero otherwise. |
| 6620 | |
| 6621 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 6622 | |
| 6623 | Register scratch = result_; |
| 6624 | |
| 6625 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 6626 | __ dec(scratch); |
| 6627 | __ SmiUntag(scratch); |
| 6628 | __ push(scratch); |
| 6629 | |
| 6630 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6631 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6632 | // undefined value), it guarantees the hash table doesn't contain the |
| 6633 | // property. It's true even if some slots represent deleted properties |
| 6634 | // (their names are the null value). |
| 6635 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 6636 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6637 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 6638 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6639 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6640 | } |
| 6641 | __ and_(scratch, Operand(esp, 0)); |
| 6642 | |
| 6643 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6644 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6645 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 6646 | |
| 6647 | // Having undefined at this place means the name is not contained. |
| 6648 | ASSERT_EQ(kSmiTagSize, 1); |
| 6649 | __ mov(scratch, Operand(dictionary_, |
| 6650 | index_, |
| 6651 | times_pointer_size, |
| 6652 | kElementsStartOffset - kHeapObjectTag)); |
| 6653 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 6654 | __ j(equal, ¬_in_dictionary); |
| 6655 | |
| 6656 | // Stop if found the property. |
| 6657 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 6658 | __ j(equal, &in_dictionary); |
| 6659 | |
| 6660 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6661 | // 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] | 6662 | // 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] | 6663 | // key we are looking for. |
| 6664 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6665 | // Check if the entry name is not a unique name. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6666 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6667 | __ JumpIfNotUniqueName(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 6668 | &maybe_in_dictionary); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6669 | } |
| 6670 | } |
| 6671 | |
| 6672 | __ bind(&maybe_in_dictionary); |
| 6673 | // If we are doing negative lookup then probing failure should be |
| 6674 | // treated as a lookup success. For positive lookup probing failure |
| 6675 | // should be treated as lookup failure. |
| 6676 | if (mode_ == POSITIVE_LOOKUP) { |
| 6677 | __ mov(result_, Immediate(0)); |
| 6678 | __ Drop(1); |
| 6679 | __ ret(2 * kPointerSize); |
| 6680 | } |
| 6681 | |
| 6682 | __ bind(&in_dictionary); |
| 6683 | __ mov(result_, Immediate(1)); |
| 6684 | __ Drop(1); |
| 6685 | __ ret(2 * kPointerSize); |
| 6686 | |
| 6687 | __ bind(¬_in_dictionary); |
| 6688 | __ mov(result_, Immediate(0)); |
| 6689 | __ Drop(1); |
| 6690 | __ ret(2 * kPointerSize); |
| 6691 | } |
| 6692 | |
| 6693 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6694 | struct AheadOfTimeWriteBarrierStubList { |
| 6695 | Register object, value, address; |
| 6696 | RememberedSetAction action; |
| 6697 | }; |
| 6698 | |
| 6699 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6700 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 6701 | |
| 6702 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6703 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6704 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6705 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6706 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 6707 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6708 | // Used in StoreStubCompiler::CompileStoreField and |
| 6709 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6710 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6711 | // GenerateStoreField calls the stub with two different permutations of |
| 6712 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6713 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6714 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6715 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6716 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6717 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6718 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6719 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 6720 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 6721 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 6722 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6723 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6724 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 6725 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6726 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6727 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 6728 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 6729 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6730 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6731 | // FastNewClosureStub and StringAddStub::Generate |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 6732 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 6733 | // StringAddStub::Generate |
| 6734 | { REG(ecx), REG(eax), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6735 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6736 | { 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] | 6737 | }; |
| 6738 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6739 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6740 | |
dslomov@chromium.org | e97852d | 2013-09-12 09:02:59 +0000 | [diff] [blame] | 6741 | bool RecordWriteStub::IsPregenerated(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6742 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6743 | !entry->object.is(no_reg); |
| 6744 | entry++) { |
| 6745 | if (object_.is(entry->object) && |
| 6746 | value_.is(entry->value) && |
| 6747 | address_.is(entry->address) && |
| 6748 | remembered_set_action_ == entry->action && |
| 6749 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 6750 | return true; |
| 6751 | } |
| 6752 | } |
| 6753 | return false; |
| 6754 | } |
| 6755 | |
| 6756 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6757 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 6758 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6759 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
| 6760 | stub.GetCode(isolate)->set_is_pregenerated(true); |
| 6761 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6762 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6763 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6764 | } |
| 6765 | } |
| 6766 | |
| 6767 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6768 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 6769 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6770 | !entry->object.is(no_reg); |
| 6771 | entry++) { |
| 6772 | RecordWriteStub stub(entry->object, |
| 6773 | entry->value, |
| 6774 | entry->address, |
| 6775 | entry->action, |
| 6776 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6777 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6778 | } |
| 6779 | } |
| 6780 | |
| 6781 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 6782 | bool CodeStub::CanUseFPRegisters() { |
| 6783 | return CpuFeatures::IsSupported(SSE2); |
| 6784 | } |
| 6785 | |
| 6786 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6787 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 6788 | // the value has just been written into the object, now this stub makes sure |
| 6789 | // we keep the GC informed. The word in the object where the value has been |
| 6790 | // written is in the address register. |
| 6791 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 6792 | Label skip_to_incremental_noncompacting; |
| 6793 | Label skip_to_incremental_compacting; |
| 6794 | |
| 6795 | // The first two instructions are generated with labels so as to get the |
| 6796 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 6797 | // forth between a compare instructions (a nop in this position) and the |
| 6798 | // real branch when we start and stop incremental heap marking. |
| 6799 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 6800 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 6801 | |
| 6802 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 6803 | __ RememberedSetHelper(object_, |
| 6804 | address_, |
| 6805 | value_, |
| 6806 | save_fp_regs_mode_, |
| 6807 | MacroAssembler::kReturnAtEnd); |
| 6808 | } else { |
| 6809 | __ ret(0); |
| 6810 | } |
| 6811 | |
| 6812 | __ bind(&skip_to_incremental_noncompacting); |
| 6813 | GenerateIncremental(masm, INCREMENTAL); |
| 6814 | |
| 6815 | __ bind(&skip_to_incremental_compacting); |
| 6816 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 6817 | |
| 6818 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 6819 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 6820 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 6821 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 6822 | } |
| 6823 | |
| 6824 | |
| 6825 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 6826 | regs_.Save(masm); |
| 6827 | |
| 6828 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 6829 | Label dont_need_remembered_set; |
| 6830 | |
| 6831 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 6832 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 6833 | regs_.scratch0(), |
| 6834 | &dont_need_remembered_set); |
| 6835 | |
| 6836 | __ CheckPageFlag(regs_.object(), |
| 6837 | regs_.scratch0(), |
| 6838 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 6839 | not_zero, |
| 6840 | &dont_need_remembered_set); |
| 6841 | |
| 6842 | // First notify the incremental marker if necessary, then update the |
| 6843 | // remembered set. |
| 6844 | CheckNeedsToInformIncrementalMarker( |
| 6845 | masm, |
| 6846 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 6847 | mode); |
| 6848 | InformIncrementalMarker(masm, mode); |
| 6849 | regs_.Restore(masm); |
| 6850 | __ RememberedSetHelper(object_, |
| 6851 | address_, |
| 6852 | value_, |
| 6853 | save_fp_regs_mode_, |
| 6854 | MacroAssembler::kReturnAtEnd); |
| 6855 | |
| 6856 | __ bind(&dont_need_remembered_set); |
| 6857 | } |
| 6858 | |
| 6859 | CheckNeedsToInformIncrementalMarker( |
| 6860 | masm, |
| 6861 | kReturnOnNoNeedToInformIncrementalMarker, |
| 6862 | mode); |
| 6863 | InformIncrementalMarker(masm, mode); |
| 6864 | regs_.Restore(masm); |
| 6865 | __ ret(0); |
| 6866 | } |
| 6867 | |
| 6868 | |
| 6869 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 6870 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 6871 | int argument_count = 3; |
| 6872 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 6873 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 6874 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6875 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 6876 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6877 | |
| 6878 | AllowExternalCallThatCantCauseGC scope(masm); |
| 6879 | if (mode == INCREMENTAL_COMPACTION) { |
| 6880 | __ CallCFunction( |
| 6881 | ExternalReference::incremental_evacuation_record_write_function( |
| 6882 | masm->isolate()), |
| 6883 | argument_count); |
| 6884 | } else { |
| 6885 | ASSERT(mode == INCREMENTAL); |
| 6886 | __ CallCFunction( |
| 6887 | ExternalReference::incremental_marking_record_write_function( |
| 6888 | masm->isolate()), |
| 6889 | argument_count); |
| 6890 | } |
| 6891 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 6892 | } |
| 6893 | |
| 6894 | |
| 6895 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 6896 | MacroAssembler* masm, |
| 6897 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 6898 | Mode mode) { |
| 6899 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 6900 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 6901 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 6902 | __ and_(regs_.scratch0(), regs_.object()); |
| 6903 | __ mov(regs_.scratch1(), |
| 6904 | Operand(regs_.scratch0(), |
| 6905 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 6906 | __ sub(regs_.scratch1(), Immediate(1)); |
| 6907 | __ mov(Operand(regs_.scratch0(), |
| 6908 | MemoryChunk::kWriteBarrierCounterOffset), |
| 6909 | regs_.scratch1()); |
| 6910 | __ j(negative, &need_incremental); |
| 6911 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6912 | // Let's look at the color of the object: If it is not black we don't have |
| 6913 | // to inform the incremental marker. |
| 6914 | __ JumpIfBlack(regs_.object(), |
| 6915 | regs_.scratch0(), |
| 6916 | regs_.scratch1(), |
| 6917 | &object_is_black, |
| 6918 | Label::kNear); |
| 6919 | |
| 6920 | regs_.Restore(masm); |
| 6921 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 6922 | __ RememberedSetHelper(object_, |
| 6923 | address_, |
| 6924 | value_, |
| 6925 | save_fp_regs_mode_, |
| 6926 | MacroAssembler::kReturnAtEnd); |
| 6927 | } else { |
| 6928 | __ ret(0); |
| 6929 | } |
| 6930 | |
| 6931 | __ bind(&object_is_black); |
| 6932 | |
| 6933 | // Get the value from the slot. |
| 6934 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 6935 | |
| 6936 | if (mode == INCREMENTAL_COMPACTION) { |
| 6937 | Label ensure_not_white; |
| 6938 | |
| 6939 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 6940 | regs_.scratch1(), // Scratch. |
| 6941 | MemoryChunk::kEvacuationCandidateMask, |
| 6942 | zero, |
| 6943 | &ensure_not_white, |
| 6944 | Label::kNear); |
| 6945 | |
| 6946 | __ CheckPageFlag(regs_.object(), |
| 6947 | regs_.scratch1(), // Scratch. |
| 6948 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 6949 | not_zero, |
| 6950 | &ensure_not_white, |
| 6951 | Label::kNear); |
| 6952 | |
| 6953 | __ jmp(&need_incremental); |
| 6954 | |
| 6955 | __ bind(&ensure_not_white); |
| 6956 | } |
| 6957 | |
| 6958 | // We need an extra register for this, so we push the object register |
| 6959 | // temporarily. |
| 6960 | __ push(regs_.object()); |
| 6961 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 6962 | regs_.scratch1(), // Scratch. |
| 6963 | regs_.object(), // Scratch. |
| 6964 | &need_incremental_pop_object, |
| 6965 | Label::kNear); |
| 6966 | __ pop(regs_.object()); |
| 6967 | |
| 6968 | regs_.Restore(masm); |
| 6969 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 6970 | __ RememberedSetHelper(object_, |
| 6971 | address_, |
| 6972 | value_, |
| 6973 | save_fp_regs_mode_, |
| 6974 | MacroAssembler::kReturnAtEnd); |
| 6975 | } else { |
| 6976 | __ ret(0); |
| 6977 | } |
| 6978 | |
| 6979 | __ bind(&need_incremental_pop_object); |
| 6980 | __ pop(regs_.object()); |
| 6981 | |
| 6982 | __ bind(&need_incremental); |
| 6983 | |
| 6984 | // Fall through when we need to inform the incremental marker. |
| 6985 | } |
| 6986 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 6987 | |
| 6988 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 6989 | // ----------- S t a t e ------------- |
| 6990 | // -- eax : element value to store |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 6991 | // -- ecx : element index as smi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 6992 | // -- esp[0] : return address |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 6993 | // -- esp[4] : array literal index in function |
| 6994 | // -- esp[8] : array literal |
| 6995 | // clobbers ebx, edx, edi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 6996 | // ----------------------------------- |
| 6997 | |
| 6998 | Label element_done; |
| 6999 | Label double_elements; |
| 7000 | Label smi_element; |
| 7001 | Label slow_elements; |
| 7002 | Label slow_elements_from_double; |
| 7003 | Label fast_elements; |
| 7004 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7005 | // Get array literal index, array literal and its map. |
| 7006 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 7007 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 7008 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 7009 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7010 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7011 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7012 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7013 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7014 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7015 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7016 | // Store into the array literal requires a elements transition. Call into |
| 7017 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7018 | |
| 7019 | __ bind(&slow_elements); |
| 7020 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7021 | // call. |
| 7022 | __ push(ebx); |
| 7023 | __ push(ecx); |
| 7024 | __ push(eax); |
| 7025 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7026 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7027 | __ push(edx); |
| 7028 | __ push(edi); // Return return address so that tail call returns to right |
| 7029 | // place. |
| 7030 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7031 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7032 | __ bind(&slow_elements_from_double); |
| 7033 | __ pop(edx); |
| 7034 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7035 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7036 | // 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] | 7037 | __ bind(&fast_elements); |
| 7038 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7039 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7040 | FixedArrayBase::kHeaderSize)); |
| 7041 | __ mov(Operand(ecx, 0), eax); |
| 7042 | // Update the write barrier for the array store. |
| 7043 | __ RecordWrite(ebx, ecx, eax, |
| 7044 | kDontSaveFPRegs, |
| 7045 | EMIT_REMEMBERED_SET, |
| 7046 | OMIT_SMI_CHECK); |
| 7047 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7048 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7049 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7050 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7051 | __ bind(&smi_element); |
| 7052 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7053 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7054 | FixedArrayBase::kHeaderSize), eax); |
| 7055 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7056 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7057 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7058 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7059 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7060 | __ push(edx); |
| 7061 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7062 | __ StoreNumberToDoubleElements(eax, |
| 7063 | edx, |
| 7064 | ecx, |
| 7065 | edi, |
| 7066 | xmm0, |
| 7067 | &slow_elements_from_double, |
| 7068 | false); |
| 7069 | __ pop(edx); |
| 7070 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7071 | } |
| 7072 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7073 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7074 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7075 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7076 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7077 | int parameter_count_offset = |
| 7078 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7079 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7080 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7081 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7082 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 7083 | ? kPointerSize |
| 7084 | : 0; |
| 7085 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7086 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7087 | } |
| 7088 | |
| 7089 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7090 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7091 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 7092 | // It's always safe to call the entry hook stub, as the hook itself |
| 7093 | // is not allowed to call back to V8. |
| 7094 | AllowStubCallsScope allow_stub_calls(masm, true); |
| 7095 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7096 | ProfileEntryHookStub stub; |
| 7097 | masm->CallStub(&stub); |
| 7098 | } |
| 7099 | } |
| 7100 | |
| 7101 | |
| 7102 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7103 | // Save volatile registers. |
| 7104 | const int kNumSavedRegisters = 3; |
| 7105 | __ push(eax); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7106 | __ push(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7107 | __ push(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7108 | |
| 7109 | // Calculate and push the original stack pointer. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7110 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7111 | __ push(eax); |
| 7112 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7113 | // Retrieve our return address and use it to calculate the calling |
| 7114 | // function's address. |
| 7115 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7116 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7117 | __ push(eax); |
| 7118 | |
| 7119 | // Call the entry hook. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7120 | ASSERT(masm->isolate()->function_entry_hook() != NULL); |
| 7121 | __ call(FUNCTION_ADDR(masm->isolate()->function_entry_hook()), |
| 7122 | RelocInfo::RUNTIME_ENTRY); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7123 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7124 | |
| 7125 | // Restore ecx. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7126 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7127 | __ pop(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7128 | __ pop(eax); |
| 7129 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7130 | __ ret(0); |
| 7131 | } |
| 7132 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7133 | |
| 7134 | template<class T> |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7135 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 7136 | AllocationSiteOverrideMode mode) { |
| 7137 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 7138 | T stub(GetInitialFastElementsKind(), |
| 7139 | CONTEXT_CHECK_REQUIRED, |
| 7140 | mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7141 | __ TailCallStub(&stub); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7142 | } else if (mode == DONT_OVERRIDE) { |
| 7143 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7144 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7145 | for (int i = 0; i <= last_index; ++i) { |
| 7146 | Label next; |
| 7147 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7148 | __ cmp(edx, kind); |
| 7149 | __ j(not_equal, &next); |
| 7150 | T stub(kind); |
| 7151 | __ TailCallStub(&stub); |
| 7152 | __ bind(&next); |
| 7153 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7154 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7155 | // If we reached this point there is a problem. |
| 7156 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 7157 | } else { |
| 7158 | UNREACHABLE(); |
| 7159 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7160 | } |
| 7161 | |
| 7162 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7163 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 7164 | AllocationSiteOverrideMode mode) { |
| 7165 | // ebx - type info cell (if mode != DISABLE_ALLOCATION_SITES) |
| 7166 | // edx - kind (if mode != DISABLE_ALLOCATION_SITES) |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7167 | // eax - number of arguments |
| 7168 | // edi - constructor? |
| 7169 | // esp[0] - return address |
| 7170 | // esp[4] - last argument |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7171 | Label normal_sequence; |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7172 | if (mode == DONT_OVERRIDE) { |
| 7173 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 7174 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 7175 | ASSERT(FAST_ELEMENTS == 2); |
| 7176 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 7177 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 7178 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 7179 | |
| 7180 | // is the low bit set? If so, we are holey and that is good. |
| 7181 | __ test_b(edx, 1); |
| 7182 | __ j(not_zero, &normal_sequence); |
| 7183 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7184 | |
| 7185 | // look at the first argument |
| 7186 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7187 | __ test(ecx, ecx); |
| 7188 | __ j(zero, &normal_sequence); |
| 7189 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7190 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 7191 | ElementsKind initial = GetInitialFastElementsKind(); |
| 7192 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7193 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7194 | ArraySingleArgumentConstructorStub stub_holey(holey_initial, |
| 7195 | CONTEXT_CHECK_REQUIRED, |
| 7196 | DISABLE_ALLOCATION_SITES); |
| 7197 | __ TailCallStub(&stub_holey); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7198 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7199 | __ bind(&normal_sequence); |
| 7200 | ArraySingleArgumentConstructorStub stub(initial, |
| 7201 | CONTEXT_CHECK_REQUIRED, |
| 7202 | DISABLE_ALLOCATION_SITES); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7203 | __ TailCallStub(&stub); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7204 | } else if (mode == DONT_OVERRIDE) { |
| 7205 | // We are going to create a holey array, but our kind is non-holey. |
| 7206 | // Fix kind and retry. |
| 7207 | __ inc(edx); |
| 7208 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
| 7209 | if (FLAG_debug_code) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 7210 | Handle<Map> allocation_site_map = |
| 7211 | masm->isolate()->factory()->allocation_site_map(); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7212 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 7213 | __ Assert(equal, kExpectedAllocationSiteInCell); |
| 7214 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7215 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7216 | // Save the resulting elements kind in type info |
| 7217 | __ SmiTag(edx); |
| 7218 | __ mov(FieldOperand(ecx, AllocationSite::kTransitionInfoOffset), edx); |
| 7219 | __ SmiUntag(edx); |
| 7220 | |
| 7221 | __ bind(&normal_sequence); |
| 7222 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7223 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7224 | for (int i = 0; i <= last_index; ++i) { |
| 7225 | Label next; |
| 7226 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7227 | __ cmp(edx, kind); |
| 7228 | __ j(not_equal, &next); |
| 7229 | ArraySingleArgumentConstructorStub stub(kind); |
| 7230 | __ TailCallStub(&stub); |
| 7231 | __ bind(&next); |
| 7232 | } |
| 7233 | |
| 7234 | // If we reached this point there is a problem. |
| 7235 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 7236 | } else { |
| 7237 | UNREACHABLE(); |
| 7238 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7239 | } |
| 7240 | |
| 7241 | |
| 7242 | template<class T> |
| 7243 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7244 | ElementsKind initial_kind = GetInitialFastElementsKind(); |
| 7245 | ElementsKind initial_holey_kind = GetHoleyElementsKind(initial_kind); |
| 7246 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7247 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 7248 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7249 | for (int i = 0; i <= to_index; ++i) { |
| 7250 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7251 | T stub(kind); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7252 | stub.GetCode(isolate)->set_is_pregenerated(true); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7253 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE || |
| 7254 | (!FLAG_track_allocation_sites && |
| 7255 | (kind == initial_kind || kind == initial_holey_kind))) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7256 | T stub1(kind, CONTEXT_CHECK_REQUIRED, DISABLE_ALLOCATION_SITES); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7257 | stub1.GetCode(isolate)->set_is_pregenerated(true); |
| 7258 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7259 | } |
| 7260 | } |
| 7261 | |
| 7262 | |
| 7263 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 7264 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 7265 | isolate); |
| 7266 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 7267 | isolate); |
| 7268 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 7269 | isolate); |
| 7270 | } |
| 7271 | |
| 7272 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7273 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 7274 | Isolate* isolate) { |
| 7275 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 7276 | for (int i = 0; i < 2; i++) { |
| 7277 | // For internal arrays we only need a few things |
| 7278 | InternalArrayNoArgumentConstructorStub stubh1(kinds[i]); |
| 7279 | stubh1.GetCode(isolate)->set_is_pregenerated(true); |
| 7280 | InternalArraySingleArgumentConstructorStub stubh2(kinds[i]); |
| 7281 | stubh2.GetCode(isolate)->set_is_pregenerated(true); |
| 7282 | InternalArrayNArgumentsConstructorStub stubh3(kinds[i]); |
| 7283 | stubh3.GetCode(isolate)->set_is_pregenerated(true); |
| 7284 | } |
| 7285 | } |
| 7286 | |
| 7287 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7288 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 7289 | MacroAssembler* masm, |
| 7290 | AllocationSiteOverrideMode mode) { |
| 7291 | if (argument_count_ == ANY) { |
| 7292 | Label not_zero_case, not_one_case; |
| 7293 | __ test(eax, eax); |
| 7294 | __ j(not_zero, ¬_zero_case); |
| 7295 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 7296 | |
| 7297 | __ bind(¬_zero_case); |
| 7298 | __ cmp(eax, 1); |
| 7299 | __ j(greater, ¬_one_case); |
| 7300 | CreateArrayDispatchOneArgument(masm, mode); |
| 7301 | |
| 7302 | __ bind(¬_one_case); |
| 7303 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 7304 | } else if (argument_count_ == NONE) { |
| 7305 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 7306 | } else if (argument_count_ == ONE) { |
| 7307 | CreateArrayDispatchOneArgument(masm, mode); |
| 7308 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 7309 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 7310 | } else { |
| 7311 | UNREACHABLE(); |
| 7312 | } |
| 7313 | } |
| 7314 | |
| 7315 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7316 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7317 | // ----------- S t a t e ------------- |
| 7318 | // -- eax : argc (only if argument_count_ == ANY) |
| 7319 | // -- ebx : type info cell |
| 7320 | // -- edi : constructor |
| 7321 | // -- esp[0] : return address |
| 7322 | // -- esp[4] : last argument |
| 7323 | // ----------------------------------- |
| 7324 | Handle<Object> undefined_sentinel( |
| 7325 | masm->isolate()->heap()->undefined_value(), |
| 7326 | masm->isolate()); |
| 7327 | |
| 7328 | if (FLAG_debug_code) { |
| 7329 | // The array construct code is only set for the global and natives |
| 7330 | // builtin Array functions which always have maps. |
| 7331 | |
| 7332 | // Initial map for the builtin Array function should be a map. |
| 7333 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7334 | // Will both indicate a NULL and a Smi. |
| 7335 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7336 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7337 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7338 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7339 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7340 | // We should either have undefined in ebx or a valid cell |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7341 | Label okay_here; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7342 | Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7343 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7344 | __ j(equal, &okay_here); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7345 | __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7346 | __ Assert(equal, kExpectedPropertyCellInRegisterEbx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7347 | __ bind(&okay_here); |
| 7348 | } |
| 7349 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7350 | Label no_info; |
| 7351 | // If the type cell is undefined, or contains anything other than an |
| 7352 | // AllocationSite, call an array constructor that doesn't use AllocationSites. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7353 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7354 | __ j(equal, &no_info); |
| 7355 | __ mov(edx, FieldOperand(ebx, Cell::kValueOffset)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 7356 | __ cmp(FieldOperand(edx, 0), Immediate( |
| 7357 | masm->isolate()->factory()->allocation_site_map())); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7358 | __ j(not_equal, &no_info); |
| 7359 | |
| 7360 | __ mov(edx, FieldOperand(edx, AllocationSite::kTransitionInfoOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7361 | __ SmiUntag(edx); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7362 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 7363 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7364 | __ bind(&no_info); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 7365 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7366 | } |
| 7367 | |
| 7368 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7369 | void InternalArrayConstructorStub::GenerateCase( |
| 7370 | MacroAssembler* masm, ElementsKind kind) { |
| 7371 | Label not_zero_case, not_one_case; |
| 7372 | Label normal_sequence; |
| 7373 | |
| 7374 | __ test(eax, eax); |
| 7375 | __ j(not_zero, ¬_zero_case); |
| 7376 | InternalArrayNoArgumentConstructorStub stub0(kind); |
| 7377 | __ TailCallStub(&stub0); |
| 7378 | |
| 7379 | __ bind(¬_zero_case); |
| 7380 | __ cmp(eax, 1); |
| 7381 | __ j(greater, ¬_one_case); |
| 7382 | |
| 7383 | if (IsFastPackedElementsKind(kind)) { |
| 7384 | // We might need to create a holey array |
| 7385 | // look at the first argument |
| 7386 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7387 | __ test(ecx, ecx); |
| 7388 | __ j(zero, &normal_sequence); |
| 7389 | |
| 7390 | InternalArraySingleArgumentConstructorStub |
| 7391 | stub1_holey(GetHoleyElementsKind(kind)); |
| 7392 | __ TailCallStub(&stub1_holey); |
| 7393 | } |
| 7394 | |
| 7395 | __ bind(&normal_sequence); |
| 7396 | InternalArraySingleArgumentConstructorStub stub1(kind); |
| 7397 | __ TailCallStub(&stub1); |
| 7398 | |
| 7399 | __ bind(¬_one_case); |
| 7400 | InternalArrayNArgumentsConstructorStub stubN(kind); |
| 7401 | __ TailCallStub(&stubN); |
| 7402 | } |
| 7403 | |
| 7404 | |
| 7405 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7406 | // ----------- S t a t e ------------- |
| 7407 | // -- eax : argc |
| 7408 | // -- ebx : type info cell |
| 7409 | // -- edi : constructor |
| 7410 | // -- esp[0] : return address |
| 7411 | // -- esp[4] : last argument |
| 7412 | // ----------------------------------- |
| 7413 | |
| 7414 | if (FLAG_debug_code) { |
| 7415 | // The array construct code is only set for the global and natives |
| 7416 | // builtin Array functions which always have maps. |
| 7417 | |
| 7418 | // Initial map for the builtin Array function should be a map. |
| 7419 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7420 | // Will both indicate a NULL and a Smi. |
| 7421 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7422 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7423 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7424 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7425 | } |
| 7426 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7427 | // Figure out the right elements kind |
| 7428 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7429 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7430 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 7431 | // but the following masking takes care of that anyway. |
| 7432 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 7433 | // Retrieve elements_kind from bit field 2. |
| 7434 | __ and_(ecx, Map::kElementsKindMask); |
| 7435 | __ shr(ecx, Map::kElementsKindShift); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7436 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7437 | if (FLAG_debug_code) { |
| 7438 | Label done; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7439 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7440 | __ j(equal, &done); |
| 7441 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 7442 | __ Assert(equal, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 7443 | kInvalidElementsKindForInternalArrayOrInternalPackedArray); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7444 | __ bind(&done); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7445 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7446 | |
| 7447 | Label fast_elements_case; |
| 7448 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 7449 | __ j(equal, &fast_elements_case); |
| 7450 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 7451 | |
| 7452 | __ bind(&fast_elements_case); |
| 7453 | GenerateCase(masm, FAST_ELEMENTS); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7454 | } |
| 7455 | |
| 7456 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7457 | #undef __ |
| 7458 | |
| 7459 | } } // namespace v8::internal |
| 7460 | |
| 7461 | #endif // V8_TARGET_ARCH_IA32 |