yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 30 | #if V8_TARGET_ARCH_IA32 |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 31 | |
| 32 | #include "bootstrapper.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 33 | #include "code-stubs.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 34 | #include "isolate.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 35 | #include "jsregexp.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 36 | #include "regexp-macro-assembler.h" |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 37 | #include "runtime.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 38 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 39 | #include "codegen.h" |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 40 | #include "runtime.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 41 | |
| 42 | namespace v8 { |
| 43 | namespace internal { |
| 44 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 45 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame^] | 46 | void ToNumberStub::InitializeInterfaceDescriptor( |
| 47 | Isolate* isolate, |
| 48 | CodeStubInterfaceDescriptor* descriptor) { |
| 49 | static Register registers[] = { eax }; |
| 50 | descriptor->register_param_count_ = 1; |
| 51 | descriptor->register_params_ = registers; |
| 52 | descriptor->deoptimization_handler_ = NULL; |
| 53 | } |
| 54 | |
| 55 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 56 | void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( |
| 57 | Isolate* isolate, |
| 58 | CodeStubInterfaceDescriptor* descriptor) { |
| 59 | static Register registers[] = { eax, ebx, ecx }; |
| 60 | descriptor->register_param_count_ = 3; |
| 61 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 62 | descriptor->deoptimization_handler_ = |
| 63 | Runtime::FunctionForId(Runtime::kCreateArrayLiteralShallow)->entry; |
| 64 | } |
| 65 | |
| 66 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 67 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 68 | Isolate* isolate, |
| 69 | CodeStubInterfaceDescriptor* descriptor) { |
| 70 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 71 | descriptor->register_param_count_ = 4; |
| 72 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 73 | descriptor->deoptimization_handler_ = |
| 74 | Runtime::FunctionForId(Runtime::kCreateObjectLiteralShallow)->entry; |
| 75 | } |
| 76 | |
| 77 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 78 | void CreateAllocationSiteStub::InitializeInterfaceDescriptor( |
| 79 | Isolate* isolate, |
| 80 | CodeStubInterfaceDescriptor* descriptor) { |
| 81 | static Register registers[] = { ebx }; |
| 82 | descriptor->register_param_count_ = 1; |
| 83 | descriptor->register_params_ = registers; |
| 84 | descriptor->deoptimization_handler_ = NULL; |
| 85 | } |
| 86 | |
| 87 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 88 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 89 | Isolate* isolate, |
| 90 | CodeStubInterfaceDescriptor* descriptor) { |
| 91 | static Register registers[] = { edx, ecx }; |
| 92 | descriptor->register_param_count_ = 2; |
| 93 | descriptor->register_params_ = registers; |
| 94 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 95 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 99 | void LoadFieldStub::InitializeInterfaceDescriptor( |
| 100 | Isolate* isolate, |
| 101 | CodeStubInterfaceDescriptor* descriptor) { |
| 102 | static Register registers[] = { edx }; |
| 103 | descriptor->register_param_count_ = 1; |
| 104 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 105 | descriptor->deoptimization_handler_ = NULL; |
| 106 | } |
| 107 | |
| 108 | |
| 109 | void KeyedLoadFieldStub::InitializeInterfaceDescriptor( |
| 110 | Isolate* isolate, |
| 111 | CodeStubInterfaceDescriptor* descriptor) { |
| 112 | static Register registers[] = { edx }; |
| 113 | descriptor->register_param_count_ = 1; |
| 114 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 115 | descriptor->deoptimization_handler_ = NULL; |
| 116 | } |
| 117 | |
| 118 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 119 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 120 | Isolate* isolate, |
| 121 | CodeStubInterfaceDescriptor* descriptor) { |
| 122 | static Register registers[] = { edx, ecx, eax }; |
| 123 | descriptor->register_param_count_ = 3; |
| 124 | descriptor->register_params_ = registers; |
| 125 | descriptor->deoptimization_handler_ = |
| 126 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 127 | } |
| 128 | |
| 129 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 130 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 131 | Isolate* isolate, |
| 132 | CodeStubInterfaceDescriptor* descriptor) { |
| 133 | static Register registers[] = { eax, ebx }; |
| 134 | descriptor->register_param_count_ = 2; |
| 135 | descriptor->register_params_ = registers; |
| 136 | descriptor->deoptimization_handler_ = |
| 137 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 138 | } |
| 139 | |
| 140 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 141 | static void InitializeArrayConstructorDescriptor( |
| 142 | Isolate* isolate, |
| 143 | CodeStubInterfaceDescriptor* descriptor, |
| 144 | int constant_stack_parameter_count) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 145 | // register state |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 146 | // eax -- number of arguments |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 147 | // edi -- function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 148 | // ebx -- type info cell with elements kind |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 149 | static Register registers[] = { edi, ebx }; |
| 150 | descriptor->register_param_count_ = 2; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 151 | |
| 152 | if (constant_stack_parameter_count != 0) { |
| 153 | // stack param count needs (constructor pointer, and single argument) |
| 154 | descriptor->stack_parameter_count_ = &eax; |
| 155 | } |
| 156 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 157 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 158 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 159 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 160 | Runtime::FunctionForId(Runtime::kArrayConstructor)->entry; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 164 | static void InitializeInternalArrayConstructorDescriptor( |
| 165 | Isolate* isolate, |
| 166 | CodeStubInterfaceDescriptor* descriptor, |
| 167 | int constant_stack_parameter_count) { |
| 168 | // register state |
| 169 | // eax -- number of arguments |
| 170 | // edi -- constructor function |
| 171 | static Register registers[] = { edi }; |
| 172 | descriptor->register_param_count_ = 1; |
| 173 | |
| 174 | if (constant_stack_parameter_count != 0) { |
| 175 | // stack param count needs (constructor pointer, and single argument) |
| 176 | descriptor->stack_parameter_count_ = &eax; |
| 177 | } |
| 178 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
| 179 | descriptor->register_params_ = registers; |
| 180 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
| 181 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 182 | Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 186 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 187 | Isolate* isolate, |
| 188 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 189 | InitializeArrayConstructorDescriptor(isolate, descriptor, 0); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | |
| 193 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 194 | Isolate* isolate, |
| 195 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 196 | InitializeArrayConstructorDescriptor(isolate, descriptor, 1); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | |
| 200 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 201 | Isolate* isolate, |
| 202 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 203 | InitializeArrayConstructorDescriptor(isolate, descriptor, -1); |
| 204 | } |
| 205 | |
| 206 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 207 | void InternalArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 208 | Isolate* isolate, |
| 209 | CodeStubInterfaceDescriptor* descriptor) { |
| 210 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 0); |
| 211 | } |
| 212 | |
| 213 | |
| 214 | void InternalArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 215 | Isolate* isolate, |
| 216 | CodeStubInterfaceDescriptor* descriptor) { |
| 217 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 1); |
| 218 | } |
| 219 | |
| 220 | |
| 221 | void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 222 | Isolate* isolate, |
| 223 | CodeStubInterfaceDescriptor* descriptor) { |
| 224 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, -1); |
| 225 | } |
| 226 | |
| 227 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 228 | void CompareNilICStub::InitializeInterfaceDescriptor( |
| 229 | Isolate* isolate, |
| 230 | CodeStubInterfaceDescriptor* descriptor) { |
| 231 | static Register registers[] = { eax }; |
| 232 | descriptor->register_param_count_ = 1; |
| 233 | descriptor->register_params_ = registers; |
| 234 | descriptor->deoptimization_handler_ = |
| 235 | FUNCTION_ADDR(CompareNilIC_Miss); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 236 | descriptor->SetMissHandler( |
| 237 | ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 238 | } |
| 239 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 240 | void ToBooleanStub::InitializeInterfaceDescriptor( |
| 241 | Isolate* isolate, |
| 242 | CodeStubInterfaceDescriptor* descriptor) { |
| 243 | static Register registers[] = { eax }; |
| 244 | descriptor->register_param_count_ = 1; |
| 245 | descriptor->register_params_ = registers; |
| 246 | descriptor->deoptimization_handler_ = |
| 247 | FUNCTION_ADDR(ToBooleanIC_Miss); |
| 248 | descriptor->SetMissHandler( |
| 249 | ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate)); |
| 250 | } |
| 251 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 252 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 253 | void UnaryOpStub::InitializeInterfaceDescriptor( |
| 254 | Isolate* isolate, |
| 255 | CodeStubInterfaceDescriptor* descriptor) { |
| 256 | static Register registers[] = { eax }; |
| 257 | descriptor->register_param_count_ = 1; |
| 258 | descriptor->register_params_ = registers; |
| 259 | descriptor->deoptimization_handler_ = |
| 260 | FUNCTION_ADDR(UnaryOpIC_Miss); |
| 261 | } |
| 262 | |
| 263 | |
| 264 | void StoreGlobalStub::InitializeInterfaceDescriptor( |
| 265 | Isolate* isolate, |
| 266 | CodeStubInterfaceDescriptor* descriptor) { |
| 267 | static Register registers[] = { edx, ecx, eax }; |
| 268 | descriptor->register_param_count_ = 3; |
| 269 | descriptor->register_params_ = registers; |
| 270 | descriptor->deoptimization_handler_ = |
| 271 | FUNCTION_ADDR(StoreIC_MissFromStubFailure); |
| 272 | } |
| 273 | |
| 274 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 275 | void ElementsTransitionAndStoreStub::InitializeInterfaceDescriptor( |
| 276 | Isolate* isolate, |
| 277 | CodeStubInterfaceDescriptor* descriptor) { |
| 278 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 279 | descriptor->register_param_count_ = 4; |
| 280 | descriptor->register_params_ = registers; |
| 281 | descriptor->deoptimization_handler_ = |
| 282 | FUNCTION_ADDR(ElementsTransitionAndStoreIC_Miss); |
| 283 | } |
| 284 | |
| 285 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 286 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 287 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 288 | |
| 289 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
| 290 | // Update the static counter each time a new code stub is generated. |
| 291 | Isolate* isolate = masm->isolate(); |
| 292 | isolate->counters()->code_stubs()->Increment(); |
| 293 | |
| 294 | CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
| 295 | int param_count = descriptor->register_param_count_; |
| 296 | { |
| 297 | // Call the runtime system in a fresh internal frame. |
| 298 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 299 | ASSERT(descriptor->register_param_count_ == 0 || |
| 300 | eax.is(descriptor->register_params_[param_count - 1])); |
| 301 | // Push arguments |
| 302 | for (int i = 0; i < param_count; ++i) { |
| 303 | __ push(descriptor->register_params_[i]); |
| 304 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 305 | ExternalReference miss = descriptor->miss_handler(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 306 | __ CallExternalReference(miss, descriptor->register_param_count_); |
| 307 | } |
| 308 | |
| 309 | __ ret(0); |
| 310 | } |
| 311 | |
| 312 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 313 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 314 | // Create a new closure from the given function info in new |
| 315 | // space. Set the context to the current context in esi. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 316 | Counters* counters = masm->isolate()->counters(); |
| 317 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 318 | Label gc; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 319 | __ Allocate(JSFunction::kSize, eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 320 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 321 | __ IncrementCounter(counters->fast_new_closure_total(), 1); |
| 322 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 323 | // Get the function info from the stack. |
| 324 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 325 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 326 | int map_index = Context::FunctionMapIndex(language_mode_, is_generator_); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 327 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 328 | // Compute the function map in the current native context and set that |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 329 | // as the map of the allocated object. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 330 | __ mov(ecx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 331 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 332 | __ mov(ebx, Operand(ecx, Context::SlotOffset(map_index))); |
| 333 | __ mov(FieldOperand(eax, JSObject::kMapOffset), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 334 | |
| 335 | // Initialize the rest of the function. We don't have to update the |
| 336 | // write barrier because the allocated object is in new space. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 337 | Factory* factory = masm->isolate()->factory(); |
| 338 | __ mov(ebx, Immediate(factory->empty_fixed_array())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 339 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ebx); |
| 340 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 341 | __ mov(FieldOperand(eax, JSFunction::kPrototypeOrInitialMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 342 | Immediate(factory->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 343 | __ mov(FieldOperand(eax, JSFunction::kSharedFunctionInfoOffset), edx); |
| 344 | __ mov(FieldOperand(eax, JSFunction::kContextOffset), esi); |
| 345 | __ mov(FieldOperand(eax, JSFunction::kLiteralsOffset), ebx); |
| 346 | |
| 347 | // Initialize the code pointer in the function to be the one |
| 348 | // found in the shared function info object. |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 349 | // But first check if there is an optimized version for our context. |
| 350 | Label check_optimized; |
| 351 | Label install_unoptimized; |
| 352 | if (FLAG_cache_optimized_code) { |
| 353 | __ mov(ebx, FieldOperand(edx, SharedFunctionInfo::kOptimizedCodeMapOffset)); |
| 354 | __ test(ebx, ebx); |
| 355 | __ j(not_zero, &check_optimized, Label::kNear); |
| 356 | } |
| 357 | __ bind(&install_unoptimized); |
| 358 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), |
| 359 | Immediate(factory->undefined_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 360 | __ mov(edx, FieldOperand(edx, SharedFunctionInfo::kCodeOffset)); |
| 361 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 362 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 363 | |
| 364 | // Return and remove the on-stack parameter. |
| 365 | __ ret(1 * kPointerSize); |
| 366 | |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 367 | __ bind(&check_optimized); |
| 368 | |
| 369 | __ IncrementCounter(counters->fast_new_closure_try_optimized(), 1); |
| 370 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 371 | // ecx holds native context, ebx points to fixed array of 3-element entries |
| 372 | // (native context, optimized code, literals). |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 373 | // Map must never be empty, so check the first elements. |
| 374 | Label install_optimized; |
| 375 | // Speculatively move code object into edx. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 376 | __ mov(edx, FieldOperand(ebx, SharedFunctionInfo::kFirstCodeSlot)); |
| 377 | __ cmp(ecx, FieldOperand(ebx, SharedFunctionInfo::kFirstContextSlot)); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 378 | __ j(equal, &install_optimized); |
| 379 | |
| 380 | // Iterate through the rest of map backwards. edx holds an index as a Smi. |
| 381 | Label loop; |
| 382 | Label restore; |
| 383 | __ mov(edx, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 384 | __ bind(&loop); |
| 385 | // Do not double check first entry. |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 386 | __ cmp(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kSecondEntryIndex))); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 387 | __ j(equal, &restore); |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 388 | __ sub(edx, Immediate(Smi::FromInt(SharedFunctionInfo::kEntryLength))); |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 389 | __ cmp(ecx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 0)); |
| 390 | __ j(not_equal, &loop, Label::kNear); |
| 391 | // Hit: fetch the optimized code. |
| 392 | __ mov(edx, CodeGenerator::FixedArrayElementOperand(ebx, edx, 1)); |
| 393 | |
| 394 | __ bind(&install_optimized); |
| 395 | __ IncrementCounter(counters->fast_new_closure_install_optimized(), 1); |
| 396 | |
| 397 | // TODO(fschneider): Idea: store proper code pointers in the optimized code |
| 398 | // map and either unmangle them on marking or do nothing as the whole map is |
| 399 | // discarded on major GC anyway. |
| 400 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
| 401 | __ mov(FieldOperand(eax, JSFunction::kCodeEntryOffset), edx); |
| 402 | |
| 403 | // Now link a function into a list of optimized functions. |
| 404 | __ mov(edx, ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST)); |
| 405 | |
| 406 | __ mov(FieldOperand(eax, JSFunction::kNextFunctionLinkOffset), edx); |
| 407 | // No need for write barrier as JSFunction (eax) is in the new space. |
| 408 | |
| 409 | __ mov(ContextOperand(ecx, Context::OPTIMIZED_FUNCTIONS_LIST), eax); |
| 410 | // Store JSFunction (eax) into edx before issuing write barrier as |
| 411 | // it clobbers all the registers passed. |
| 412 | __ mov(edx, eax); |
| 413 | __ RecordWriteContextSlot( |
| 414 | ecx, |
| 415 | Context::SlotOffset(Context::OPTIMIZED_FUNCTIONS_LIST), |
| 416 | edx, |
| 417 | ebx, |
| 418 | kDontSaveFPRegs); |
| 419 | |
| 420 | // Return and remove the on-stack parameter. |
| 421 | __ ret(1 * kPointerSize); |
| 422 | |
| 423 | __ bind(&restore); |
| 424 | // Restore SharedFunctionInfo into edx. |
| 425 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 426 | __ jmp(&install_unoptimized); |
| 427 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 428 | // Create a new closure through the slower runtime call. |
| 429 | __ bind(&gc); |
| 430 | __ pop(ecx); // Temporarily remove return address. |
| 431 | __ pop(edx); |
| 432 | __ push(esi); |
| 433 | __ push(edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 434 | __ push(Immediate(factory->false_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 435 | __ push(ecx); // Restore return address. |
vegorov@chromium.org | 21b5e95 | 2010-11-23 10:24:40 +0000 | [diff] [blame] | 436 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | |
| 440 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 441 | // Try to allocate the context in new space. |
| 442 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 443 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 444 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 445 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 446 | |
| 447 | // Get the function from the stack. |
| 448 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 449 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 450 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 451 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 452 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 453 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 454 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 455 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 456 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 457 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 458 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 459 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 460 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 461 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 462 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 463 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 464 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 465 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 466 | |
| 467 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 468 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 469 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 470 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 471 | } |
| 472 | |
| 473 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 474 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 475 | __ ret(1 * kPointerSize); |
| 476 | |
| 477 | // Need to collect. Call into runtime system. |
| 478 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 479 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 483 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 484 | // Stack layout on entry: |
| 485 | // |
| 486 | // [esp + (1 * kPointerSize)]: function |
| 487 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 488 | |
| 489 | // Try to allocate the context in new space. |
| 490 | Label gc; |
| 491 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 492 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 493 | |
| 494 | // Get the function or sentinel from the stack. |
| 495 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 496 | |
| 497 | // Get the serialized scope info from the stack. |
| 498 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 499 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 500 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 501 | Factory* factory = masm->isolate()->factory(); |
| 502 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 503 | factory->block_context_map()); |
| 504 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 505 | Immediate(Smi::FromInt(length))); |
| 506 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 507 | // If this block context is nested in the native context we get a smi |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 508 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 509 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 510 | // we still have to look up. |
| 511 | Label after_sentinel; |
| 512 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 513 | if (FLAG_debug_code) { |
| 514 | const char* message = "Expected 0 as a Smi sentinel"; |
| 515 | __ cmp(ecx, 0); |
| 516 | __ Assert(equal, message); |
| 517 | } |
| 518 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 519 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 520 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 521 | __ bind(&after_sentinel); |
| 522 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 523 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 524 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 525 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 526 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 527 | |
| 528 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 529 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 530 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 531 | |
| 532 | // Initialize the rest of the slots to the hole value. |
| 533 | if (slots_ == 1) { |
| 534 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 535 | factory->the_hole_value()); |
| 536 | } else { |
| 537 | __ mov(ebx, factory->the_hole_value()); |
| 538 | for (int i = 0; i < slots_; i++) { |
| 539 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | // Return and remove the on-stack parameters. |
| 544 | __ mov(esi, eax); |
| 545 | __ ret(2 * kPointerSize); |
| 546 | |
| 547 | // Need to collect. Call into runtime system. |
| 548 | __ bind(&gc); |
| 549 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 550 | } |
| 551 | |
| 552 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 553 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 554 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 555 | // store the registers in any particular way, but we do have to store and |
| 556 | // restore them. |
| 557 | __ pushad(); |
| 558 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 559 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 560 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 561 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 562 | XMMRegister reg = XMMRegister::from_code(i); |
| 563 | __ movdbl(Operand(esp, i * kDoubleSize), reg); |
| 564 | } |
| 565 | } |
| 566 | const int argument_count = 1; |
| 567 | |
| 568 | AllowExternalCallThatCantCauseGC scope(masm); |
| 569 | __ PrepareCallCFunction(argument_count, ecx); |
| 570 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 571 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 572 | __ CallCFunction( |
| 573 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 574 | argument_count); |
| 575 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 576 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 577 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 578 | XMMRegister reg = XMMRegister::from_code(i); |
| 579 | __ movdbl(reg, Operand(esp, i * kDoubleSize)); |
| 580 | } |
| 581 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 582 | } |
| 583 | __ popad(); |
| 584 | __ ret(0); |
| 585 | } |
| 586 | |
| 587 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 588 | class FloatingPointHelper : public AllStatic { |
| 589 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 590 | enum ArgLocation { |
| 591 | ARGS_ON_STACK, |
| 592 | ARGS_IN_REGISTERS |
| 593 | }; |
| 594 | |
| 595 | // Code pattern for loading a floating point value. Input value must |
| 596 | // be either a smi or a heap number object (fp value). Requirements: |
| 597 | // operand in register number. Returns operand as floating point number |
| 598 | // on FPU stack. |
| 599 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 600 | |
| 601 | // Code pattern for loading floating point values. Input values must |
| 602 | // be either smi or heap number objects (fp values). Requirements: |
| 603 | // operand_1 on TOS+1 or in edx, operand_2 on TOS+2 or in eax. |
| 604 | // Returns operands as floating point numbers on FPU stack. |
| 605 | static void LoadFloatOperands(MacroAssembler* masm, |
| 606 | Register scratch, |
| 607 | ArgLocation arg_location = ARGS_ON_STACK); |
| 608 | |
| 609 | // Similar to LoadFloatOperand but assumes that both operands are smis. |
| 610 | // Expects operands in edx, eax. |
| 611 | static void LoadFloatSmis(MacroAssembler* masm, Register scratch); |
| 612 | |
| 613 | // Test if operands are smi or number objects (fp). Requirements: |
| 614 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 615 | // operands, jumps to the non_float label otherwise. |
| 616 | static void CheckFloatOperands(MacroAssembler* masm, |
| 617 | Label* non_float, |
| 618 | Register scratch); |
| 619 | |
| 620 | // Takes the operands in edx and eax and loads them as integers in eax |
| 621 | // and ecx. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 622 | static void LoadUnknownsAsIntegers(MacroAssembler* masm, |
| 623 | bool use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 624 | BinaryOpIC::TypeInfo left_type, |
| 625 | BinaryOpIC::TypeInfo right_type, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 626 | Label* operand_conversion_failure); |
| 627 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 628 | // Assumes that operands are smis or heap numbers and loads them |
| 629 | // into xmm0 and xmm1. Operands are in edx and eax. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 630 | // Leaves operands unchanged. |
| 631 | static void LoadSSE2Operands(MacroAssembler* masm); |
| 632 | |
| 633 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 634 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 635 | // either operand is not a number. Operands are in edx and eax. |
| 636 | // Leaves operands unchanged. |
| 637 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
| 638 | |
| 639 | // Similar to LoadSSE2Operands but assumes that both operands are smis. |
| 640 | // Expects operands in edx, eax. |
| 641 | static void LoadSSE2Smis(MacroAssembler* masm, Register scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 642 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 643 | // Checks that |operand| has an int32 value. If |int32_result| is different |
| 644 | // from |scratch|, it will contain that int32 value. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 645 | static void CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 646 | Label* non_int32, |
| 647 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 648 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 649 | Register scratch, |
| 650 | XMMRegister xmm_scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 651 | }; |
| 652 | |
| 653 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 654 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 655 | Register input_reg = this->source(); |
| 656 | Register final_result_reg = this->destination(); |
| 657 | ASSERT(is_truncating()); |
| 658 | |
| 659 | Label check_negative, process_64_bits, done, done_no_stash; |
| 660 | |
| 661 | int double_offset = offset(); |
| 662 | |
| 663 | // Account for return address and saved regs if input is esp. |
| 664 | if (input_reg.is(esp)) double_offset += 3 * kPointerSize; |
| 665 | |
| 666 | MemOperand mantissa_operand(MemOperand(input_reg, double_offset)); |
| 667 | MemOperand exponent_operand(MemOperand(input_reg, |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 668 | double_offset + kDoubleSize / 2)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 669 | |
| 670 | Register scratch1; |
| 671 | { |
| 672 | Register scratch_candidates[3] = { ebx, edx, edi }; |
| 673 | for (int i = 0; i < 3; i++) { |
| 674 | scratch1 = scratch_candidates[i]; |
| 675 | if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break; |
| 676 | } |
| 677 | } |
| 678 | // Since we must use ecx for shifts below, use some other register (eax) |
| 679 | // to calculate the result if ecx is the requested return register. |
| 680 | Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg; |
| 681 | // Save ecx if it isn't the return register and therefore volatile, or if it |
| 682 | // is the return register, then save the temp register we use in its stead for |
| 683 | // the result. |
| 684 | Register save_reg = final_result_reg.is(ecx) ? eax : ecx; |
| 685 | __ push(scratch1); |
| 686 | __ push(save_reg); |
| 687 | |
| 688 | bool stash_exponent_copy = !input_reg.is(esp); |
| 689 | __ mov(scratch1, mantissa_operand); |
| 690 | if (CpuFeatures::IsSupported(SSE3)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 691 | CpuFeatureScope scope(masm, SSE3); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 692 | // Load x87 register with heap number. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 693 | __ fld_d(mantissa_operand); |
| 694 | } |
| 695 | __ mov(ecx, exponent_operand); |
| 696 | if (stash_exponent_copy) __ push(ecx); |
| 697 | |
| 698 | __ and_(ecx, HeapNumber::kExponentMask); |
| 699 | __ shr(ecx, HeapNumber::kExponentShift); |
| 700 | __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias)); |
| 701 | __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits)); |
| 702 | __ j(below, &process_64_bits); |
| 703 | |
| 704 | // Result is entirely in lower 32-bits of mantissa |
| 705 | int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize; |
| 706 | if (CpuFeatures::IsSupported(SSE3)) { |
| 707 | __ fstp(0); |
| 708 | } |
| 709 | __ sub(ecx, Immediate(delta)); |
| 710 | __ xor_(result_reg, result_reg); |
| 711 | __ cmp(ecx, Immediate(31)); |
| 712 | __ j(above, &done); |
| 713 | __ shl_cl(scratch1); |
| 714 | __ jmp(&check_negative); |
| 715 | |
| 716 | __ bind(&process_64_bits); |
| 717 | if (CpuFeatures::IsSupported(SSE3)) { |
| 718 | CpuFeatureScope scope(masm, SSE3); |
| 719 | if (stash_exponent_copy) { |
| 720 | // Already a copy of the exponent on the stack, overwrite it. |
| 721 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 722 | __ sub(esp, Immediate(kDoubleSize / 2)); |
| 723 | } else { |
| 724 | // Reserve space for 64 bit answer. |
| 725 | __ sub(esp, Immediate(kDoubleSize)); // Nolint. |
| 726 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 727 | // Do conversion, which cannot fail because we checked the exponent. |
| 728 | __ fisttp_d(Operand(esp, 0)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 729 | __ mov(result_reg, Operand(esp, 0)); // Load low word of answer as result |
| 730 | __ add(esp, Immediate(kDoubleSize)); |
| 731 | __ jmp(&done_no_stash); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 732 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 733 | // Result must be extracted from shifted 32-bit mantissa |
| 734 | __ sub(ecx, Immediate(delta)); |
| 735 | __ neg(ecx); |
| 736 | if (stash_exponent_copy) { |
| 737 | __ mov(result_reg, MemOperand(esp, 0)); |
| 738 | } else { |
| 739 | __ mov(result_reg, exponent_operand); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 740 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 741 | __ and_(result_reg, |
| 742 | Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32))); |
| 743 | __ add(result_reg, |
| 744 | Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32))); |
| 745 | __ shrd(result_reg, scratch1); |
| 746 | __ shr_cl(result_reg); |
| 747 | __ test(ecx, Immediate(32)); |
| 748 | if (CpuFeatures::IsSupported(CMOV)) { |
| 749 | CpuFeatureScope use_cmov(masm, CMOV); |
| 750 | __ cmov(not_equal, scratch1, result_reg); |
| 751 | } else { |
| 752 | Label skip_mov; |
| 753 | __ j(equal, &skip_mov, Label::kNear); |
| 754 | __ mov(scratch1, result_reg); |
| 755 | __ bind(&skip_mov); |
| 756 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 757 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 758 | |
| 759 | // If the double was negative, negate the integer result. |
| 760 | __ bind(&check_negative); |
| 761 | __ mov(result_reg, scratch1); |
| 762 | __ neg(result_reg); |
| 763 | if (stash_exponent_copy) { |
| 764 | __ cmp(MemOperand(esp, 0), Immediate(0)); |
| 765 | } else { |
| 766 | __ cmp(exponent_operand, Immediate(0)); |
| 767 | } |
| 768 | if (CpuFeatures::IsSupported(CMOV)) { |
| 769 | CpuFeatureScope use_cmov(masm, CMOV); |
| 770 | __ cmov(greater, result_reg, scratch1); |
| 771 | } else { |
| 772 | Label skip_mov; |
| 773 | __ j(less_equal, &skip_mov, Label::kNear); |
| 774 | __ mov(result_reg, scratch1); |
| 775 | __ bind(&skip_mov); |
| 776 | } |
| 777 | |
| 778 | // Restore registers |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 779 | __ bind(&done); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 780 | if (stash_exponent_copy) { |
| 781 | __ add(esp, Immediate(kDoubleSize / 2)); |
| 782 | } |
| 783 | __ bind(&done_no_stash); |
| 784 | if (!final_result_reg.is(result_reg)) { |
| 785 | ASSERT(final_result_reg.is(ecx)); |
| 786 | __ mov(final_result_reg, result_reg); |
| 787 | } |
| 788 | __ pop(save_reg); |
| 789 | __ pop(scratch1); |
| 790 | __ ret(0); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 794 | // Uses SSE2 to convert the heap number in |source| to an integer. Jumps to |
| 795 | // |conversion_failure| if the heap number did not contain an int32 value. |
| 796 | // Result is in ecx. Trashes ebx, xmm0, and xmm1. |
| 797 | static void ConvertHeapNumberToInt32(MacroAssembler* masm, |
| 798 | Register source, |
| 799 | Label* conversion_failure) { |
| 800 | __ movdbl(xmm0, FieldOperand(source, HeapNumber::kValueOffset)); |
| 801 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 802 | masm, conversion_failure, xmm0, ecx, ebx, xmm1); |
| 803 | } |
| 804 | |
| 805 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 806 | void BinaryOpStub::Initialize() { |
| 807 | platform_specific_bit_ = CpuFeatures::IsSupported(SSE3); |
| 808 | } |
| 809 | |
| 810 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 811 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 812 | __ pop(ecx); // Save return address. |
| 813 | __ push(edx); |
| 814 | __ push(eax); |
| 815 | // Left and right arguments are now on top. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 816 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 817 | |
| 818 | __ push(ecx); // Push return address. |
| 819 | |
| 820 | // Patch the caller to an appropriate specialized stub and return the |
| 821 | // operation result to the caller of the stub. |
| 822 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 823 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 824 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 825 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 826 | 1); |
| 827 | } |
| 828 | |
| 829 | |
| 830 | // Prepare for a type transition runtime call when the args are already on |
| 831 | // the stack, under the return address. |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 832 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 833 | __ pop(ecx); // Save return address. |
| 834 | // Left and right arguments are already on top of the stack. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 835 | __ push(Immediate(Smi::FromInt(MinorKey()))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 836 | |
| 837 | __ push(ecx); // Push return address. |
| 838 | |
| 839 | // Patch the caller to an appropriate specialized stub and return the |
| 840 | // operation result to the caller of the stub. |
| 841 | __ TailCallExternalReference( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 842 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 843 | masm->isolate()), |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 844 | 3, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 845 | 1); |
| 846 | } |
| 847 | |
| 848 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 849 | static void BinaryOpStub_GenerateRegisterArgsPop(MacroAssembler* masm) { |
| 850 | __ pop(ecx); |
| 851 | __ pop(eax); |
| 852 | __ pop(edx); |
| 853 | __ push(ecx); |
| 854 | } |
| 855 | |
| 856 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 857 | static void BinaryOpStub_GenerateSmiCode( |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 858 | MacroAssembler* masm, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 859 | Label* slow, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 860 | BinaryOpStub::SmiCodeGenerateHeapNumberResults allow_heapnumber_results, |
| 861 | Token::Value op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 862 | // 1. Move arguments into edx, eax except for DIV and MOD, which need the |
| 863 | // dividend in eax and edx free for the division. Use eax, ebx for those. |
| 864 | Comment load_comment(masm, "-- Load arguments"); |
| 865 | Register left = edx; |
| 866 | Register right = eax; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 867 | if (op == Token::DIV || op == Token::MOD) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 868 | left = eax; |
| 869 | right = ebx; |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 870 | __ mov(ebx, eax); |
| 871 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | |
| 875 | // 2. Prepare the smi check of both operands by oring them together. |
| 876 | Comment smi_check_comment(masm, "-- Smi check arguments"); |
| 877 | Label not_smis; |
| 878 | Register combined = ecx; |
| 879 | ASSERT(!left.is(combined) && !right.is(combined)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 880 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 881 | case Token::BIT_OR: |
| 882 | // Perform the operation into eax and smi check the result. Preserve |
| 883 | // eax in case the result is not a smi. |
| 884 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 885 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 886 | __ or_(right, left); // Bitwise or is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 887 | combined = right; |
| 888 | break; |
| 889 | |
| 890 | case Token::BIT_XOR: |
| 891 | case Token::BIT_AND: |
| 892 | case Token::ADD: |
| 893 | case Token::SUB: |
| 894 | case Token::MUL: |
| 895 | case Token::DIV: |
| 896 | case Token::MOD: |
| 897 | __ mov(combined, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 898 | __ or_(combined, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 899 | break; |
| 900 | |
| 901 | case Token::SHL: |
| 902 | case Token::SAR: |
| 903 | case Token::SHR: |
| 904 | // Move the right operand into ecx for the shift operation, use eax |
| 905 | // for the smi check register. |
| 906 | ASSERT(!left.is(ecx) && !right.is(ecx)); |
| 907 | __ mov(ecx, right); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 908 | __ or_(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 909 | combined = right; |
| 910 | break; |
| 911 | |
| 912 | default: |
| 913 | break; |
| 914 | } |
| 915 | |
| 916 | // 3. Perform the smi check of the operands. |
| 917 | STATIC_ASSERT(kSmiTag == 0); // Adjust zero check if not the case. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 918 | __ JumpIfNotSmi(combined, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 919 | |
| 920 | // 4. Operands are both smis, perform the operation leaving the result in |
| 921 | // eax and check the result if necessary. |
| 922 | Comment perform_smi(masm, "-- Perform smi operation"); |
| 923 | Label use_fp_on_smis; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 924 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 925 | case Token::BIT_OR: |
| 926 | // Nothing to do. |
| 927 | break; |
| 928 | |
| 929 | case Token::BIT_XOR: |
| 930 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 931 | __ xor_(right, left); // Bitwise xor is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 932 | break; |
| 933 | |
| 934 | case Token::BIT_AND: |
| 935 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 936 | __ and_(right, left); // Bitwise and is commutative. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 937 | break; |
| 938 | |
| 939 | case Token::SHL: |
| 940 | // Remove tags from operands (but keep sign). |
| 941 | __ SmiUntag(left); |
| 942 | __ SmiUntag(ecx); |
| 943 | // Perform the operation. |
| 944 | __ shl_cl(left); |
| 945 | // Check that the *signed* result fits in a smi. |
| 946 | __ cmp(left, 0xc0000000); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 947 | __ j(sign, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 948 | // Tag the result and store it in register eax. |
| 949 | __ SmiTag(left); |
| 950 | __ mov(eax, left); |
| 951 | break; |
| 952 | |
| 953 | case Token::SAR: |
| 954 | // Remove tags from operands (but keep sign). |
| 955 | __ SmiUntag(left); |
| 956 | __ SmiUntag(ecx); |
| 957 | // Perform the operation. |
| 958 | __ sar_cl(left); |
| 959 | // Tag the result and store it in register eax. |
| 960 | __ SmiTag(left); |
| 961 | __ mov(eax, left); |
| 962 | break; |
| 963 | |
| 964 | case Token::SHR: |
| 965 | // Remove tags from operands (but keep sign). |
| 966 | __ SmiUntag(left); |
| 967 | __ SmiUntag(ecx); |
| 968 | // Perform the operation. |
| 969 | __ shr_cl(left); |
| 970 | // Check that the *unsigned* result fits in a smi. |
| 971 | // Neither of the two high-order bits can be set: |
| 972 | // - 0x80000000: high bit would be lost when smi tagging. |
| 973 | // - 0x40000000: this number would convert to negative when |
| 974 | // Smi tagging these two cases can only happen with shifts |
| 975 | // by 0 or 1 when handed a valid smi. |
| 976 | __ test(left, Immediate(0xc0000000)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 977 | __ j(not_zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 978 | // Tag the result and store it in register eax. |
| 979 | __ SmiTag(left); |
| 980 | __ mov(eax, left); |
| 981 | break; |
| 982 | |
| 983 | case Token::ADD: |
| 984 | ASSERT(right.is(eax)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 985 | __ add(right, left); // Addition is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 986 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 987 | break; |
| 988 | |
| 989 | case Token::SUB: |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 990 | __ sub(left, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 991 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 992 | __ mov(eax, left); |
| 993 | break; |
| 994 | |
| 995 | case Token::MUL: |
| 996 | // If the smi tag is 0 we can just leave the tag on one operand. |
| 997 | STATIC_ASSERT(kSmiTag == 0); // Adjust code below if not the case. |
| 998 | // We can't revert the multiplication if the result is not a smi |
| 999 | // so save the right operand. |
| 1000 | __ mov(ebx, right); |
| 1001 | // Remove tag from one of the operands (but keep sign). |
| 1002 | __ SmiUntag(right); |
| 1003 | // Do multiplication. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1004 | __ imul(right, left); // Multiplication is commutative. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1005 | __ j(overflow, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1006 | // Check for negative zero result. Use combined = left | right. |
| 1007 | __ NegativeZeroTest(right, combined, &use_fp_on_smis); |
| 1008 | break; |
| 1009 | |
| 1010 | case Token::DIV: |
| 1011 | // We can't revert the division if the result is not a smi so |
| 1012 | // save the left operand. |
| 1013 | __ mov(edi, left); |
| 1014 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1015 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1016 | __ j(zero, &use_fp_on_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1017 | // Sign extend left into edx:eax. |
| 1018 | ASSERT(left.is(eax)); |
| 1019 | __ cdq(); |
| 1020 | // Divide edx:eax by right. |
| 1021 | __ idiv(right); |
| 1022 | // Check for the corner case of dividing the most negative smi by |
| 1023 | // -1. We cannot use the overflow flag, since it is not set by idiv |
| 1024 | // instruction. |
| 1025 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1); |
| 1026 | __ cmp(eax, 0x40000000); |
| 1027 | __ j(equal, &use_fp_on_smis); |
| 1028 | // Check for negative zero result. Use combined = left | right. |
| 1029 | __ NegativeZeroTest(eax, combined, &use_fp_on_smis); |
| 1030 | // Check that the remainder is zero. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1031 | __ test(edx, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1032 | __ j(not_zero, &use_fp_on_smis); |
| 1033 | // Tag the result and store it in register eax. |
| 1034 | __ SmiTag(eax); |
| 1035 | break; |
| 1036 | |
| 1037 | case Token::MOD: |
| 1038 | // Check for 0 divisor. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1039 | __ test(right, right); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1040 | __ j(zero, ¬_smis); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1041 | |
| 1042 | // Sign extend left into edx:eax. |
| 1043 | ASSERT(left.is(eax)); |
| 1044 | __ cdq(); |
| 1045 | // Divide edx:eax by right. |
| 1046 | __ idiv(right); |
| 1047 | // Check for negative zero result. Use combined = left | right. |
| 1048 | __ NegativeZeroTest(edx, combined, slow); |
| 1049 | // Move remainder to register eax. |
| 1050 | __ mov(eax, edx); |
| 1051 | break; |
| 1052 | |
| 1053 | default: |
| 1054 | UNREACHABLE(); |
| 1055 | } |
| 1056 | |
| 1057 | // 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] | 1058 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1059 | case Token::ADD: |
| 1060 | case Token::SUB: |
| 1061 | case Token::MUL: |
| 1062 | case Token::DIV: |
| 1063 | __ ret(0); |
| 1064 | break; |
| 1065 | case Token::MOD: |
| 1066 | case Token::BIT_OR: |
| 1067 | case Token::BIT_AND: |
| 1068 | case Token::BIT_XOR: |
| 1069 | case Token::SAR: |
| 1070 | case Token::SHL: |
| 1071 | case Token::SHR: |
| 1072 | __ ret(2 * kPointerSize); |
| 1073 | break; |
| 1074 | default: |
| 1075 | UNREACHABLE(); |
| 1076 | } |
| 1077 | |
| 1078 | // 6. For some operations emit inline code to perform floating point |
| 1079 | // operations on known smis (e.g., if the result of the operation |
| 1080 | // overflowed the smi range). |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1081 | if (allow_heapnumber_results == BinaryOpStub::NO_HEAPNUMBER_RESULTS) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1082 | __ bind(&use_fp_on_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1083 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1084 | // Undo the effects of some operations, and some register moves. |
| 1085 | case Token::SHL: |
| 1086 | // The arguments are saved on the stack, and only used from there. |
| 1087 | break; |
| 1088 | case Token::ADD: |
| 1089 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1090 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1091 | break; |
| 1092 | case Token::SUB: |
| 1093 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1094 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1095 | break; |
| 1096 | case Token::MUL: |
| 1097 | // Right was clobbered but a copy is in ebx. |
| 1098 | __ mov(right, ebx); |
| 1099 | break; |
| 1100 | case Token::DIV: |
| 1101 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1102 | // division. They should be in eax, ebx for jump to not_smi. |
| 1103 | __ mov(eax, edi); |
| 1104 | break; |
| 1105 | default: |
| 1106 | // No other operators jump to use_fp_on_smis. |
| 1107 | break; |
| 1108 | } |
| 1109 | __ jmp(¬_smis); |
| 1110 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1111 | ASSERT(allow_heapnumber_results == BinaryOpStub::ALLOW_HEAPNUMBER_RESULTS); |
| 1112 | switch (op) { |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1113 | case Token::SHL: |
| 1114 | case Token::SHR: { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1115 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1116 | __ bind(&use_fp_on_smis); |
| 1117 | // Result we want is in left == edx, so we can put the allocated heap |
| 1118 | // number in eax. |
| 1119 | __ AllocateHeapNumber(eax, ecx, ebx, slow); |
| 1120 | // Store the result in the HeapNumber and return. |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1121 | // It's OK to overwrite the arguments on the stack because we |
| 1122 | // are about to return. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1123 | if (op == Token::SHR) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1124 | __ mov(Operand(esp, 1 * kPointerSize), left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1125 | __ mov(Operand(esp, 2 * kPointerSize), Immediate(0)); |
| 1126 | __ fild_d(Operand(esp, 1 * kPointerSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1127 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1128 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1129 | ASSERT_EQ(Token::SHL, op); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1130 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1131 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1132 | __ cvtsi2sd(xmm0, left); |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1133 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1134 | } else { |
| 1135 | __ mov(Operand(esp, 1 * kPointerSize), left); |
| 1136 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1137 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1138 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1139 | } |
ager@chromium.org | ea91cc5 | 2011-05-23 06:06:11 +0000 | [diff] [blame] | 1140 | __ ret(2 * kPointerSize); |
| 1141 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | case Token::ADD: |
| 1145 | case Token::SUB: |
| 1146 | case Token::MUL: |
| 1147 | case Token::DIV: { |
| 1148 | Comment perform_float(masm, "-- Perform float operation on smis"); |
| 1149 | __ bind(&use_fp_on_smis); |
| 1150 | // Restore arguments to edx, eax. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1151 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1152 | case Token::ADD: |
| 1153 | // Revert right = right + left. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1154 | __ sub(right, left); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1155 | break; |
| 1156 | case Token::SUB: |
| 1157 | // Revert left = left - right. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1158 | __ add(left, right); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1159 | break; |
| 1160 | case Token::MUL: |
| 1161 | // Right was clobbered but a copy is in ebx. |
| 1162 | __ mov(right, ebx); |
| 1163 | break; |
| 1164 | case Token::DIV: |
| 1165 | // Left was clobbered but a copy is in edi. Right is in ebx for |
| 1166 | // division. |
| 1167 | __ mov(edx, edi); |
| 1168 | __ mov(eax, right); |
| 1169 | break; |
| 1170 | default: UNREACHABLE(); |
| 1171 | break; |
| 1172 | } |
| 1173 | __ AllocateHeapNumber(ecx, ebx, no_reg, slow); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1174 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1175 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1176 | FloatingPointHelper::LoadSSE2Smis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1177 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1178 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1179 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1180 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1181 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1182 | default: UNREACHABLE(); |
| 1183 | } |
| 1184 | __ movdbl(FieldOperand(ecx, HeapNumber::kValueOffset), xmm0); |
| 1185 | } else { // SSE2 not available, use FPU. |
| 1186 | FloatingPointHelper::LoadFloatSmis(masm, ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1187 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1188 | case Token::ADD: __ faddp(1); break; |
| 1189 | case Token::SUB: __ fsubp(1); break; |
| 1190 | case Token::MUL: __ fmulp(1); break; |
| 1191 | case Token::DIV: __ fdivp(1); break; |
| 1192 | default: UNREACHABLE(); |
| 1193 | } |
| 1194 | __ fstp_d(FieldOperand(ecx, HeapNumber::kValueOffset)); |
| 1195 | } |
| 1196 | __ mov(eax, ecx); |
| 1197 | __ ret(0); |
| 1198 | break; |
| 1199 | } |
| 1200 | |
| 1201 | default: |
| 1202 | break; |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | // 7. Non-smi operands, fall out to the non-smi code with the operands in |
| 1207 | // edx and eax. |
| 1208 | Comment done_comment(masm, "-- Enter non-smi code"); |
| 1209 | __ bind(¬_smis); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1210 | switch (op) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1211 | case Token::BIT_OR: |
| 1212 | case Token::SHL: |
| 1213 | case Token::SAR: |
| 1214 | case Token::SHR: |
| 1215 | // Right operand is saved in ecx and eax was destroyed by the smi |
| 1216 | // check. |
| 1217 | __ mov(eax, ecx); |
| 1218 | break; |
| 1219 | |
| 1220 | case Token::DIV: |
| 1221 | case Token::MOD: |
| 1222 | // Operands are in eax, ebx at this point. |
| 1223 | __ mov(edx, eax); |
| 1224 | __ mov(eax, ebx); |
| 1225 | break; |
| 1226 | |
| 1227 | default: |
| 1228 | break; |
| 1229 | } |
| 1230 | } |
| 1231 | |
| 1232 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1233 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1234 | Label right_arg_changed, call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1235 | |
| 1236 | switch (op_) { |
| 1237 | case Token::ADD: |
| 1238 | case Token::SUB: |
| 1239 | case Token::MUL: |
| 1240 | case Token::DIV: |
| 1241 | break; |
| 1242 | case Token::MOD: |
| 1243 | case Token::BIT_OR: |
| 1244 | case Token::BIT_AND: |
| 1245 | case Token::BIT_XOR: |
| 1246 | case Token::SAR: |
| 1247 | case Token::SHL: |
| 1248 | case Token::SHR: |
| 1249 | GenerateRegisterArgsPush(masm); |
| 1250 | break; |
| 1251 | default: |
| 1252 | UNREACHABLE(); |
| 1253 | } |
| 1254 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1255 | if (op_ == Token::MOD && encoded_right_arg_.has_value) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1256 | // It is guaranteed that the value will fit into a Smi, because if it |
| 1257 | // didn't, we wouldn't be here, see BinaryOp_Patch. |
| 1258 | __ cmp(eax, Immediate(Smi::FromInt(fixed_right_arg_value()))); |
| 1259 | __ j(not_equal, &right_arg_changed); |
| 1260 | } |
| 1261 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1262 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 1263 | result_type_ == BinaryOpIC::SMI) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1264 | BinaryOpStub_GenerateSmiCode( |
| 1265 | masm, &call_runtime, NO_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1266 | } else { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1267 | BinaryOpStub_GenerateSmiCode( |
| 1268 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1269 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1270 | |
| 1271 | // Code falls through if the result is not returned as either a smi or heap |
| 1272 | // number. |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1273 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1274 | switch (op_) { |
| 1275 | case Token::ADD: |
| 1276 | case Token::SUB: |
| 1277 | case Token::MUL: |
| 1278 | case Token::DIV: |
| 1279 | GenerateTypeTransition(masm); |
| 1280 | break; |
| 1281 | case Token::MOD: |
| 1282 | case Token::BIT_OR: |
| 1283 | case Token::BIT_AND: |
| 1284 | case Token::BIT_XOR: |
| 1285 | case Token::SAR: |
| 1286 | case Token::SHL: |
| 1287 | case Token::SHR: |
| 1288 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1289 | break; |
| 1290 | default: |
| 1291 | UNREACHABLE(); |
| 1292 | } |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1293 | |
| 1294 | __ bind(&call_runtime); |
| 1295 | switch (op_) { |
| 1296 | case Token::ADD: |
| 1297 | case Token::SUB: |
| 1298 | case Token::MUL: |
| 1299 | case Token::DIV: |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1300 | break; |
| 1301 | case Token::MOD: |
| 1302 | case Token::BIT_OR: |
| 1303 | case Token::BIT_AND: |
| 1304 | case Token::BIT_XOR: |
| 1305 | case Token::SAR: |
| 1306 | case Token::SHL: |
| 1307 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1308 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
ulan@chromium.org | 906e2fb | 2013-05-14 08:14:38 +0000 | [diff] [blame] | 1309 | break; |
| 1310 | default: |
| 1311 | UNREACHABLE(); |
| 1312 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1313 | |
| 1314 | { |
| 1315 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1316 | __ push(edx); |
| 1317 | __ push(eax); |
| 1318 | GenerateCallRuntime(masm); |
| 1319 | } |
| 1320 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
| 1323 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1324 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1325 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1326 | ASSERT(left_type_ == BinaryOpIC::STRING && right_type_ == BinaryOpIC::STRING); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1327 | ASSERT(op_ == Token::ADD); |
| 1328 | // If both arguments are strings, call the string add stub. |
| 1329 | // Otherwise, do a transition. |
| 1330 | |
| 1331 | // Registers containing left and right operands respectively. |
| 1332 | Register left = edx; |
| 1333 | Register right = eax; |
| 1334 | |
| 1335 | // Test if left operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1336 | __ JumpIfSmi(left, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1337 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1338 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1339 | |
| 1340 | // Test if right operand is a string. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1341 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1342 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1343 | __ j(above_equal, &call_runtime, Label::kNear); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1344 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1345 | StringAddStub string_add_stub( |
| 1346 | (StringAddFlags)(STRING_ADD_CHECK_NONE | STRING_ADD_ERECT_FRAME)); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1347 | GenerateRegisterArgsPush(masm); |
| 1348 | __ TailCallStub(&string_add_stub); |
| 1349 | |
| 1350 | __ bind(&call_runtime); |
| 1351 | GenerateTypeTransition(masm); |
| 1352 | } |
| 1353 | |
| 1354 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1355 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 1356 | Label* alloc_failure, |
| 1357 | OverwriteMode mode); |
| 1358 | |
| 1359 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1360 | // Input: |
| 1361 | // edx: left operand (tagged) |
| 1362 | // eax: right operand (tagged) |
| 1363 | // Output: |
| 1364 | // eax: result (tagged) |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1365 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1366 | Label call_runtime; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1367 | ASSERT(Max(left_type_, right_type_) == BinaryOpIC::INT32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1368 | |
| 1369 | // Floating point case. |
| 1370 | switch (op_) { |
| 1371 | case Token::ADD: |
| 1372 | case Token::SUB: |
| 1373 | case Token::MUL: |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1374 | case Token::DIV: |
| 1375 | case Token::MOD: { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1376 | Label not_floats, not_int32, right_arg_changed; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1377 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1378 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1379 | // It could be that only SMIs have been seen at either the left |
| 1380 | // or the right operand. For precise type feedback, patch the IC |
| 1381 | // again if this changes. |
| 1382 | // In theory, we would need the same check in the non-SSE2 case, |
| 1383 | // but since we don't support Crankshaft on such hardware we can |
| 1384 | // afford not to care about precise type feedback. |
| 1385 | if (left_type_ == BinaryOpIC::SMI) { |
| 1386 | __ JumpIfNotSmi(edx, ¬_int32); |
| 1387 | } |
| 1388 | if (right_type_ == BinaryOpIC::SMI) { |
| 1389 | __ JumpIfNotSmi(eax, ¬_int32); |
| 1390 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1391 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1392 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1393 | masm, ¬_int32, xmm0, ebx, ecx, xmm2); |
| 1394 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
| 1395 | masm, ¬_int32, xmm1, edi, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1396 | if (op_ == Token::MOD) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 1397 | if (encoded_right_arg_.has_value) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1398 | __ cmp(edi, Immediate(fixed_right_arg_value())); |
| 1399 | __ j(not_equal, &right_arg_changed); |
| 1400 | } |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1401 | GenerateRegisterArgsPush(masm); |
| 1402 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1403 | } else { |
| 1404 | switch (op_) { |
| 1405 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1406 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1407 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1408 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1409 | default: UNREACHABLE(); |
| 1410 | } |
| 1411 | // Check result type if it is currently Int32. |
| 1412 | if (result_type_ <= BinaryOpIC::INT32) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 1413 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1414 | masm, ¬_int32, xmm0, ecx, ecx, xmm2); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1415 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1416 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1417 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1418 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1419 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1420 | } else { // SSE2 not available, use FPU. |
| 1421 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1422 | FloatingPointHelper::LoadFloatOperands( |
| 1423 | masm, |
| 1424 | ecx, |
| 1425 | FloatingPointHelper::ARGS_IN_REGISTERS); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1426 | if (op_ == Token::MOD) { |
| 1427 | // The operands are now on the FPU stack, but we don't need them. |
| 1428 | __ fstp(0); |
| 1429 | __ fstp(0); |
| 1430 | GenerateRegisterArgsPush(masm); |
| 1431 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
| 1432 | } else { |
| 1433 | switch (op_) { |
| 1434 | case Token::ADD: __ faddp(1); break; |
| 1435 | case Token::SUB: __ fsubp(1); break; |
| 1436 | case Token::MUL: __ fmulp(1); break; |
| 1437 | case Token::DIV: __ fdivp(1); break; |
| 1438 | default: UNREACHABLE(); |
| 1439 | } |
| 1440 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1441 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1442 | masm, &after_alloc_failure, mode_); |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1443 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1444 | __ ret(0); |
| 1445 | __ bind(&after_alloc_failure); |
| 1446 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1447 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1448 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1449 | } |
| 1450 | |
| 1451 | __ bind(¬_floats); |
| 1452 | __ bind(¬_int32); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1453 | __ bind(&right_arg_changed); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1454 | GenerateTypeTransition(masm); |
| 1455 | break; |
| 1456 | } |
| 1457 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1458 | case Token::BIT_OR: |
| 1459 | case Token::BIT_AND: |
| 1460 | case Token::BIT_XOR: |
| 1461 | case Token::SAR: |
| 1462 | case Token::SHL: |
| 1463 | case Token::SHR: { |
| 1464 | GenerateRegisterArgsPush(masm); |
| 1465 | Label not_floats; |
| 1466 | Label not_int32; |
| 1467 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1468 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1469 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1470 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1471 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1472 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1473 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1474 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1475 | case Token::SAR: __ sar_cl(eax); break; |
| 1476 | case Token::SHL: __ shl_cl(eax); break; |
| 1477 | case Token::SHR: __ shr_cl(eax); break; |
| 1478 | default: UNREACHABLE(); |
| 1479 | } |
| 1480 | if (op_ == Token::SHR) { |
| 1481 | // Check if result is non-negative and fits in a smi. |
| 1482 | __ test(eax, Immediate(0xc0000000)); |
| 1483 | __ j(not_zero, &call_runtime); |
| 1484 | } else { |
| 1485 | // Check if result fits in a smi. |
| 1486 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1487 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1488 | } |
| 1489 | // Tag smi result and return. |
| 1490 | __ SmiTag(eax); |
| 1491 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1492 | |
| 1493 | // All ops except SHR return a signed int32 that we load in |
| 1494 | // a HeapNumber. |
| 1495 | if (op_ != Token::SHR) { |
| 1496 | __ bind(&non_smi_result); |
| 1497 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1498 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1499 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1500 | switch (mode_) { |
| 1501 | case OVERWRITE_LEFT: |
| 1502 | case OVERWRITE_RIGHT: |
| 1503 | // If the operand was an object, we skip the |
| 1504 | // allocation of a heap number. |
| 1505 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1506 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1507 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1508 | // Fall through! |
| 1509 | case NO_OVERWRITE: |
| 1510 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1511 | __ bind(&skip_allocation); |
| 1512 | break; |
| 1513 | default: UNREACHABLE(); |
| 1514 | } |
| 1515 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1516 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1517 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1518 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1519 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1520 | } else { |
| 1521 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1522 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1523 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1524 | } |
| 1525 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1526 | } |
| 1527 | |
| 1528 | __ bind(¬_floats); |
| 1529 | __ bind(¬_int32); |
| 1530 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1531 | break; |
| 1532 | } |
| 1533 | default: UNREACHABLE(); break; |
| 1534 | } |
| 1535 | |
svenpanne@chromium.org | fb04633 | 2012-04-19 12:02:44 +0000 | [diff] [blame] | 1536 | // If an allocation fails, or SHR hits a hard case, use the runtime system to |
| 1537 | // get the correct result. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1538 | __ bind(&call_runtime); |
| 1539 | |
| 1540 | switch (op_) { |
| 1541 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1542 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1543 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1544 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1545 | break; |
| 1546 | case Token::MOD: |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1547 | return; // Handled above. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1548 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1549 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1550 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1551 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1552 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1553 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1554 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1555 | break; |
| 1556 | default: |
| 1557 | UNREACHABLE(); |
| 1558 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1559 | |
| 1560 | { |
| 1561 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1562 | __ push(edx); |
| 1563 | __ push(eax); |
| 1564 | GenerateCallRuntime(masm); |
| 1565 | } |
| 1566 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1567 | } |
| 1568 | |
| 1569 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1570 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1571 | if (op_ == Token::ADD) { |
| 1572 | // Handle string addition here, because it is the only operation |
| 1573 | // that does not do a ToNumber conversion on the operands. |
| 1574 | GenerateAddStrings(masm); |
| 1575 | } |
| 1576 | |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1577 | Factory* factory = masm->isolate()->factory(); |
| 1578 | |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1579 | // Convert odd ball arguments to numbers. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1580 | Label check, done; |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1581 | __ cmp(edx, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1582 | __ j(not_equal, &check, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1583 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1584 | __ xor_(edx, edx); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1585 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1586 | __ mov(edx, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1587 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1588 | __ jmp(&done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1589 | __ bind(&check); |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1590 | __ cmp(eax, factory->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1591 | __ j(not_equal, &done, Label::kNear); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1592 | if (Token::IsBitOp(op_)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1593 | __ xor_(eax, eax); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1594 | } else { |
danno@chromium.org | 160a7b0 | 2011-04-18 15:51:38 +0000 | [diff] [blame] | 1595 | __ mov(eax, Immediate(factory->nan_value())); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1596 | } |
| 1597 | __ bind(&done); |
| 1598 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1599 | GenerateNumberStub(masm); |
lrn@chromium.org | 7516f05 | 2011-03-30 08:52:27 +0000 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 1603 | void BinaryOpStub::GenerateNumberStub(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1604 | Label call_runtime; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1605 | |
| 1606 | // Floating point case. |
| 1607 | switch (op_) { |
| 1608 | case Token::ADD: |
| 1609 | case Token::SUB: |
| 1610 | case Token::MUL: |
| 1611 | case Token::DIV: { |
| 1612 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1613 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1614 | CpuFeatureScope use_sse2(masm, SSE2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1615 | |
| 1616 | // It could be that only SMIs have been seen at either the left |
| 1617 | // or the right operand. For precise type feedback, patch the IC |
| 1618 | // again if this changes. |
| 1619 | // In theory, we would need the same check in the non-SSE2 case, |
| 1620 | // but since we don't support Crankshaft on such hardware we can |
| 1621 | // afford not to care about precise type feedback. |
| 1622 | if (left_type_ == BinaryOpIC::SMI) { |
| 1623 | __ JumpIfNotSmi(edx, ¬_floats); |
| 1624 | } |
| 1625 | if (right_type_ == BinaryOpIC::SMI) { |
| 1626 | __ JumpIfNotSmi(eax, ¬_floats); |
| 1627 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1628 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1629 | if (left_type_ == BinaryOpIC::INT32) { |
| 1630 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1631 | masm, ¬_floats, xmm0, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1632 | } |
| 1633 | if (right_type_ == BinaryOpIC::INT32) { |
| 1634 | FloatingPointHelper::CheckSSE2OperandIsInt32( |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1635 | masm, ¬_floats, xmm1, ecx, ecx, xmm2); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1636 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1637 | |
| 1638 | switch (op_) { |
| 1639 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1640 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1641 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1642 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1643 | default: UNREACHABLE(); |
| 1644 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1645 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1646 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1647 | __ ret(0); |
| 1648 | } else { // SSE2 not available, use FPU. |
| 1649 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1650 | FloatingPointHelper::LoadFloatOperands( |
| 1651 | masm, |
| 1652 | ecx, |
| 1653 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1654 | switch (op_) { |
| 1655 | case Token::ADD: __ faddp(1); break; |
| 1656 | case Token::SUB: __ fsubp(1); break; |
| 1657 | case Token::MUL: __ fmulp(1); break; |
| 1658 | case Token::DIV: __ fdivp(1); break; |
| 1659 | default: UNREACHABLE(); |
| 1660 | } |
| 1661 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1662 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1663 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1664 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1665 | __ ret(0); |
| 1666 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1667 | __ fstp(0); // Pop FPU stack before calling runtime. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1668 | __ jmp(&call_runtime); |
| 1669 | } |
| 1670 | |
| 1671 | __ bind(¬_floats); |
| 1672 | GenerateTypeTransition(masm); |
| 1673 | break; |
| 1674 | } |
| 1675 | |
| 1676 | case Token::MOD: { |
| 1677 | // For MOD we go directly to runtime in the non-smi case. |
| 1678 | break; |
| 1679 | } |
| 1680 | case Token::BIT_OR: |
| 1681 | case Token::BIT_AND: |
| 1682 | case Token::BIT_XOR: |
| 1683 | case Token::SAR: |
| 1684 | case Token::SHL: |
| 1685 | case Token::SHR: { |
| 1686 | GenerateRegisterArgsPush(masm); |
| 1687 | Label not_floats; |
| 1688 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1689 | // We do not check the input arguments here, as any value is |
| 1690 | // unconditionally truncated to an int32 anyway. To get the |
| 1691 | // right optimized code, int32 type feedback is just right. |
| 1692 | bool use_sse3 = platform_specific_bit_; |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1693 | FloatingPointHelper::LoadUnknownsAsIntegers( |
| 1694 | masm, use_sse3, left_type_, right_type_, ¬_floats); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1695 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1696 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1697 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1698 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1699 | case Token::SAR: __ sar_cl(eax); break; |
| 1700 | case Token::SHL: __ shl_cl(eax); break; |
| 1701 | case Token::SHR: __ shr_cl(eax); break; |
| 1702 | default: UNREACHABLE(); |
| 1703 | } |
| 1704 | if (op_ == Token::SHR) { |
| 1705 | // Check if result is non-negative and fits in a smi. |
| 1706 | __ test(eax, Immediate(0xc0000000)); |
| 1707 | __ j(not_zero, &call_runtime); |
| 1708 | } else { |
| 1709 | // Check if result fits in a smi. |
| 1710 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1711 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1712 | } |
| 1713 | // Tag smi result and return. |
| 1714 | __ SmiTag(eax); |
| 1715 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1716 | |
| 1717 | // All ops except SHR return a signed int32 that we load in |
| 1718 | // a HeapNumber. |
| 1719 | if (op_ != Token::SHR) { |
| 1720 | __ bind(&non_smi_result); |
| 1721 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1722 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1723 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1724 | switch (mode_) { |
| 1725 | case OVERWRITE_LEFT: |
| 1726 | case OVERWRITE_RIGHT: |
| 1727 | // If the operand was an object, we skip the |
| 1728 | // allocation of a heap number. |
| 1729 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1730 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1731 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1732 | // Fall through! |
| 1733 | case NO_OVERWRITE: |
| 1734 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1735 | __ bind(&skip_allocation); |
| 1736 | break; |
| 1737 | default: UNREACHABLE(); |
| 1738 | } |
| 1739 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1740 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1741 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1742 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1743 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1744 | } else { |
| 1745 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1746 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1747 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1748 | } |
| 1749 | __ ret(2 * kPointerSize); // Drop two pushed arguments from the stack. |
| 1750 | } |
| 1751 | |
| 1752 | __ bind(¬_floats); |
| 1753 | GenerateTypeTransitionWithSavedArgs(masm); |
| 1754 | break; |
| 1755 | } |
| 1756 | default: UNREACHABLE(); break; |
| 1757 | } |
| 1758 | |
| 1759 | // If an allocation fails, or SHR or MOD hit a hard case, |
| 1760 | // use the runtime system to get the correct result. |
| 1761 | __ bind(&call_runtime); |
| 1762 | |
| 1763 | switch (op_) { |
| 1764 | case Token::ADD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1765 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1766 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1767 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1768 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1769 | break; |
| 1770 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1771 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1772 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1773 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1774 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1775 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1776 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1777 | break; |
| 1778 | default: |
| 1779 | UNREACHABLE(); |
| 1780 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1781 | |
| 1782 | { |
| 1783 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1784 | __ push(edx); |
| 1785 | __ push(eax); |
| 1786 | GenerateCallRuntime(masm); |
| 1787 | } |
| 1788 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1792 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1793 | Label call_runtime; |
| 1794 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1795 | Counters* counters = masm->isolate()->counters(); |
| 1796 | __ IncrementCounter(counters->generic_binary_stub_calls(), 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1797 | |
| 1798 | switch (op_) { |
| 1799 | case Token::ADD: |
| 1800 | case Token::SUB: |
| 1801 | case Token::MUL: |
| 1802 | case Token::DIV: |
| 1803 | break; |
| 1804 | case Token::MOD: |
| 1805 | case Token::BIT_OR: |
| 1806 | case Token::BIT_AND: |
| 1807 | case Token::BIT_XOR: |
| 1808 | case Token::SAR: |
| 1809 | case Token::SHL: |
| 1810 | case Token::SHR: |
| 1811 | GenerateRegisterArgsPush(masm); |
| 1812 | break; |
| 1813 | default: |
| 1814 | UNREACHABLE(); |
| 1815 | } |
| 1816 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1817 | BinaryOpStub_GenerateSmiCode( |
| 1818 | masm, &call_runtime, ALLOW_HEAPNUMBER_RESULTS, op_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1819 | |
| 1820 | // Floating point case. |
| 1821 | switch (op_) { |
| 1822 | case Token::ADD: |
| 1823 | case Token::SUB: |
| 1824 | case Token::MUL: |
| 1825 | case Token::DIV: { |
| 1826 | Label not_floats; |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1827 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1828 | CpuFeatureScope use_sse2(masm, SSE2); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1829 | FloatingPointHelper::LoadSSE2Operands(masm, ¬_floats); |
| 1830 | |
| 1831 | switch (op_) { |
| 1832 | case Token::ADD: __ addsd(xmm0, xmm1); break; |
| 1833 | case Token::SUB: __ subsd(xmm0, xmm1); break; |
| 1834 | case Token::MUL: __ mulsd(xmm0, xmm1); break; |
| 1835 | case Token::DIV: __ divsd(xmm0, xmm1); break; |
| 1836 | default: UNREACHABLE(); |
| 1837 | } |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1838 | BinaryOpStub_GenerateHeapResultAllocation(masm, &call_runtime, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1839 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1840 | __ ret(0); |
| 1841 | } else { // SSE2 not available, use FPU. |
| 1842 | FloatingPointHelper::CheckFloatOperands(masm, ¬_floats, ebx); |
| 1843 | FloatingPointHelper::LoadFloatOperands( |
| 1844 | masm, |
| 1845 | ecx, |
| 1846 | FloatingPointHelper::ARGS_IN_REGISTERS); |
| 1847 | switch (op_) { |
| 1848 | case Token::ADD: __ faddp(1); break; |
| 1849 | case Token::SUB: __ fsubp(1); break; |
| 1850 | case Token::MUL: __ fmulp(1); break; |
| 1851 | case Token::DIV: __ fdivp(1); break; |
| 1852 | default: UNREACHABLE(); |
| 1853 | } |
| 1854 | Label after_alloc_failure; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1855 | BinaryOpStub_GenerateHeapResultAllocation( |
| 1856 | masm, &after_alloc_failure, mode_); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1857 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1858 | __ ret(0); |
| 1859 | __ bind(&after_alloc_failure); |
jkummerow@chromium.org | 28faa98 | 2012-04-13 09:58:30 +0000 | [diff] [blame] | 1860 | __ fstp(0); // Pop FPU stack before calling runtime. |
| 1861 | __ jmp(&call_runtime); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1862 | } |
| 1863 | __ bind(¬_floats); |
| 1864 | break; |
| 1865 | } |
| 1866 | case Token::MOD: { |
| 1867 | // For MOD we go directly to runtime in the non-smi case. |
| 1868 | break; |
| 1869 | } |
| 1870 | case Token::BIT_OR: |
| 1871 | case Token::BIT_AND: |
| 1872 | case Token::BIT_XOR: |
| 1873 | case Token::SAR: |
| 1874 | case Token::SHL: |
| 1875 | case Token::SHR: { |
| 1876 | Label non_smi_result; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1877 | bool use_sse3 = platform_specific_bit_; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1878 | FloatingPointHelper::LoadUnknownsAsIntegers(masm, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1879 | use_sse3, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 1880 | BinaryOpIC::GENERIC, |
| 1881 | BinaryOpIC::GENERIC, |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1882 | &call_runtime); |
| 1883 | switch (op_) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1884 | case Token::BIT_OR: __ or_(eax, ecx); break; |
| 1885 | case Token::BIT_AND: __ and_(eax, ecx); break; |
| 1886 | case Token::BIT_XOR: __ xor_(eax, ecx); break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1887 | case Token::SAR: __ sar_cl(eax); break; |
| 1888 | case Token::SHL: __ shl_cl(eax); break; |
| 1889 | case Token::SHR: __ shr_cl(eax); break; |
| 1890 | default: UNREACHABLE(); |
| 1891 | } |
| 1892 | if (op_ == Token::SHR) { |
| 1893 | // Check if result is non-negative and fits in a smi. |
| 1894 | __ test(eax, Immediate(0xc0000000)); |
| 1895 | __ j(not_zero, &call_runtime); |
| 1896 | } else { |
| 1897 | // Check if result fits in a smi. |
| 1898 | __ cmp(eax, 0xc0000000); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1899 | __ j(negative, &non_smi_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1900 | } |
| 1901 | // Tag smi result and return. |
| 1902 | __ SmiTag(eax); |
| 1903 | __ ret(2 * kPointerSize); // Drop the arguments from the stack. |
| 1904 | |
| 1905 | // All ops except SHR return a signed int32 that we load in |
| 1906 | // a HeapNumber. |
| 1907 | if (op_ != Token::SHR) { |
| 1908 | __ bind(&non_smi_result); |
| 1909 | // Allocate a heap number if needed. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1910 | __ mov(ebx, eax); // ebx: result |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1911 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1912 | switch (mode_) { |
| 1913 | case OVERWRITE_LEFT: |
| 1914 | case OVERWRITE_RIGHT: |
| 1915 | // If the operand was an object, we skip the |
| 1916 | // allocation of a heap number. |
| 1917 | __ mov(eax, Operand(esp, mode_ == OVERWRITE_RIGHT ? |
| 1918 | 1 * kPointerSize : 2 * kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1919 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1920 | // Fall through! |
| 1921 | case NO_OVERWRITE: |
| 1922 | __ AllocateHeapNumber(eax, ecx, edx, &call_runtime); |
| 1923 | __ bind(&skip_allocation); |
| 1924 | break; |
| 1925 | default: UNREACHABLE(); |
| 1926 | } |
| 1927 | // Store the result in the HeapNumber and return. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 1928 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1929 | CpuFeatureScope use_sse2(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1930 | __ cvtsi2sd(xmm0, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1931 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm0); |
| 1932 | } else { |
| 1933 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1934 | __ fild_s(Operand(esp, 1 * kPointerSize)); |
| 1935 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 1936 | } |
| 1937 | __ ret(2 * kPointerSize); |
| 1938 | } |
| 1939 | break; |
| 1940 | } |
| 1941 | default: UNREACHABLE(); break; |
| 1942 | } |
| 1943 | |
| 1944 | // If all else fails, use the runtime system to get the correct |
| 1945 | // result. |
| 1946 | __ bind(&call_runtime); |
| 1947 | switch (op_) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1948 | case Token::ADD: |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1949 | GenerateAddStrings(masm); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1950 | // Fall through. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1951 | case Token::SUB: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1952 | case Token::MUL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1953 | case Token::DIV: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1954 | break; |
| 1955 | case Token::MOD: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1956 | case Token::BIT_OR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1957 | case Token::BIT_AND: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1958 | case Token::BIT_XOR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1959 | case Token::SAR: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1960 | case Token::SHL: |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1961 | case Token::SHR: |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1962 | BinaryOpStub_GenerateRegisterArgsPop(masm); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1963 | break; |
| 1964 | default: |
| 1965 | UNREACHABLE(); |
| 1966 | } |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 1967 | |
| 1968 | { |
| 1969 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 1970 | __ push(edx); |
| 1971 | __ push(eax); |
| 1972 | GenerateCallRuntime(masm); |
| 1973 | } |
| 1974 | __ ret(0); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1975 | } |
| 1976 | |
| 1977 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 1978 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
fschneider@chromium.org | 3a5fd78 | 2011-02-24 10:10:44 +0000 | [diff] [blame] | 1979 | ASSERT(op_ == Token::ADD); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1980 | Label left_not_string, call_runtime; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1981 | |
| 1982 | // Registers containing left and right operands respectively. |
| 1983 | Register left = edx; |
| 1984 | Register right = eax; |
| 1985 | |
| 1986 | // Test if left operand is a string. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1987 | __ JumpIfSmi(left, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1988 | __ CmpObjectType(left, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1989 | __ j(above_equal, &left_not_string, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1990 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 1991 | StringAddStub string_add_left_stub( |
| 1992 | (StringAddFlags)(STRING_ADD_CHECK_RIGHT | STRING_ADD_ERECT_FRAME)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1993 | GenerateRegisterArgsPush(masm); |
| 1994 | __ TailCallStub(&string_add_left_stub); |
| 1995 | |
| 1996 | // Left operand is not a string, test right. |
| 1997 | __ bind(&left_not_string); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1998 | __ JumpIfSmi(right, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 1999 | __ CmpObjectType(right, FIRST_NONSTRING_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2000 | __ j(above_equal, &call_runtime, Label::kNear); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2001 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 2002 | StringAddStub string_add_right_stub( |
| 2003 | (StringAddFlags)(STRING_ADD_CHECK_LEFT | STRING_ADD_ERECT_FRAME)); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2004 | GenerateRegisterArgsPush(masm); |
| 2005 | __ TailCallStub(&string_add_right_stub); |
| 2006 | |
| 2007 | // Neither argument is a string. |
| 2008 | __ bind(&call_runtime); |
| 2009 | } |
| 2010 | |
| 2011 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2012 | static void BinaryOpStub_GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2013 | Label* alloc_failure, |
| 2014 | OverwriteMode mode) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2015 | Label skip_allocation; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2016 | switch (mode) { |
| 2017 | case OVERWRITE_LEFT: { |
| 2018 | // If the argument in edx is already an object, we skip the |
| 2019 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2020 | __ JumpIfNotSmi(edx, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2021 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2022 | // for the possible runtime call. |
| 2023 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2024 | // Now edx can be overwritten losing one of the arguments as we are |
| 2025 | // now done and will not need it any more. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2026 | __ mov(edx, ebx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2027 | __ bind(&skip_allocation); |
| 2028 | // Use object in edx as a result holder |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2029 | __ mov(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2030 | break; |
| 2031 | } |
| 2032 | case OVERWRITE_RIGHT: |
| 2033 | // If the argument in eax is already an object, we skip the |
| 2034 | // allocation of a heap number. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2035 | __ JumpIfNotSmi(eax, &skip_allocation, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2036 | // Fall through! |
| 2037 | case NO_OVERWRITE: |
| 2038 | // Allocate a heap number for the result. Keep eax and edx intact |
| 2039 | // for the possible runtime call. |
| 2040 | __ AllocateHeapNumber(ebx, ecx, no_reg, alloc_failure); |
| 2041 | // Now eax can be overwritten losing one of the arguments as we are |
| 2042 | // now done and will not need it any more. |
| 2043 | __ mov(eax, ebx); |
| 2044 | __ bind(&skip_allocation); |
| 2045 | break; |
| 2046 | default: UNREACHABLE(); |
| 2047 | } |
| 2048 | } |
| 2049 | |
| 2050 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2051 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2052 | __ pop(ecx); |
| 2053 | __ push(edx); |
| 2054 | __ push(eax); |
| 2055 | __ push(ecx); |
| 2056 | } |
| 2057 | |
| 2058 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2059 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2060 | // TAGGED case: |
| 2061 | // Input: |
| 2062 | // esp[4]: tagged number input argument (should be number). |
| 2063 | // esp[0]: return address. |
| 2064 | // Output: |
| 2065 | // eax: tagged double result. |
| 2066 | // UNTAGGED case: |
| 2067 | // Input:: |
| 2068 | // esp[0]: return address. |
| 2069 | // xmm1: untagged double input argument |
| 2070 | // Output: |
| 2071 | // xmm1: untagged double result. |
| 2072 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2073 | Label runtime_call; |
| 2074 | Label runtime_call_clear_stack; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2075 | Label skip_cache; |
| 2076 | const bool tagged = (argument_type_ == TAGGED); |
| 2077 | if (tagged) { |
| 2078 | // Test that eax is a number. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2079 | Label input_not_smi; |
| 2080 | Label loaded; |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2081 | __ mov(eax, Operand(esp, kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2082 | __ JumpIfNotSmi(eax, &input_not_smi, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2083 | // Input is a smi. Untag and load it onto the FPU stack. |
| 2084 | // Then load the low and high words of the double into ebx, edx. |
| 2085 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2086 | __ sar(eax, 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2087 | __ sub(esp, Immediate(2 * kPointerSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2088 | __ mov(Operand(esp, 0), eax); |
| 2089 | __ fild_s(Operand(esp, 0)); |
| 2090 | __ fst_d(Operand(esp, 0)); |
| 2091 | __ pop(edx); |
| 2092 | __ pop(ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2093 | __ jmp(&loaded, Label::kNear); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2094 | __ bind(&input_not_smi); |
| 2095 | // Check if input is a HeapNumber. |
| 2096 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2097 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2098 | __ cmp(ebx, Immediate(factory->heap_number_map())); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2099 | __ j(not_equal, &runtime_call); |
| 2100 | // Input is a HeapNumber. Push it on the FPU stack and load its |
| 2101 | // low and high words into ebx, edx. |
| 2102 | __ fld_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2103 | __ mov(edx, FieldOperand(eax, HeapNumber::kExponentOffset)); |
| 2104 | __ mov(ebx, FieldOperand(eax, HeapNumber::kMantissaOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2105 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2106 | __ bind(&loaded); |
| 2107 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2108 | CpuFeatureScope scope(masm, SSE2); |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 2109 | if (CpuFeatures::IsSupported(SSE4_1)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2110 | CpuFeatureScope sse4_scope(masm, SSE4_1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2111 | __ pextrd(edx, xmm1, 0x1); // copy xmm1[63..32] to edx. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2112 | } else { |
| 2113 | __ pshufd(xmm0, xmm1, 0x1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2114 | __ movd(edx, xmm0); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2115 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2116 | __ movd(ebx, xmm1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | // ST[0] or xmm1 == double value |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2120 | // ebx = low 32 bits of double value |
| 2121 | // edx = high 32 bits of double value |
| 2122 | // Compute hash (the shifts are arithmetic): |
| 2123 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 2124 | __ mov(ecx, ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2125 | __ xor_(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2126 | __ mov(eax, ecx); |
| 2127 | __ sar(eax, 16); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2128 | __ xor_(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2129 | __ mov(eax, ecx); |
| 2130 | __ sar(eax, 8); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2131 | __ xor_(ecx, eax); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2132 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2133 | __ and_(ecx, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2134 | Immediate(TranscendentalCache::SubCache::kCacheSize - 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2135 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2136 | // ST[0] or xmm1 == double value. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2137 | // ebx = low 32 bits of double value. |
| 2138 | // edx = high 32 bits of double value. |
| 2139 | // ecx = TranscendentalCache::hash(double value). |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2140 | ExternalReference cache_array = |
| 2141 | ExternalReference::transcendental_cache_array_address(masm->isolate()); |
| 2142 | __ mov(eax, Immediate(cache_array)); |
| 2143 | int cache_array_index = |
| 2144 | type_ * sizeof(masm->isolate()->transcendental_cache()->caches_[0]); |
| 2145 | __ mov(eax, Operand(eax, cache_array_index)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2146 | // Eax points to the cache for the type type_. |
| 2147 | // 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] | 2148 | __ test(eax, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2149 | __ j(zero, &runtime_call_clear_stack); |
| 2150 | #ifdef DEBUG |
| 2151 | // Check that the layout of cache elements match expectations. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2152 | { TranscendentalCache::SubCache::Element test_elem[2]; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2153 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 2154 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 2155 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 2156 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 2157 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 2158 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 2159 | CHECK_EQ(0, elem_in0 - elem_start); |
| 2160 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 2161 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 2162 | } |
| 2163 | #endif |
| 2164 | // Find the address of the ecx'th entry in the cache, i.e., &eax[ecx*12]. |
| 2165 | __ lea(ecx, Operand(ecx, ecx, times_2, 0)); |
| 2166 | __ lea(ecx, Operand(eax, ecx, times_4, 0)); |
| 2167 | // 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] | 2168 | Label cache_miss; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2169 | __ cmp(ebx, Operand(ecx, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2170 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2171 | __ cmp(edx, Operand(ecx, kIntSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2172 | __ j(not_equal, &cache_miss, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2173 | // Cache hit! |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2174 | Counters* counters = masm->isolate()->counters(); |
| 2175 | __ IncrementCounter(counters->transcendental_cache_hit(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2176 | __ mov(eax, Operand(ecx, 2 * kIntSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2177 | if (tagged) { |
| 2178 | __ fstp(0); |
| 2179 | __ ret(kPointerSize); |
| 2180 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2181 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2182 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2183 | __ Ret(); |
| 2184 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2185 | |
| 2186 | __ bind(&cache_miss); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2187 | __ IncrementCounter(counters->transcendental_cache_miss(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2188 | // Update cache with new value. |
| 2189 | // We are short on registers, so use no_reg as scratch. |
| 2190 | // This gives slightly larger code. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2191 | if (tagged) { |
| 2192 | __ AllocateHeapNumber(eax, edi, no_reg, &runtime_call_clear_stack); |
| 2193 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2194 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2195 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2196 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2197 | __ movdbl(Operand(esp, 0), xmm1); |
| 2198 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2199 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2200 | } |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2201 | GenerateOperation(masm, type_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2202 | __ mov(Operand(ecx, 0), ebx); |
| 2203 | __ mov(Operand(ecx, kIntSize), edx); |
| 2204 | __ mov(Operand(ecx, 2 * kIntSize), eax); |
| 2205 | __ fstp_d(FieldOperand(eax, HeapNumber::kValueOffset)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2206 | if (tagged) { |
| 2207 | __ ret(kPointerSize); |
| 2208 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2209 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2210 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2211 | __ Ret(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2212 | |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2213 | // Skip cache and return answer directly, only in untagged case. |
| 2214 | __ bind(&skip_cache); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2215 | __ sub(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2216 | __ movdbl(Operand(esp, 0), xmm1); |
| 2217 | __ fld_d(Operand(esp, 0)); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2218 | GenerateOperation(masm, type_); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2219 | __ fstp_d(Operand(esp, 0)); |
| 2220 | __ movdbl(xmm1, Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2221 | __ add(esp, Immediate(kDoubleSize)); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2222 | // We return the value in xmm1 without adding it to the cache, but |
| 2223 | // 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] | 2224 | { |
| 2225 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2226 | // Allocate an unused object bigger than a HeapNumber. |
| 2227 | __ push(Immediate(Smi::FromInt(2 * kDoubleSize))); |
| 2228 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 2229 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2230 | __ Ret(); |
| 2231 | } |
| 2232 | |
| 2233 | // Call runtime, doing whatever allocation and cleanup is necessary. |
| 2234 | if (tagged) { |
| 2235 | __ bind(&runtime_call_clear_stack); |
| 2236 | __ fstp(0); |
| 2237 | __ bind(&runtime_call); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2238 | ExternalReference runtime = |
| 2239 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 2240 | __ TailCallExternalReference(runtime, 1, 1); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2241 | } else { // UNTAGGED. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2242 | CpuFeatureScope scope(masm, SSE2); |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2243 | __ bind(&runtime_call_clear_stack); |
| 2244 | __ bind(&runtime_call); |
| 2245 | __ AllocateHeapNumber(eax, edi, no_reg, &skip_cache); |
| 2246 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), xmm1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2247 | { |
| 2248 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2249 | __ push(eax); |
| 2250 | __ CallRuntime(RuntimeFunction(), 1); |
| 2251 | } |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2252 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2253 | __ Ret(); |
| 2254 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2255 | } |
| 2256 | |
| 2257 | |
| 2258 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 2259 | switch (type_) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2260 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 2261 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2262 | case TranscendentalCache::TAN: return Runtime::kMath_tan; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2263 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2264 | default: |
| 2265 | UNIMPLEMENTED(); |
| 2266 | return Runtime::kAbort; |
| 2267 | } |
| 2268 | } |
| 2269 | |
| 2270 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2271 | void TranscendentalCacheStub::GenerateOperation( |
| 2272 | MacroAssembler* masm, TranscendentalCache::Type type) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2273 | // Only free register is edi. |
whesse@chromium.org | 023421e | 2010-12-21 12:19:12 +0000 | [diff] [blame] | 2274 | // Input value is on FP stack, and also in ebx/edx. |
| 2275 | // Input value is possibly in xmm1. |
| 2276 | // Address of result (a newly allocated HeapNumber) may be in eax. |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2277 | if (type == TranscendentalCache::SIN || |
| 2278 | type == TranscendentalCache::COS || |
| 2279 | type == TranscendentalCache::TAN) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2280 | // Both fsin and fcos require arguments in the range +/-2^63 and |
| 2281 | // return NaN for infinities and NaN. They can share all code except |
| 2282 | // the actual fsin/fcos operation. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2283 | Label in_range, done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2284 | // If argument is outside the range -2^63..2^63, fsin/cos doesn't |
| 2285 | // work. We must reduce it to the appropriate range. |
| 2286 | __ mov(edi, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2287 | __ and_(edi, Immediate(0x7ff00000)); // Exponent only. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2288 | int supported_exponent_limit = |
| 2289 | (63 + HeapNumber::kExponentBias) << HeapNumber::kExponentShift; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2290 | __ cmp(edi, Immediate(supported_exponent_limit)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2291 | __ j(below, &in_range, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2292 | // Check for infinity and NaN. Both return NaN for sin. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2293 | __ cmp(edi, Immediate(0x7ff00000)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2294 | Label non_nan_result; |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2295 | __ j(not_equal, &non_nan_result, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2296 | // Input is +/-Infinity or NaN. Result is NaN. |
| 2297 | __ fstp(0); |
| 2298 | // NaN is represented by 0x7ff8000000000000. |
| 2299 | __ push(Immediate(0x7ff80000)); |
| 2300 | __ push(Immediate(0)); |
| 2301 | __ fld_d(Operand(esp, 0)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2302 | __ add(esp, Immediate(2 * kPointerSize)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2303 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2304 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2305 | __ bind(&non_nan_result); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2306 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2307 | // Use fpmod to restrict argument to the range +/-2*PI. |
| 2308 | __ mov(edi, eax); // Save eax before using fnstsw_ax. |
| 2309 | __ fldpi(); |
| 2310 | __ fadd(0); |
| 2311 | __ fld(1); |
| 2312 | // FPU Stack: input, 2*pi, input. |
| 2313 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2314 | Label no_exceptions; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2315 | __ fwait(); |
| 2316 | __ fnstsw_ax(); |
| 2317 | // Clear if Illegal Operand or Zero Division exceptions are set. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2318 | __ test(eax, Immediate(5)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2319 | __ j(zero, &no_exceptions, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2320 | __ fnclex(); |
| 2321 | __ bind(&no_exceptions); |
| 2322 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2323 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2324 | // Compute st(0) % st(1) |
| 2325 | { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2326 | Label partial_remainder_loop; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2327 | __ bind(&partial_remainder_loop); |
| 2328 | __ fprem1(); |
| 2329 | __ fwait(); |
| 2330 | __ fnstsw_ax(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2331 | __ test(eax, Immediate(0x400 /* C2 */)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2332 | // If C2 is set, computation only has partial result. Loop to |
| 2333 | // continue computation. |
| 2334 | __ j(not_zero, &partial_remainder_loop); |
| 2335 | } |
| 2336 | // FPU Stack: input, 2*pi, input % 2*pi |
| 2337 | __ fstp(2); |
| 2338 | __ fstp(0); |
| 2339 | __ mov(eax, edi); // Restore eax (allocated HeapNumber pointer). |
| 2340 | |
| 2341 | // FPU Stack: input % 2*pi |
| 2342 | __ bind(&in_range); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2343 | switch (type) { |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2344 | case TranscendentalCache::SIN: |
| 2345 | __ fsin(); |
| 2346 | break; |
| 2347 | case TranscendentalCache::COS: |
| 2348 | __ fcos(); |
| 2349 | break; |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2350 | case TranscendentalCache::TAN: |
| 2351 | // FPTAN calculates tangent onto st(0) and pushes 1.0 onto the |
| 2352 | // FP register stack. |
| 2353 | __ fptan(); |
| 2354 | __ fstp(0); // Pop FP register stack. |
| 2355 | break; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2356 | default: |
| 2357 | UNREACHABLE(); |
| 2358 | } |
| 2359 | __ bind(&done); |
| 2360 | } else { |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 2361 | ASSERT(type == TranscendentalCache::LOG); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2362 | __ fldln2(); |
| 2363 | __ fxch(); |
| 2364 | __ fyl2x(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2365 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2366 | } |
| 2367 | |
| 2368 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2369 | // Input: edx, eax are the left and right objects of a bit op. |
| 2370 | // 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] | 2371 | // Warning: can clobber inputs even when it jumps to |conversion_failure|! |
| 2372 | void FloatingPointHelper::LoadUnknownsAsIntegers( |
| 2373 | MacroAssembler* masm, |
| 2374 | bool use_sse3, |
| 2375 | BinaryOpIC::TypeInfo left_type, |
| 2376 | BinaryOpIC::TypeInfo right_type, |
| 2377 | Label* conversion_failure) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2378 | // Check float operands. |
| 2379 | Label arg1_is_object, check_undefined_arg1; |
| 2380 | Label arg2_is_object, check_undefined_arg2; |
| 2381 | Label load_arg2, done; |
| 2382 | |
| 2383 | // Test if arg1 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2384 | if (left_type == BinaryOpIC::SMI) { |
| 2385 | __ JumpIfNotSmi(edx, conversion_failure); |
| 2386 | } else { |
| 2387 | __ JumpIfNotSmi(edx, &arg1_is_object, Label::kNear); |
| 2388 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2389 | |
| 2390 | __ SmiUntag(edx); |
| 2391 | __ jmp(&load_arg2); |
| 2392 | |
| 2393 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2394 | __ bind(&check_undefined_arg1); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2395 | Factory* factory = masm->isolate()->factory(); |
| 2396 | __ cmp(edx, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2397 | __ j(not_equal, conversion_failure); |
| 2398 | __ mov(edx, Immediate(0)); |
| 2399 | __ jmp(&load_arg2); |
| 2400 | |
| 2401 | __ bind(&arg1_is_object); |
| 2402 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2403 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2404 | __ j(not_equal, &check_undefined_arg1); |
| 2405 | |
| 2406 | // Get the untagged integer version of the edx heap number in ecx. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2407 | if (left_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2408 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2409 | ConvertHeapNumberToInt32(masm, edx, conversion_failure); |
| 2410 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2411 | DoubleToIStub stub(edx, ecx, HeapNumber::kValueOffset - kHeapObjectTag, |
| 2412 | true); |
| 2413 | __ call(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2414 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2415 | __ mov(edx, ecx); |
| 2416 | |
| 2417 | // Here edx has the untagged integer, eax has a Smi or a heap number. |
| 2418 | __ bind(&load_arg2); |
| 2419 | |
| 2420 | // Test if arg2 is a Smi. |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2421 | if (right_type == BinaryOpIC::SMI) { |
| 2422 | __ JumpIfNotSmi(eax, conversion_failure); |
| 2423 | } else { |
| 2424 | __ JumpIfNotSmi(eax, &arg2_is_object, Label::kNear); |
| 2425 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2426 | |
| 2427 | __ SmiUntag(eax); |
| 2428 | __ mov(ecx, eax); |
| 2429 | __ jmp(&done); |
| 2430 | |
| 2431 | // If the argument is undefined it converts to zero (ECMA-262, section 9.5). |
| 2432 | __ bind(&check_undefined_arg2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2433 | __ cmp(eax, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2434 | __ j(not_equal, conversion_failure); |
| 2435 | __ mov(ecx, Immediate(0)); |
| 2436 | __ jmp(&done); |
| 2437 | |
| 2438 | __ bind(&arg2_is_object); |
| 2439 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2440 | __ cmp(ebx, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2441 | __ j(not_equal, &check_undefined_arg2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2442 | // 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] | 2443 | |
| 2444 | if (right_type == BinaryOpIC::INT32 && CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2445 | CpuFeatureScope use_sse2(masm, SSE2); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2446 | ConvertHeapNumberToInt32(masm, eax, conversion_failure); |
| 2447 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 2448 | DoubleToIStub stub(eax, ecx, HeapNumber::kValueOffset - kHeapObjectTag, |
| 2449 | true); |
| 2450 | __ call(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2451 | } |
| 2452 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2453 | __ bind(&done); |
| 2454 | __ mov(eax, edx); |
| 2455 | } |
| 2456 | |
| 2457 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2458 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 2459 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2460 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2461 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2462 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2463 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2464 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2465 | |
| 2466 | __ bind(&load_smi); |
| 2467 | __ SmiUntag(number); |
| 2468 | __ push(number); |
| 2469 | __ fild_s(Operand(esp, 0)); |
| 2470 | __ pop(number); |
| 2471 | |
| 2472 | __ bind(&done); |
| 2473 | } |
| 2474 | |
| 2475 | |
| 2476 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2477 | Label load_smi_edx, load_eax, load_smi_eax, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2478 | // Load operand in edx into xmm0. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2479 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2480 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2481 | |
| 2482 | __ bind(&load_eax); |
| 2483 | // Load operand in eax into xmm1. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2484 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2485 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2486 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2487 | |
| 2488 | __ bind(&load_smi_edx); |
| 2489 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2490 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2491 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2492 | __ jmp(&load_eax); |
| 2493 | |
| 2494 | __ bind(&load_smi_eax); |
| 2495 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2496 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2497 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
| 2498 | |
| 2499 | __ bind(&done); |
| 2500 | } |
| 2501 | |
| 2502 | |
| 2503 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 2504 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2505 | 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] | 2506 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2507 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2508 | Factory* factory = masm->isolate()->factory(); |
| 2509 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2510 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
| 2511 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 2512 | __ bind(&load_eax); |
| 2513 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2514 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2515 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2516 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2517 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 2518 | __ bind(&load_smi_edx); |
| 2519 | __ SmiUntag(edx); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2520 | __ cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2521 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 2522 | __ jmp(&load_eax); |
| 2523 | __ bind(&load_smi_eax); |
| 2524 | __ SmiUntag(eax); // Untag smi before converting to float. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2525 | __ cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2526 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2527 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2528 | __ bind(&load_float_eax); |
| 2529 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
| 2530 | __ bind(&done); |
| 2531 | } |
| 2532 | |
| 2533 | |
| 2534 | void FloatingPointHelper::LoadSSE2Smis(MacroAssembler* masm, |
| 2535 | Register scratch) { |
| 2536 | const Register left = edx; |
| 2537 | const Register right = eax; |
| 2538 | __ mov(scratch, left); |
| 2539 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2540 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2541 | __ cvtsi2sd(xmm0, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2542 | |
| 2543 | __ mov(scratch, right); |
| 2544 | __ SmiUntag(scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2545 | __ cvtsi2sd(xmm1, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2549 | void FloatingPointHelper::CheckSSE2OperandIsInt32(MacroAssembler* masm, |
| 2550 | Label* non_int32, |
| 2551 | XMMRegister operand, |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2552 | Register int32_result, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2553 | Register scratch, |
| 2554 | XMMRegister xmm_scratch) { |
hpayer@chromium.org | 7c3372b | 2013-02-13 17:26:04 +0000 | [diff] [blame] | 2555 | __ cvttsd2si(int32_result, Operand(operand)); |
| 2556 | __ cvtsi2sd(xmm_scratch, int32_result); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2557 | __ pcmpeqd(xmm_scratch, operand); |
ulan@chromium.org | 4121f23 | 2012-12-27 15:57:11 +0000 | [diff] [blame] | 2558 | __ movmskps(scratch, xmm_scratch); |
| 2559 | // Two least significant bits should be both set. |
| 2560 | __ not_(scratch); |
| 2561 | __ test(scratch, Immediate(3)); |
| 2562 | __ j(not_zero, non_int32); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2566 | void FloatingPointHelper::LoadFloatOperands(MacroAssembler* masm, |
| 2567 | Register scratch, |
| 2568 | ArgLocation arg_location) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2569 | Label load_smi_1, load_smi_2, done_load_1, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2570 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2571 | __ mov(scratch, edx); |
| 2572 | } else { |
| 2573 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 2574 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2575 | __ JumpIfSmi(scratch, &load_smi_1, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2576 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
| 2577 | __ bind(&done_load_1); |
| 2578 | |
| 2579 | if (arg_location == ARGS_IN_REGISTERS) { |
| 2580 | __ mov(scratch, eax); |
| 2581 | } else { |
| 2582 | __ mov(scratch, Operand(esp, 1 * kPointerSize)); |
| 2583 | } |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2584 | __ JumpIfSmi(scratch, &load_smi_2, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2585 | __ fld_d(FieldOperand(scratch, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2586 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2587 | |
| 2588 | __ bind(&load_smi_1); |
| 2589 | __ SmiUntag(scratch); |
| 2590 | __ push(scratch); |
| 2591 | __ fild_s(Operand(esp, 0)); |
| 2592 | __ pop(scratch); |
| 2593 | __ jmp(&done_load_1); |
| 2594 | |
| 2595 | __ bind(&load_smi_2); |
| 2596 | __ SmiUntag(scratch); |
| 2597 | __ push(scratch); |
| 2598 | __ fild_s(Operand(esp, 0)); |
| 2599 | __ pop(scratch); |
| 2600 | |
| 2601 | __ bind(&done); |
| 2602 | } |
| 2603 | |
| 2604 | |
| 2605 | void FloatingPointHelper::LoadFloatSmis(MacroAssembler* masm, |
| 2606 | Register scratch) { |
| 2607 | const Register left = edx; |
| 2608 | const Register right = eax; |
| 2609 | __ mov(scratch, left); |
| 2610 | ASSERT(!scratch.is(right)); // We're about to clobber scratch. |
| 2611 | __ SmiUntag(scratch); |
| 2612 | __ push(scratch); |
| 2613 | __ fild_s(Operand(esp, 0)); |
| 2614 | |
| 2615 | __ mov(scratch, right); |
| 2616 | __ SmiUntag(scratch); |
| 2617 | __ mov(Operand(esp, 0), scratch); |
| 2618 | __ fild_s(Operand(esp, 0)); |
| 2619 | __ pop(scratch); |
| 2620 | } |
| 2621 | |
| 2622 | |
| 2623 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 2624 | Label* non_float, |
| 2625 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2626 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2627 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 2628 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2629 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2630 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2631 | Factory* factory = masm->isolate()->factory(); |
| 2632 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2633 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 2634 | |
| 2635 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2636 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2637 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2638 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2639 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 2640 | |
| 2641 | // Fall-through: Both operands are numbers. |
| 2642 | __ bind(&done); |
| 2643 | } |
| 2644 | |
| 2645 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2646 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2647 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2648 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2649 | const Register exponent = eax; |
| 2650 | const Register base = edx; |
| 2651 | const Register scratch = ecx; |
| 2652 | const XMMRegister double_result = xmm3; |
| 2653 | const XMMRegister double_base = xmm2; |
| 2654 | const XMMRegister double_exponent = xmm1; |
| 2655 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2656 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2657 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2658 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2659 | // Save 1 in double_result - we need this several times later on. |
| 2660 | __ mov(scratch, Immediate(1)); |
| 2661 | __ cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2662 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2663 | if (exponent_type_ == ON_STACK) { |
| 2664 | Label base_is_smi, unpack_exponent; |
| 2665 | // The exponent and base are supplied as arguments on the stack. |
| 2666 | // This can only happen if the stub is called from non-optimized code. |
| 2667 | // Load input parameters from stack. |
| 2668 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 2669 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 2670 | |
| 2671 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 2672 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 2673 | factory->heap_number_map()); |
| 2674 | __ j(not_equal, &call_runtime); |
| 2675 | |
| 2676 | __ movdbl(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
| 2677 | __ jmp(&unpack_exponent, Label::kNear); |
| 2678 | |
| 2679 | __ bind(&base_is_smi); |
| 2680 | __ SmiUntag(base); |
| 2681 | __ cvtsi2sd(double_base, base); |
| 2682 | |
| 2683 | __ bind(&unpack_exponent); |
| 2684 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2685 | __ SmiUntag(exponent); |
| 2686 | __ jmp(&int_exponent); |
| 2687 | |
| 2688 | __ bind(&exponent_not_smi); |
| 2689 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 2690 | factory->heap_number_map()); |
| 2691 | __ j(not_equal, &call_runtime); |
| 2692 | __ movdbl(double_exponent, |
| 2693 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2694 | } else if (exponent_type_ == TAGGED) { |
| 2695 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 2696 | __ SmiUntag(exponent); |
| 2697 | __ jmp(&int_exponent); |
| 2698 | |
| 2699 | __ bind(&exponent_not_smi); |
| 2700 | __ movdbl(double_exponent, |
| 2701 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 2702 | } |
| 2703 | |
| 2704 | if (exponent_type_ != INTEGER) { |
| 2705 | Label fast_power; |
| 2706 | // Detect integer exponents stored as double. |
| 2707 | __ cvttsd2si(exponent, Operand(double_exponent)); |
| 2708 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
| 2709 | __ cmp(exponent, Immediate(0x80000000u)); |
| 2710 | __ j(equal, &call_runtime); |
| 2711 | __ cvtsi2sd(double_scratch, exponent); |
| 2712 | // Already ruled out NaNs for exponent. |
| 2713 | __ ucomisd(double_exponent, double_scratch); |
| 2714 | __ j(equal, &int_exponent); |
| 2715 | |
| 2716 | if (exponent_type_ == ON_STACK) { |
| 2717 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 2718 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 2719 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 2720 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 2721 | // Test for 0.5. |
| 2722 | // Load double_scratch with 0.5. |
| 2723 | __ mov(scratch, Immediate(0x3F000000u)); |
| 2724 | __ movd(double_scratch, scratch); |
| 2725 | __ cvtss2sd(double_scratch, double_scratch); |
| 2726 | // Already ruled out NaNs for exponent. |
| 2727 | __ ucomisd(double_scratch, double_exponent); |
| 2728 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 2729 | |
| 2730 | // Calculates square root of base. Check for the special case of |
| 2731 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 2732 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2733 | // 9 bits set and the lowest 23 bits cleared. |
| 2734 | __ mov(scratch, 0xFF800000u); |
| 2735 | __ movd(double_scratch, scratch); |
| 2736 | __ cvtss2sd(double_scratch, double_scratch); |
| 2737 | __ ucomisd(double_base, double_scratch); |
| 2738 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2739 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2740 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 2741 | __ j(carry, &continue_sqrt, Label::kNear); |
| 2742 | |
| 2743 | // Set result to Infinity in the special case. |
| 2744 | __ xorps(double_result, double_result); |
| 2745 | __ subsd(double_result, double_scratch); |
| 2746 | __ jmp(&done); |
| 2747 | |
| 2748 | __ bind(&continue_sqrt); |
| 2749 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2750 | __ xorps(double_scratch, double_scratch); |
| 2751 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 2752 | __ sqrtsd(double_result, double_scratch); |
| 2753 | __ jmp(&done); |
| 2754 | |
| 2755 | // Test for -0.5. |
| 2756 | __ bind(¬_plus_half); |
| 2757 | // Load double_exponent with -0.5 by substracting 1. |
| 2758 | __ subsd(double_scratch, double_result); |
| 2759 | // Already ruled out NaNs for exponent. |
| 2760 | __ ucomisd(double_scratch, double_exponent); |
| 2761 | __ j(not_equal, &fast_power, Label::kNear); |
| 2762 | |
| 2763 | // Calculates reciprocal of square root of base. Check for the special |
| 2764 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 2765 | // According to IEEE-754, single-precision -Infinity has the highest |
| 2766 | // 9 bits set and the lowest 23 bits cleared. |
| 2767 | __ mov(scratch, 0xFF800000u); |
| 2768 | __ movd(double_scratch, scratch); |
| 2769 | __ cvtss2sd(double_scratch, double_scratch); |
| 2770 | __ ucomisd(double_base, double_scratch); |
| 2771 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 2772 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 2773 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 2774 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 2775 | |
| 2776 | // Set result to 0 in the special case. |
| 2777 | __ xorps(double_result, double_result); |
| 2778 | __ jmp(&done); |
| 2779 | |
| 2780 | __ bind(&continue_rsqrt); |
| 2781 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 2782 | __ xorps(double_exponent, double_exponent); |
| 2783 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 2784 | __ sqrtsd(double_exponent, double_exponent); |
| 2785 | __ divsd(double_result, double_exponent); |
| 2786 | __ jmp(&done); |
| 2787 | } |
| 2788 | |
| 2789 | // Using FPU instructions to calculate power. |
| 2790 | Label fast_power_failed; |
| 2791 | __ bind(&fast_power); |
| 2792 | __ fnclex(); // Clear flags to catch exceptions later. |
| 2793 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 2794 | __ sub(esp, Immediate(kDoubleSize)); |
| 2795 | __ movdbl(Operand(esp, 0), double_exponent); |
| 2796 | __ fld_d(Operand(esp, 0)); // E |
| 2797 | __ movdbl(Operand(esp, 0), double_base); |
| 2798 | __ fld_d(Operand(esp, 0)); // B, E |
| 2799 | |
| 2800 | // Exponent is in st(1) and base is in st(0) |
| 2801 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 2802 | // FYL2X calculates st(1) * log2(st(0)) |
| 2803 | __ fyl2x(); // X |
| 2804 | __ fld(0); // X, X |
| 2805 | __ frndint(); // rnd(X), X |
| 2806 | __ fsub(1); // rnd(X), X-rnd(X) |
| 2807 | __ fxch(1); // X - rnd(X), rnd(X) |
| 2808 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 2809 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 2810 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2811 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2812 | // FSCALE calculates st(0) * 2^st(1) |
| 2813 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 2814 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2815 | // Bail out to runtime in case of exceptions in the status word. |
| 2816 | __ fnstsw_ax(); |
| 2817 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 2818 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 2819 | __ fstp_d(Operand(esp, 0)); |
| 2820 | __ movdbl(double_result, Operand(esp, 0)); |
| 2821 | __ add(esp, Immediate(kDoubleSize)); |
| 2822 | __ jmp(&done); |
| 2823 | |
| 2824 | __ bind(&fast_power_failed); |
| 2825 | __ fninit(); |
| 2826 | __ add(esp, Immediate(kDoubleSize)); |
| 2827 | __ jmp(&call_runtime); |
| 2828 | } |
| 2829 | |
| 2830 | // Calculate power with integer exponent. |
| 2831 | __ bind(&int_exponent); |
| 2832 | const XMMRegister double_scratch2 = double_exponent; |
| 2833 | __ mov(scratch, exponent); // Back up exponent. |
| 2834 | __ movsd(double_scratch, double_base); // Back up base. |
| 2835 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2836 | |
| 2837 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 2838 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2839 | __ test(scratch, scratch); |
| 2840 | __ j(positive, &no_neg, Label::kNear); |
| 2841 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2842 | __ bind(&no_neg); |
| 2843 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2844 | __ j(zero, &while_false, Label::kNear); |
| 2845 | __ shr(scratch, 1); |
| 2846 | // Above condition means CF==0 && ZF==0. This means that the |
| 2847 | // bit that has been shifted out is 0 and the result is not 0. |
| 2848 | __ j(above, &while_true, Label::kNear); |
| 2849 | __ movsd(double_result, double_scratch); |
| 2850 | __ j(zero, &while_false, Label::kNear); |
| 2851 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2852 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2853 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2854 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2855 | __ j(above, &while_true, Label::kNear); |
| 2856 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2857 | __ j(not_zero, &while_true); |
| 2858 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2859 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2860 | // scratch has the original value of the exponent - if the exponent is |
| 2861 | // negative, return 1/result. |
| 2862 | __ test(exponent, exponent); |
| 2863 | __ j(positive, &done); |
| 2864 | __ divsd(double_scratch2, double_result); |
| 2865 | __ movsd(double_result, double_scratch2); |
| 2866 | // Test whether result is zero. Bail out to check for subnormal result. |
| 2867 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 2868 | __ xorps(double_scratch2, double_scratch2); |
| 2869 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 2870 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 2871 | // and may not have contained the exponent value in the first place when the |
| 2872 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 2873 | __ j(not_equal, &done); |
| 2874 | __ cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2875 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2876 | // Returning or bailing out. |
| 2877 | Counters* counters = masm->isolate()->counters(); |
| 2878 | if (exponent_type_ == ON_STACK) { |
| 2879 | // The arguments are still on the stack. |
| 2880 | __ bind(&call_runtime); |
| 2881 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2882 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2883 | // The stub is called from non-optimized code, which expects the result |
| 2884 | // as heap number in exponent. |
| 2885 | __ bind(&done); |
| 2886 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
| 2887 | __ movdbl(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
| 2888 | __ IncrementCounter(counters->math_pow(), 1); |
| 2889 | __ ret(2 * kPointerSize); |
| 2890 | } else { |
| 2891 | __ bind(&call_runtime); |
| 2892 | { |
| 2893 | AllowExternalCallThatCantCauseGC scope(masm); |
| 2894 | __ PrepareCallCFunction(4, scratch); |
| 2895 | __ movdbl(Operand(esp, 0 * kDoubleSize), double_base); |
| 2896 | __ movdbl(Operand(esp, 1 * kDoubleSize), double_exponent); |
| 2897 | __ CallCFunction( |
| 2898 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 2899 | } |
| 2900 | // Return value is in st(0) on ia32. |
| 2901 | // Store it into the (fixed) result register. |
| 2902 | __ sub(esp, Immediate(kDoubleSize)); |
| 2903 | __ fstp_d(Operand(esp, 0)); |
| 2904 | __ movdbl(double_result, Operand(esp, 0)); |
| 2905 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2906 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 2907 | __ bind(&done); |
| 2908 | __ IncrementCounter(counters->math_pow(), 1); |
| 2909 | __ ret(0); |
| 2910 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2914 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 2915 | // ----------- S t a t e ------------- |
| 2916 | // -- ecx : name |
| 2917 | // -- edx : receiver |
| 2918 | // -- esp[0] : return address |
| 2919 | // ----------------------------------- |
| 2920 | Label miss; |
| 2921 | |
| 2922 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2923 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2924 | __ j(not_equal, &miss); |
| 2925 | } |
| 2926 | |
| 2927 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 2928 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2929 | StubCompiler::TailCallBuiltin( |
| 2930 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2931 | } |
| 2932 | |
| 2933 | |
| 2934 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 2935 | // ----------- S t a t e ------------- |
| 2936 | // -- ecx : name |
| 2937 | // -- edx : receiver |
| 2938 | // -- esp[0] : return address |
| 2939 | // ----------------------------------- |
| 2940 | Label miss; |
| 2941 | |
| 2942 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2943 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2944 | __ j(not_equal, &miss); |
| 2945 | } |
| 2946 | |
| 2947 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss, |
| 2948 | support_wrapper_); |
| 2949 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2950 | StubCompiler::TailCallBuiltin( |
| 2951 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 2952 | } |
| 2953 | |
| 2954 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2955 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 2956 | // ----------- S t a t e ------------- |
| 2957 | // -- eax : value |
| 2958 | // -- ecx : name |
| 2959 | // -- edx : receiver |
| 2960 | // -- esp[0] : return address |
| 2961 | // ----------------------------------- |
| 2962 | // |
| 2963 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 2964 | // (currently anything except for external arrays which means anything with |
| 2965 | // elements of FixedArray type). Value must be a number, but only smis are |
| 2966 | // accepted as the most common case. |
| 2967 | |
| 2968 | Label miss; |
| 2969 | |
| 2970 | Register receiver = edx; |
| 2971 | Register value = eax; |
| 2972 | Register scratch = ebx; |
| 2973 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2974 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2975 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 2976 | __ j(not_equal, &miss); |
| 2977 | } |
| 2978 | |
| 2979 | // Check that the receiver isn't a smi. |
| 2980 | __ JumpIfSmi(receiver, &miss); |
| 2981 | |
| 2982 | // Check that the object is a JS array. |
| 2983 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 2984 | __ j(not_equal, &miss); |
| 2985 | |
| 2986 | // Check that elements are FixedArray. |
| 2987 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 2988 | // fast elements (including COW). |
| 2989 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 2990 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 2991 | __ j(not_equal, &miss); |
| 2992 | |
| 2993 | // Check that the array has fast properties, otherwise the length |
| 2994 | // property might have been redefined. |
| 2995 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 2996 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 2997 | Heap::kHashTableMapRootIndex); |
| 2998 | __ j(equal, &miss); |
| 2999 | |
| 3000 | // Check that value is a smi. |
| 3001 | __ JumpIfNotSmi(value, &miss); |
| 3002 | |
| 3003 | // Prepare tail call to StoreIC_ArrayLength. |
| 3004 | __ pop(scratch); |
| 3005 | __ push(receiver); |
| 3006 | __ push(value); |
| 3007 | __ push(scratch); // return address |
| 3008 | |
| 3009 | ExternalReference ref = |
| 3010 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 3011 | __ TailCallExternalReference(ref, 2, 1); |
| 3012 | |
| 3013 | __ bind(&miss); |
| 3014 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 3015 | StubCompiler::TailCallBuiltin( |
| 3016 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 3017 | } |
| 3018 | |
| 3019 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3020 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3021 | // The key is in edx and the parameter count is in eax. |
| 3022 | |
| 3023 | // The displacement is used for skipping the frame pointer on the |
| 3024 | // stack. It is the offset of the last parameter (if any) relative |
| 3025 | // to the frame pointer. |
| 3026 | static const int kDisplacement = 1 * kPointerSize; |
| 3027 | |
| 3028 | // Check that the key is a smi. |
| 3029 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3030 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3031 | |
| 3032 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3033 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3034 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3035 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3036 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3037 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3038 | |
| 3039 | // Check index against formal parameters count limit passed in |
| 3040 | // through register eax. Use unsigned comparison to get negative |
| 3041 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3042 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3043 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3044 | |
| 3045 | // Read the argument from the stack and return it. |
| 3046 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3047 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3048 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 3049 | __ neg(edx); |
| 3050 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3051 | __ ret(0); |
| 3052 | |
| 3053 | // Arguments adaptor case: Check index against actual arguments |
| 3054 | // limit found in the arguments adaptor frame. Use unsigned |
| 3055 | // comparison to get negative check for free. |
| 3056 | __ bind(&adaptor); |
| 3057 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3058 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3059 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3060 | |
| 3061 | // Read the argument from the stack and return it. |
| 3062 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3063 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 3064 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 3065 | __ neg(edx); |
| 3066 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 3067 | __ ret(0); |
| 3068 | |
| 3069 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3070 | // by calling the runtime system. |
| 3071 | __ bind(&slow); |
| 3072 | __ pop(ebx); // Return address. |
| 3073 | __ push(edx); |
| 3074 | __ push(ebx); |
| 3075 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3076 | } |
| 3077 | |
| 3078 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3079 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3080 | // esp[0] : return address |
| 3081 | // esp[4] : number of parameters |
| 3082 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3083 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3084 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3085 | // Check if the calling frame is an arguments adaptor frame. |
| 3086 | Label runtime; |
| 3087 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3088 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3089 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3090 | __ j(not_equal, &runtime, Label::kNear); |
| 3091 | |
| 3092 | // Patch the arguments.length and the parameters pointer. |
| 3093 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3094 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 3095 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3096 | StandardFrameConstants::kCallerSPOffset)); |
| 3097 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3098 | |
| 3099 | __ bind(&runtime); |
| 3100 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3101 | } |
| 3102 | |
| 3103 | |
| 3104 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3105 | Isolate* isolate = masm->isolate(); |
| 3106 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3107 | // esp[0] : return address |
| 3108 | // esp[4] : number of parameters (tagged) |
| 3109 | // esp[8] : receiver displacement |
| 3110 | // esp[12] : function |
| 3111 | |
| 3112 | // ebx = parameter count (tagged) |
| 3113 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3114 | |
| 3115 | // Check if the calling frame is an arguments adaptor frame. |
| 3116 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 3117 | // Generate* functions. |
| 3118 | Label runtime; |
| 3119 | Label adaptor_frame, try_allocate; |
| 3120 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3121 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3122 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3123 | __ j(equal, &adaptor_frame, Label::kNear); |
| 3124 | |
| 3125 | // No adaptor, parameter count = argument count. |
| 3126 | __ mov(ecx, ebx); |
| 3127 | __ jmp(&try_allocate, Label::kNear); |
| 3128 | |
| 3129 | // We have an adaptor frame. Patch the parameters pointer. |
| 3130 | __ bind(&adaptor_frame); |
| 3131 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3132 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3133 | StandardFrameConstants::kCallerSPOffset)); |
| 3134 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3135 | |
| 3136 | // ebx = parameter count (tagged) |
| 3137 | // ecx = argument count (tagged) |
| 3138 | // esp[4] = parameter count (tagged) |
| 3139 | // esp[8] = address of receiver argument |
| 3140 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3141 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3142 | __ j(less_equal, &try_allocate, Label::kNear); |
| 3143 | __ mov(ebx, ecx); |
| 3144 | |
| 3145 | __ bind(&try_allocate); |
| 3146 | |
| 3147 | // Save mapped parameter count. |
| 3148 | __ push(ebx); |
| 3149 | |
| 3150 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3151 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3152 | const int kParameterMapHeaderSize = |
| 3153 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3154 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3155 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3156 | __ j(zero, &no_parameter_map, Label::kNear); |
| 3157 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 3158 | __ bind(&no_parameter_map); |
| 3159 | |
| 3160 | // 2. Backing store. |
| 3161 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 3162 | |
| 3163 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3164 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3165 | |
| 3166 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3167 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3168 | |
| 3169 | // eax = address of new object(s) (tagged) |
| 3170 | // ecx = argument count (tagged) |
| 3171 | // esp[0] = mapped parameter count (tagged) |
| 3172 | // esp[8] = parameter count (tagged) |
| 3173 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3174 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3175 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3176 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3177 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3178 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3179 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3180 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 3181 | __ mov(edi, Operand(edi, |
| 3182 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 3183 | __ jmp(©, Label::kNear); |
| 3184 | |
| 3185 | __ bind(&has_mapped_parameters); |
| 3186 | __ mov(edi, Operand(edi, |
| 3187 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 3188 | __ bind(©); |
| 3189 | |
| 3190 | // eax = address of new object (tagged) |
| 3191 | // ebx = mapped parameter count (tagged) |
| 3192 | // ecx = argument count (tagged) |
| 3193 | // edi = address of boilerplate object (tagged) |
| 3194 | // esp[0] = mapped parameter count (tagged) |
| 3195 | // esp[8] = parameter count (tagged) |
| 3196 | // esp[12] = address of receiver argument |
| 3197 | // Copy the JS object part. |
| 3198 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3199 | __ mov(edx, FieldOperand(edi, i)); |
| 3200 | __ mov(FieldOperand(eax, i), edx); |
| 3201 | } |
| 3202 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3203 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3204 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 3205 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 3206 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3207 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 3208 | edx); |
| 3209 | |
| 3210 | // Use the length (smi tagged) and set that as an in-object property too. |
| 3211 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 3212 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 3213 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 3214 | ecx); |
| 3215 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3216 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3217 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 3218 | // backing store. |
| 3219 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 3220 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3221 | |
| 3222 | // eax = address of new object (tagged) |
| 3223 | // ebx = mapped parameter count (tagged) |
| 3224 | // ecx = argument count (tagged) |
| 3225 | // edi = address of parameter map or backing store (tagged) |
| 3226 | // esp[0] = mapped parameter count (tagged) |
| 3227 | // esp[8] = parameter count (tagged) |
| 3228 | // esp[12] = address of receiver argument |
| 3229 | // Free a register. |
| 3230 | __ push(eax); |
| 3231 | |
| 3232 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 3233 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3234 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3235 | __ j(zero, &skip_parameter_map); |
| 3236 | |
| 3237 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3238 | Immediate(isolate->factory()->non_strict_arguments_elements_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3239 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 3240 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 3241 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 3242 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 3243 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 3244 | |
| 3245 | // Copy the parameter slots and the holes in the arguments. |
| 3246 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 3247 | // where parameters are stored in reverse order, at |
| 3248 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 3249 | // The mapped parameter thus need to get indices |
| 3250 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 3251 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 3252 | // We loop from right to left. |
| 3253 | Label parameters_loop, parameters_test; |
| 3254 | __ push(ecx); |
| 3255 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 3256 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 3257 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3258 | __ sub(ebx, eax); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3259 | __ mov(ecx, isolate->factory()->the_hole_value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3260 | __ mov(edx, edi); |
| 3261 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 3262 | // eax = loop variable (tagged) |
| 3263 | // ebx = mapping index (tagged) |
| 3264 | // ecx = the hole value |
| 3265 | // edx = address of parameter map (tagged) |
| 3266 | // edi = address of backing store (tagged) |
| 3267 | // esp[0] = argument count (tagged) |
| 3268 | // esp[4] = address of new object (tagged) |
| 3269 | // esp[8] = mapped parameter count (tagged) |
| 3270 | // esp[16] = parameter count (tagged) |
| 3271 | // esp[20] = address of receiver argument |
| 3272 | __ jmp(¶meters_test, Label::kNear); |
| 3273 | |
| 3274 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3275 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3276 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 3277 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3278 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3279 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3280 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3281 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 3282 | __ pop(ecx); |
| 3283 | |
| 3284 | __ bind(&skip_parameter_map); |
| 3285 | |
| 3286 | // ecx = argument count (tagged) |
| 3287 | // edi = address of backing store (tagged) |
| 3288 | // esp[0] = address of new object (tagged) |
| 3289 | // esp[4] = mapped parameter count (tagged) |
| 3290 | // esp[12] = parameter count (tagged) |
| 3291 | // esp[16] = address of receiver argument |
| 3292 | // Copy arguments header and remaining slots (if there are any). |
| 3293 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3294 | Immediate(isolate->factory()->fixed_array_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3295 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3296 | |
| 3297 | Label arguments_loop, arguments_test; |
| 3298 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 3299 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3300 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 3301 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3302 | __ jmp(&arguments_test, Label::kNear); |
| 3303 | |
| 3304 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3305 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3306 | __ mov(eax, Operand(edx, 0)); |
| 3307 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3308 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3309 | |
| 3310 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3311 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3312 | __ j(less, &arguments_loop, Label::kNear); |
| 3313 | |
| 3314 | // Restore. |
| 3315 | __ pop(eax); // Address of arguments object. |
| 3316 | __ pop(ebx); // Parameter count. |
| 3317 | |
| 3318 | // Return and remove the on-stack parameters. |
| 3319 | __ ret(3 * kPointerSize); |
| 3320 | |
| 3321 | // Do the runtime call to allocate the arguments object. |
| 3322 | __ bind(&runtime); |
| 3323 | __ pop(eax); // Remove saved parameter count. |
| 3324 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 3325 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3326 | } |
| 3327 | |
| 3328 | |
| 3329 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3330 | Isolate* isolate = masm->isolate(); |
| 3331 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3332 | // esp[0] : return address |
| 3333 | // esp[4] : number of parameters |
| 3334 | // esp[8] : receiver displacement |
| 3335 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3336 | |
| 3337 | // Check if the calling frame is an arguments adaptor frame. |
| 3338 | Label adaptor_frame, try_allocate, runtime; |
| 3339 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 3340 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3341 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3342 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3343 | |
| 3344 | // Get the length from the frame. |
| 3345 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3346 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3347 | |
| 3348 | // Patch the arguments.length and the parameters pointer. |
| 3349 | __ bind(&adaptor_frame); |
| 3350 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3351 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3352 | __ lea(edx, Operand(edx, ecx, times_2, |
| 3353 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3354 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 3355 | |
| 3356 | // Try the new space allocation. Start out with computing the size of |
| 3357 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3358 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3359 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3360 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3361 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3362 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 3363 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3364 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3365 | |
| 3366 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3367 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3368 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3369 | // Get the arguments boilerplate from the current native context. |
| 3370 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 3371 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3372 | const int offset = |
| 3373 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 3374 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3375 | |
| 3376 | // Copy the JS object part. |
| 3377 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 3378 | __ mov(ebx, FieldOperand(edi, i)); |
| 3379 | __ mov(FieldOperand(eax, i), ebx); |
| 3380 | } |
| 3381 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3382 | // 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] | 3383 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3384 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3385 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3386 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3387 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3388 | |
| 3389 | // If there are no actual arguments, we're done. |
| 3390 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3391 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3392 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3393 | |
| 3394 | // Get the parameters pointer from the stack. |
| 3395 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 3396 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3397 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3398 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3399 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3400 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 3401 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 3402 | Immediate(isolate->factory()->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3403 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3404 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 3405 | // Untag the length for the loop below. |
| 3406 | __ SmiUntag(ecx); |
| 3407 | |
| 3408 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3409 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3410 | __ bind(&loop); |
| 3411 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 3412 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3413 | __ add(edi, Immediate(kPointerSize)); |
| 3414 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3415 | __ dec(ecx); |
| 3416 | __ j(not_zero, &loop); |
| 3417 | |
| 3418 | // Return and remove the on-stack parameters. |
| 3419 | __ bind(&done); |
| 3420 | __ ret(3 * kPointerSize); |
| 3421 | |
| 3422 | // Do the runtime call to allocate the arguments object. |
| 3423 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3424 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | |
| 3428 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 3429 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 3430 | // time or if regexp entry in generated code is turned off runtime switch or |
| 3431 | // at compilation. |
| 3432 | #ifdef V8_INTERPRETED_REGEXP |
| 3433 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3434 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3435 | |
| 3436 | // Stack frame on entry. |
| 3437 | // esp[0]: return address |
| 3438 | // esp[4]: last_match_info (expected JSArray) |
| 3439 | // esp[8]: previous index |
| 3440 | // esp[12]: subject string |
| 3441 | // esp[16]: JSRegExp object |
| 3442 | |
| 3443 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 3444 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 3445 | static const int kSubjectOffset = 3 * kPointerSize; |
| 3446 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 3447 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3448 | Label runtime; |
| 3449 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3450 | |
| 3451 | // Ensure that a RegExp stack is allocated. |
| 3452 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3453 | ExternalReference::address_of_regexp_stack_memory_address( |
| 3454 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3455 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3456 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3457 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3458 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3459 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3460 | |
| 3461 | // Check that the first argument is a JSRegExp object. |
| 3462 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3463 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3464 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3465 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 3466 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3467 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3468 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 3469 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3470 | if (FLAG_debug_code) { |
| 3471 | __ test(ecx, Immediate(kSmiTagMask)); |
| 3472 | __ Check(not_zero, "Unexpected type for RegExp data, FixedArray expected"); |
| 3473 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
| 3474 | __ Check(equal, "Unexpected type for RegExp data, FixedArray expected"); |
| 3475 | } |
| 3476 | |
| 3477 | // ecx: RegExp data (FixedArray) |
| 3478 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 3479 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3480 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3481 | __ j(not_equal, &runtime); |
| 3482 | |
| 3483 | // ecx: RegExp data (FixedArray) |
| 3484 | // Check that the number of captures fit in the static offsets vector buffer. |
| 3485 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3486 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 3487 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 3488 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3489 | STATIC_ASSERT(kSmiTag == 0); |
| 3490 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3491 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 3492 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3493 | __ j(above, &runtime); |
| 3494 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3495 | // Reset offset for possibly sliced string. |
| 3496 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3497 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3498 | __ JumpIfSmi(eax, &runtime); |
| 3499 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3500 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3501 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3502 | |
| 3503 | // eax: subject string |
| 3504 | // edx: subject string |
| 3505 | // ebx: subject string instance type |
| 3506 | // ecx: RegExp data (FixedArray) |
| 3507 | // Handle subject string according to its encoding and representation: |
| 3508 | // (1) Sequential two byte? If yes, go to (9). |
| 3509 | // (2) Sequential one byte? If yes, go to (6). |
| 3510 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3511 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 3512 | // Otherwise bailout. |
| 3513 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3514 | // (5b) Is subject external? If yes, go to (8). |
| 3515 | // (6) One byte sequential. Load regexp code for one byte. |
| 3516 | // (E) Carry on. |
| 3517 | /// [...] |
| 3518 | |
| 3519 | // Deferred code at the end of the stub: |
| 3520 | // (7) Not a long external string? If yes, go to (10). |
| 3521 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 3522 | // (8a) Is the external string one byte? If yes, go to (6). |
| 3523 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3524 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 3525 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3526 | |
| 3527 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 3528 | external_string /* 8 */, check_underlying /* 5a */, |
| 3529 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 3530 | not_long_external /* 10 */; |
| 3531 | |
| 3532 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3533 | __ and_(ebx, kIsNotStringMask | |
| 3534 | kStringRepresentationMask | |
| 3535 | kStringEncodingMask | |
| 3536 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3537 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3538 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3539 | |
| 3540 | // (2) Sequential one byte? If yes, go to (6). |
| 3541 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3542 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 3543 | kStringRepresentationMask | |
| 3544 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3545 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3546 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3547 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 3548 | // We check whether the subject string is a cons, since sequential strings |
| 3549 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3550 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 3551 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3552 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 3553 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3554 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3555 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3556 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3557 | // (4) Cons string. Check that it's flat. |
| 3558 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3559 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3560 | __ j(not_equal, &runtime); |
| 3561 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3562 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3563 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3564 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3565 | |
| 3566 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 3567 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3568 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3569 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 3570 | // (5b) Is subject external? If yes, go to (8). |
| 3571 | __ test_b(ebx, kStringRepresentationMask); |
| 3572 | // The underlying external string is never a short external string. |
| 3573 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 3574 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 3575 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3576 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3577 | // eax: sequential subject string (or look-alike, external string) |
| 3578 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3579 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3580 | // (6) One byte sequential. Load regexp code for one byte. |
| 3581 | __ bind(&seq_one_byte_string); |
| 3582 | // Load previous index and check range before edx is overwritten. We have |
| 3583 | // to use edx instead of eax here because it might have been only made to |
| 3584 | // look like a sequential string when it actually is an external string. |
| 3585 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3586 | __ JumpIfNotSmi(ebx, &runtime); |
| 3587 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3588 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3589 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3590 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3591 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3592 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3593 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3594 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3595 | // Check that the irregexp code has been generated for the actual string |
| 3596 | // 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] | 3597 | // a smi (code flushing support). |
| 3598 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3599 | |
| 3600 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3601 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3602 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3603 | // 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] | 3604 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3605 | Counters* counters = masm->isolate()->counters(); |
| 3606 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3607 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3608 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3609 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3610 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3611 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3612 | // Argument 9: Pass current isolate address. |
| 3613 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 3614 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3615 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3616 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 3617 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3618 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3619 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3620 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 3621 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3622 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 3623 | |
| 3624 | // Argument 6: Set the number of capture registers to zero to force global |
| 3625 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 3626 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3627 | |
| 3628 | // Argument 5: static offsets vector buffer. |
| 3629 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3630 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 3631 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3632 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3633 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3634 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3635 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 3636 | |
| 3637 | // Argument 1: Original subject string. |
| 3638 | // The original subject is in the previous stack frame. Therefore we have to |
| 3639 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 3640 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 3641 | // and thereby moves up esp by one kPointerSize.) |
| 3642 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 3643 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 3644 | |
| 3645 | // esi: original subject string |
| 3646 | // eax: underlying subject string |
| 3647 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3648 | // 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] | 3649 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3650 | // Argument 4: End of string data |
| 3651 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3652 | // Prepare start and end index of the input. |
| 3653 | // Load the length from the original sliced string if that is the case. |
| 3654 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3655 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3656 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3657 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3658 | |
| 3659 | // ebx: start index of the input string |
| 3660 | // esi: end index of the input string |
| 3661 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3662 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3663 | __ j(zero, &setup_two_byte, Label::kNear); |
| 3664 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3665 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3666 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3667 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3668 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3669 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3670 | |
| 3671 | __ bind(&setup_two_byte); |
| 3672 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3673 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 3674 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3675 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 3676 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 3677 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 3678 | |
| 3679 | __ bind(&setup_rest); |
| 3680 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3681 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3682 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 3683 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3684 | |
| 3685 | // Drop arguments and come back to JS mode. |
| 3686 | __ LeaveApiExitFrame(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3687 | |
| 3688 | // Check the result. |
| 3689 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 3690 | __ cmp(eax, 1); |
| 3691 | // We expect exactly one result since we force the called regexp to behave |
| 3692 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3693 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3694 | Label failure; |
| 3695 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3696 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3697 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 3698 | // If not exception it can only be retry. Handle that in the runtime system. |
| 3699 | __ j(not_equal, &runtime); |
| 3700 | // Result must now be exception. If there is no pending exception already a |
| 3701 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 3702 | // haven't created the exception yet. Handle that in the runtime system. |
| 3703 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3704 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3705 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3706 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3707 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3708 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3709 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3710 | // For exception, throw the exception again. |
| 3711 | |
| 3712 | // Clear the pending exception variable. |
| 3713 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 3714 | |
| 3715 | // Special handling of termination exceptions which are uncatchable |
| 3716 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3717 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3718 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3719 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3720 | |
| 3721 | // Handle normal exception by following handler chain. |
| 3722 | __ Throw(eax); |
| 3723 | |
| 3724 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 3725 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3726 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3727 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 3728 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3729 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3730 | __ ret(4 * kPointerSize); |
| 3731 | |
| 3732 | // Load RegExp data. |
| 3733 | __ bind(&success); |
| 3734 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 3735 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 3736 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 3737 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 3738 | STATIC_ASSERT(kSmiTag == 0); |
| 3739 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3740 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3741 | |
| 3742 | // edx: Number of capture registers |
| 3743 | // 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] | 3744 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3745 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3746 | __ JumpIfSmi(eax, &runtime); |
| 3747 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 3748 | __ j(not_equal, &runtime); |
| 3749 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3750 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3751 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 3752 | __ cmp(eax, factory->fixed_array_map()); |
| 3753 | __ j(not_equal, &runtime); |
| 3754 | // Check that the last match info has space for the capture registers and the |
| 3755 | // additional information. |
| 3756 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 3757 | __ SmiUntag(eax); |
| 3758 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 3759 | __ cmp(edx, eax); |
| 3760 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3761 | |
| 3762 | // ebx: last_match_info backing store (FixedArray) |
| 3763 | // edx: number of capture registers |
| 3764 | // Store the capture count. |
| 3765 | __ SmiTag(edx); // Number of capture registers to smi. |
| 3766 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 3767 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 3768 | // Store last subject and last input. |
| 3769 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3770 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3771 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3772 | __ RecordWriteField(ebx, |
| 3773 | RegExpImpl::kLastSubjectOffset, |
| 3774 | eax, |
| 3775 | edi, |
| 3776 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3777 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3778 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3779 | __ RecordWriteField(ebx, |
| 3780 | RegExpImpl::kLastInputOffset, |
| 3781 | eax, |
| 3782 | edi, |
| 3783 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3784 | |
| 3785 | // Get the static offsets vector filled by the native regexp code. |
| 3786 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3787 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3788 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 3789 | |
| 3790 | // ebx: last_match_info backing store (FixedArray) |
| 3791 | // ecx: offsets vector |
| 3792 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3793 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3794 | // Capture register counter starts from number of capture registers and |
| 3795 | // counts down until wraping after zero. |
| 3796 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3797 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3798 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3799 | // Read the value from the static offsets vector buffer. |
| 3800 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 3801 | __ SmiTag(edi); |
| 3802 | // Store the smi value in the last match info. |
| 3803 | __ mov(FieldOperand(ebx, |
| 3804 | edx, |
| 3805 | times_pointer_size, |
| 3806 | RegExpImpl::kFirstCaptureOffset), |
| 3807 | edi); |
| 3808 | __ jmp(&next_capture); |
| 3809 | __ bind(&done); |
| 3810 | |
| 3811 | // Return last match info. |
| 3812 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 3813 | __ ret(4 * kPointerSize); |
| 3814 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3815 | // Do the runtime call to execute the regexp. |
| 3816 | __ bind(&runtime); |
| 3817 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 3818 | |
| 3819 | // Deferred code for string handling. |
| 3820 | // (7) Not a long external string? If yes, go to (10). |
| 3821 | __ bind(¬_seq_nor_cons); |
| 3822 | // Compare flags are still set from (3). |
| 3823 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 3824 | |
| 3825 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3826 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3827 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3828 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3829 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3830 | if (FLAG_debug_code) { |
| 3831 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 3832 | // Sequential strings have already been ruled out. |
| 3833 | __ test_b(ebx, kIsIndirectStringMask); |
| 3834 | __ Assert(zero, "external string expected, but not found"); |
| 3835 | } |
| 3836 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 3837 | // 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] | 3838 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3839 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3840 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3841 | // (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] | 3842 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3843 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 3844 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 3845 | // eax: sequential subject string (or look-alike, external string) |
| 3846 | // edx: original subject string |
| 3847 | // ecx: RegExp data (FixedArray) |
| 3848 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 3849 | __ bind(&seq_two_byte_string); |
| 3850 | // Load previous index and check range before edx is overwritten. We have |
| 3851 | // to use edx instead of eax here because it might have been only made to |
| 3852 | // look like a sequential string when it actually is an external string. |
| 3853 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 3854 | __ JumpIfNotSmi(ebx, &runtime); |
| 3855 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 3856 | __ j(above_equal, &runtime); |
| 3857 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 3858 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 3859 | __ jmp(&check_code); // Go to (E). |
| 3860 | |
| 3861 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 3862 | __ bind(¬_long_external); |
| 3863 | // Catch non-string subject or short external string. |
| 3864 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 3865 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 3866 | __ j(not_zero, &runtime); |
| 3867 | |
| 3868 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 3869 | // Load offset into edi and replace subject string with parent. |
| 3870 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3871 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3872 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3873 | #endif // V8_INTERPRETED_REGEXP |
| 3874 | } |
| 3875 | |
| 3876 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3877 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 3878 | const int kMaxInlineLength = 100; |
| 3879 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3880 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3881 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3882 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3883 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3884 | __ j(above, &slowcase); |
| 3885 | // Smi-tagging is equivalent to multiplying by 2. |
| 3886 | STATIC_ASSERT(kSmiTag == 0); |
| 3887 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3888 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 3889 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 3890 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 3891 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 3892 | times_pointer_size, |
| 3893 | ebx, // In: Number of elements as a smi |
| 3894 | REGISTER_VALUE_IS_SMI, |
| 3895 | eax, // Out: Start of allocation (tagged). |
| 3896 | ecx, // Out: End of allocation. |
| 3897 | edx, // Scratch register |
| 3898 | &slowcase, |
| 3899 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3900 | // eax: Start of allocated area, object-tagged. |
| 3901 | |
| 3902 | // Set JSArray map to global.regexp_result_map(). |
| 3903 | // Set empty properties FixedArray. |
| 3904 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 3905 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3906 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3907 | Factory* factory = masm->isolate()->factory(); |
| 3908 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3909 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 3910 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3911 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 3912 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 3913 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 3914 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 3915 | |
| 3916 | // Set input, index and length fields from arguments. |
| 3917 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 3918 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 3919 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 3920 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 3921 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 3922 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 3923 | |
| 3924 | // Fill out the elements FixedArray. |
| 3925 | // eax: JSArray. |
| 3926 | // ebx: FixedArray. |
| 3927 | // ecx: Number of elements in array, as smi. |
| 3928 | |
| 3929 | // Set map. |
| 3930 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3931 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3932 | // Set length. |
| 3933 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3934 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3935 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3936 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3937 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3938 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3939 | // eax: JSArray. |
| 3940 | // ecx: Number of elements to fill. |
| 3941 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 3942 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3943 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3944 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3945 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3946 | __ 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] | 3947 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3948 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 3949 | __ jmp(&loop); |
| 3950 | |
| 3951 | __ bind(&done); |
| 3952 | __ ret(3 * kPointerSize); |
| 3953 | |
| 3954 | __ bind(&slowcase); |
| 3955 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 3956 | } |
| 3957 | |
| 3958 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3959 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 3960 | Register object, |
| 3961 | Register result, |
| 3962 | Register scratch1, |
| 3963 | Register scratch2, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3964 | Label* not_found) { |
| 3965 | // Use of registers. Register result is used as a temporary. |
| 3966 | Register number_string_cache = result; |
| 3967 | Register mask = scratch1; |
| 3968 | Register scratch = scratch2; |
| 3969 | |
| 3970 | // Load the number string cache. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3971 | ExternalReference roots_array_start = |
| 3972 | ExternalReference::roots_array_start(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3973 | __ mov(scratch, Immediate(Heap::kNumberStringCacheRootIndex)); |
| 3974 | __ mov(number_string_cache, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3975 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3976 | // Make the hash mask from the length of the number string cache. It |
| 3977 | // contains two elements (number and string) for each cache entry. |
| 3978 | __ mov(mask, FieldOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 3979 | __ shr(mask, kSmiTagSize + 1); // Untag length and divide it by two. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3980 | __ sub(mask, Immediate(1)); // Make mask. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3981 | |
| 3982 | // Calculate the entry in the number string cache. The hash value in the |
| 3983 | // number string cache for smis is just the smi value, and the hash for |
| 3984 | // doubles is the xor of the upper and lower words. See |
| 3985 | // Heap::GetNumberStringCache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3986 | Label smi_hash_calculated; |
| 3987 | Label load_result_from_cache; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3988 | Label not_smi; |
| 3989 | STATIC_ASSERT(kSmiTag == 0); |
| 3990 | __ JumpIfNotSmi(object, ¬_smi, Label::kNear); |
| 3991 | __ mov(scratch, object); |
| 3992 | __ SmiUntag(scratch); |
| 3993 | __ jmp(&smi_hash_calculated, Label::kNear); |
| 3994 | __ bind(¬_smi); |
| 3995 | __ cmp(FieldOperand(object, HeapObject::kMapOffset), |
| 3996 | masm->isolate()->factory()->heap_number_map()); |
| 3997 | __ j(not_equal, not_found); |
| 3998 | STATIC_ASSERT(8 == kDoubleSize); |
| 3999 | __ mov(scratch, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4000 | __ xor_(scratch, FieldOperand(object, HeapNumber::kValueOffset + 4)); |
| 4001 | // Object is heap number and hash is now in scratch. Calculate cache index. |
| 4002 | __ and_(scratch, mask); |
| 4003 | Register index = scratch; |
| 4004 | Register probe = mask; |
| 4005 | __ mov(probe, |
| 4006 | FieldOperand(number_string_cache, |
| 4007 | index, |
| 4008 | times_twice_pointer_size, |
| 4009 | FixedArray::kHeaderSize)); |
| 4010 | __ JumpIfSmi(probe, not_found); |
| 4011 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4012 | CpuFeatureScope fscope(masm, SSE2); |
| 4013 | __ movdbl(xmm0, FieldOperand(object, HeapNumber::kValueOffset)); |
| 4014 | __ movdbl(xmm1, FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4015 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4016 | } else { |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4017 | __ fld_d(FieldOperand(object, HeapNumber::kValueOffset)); |
| 4018 | __ fld_d(FieldOperand(probe, HeapNumber::kValueOffset)); |
| 4019 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4020 | } |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4021 | __ j(parity_even, not_found); // Bail out if NaN is involved. |
| 4022 | __ j(not_equal, not_found); // The cache did not contain this value. |
| 4023 | __ jmp(&load_result_from_cache, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4024 | |
| 4025 | __ bind(&smi_hash_calculated); |
| 4026 | // Object is smi and hash is now in scratch. Calculate cache index. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4027 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4028 | // Check if the entry is the smi we are looking for. |
| 4029 | __ cmp(object, |
| 4030 | FieldOperand(number_string_cache, |
| 4031 | index, |
| 4032 | times_twice_pointer_size, |
| 4033 | FixedArray::kHeaderSize)); |
| 4034 | __ j(not_equal, not_found); |
| 4035 | |
| 4036 | // Get the result from the cache. |
| 4037 | __ bind(&load_result_from_cache); |
| 4038 | __ mov(result, |
| 4039 | FieldOperand(number_string_cache, |
| 4040 | index, |
| 4041 | times_twice_pointer_size, |
| 4042 | FixedArray::kHeaderSize + kPointerSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4043 | Counters* counters = masm->isolate()->counters(); |
| 4044 | __ IncrementCounter(counters->number_to_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4045 | } |
| 4046 | |
| 4047 | |
| 4048 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 4049 | Label runtime; |
| 4050 | |
| 4051 | __ mov(ebx, Operand(esp, kPointerSize)); |
| 4052 | |
| 4053 | // Generate code to lookup number in the number string cache. |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4054 | GenerateLookupNumberStringCache(masm, ebx, eax, ecx, edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4055 | __ ret(1 * kPointerSize); |
| 4056 | |
| 4057 | __ bind(&runtime); |
| 4058 | // Handle number to string in the runtime system if not found in the cache. |
| 4059 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 4060 | } |
| 4061 | |
| 4062 | |
| 4063 | static int NegativeComparisonResult(Condition cc) { |
| 4064 | ASSERT(cc != equal); |
| 4065 | ASSERT((cc == less) || (cc == less_equal) |
| 4066 | || (cc == greater) || (cc == greater_equal)); |
| 4067 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 4068 | } |
| 4069 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4070 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4071 | static void CheckInputType(MacroAssembler* masm, |
| 4072 | Register input, |
| 4073 | CompareIC::State expected, |
| 4074 | Label* fail) { |
| 4075 | Label ok; |
| 4076 | if (expected == CompareIC::SMI) { |
| 4077 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4078 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4079 | __ JumpIfSmi(input, &ok); |
| 4080 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 4081 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 4082 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4083 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4084 | // 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] | 4085 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 4086 | __ bind(&ok); |
| 4087 | } |
| 4088 | |
| 4089 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4090 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 4091 | Label* label, |
| 4092 | Register object, |
| 4093 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4094 | __ JumpIfSmi(object, label); |
| 4095 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 4096 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4097 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 4098 | __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 4099 | __ j(not_zero, label); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | |
| 4103 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 4104 | Label check_unequal_objects; |
| 4105 | Condition cc = GetCondition(); |
| 4106 | |
| 4107 | Label miss; |
| 4108 | CheckInputType(masm, edx, left_, &miss); |
| 4109 | CheckInputType(masm, eax, right_, &miss); |
| 4110 | |
| 4111 | // Compare two smis. |
| 4112 | Label non_smi, smi_done; |
| 4113 | __ mov(ecx, edx); |
| 4114 | __ or_(ecx, eax); |
| 4115 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 4116 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 4117 | __ j(no_overflow, &smi_done, Label::kNear); |
| 4118 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 4119 | __ bind(&smi_done); |
| 4120 | __ mov(eax, edx); |
| 4121 | __ ret(0); |
| 4122 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 4123 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4124 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 4125 | // it is certain that at least one operand isn't a smi. |
| 4126 | |
| 4127 | // Identical objects can be compared fast, but there are some tricky cases |
| 4128 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4129 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4130 | { |
| 4131 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4132 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4133 | __ j(not_equal, ¬_identical); |
| 4134 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4135 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4136 | // Check for undefined. undefined OP undefined is false even though |
| 4137 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4138 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4139 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4140 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4141 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4142 | __ ret(0); |
| 4143 | __ bind(&check_for_nan); |
| 4144 | } |
| 4145 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4146 | // Test for NaN. Compare heap numbers in a general way, |
| 4147 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4148 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4149 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4150 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4151 | if (cc != equal) { |
| 4152 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 4153 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 4154 | __ j(above_equal, ¬_identical); |
| 4155 | } |
| 4156 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4157 | __ ret(0); |
| 4158 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4159 | |
| 4160 | __ bind(¬_identical); |
| 4161 | } |
| 4162 | |
| 4163 | // Strict equality can quickly decide whether objects are equal. |
| 4164 | // 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] | 4165 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4166 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4167 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4168 | // If we're doing a strict equality comparison, we don't have to do |
| 4169 | // type conversion, so we generate code to do fast comparison for objects |
| 4170 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 4171 | // slow-case code. |
| 4172 | // If either is a Smi (we know that not both are), then they can only |
| 4173 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 4174 | STATIC_ASSERT(kSmiTag == 0); |
| 4175 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 4176 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4177 | __ and_(ecx, eax); |
| 4178 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4179 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4180 | // One operand is a smi. |
| 4181 | |
| 4182 | // Check whether the non-smi is a heap number. |
| 4183 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4184 | // 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] | 4185 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4186 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4187 | __ xor_(ebx, eax); |
| 4188 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 4189 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4190 | // if eax was smi, ebx is now edx, else eax. |
| 4191 | |
| 4192 | // Check if the non-smi operand is a heap number. |
| 4193 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4194 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4195 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4196 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4197 | // Return non-equal (ebx is not zero) |
| 4198 | __ mov(eax, ebx); |
| 4199 | __ ret(0); |
| 4200 | |
| 4201 | __ bind(¬_smis); |
| 4202 | // If either operand is a JSObject or an oddball value, then they are not |
| 4203 | // equal since their pointers are different |
| 4204 | // There is no test for undetectability in strict equality. |
| 4205 | |
| 4206 | // Get the type of the first operand. |
| 4207 | // 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] | 4208 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4209 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 4210 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4211 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4212 | |
| 4213 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4214 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4215 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 4216 | __ bind(&return_not_equal); |
| 4217 | __ ret(0); |
| 4218 | |
| 4219 | __ bind(&first_non_object); |
| 4220 | // Check for oddballs: true, false, null, undefined. |
| 4221 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4222 | __ j(equal, &return_not_equal); |
| 4223 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4224 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4225 | __ j(above_equal, &return_not_equal); |
| 4226 | |
| 4227 | // Check for oddballs: true, false, null, undefined. |
| 4228 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 4229 | __ j(equal, &return_not_equal); |
| 4230 | |
| 4231 | // Fall through to the general case. |
| 4232 | __ bind(&slow); |
| 4233 | } |
| 4234 | |
| 4235 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4236 | Label non_number_comparison; |
| 4237 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4238 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4239 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4240 | CpuFeatureScope use_sse2(masm, SSE2); |
| 4241 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4242 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4243 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 4244 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4245 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4246 | // Don't base result on EFLAGS when a NaN is involved. |
| 4247 | __ j(parity_even, &unordered, Label::kNear); |
| 4248 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4249 | __ mov(eax, 0); // equal |
| 4250 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 4251 | __ cmov(above, eax, ecx); |
| 4252 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 4253 | __ cmov(below, eax, ecx); |
| 4254 | __ ret(0); |
| 4255 | } else { |
| 4256 | FloatingPointHelper::CheckFloatOperands( |
| 4257 | masm, &non_number_comparison, ebx); |
| 4258 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 4259 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 4260 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4261 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4262 | // Don't base result on EFLAGS when a NaN is involved. |
| 4263 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4264 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4265 | Label below_label, above_label; |
| 4266 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4267 | __ j(below, &below_label, Label::kNear); |
| 4268 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4269 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4270 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4271 | __ ret(0); |
| 4272 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4273 | __ bind(&below_label); |
| 4274 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4275 | __ ret(0); |
| 4276 | |
| 4277 | __ bind(&above_label); |
| 4278 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4279 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4280 | } |
| 4281 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4282 | // If one of the numbers was NaN, then the result is always false. |
| 4283 | // The cc is never not-equal. |
| 4284 | __ bind(&unordered); |
| 4285 | ASSERT(cc != not_equal); |
| 4286 | if (cc == less || cc == less_equal) { |
| 4287 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 4288 | } else { |
| 4289 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 4290 | } |
| 4291 | __ ret(0); |
| 4292 | |
| 4293 | // The number comparison code did not provide a valid result. |
| 4294 | __ bind(&non_number_comparison); |
| 4295 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4296 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4297 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4298 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4299 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 4300 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4301 | |
| 4302 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4303 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4304 | // non-zero value, which indicates not equal, so just return. |
| 4305 | __ ret(0); |
| 4306 | } |
| 4307 | |
| 4308 | __ bind(&check_for_strings); |
| 4309 | |
| 4310 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 4311 | &check_unequal_objects); |
| 4312 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4313 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4314 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4315 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4316 | edx, |
| 4317 | eax, |
| 4318 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4319 | ebx); |
| 4320 | } else { |
| 4321 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 4322 | edx, |
| 4323 | eax, |
| 4324 | ecx, |
| 4325 | ebx, |
| 4326 | edi); |
| 4327 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4328 | #ifdef DEBUG |
| 4329 | __ Abort("Unexpected fall-through from string comparison"); |
| 4330 | #endif |
| 4331 | |
| 4332 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4333 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4334 | // Non-strict equality. Objects are unequal if |
| 4335 | // they are both JSObjects and not undetectable, |
| 4336 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4337 | Label not_both_objects; |
| 4338 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4339 | // At most one is a smi, so we can test for smi by adding the two. |
| 4340 | // A smi plus a heap object has the low bit set, a heap object plus |
| 4341 | // a heap object has the low bit clear. |
| 4342 | STATIC_ASSERT(kSmiTag == 0); |
| 4343 | STATIC_ASSERT(kSmiTagMask == 1); |
| 4344 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 4345 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4346 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4347 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4348 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4349 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4350 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4351 | // We do not bail out after this point. Both are JSObjects, and |
| 4352 | // they are equal if and only if both are undetectable. |
| 4353 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 4354 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 4355 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4356 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4357 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 4358 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4359 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4360 | // The objects are both undetectable, so they both compare as the value |
| 4361 | // undefined, and are equal. |
| 4362 | __ Set(eax, Immediate(EQUAL)); |
| 4363 | __ bind(&return_unequal); |
| 4364 | // Return non-equal by returning the non-zero object pointer in eax, |
| 4365 | // or return equal if we fell through to here. |
| 4366 | __ ret(0); // rax, rdx were pushed |
| 4367 | __ bind(¬_both_objects); |
| 4368 | } |
| 4369 | |
| 4370 | // Push arguments below the return address. |
| 4371 | __ pop(ecx); |
| 4372 | __ push(edx); |
| 4373 | __ push(eax); |
| 4374 | |
| 4375 | // Figure out which native to call and setup the arguments. |
| 4376 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4377 | if (cc == equal) { |
| 4378 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4379 | } else { |
| 4380 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4381 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4382 | } |
| 4383 | |
| 4384 | // Restore return address on the stack. |
| 4385 | __ push(ecx); |
| 4386 | |
| 4387 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4388 | // tagged as a small integer. |
| 4389 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4390 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4391 | __ bind(&miss); |
| 4392 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4393 | } |
| 4394 | |
| 4395 | |
| 4396 | void StackCheckStub::Generate(MacroAssembler* masm) { |
whesse@chromium.org | 4a5224e | 2010-10-20 12:37:07 +0000 | [diff] [blame] | 4397 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4398 | } |
| 4399 | |
| 4400 | |
yangguo@chromium.org | 5645471 | 2012-02-16 15:33:53 +0000 | [diff] [blame] | 4401 | void InterruptStub::Generate(MacroAssembler* masm) { |
| 4402 | __ TailCallRuntime(Runtime::kInterrupt, 0, 1); |
| 4403 | } |
| 4404 | |
| 4405 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4406 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 4407 | // Cache the called function in a global property cell. Cache states |
| 4408 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 4409 | // megamorphic. |
| 4410 | // ebx : cache cell for call target |
| 4411 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4412 | Isolate* isolate = masm->isolate(); |
| 4413 | Label initialize, done, miss, megamorphic, not_array_function; |
| 4414 | |
| 4415 | // Load the cache state into ecx. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4416 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4417 | |
| 4418 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 4419 | // function without changing the state. |
| 4420 | __ cmp(ecx, edi); |
| 4421 | __ j(equal, &done); |
| 4422 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4423 | __ j(equal, &done); |
| 4424 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4425 | // If we came here, we need to see if we are the array function. |
| 4426 | // If we didn't have a matching function, and we didn't find the megamorph |
| 4427 | // sentinel, then we have in the cell either some other function or an |
| 4428 | // AllocationSite. Do a map check on the object in ecx. |
| 4429 | Handle<Map> allocation_site_map( |
| 4430 | masm->isolate()->heap()->allocation_site_map(), |
| 4431 | masm->isolate()); |
| 4432 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 4433 | __ j(not_equal, &miss); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4434 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4435 | // Load the global or builtins object from the current context |
| 4436 | __ LoadGlobalContext(ecx); |
| 4437 | // Make sure the function is the Array() function |
| 4438 | __ cmp(edi, Operand(ecx, |
| 4439 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4440 | __ j(not_equal, &megamorphic); |
| 4441 | __ jmp(&done); |
| 4442 | |
| 4443 | __ bind(&miss); |
| 4444 | |
| 4445 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 4446 | // megamorphic. |
| 4447 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 4448 | __ j(equal, &initialize); |
| 4449 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 4450 | // write-barrier is needed. |
| 4451 | __ bind(&megamorphic); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4452 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4453 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 4454 | __ jmp(&done, Label::kNear); |
| 4455 | |
| 4456 | // An uninitialized cache is patched with the function or sentinel to |
| 4457 | // indicate the ElementsKind if function is the Array constructor. |
| 4458 | __ bind(&initialize); |
| 4459 | __ LoadGlobalContext(ecx); |
| 4460 | // Make sure the function is the Array() function |
| 4461 | __ cmp(edi, Operand(ecx, |
| 4462 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 4463 | __ j(not_equal, ¬_array_function); |
| 4464 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4465 | // The target function is the Array constructor, |
| 4466 | // Create an AllocationSite if we don't already have it, store it in the cell |
| 4467 | { |
| 4468 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 4469 | |
| 4470 | __ push(eax); |
| 4471 | __ push(edi); |
| 4472 | __ push(ebx); |
| 4473 | |
| 4474 | CreateAllocationSiteStub create_stub; |
| 4475 | __ CallStub(&create_stub); |
| 4476 | |
| 4477 | __ pop(ebx); |
| 4478 | __ pop(edi); |
| 4479 | __ pop(eax); |
| 4480 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4481 | __ jmp(&done); |
| 4482 | |
| 4483 | __ bind(¬_array_function); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4484 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4485 | // No need for a write barrier here - cells are rescanned. |
| 4486 | |
| 4487 | __ bind(&done); |
| 4488 | } |
| 4489 | |
| 4490 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4491 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4492 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 4493 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4494 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4495 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4496 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4497 | // The receiver might implicitly be the global object. This is |
| 4498 | // indicated by passing the hole as the receiver to the call |
| 4499 | // function stub. |
| 4500 | if (ReceiverMightBeImplicit()) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4501 | Label receiver_ok; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4502 | // Get the receiver from the stack. |
| 4503 | // +1 ~ return address |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4504 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4505 | // Call as function is indicated with the hole. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4506 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 4507 | __ j(not_equal, &receiver_ok, Label::kNear); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4508 | // Patch the receiver on the stack with the global receiver object. |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4509 | __ mov(ecx, GlobalObjectOperand()); |
| 4510 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kGlobalReceiverOffset)); |
| 4511 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4512 | __ bind(&receiver_ok); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4513 | } |
| 4514 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4515 | // Check that the function really is a JavaScript function. |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4516 | __ JumpIfSmi(edi, &non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4517 | // Goto slow case if we do not have a function. |
| 4518 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4519 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4520 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4521 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4522 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4523 | } |
| 4524 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4525 | // Fast-case: Just invoke the function. |
| 4526 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4527 | |
| 4528 | if (ReceiverMightBeImplicit()) { |
| 4529 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4530 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4531 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 4532 | __ InvokeFunction(edi, |
| 4533 | actual, |
| 4534 | JUMP_FUNCTION, |
| 4535 | NullCallWrapper(), |
| 4536 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 4537 | __ bind(&call_as_function); |
| 4538 | } |
| 4539 | __ InvokeFunction(edi, |
| 4540 | actual, |
| 4541 | JUMP_FUNCTION, |
| 4542 | NullCallWrapper(), |
| 4543 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4544 | |
| 4545 | // Slow-case: Non-function called. |
| 4546 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4547 | if (RecordCallTarget()) { |
| 4548 | // 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] | 4549 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 4550 | // object (undefined) so no write barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 4551 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4552 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4553 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4554 | // Check for function proxy. |
| 4555 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4556 | __ j(not_equal, &non_function); |
| 4557 | __ pop(ecx); |
| 4558 | __ push(edi); // put proxy as additional argument under return address |
| 4559 | __ push(ecx); |
| 4560 | __ Set(eax, Immediate(argc_ + 1)); |
| 4561 | __ Set(ebx, Immediate(0)); |
| 4562 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 4563 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 4564 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4565 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4566 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4567 | } |
| 4568 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4569 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4570 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4571 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4572 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 4573 | __ Set(eax, Immediate(argc_)); |
| 4574 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 4575 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4576 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4577 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4578 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 4579 | } |
| 4580 | |
| 4581 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4582 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 4583 | // eax : number of arguments |
| 4584 | // ebx : cache cell for call target |
| 4585 | // edi : constructor function |
| 4586 | Label slow, non_function_call; |
| 4587 | |
| 4588 | // Check that function is not a smi. |
| 4589 | __ JumpIfSmi(edi, &non_function_call); |
| 4590 | // Check that function is a JSFunction. |
| 4591 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 4592 | __ j(not_equal, &slow); |
| 4593 | |
| 4594 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4595 | GenerateRecordCallTarget(masm); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4596 | } |
| 4597 | |
| 4598 | // Jump to the function-specific construct stub. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4599 | Register jmp_reg = ecx; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4600 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 4601 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 4602 | SharedFunctionInfo::kConstructStubOffset)); |
| 4603 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 4604 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 4605 | |
| 4606 | // edi: called object |
| 4607 | // eax: number of arguments |
| 4608 | // ecx: object map |
| 4609 | Label do_call; |
| 4610 | __ bind(&slow); |
| 4611 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 4612 | __ j(not_equal, &non_function_call); |
| 4613 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 4614 | __ jmp(&do_call); |
| 4615 | |
| 4616 | __ bind(&non_function_call); |
| 4617 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 4618 | __ bind(&do_call); |
| 4619 | // Set expected number of arguments to zero (not changing eax). |
| 4620 | __ Set(ebx, Immediate(0)); |
| 4621 | Handle<Code> arguments_adaptor = |
| 4622 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 4623 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 4624 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 4625 | } |
| 4626 | |
| 4627 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 4628 | bool CEntryStub::NeedsImmovableCode() { |
| 4629 | return false; |
| 4630 | } |
| 4631 | |
| 4632 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4633 | bool CEntryStub::IsPregenerated() { |
| 4634 | return (!save_doubles_ || ISOLATE->fp_stubs_generated()) && |
| 4635 | result_size_ == 1; |
| 4636 | } |
| 4637 | |
| 4638 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4639 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 4640 | CEntryStub::GenerateAheadOfTime(isolate); |
| 4641 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4642 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4643 | // 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] | 4644 | RecordWriteStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4645 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 4646 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4650 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4651 | if (CpuFeatures::IsSupported(SSE2)) { |
| 4652 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 4653 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 4654 | // which would lead to code stub initialization state being messed up. |
| 4655 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4656 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 4657 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4658 | } |
| 4659 | save_doubles_code->set_is_pregenerated(true); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4660 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 4661 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4665 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4666 | CEntryStub stub(1, kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4667 | Handle<Code> code = stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4668 | code->set_is_pregenerated(true); |
| 4669 | } |
| 4670 | |
| 4671 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4672 | static void JumpIfOOM(MacroAssembler* masm, |
| 4673 | Register value, |
| 4674 | Register scratch, |
| 4675 | Label* oom_label) { |
| 4676 | __ mov(scratch, value); |
| 4677 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 4678 | STATIC_ASSERT(kFailureTag == 3); |
| 4679 | __ and_(scratch, 0xf); |
| 4680 | __ cmp(scratch, 0xf); |
| 4681 | __ j(equal, oom_label); |
| 4682 | } |
| 4683 | |
| 4684 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4685 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 4686 | Label* throw_normal_exception, |
| 4687 | Label* throw_termination_exception, |
| 4688 | Label* throw_out_of_memory_exception, |
| 4689 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 4690 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4691 | // eax: result parameter for PerformGC, if any |
| 4692 | // ebx: pointer to C function (C callee-saved) |
| 4693 | // ebp: frame pointer (restored after C call) |
| 4694 | // esp: stack pointer (restored after C call) |
| 4695 | // edi: number of arguments including receiver (C callee-saved) |
| 4696 | // esi: pointer to the first argument (C callee-saved) |
| 4697 | |
| 4698 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 4699 | |
| 4700 | // Check stack alignment. |
| 4701 | if (FLAG_debug_code) { |
| 4702 | __ CheckStackAlignment(); |
| 4703 | } |
| 4704 | |
| 4705 | if (do_gc) { |
| 4706 | // Pass failure code returned from last attempt as first argument to |
| 4707 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 4708 | // stack alignment is known to be correct. This function takes one argument |
| 4709 | // which is passed on the stack, and we know that the stack has been |
| 4710 | // prepared to pass at least one argument. |
| 4711 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 4712 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 4713 | } |
| 4714 | |
| 4715 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4716 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4717 | if (always_allocate_scope) { |
| 4718 | __ inc(Operand::StaticVariable(scope_depth)); |
| 4719 | } |
| 4720 | |
| 4721 | // Call C function. |
| 4722 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 4723 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4724 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4725 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4726 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4727 | // Result is in eax or edx:eax - do not destroy these registers! |
| 4728 | |
| 4729 | if (always_allocate_scope) { |
| 4730 | __ dec(Operand::StaticVariable(scope_depth)); |
| 4731 | } |
| 4732 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4733 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 4734 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4735 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4736 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4737 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4738 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4739 | __ int3(); |
| 4740 | __ bind(&okay); |
| 4741 | } |
| 4742 | |
| 4743 | // Check for failure result. |
| 4744 | Label failure_returned; |
| 4745 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 4746 | __ lea(ecx, Operand(eax, 1)); |
| 4747 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 4748 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4749 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4750 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4751 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4752 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4753 | |
| 4754 | // Check that there is no pending exception, otherwise we |
| 4755 | // should have returned some failure value. |
| 4756 | if (FLAG_debug_code) { |
| 4757 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4758 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4759 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4760 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 4761 | // 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] | 4762 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 4763 | __ int3(); |
| 4764 | __ bind(&okay); |
| 4765 | __ pop(edx); |
| 4766 | } |
| 4767 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4768 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4769 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4770 | __ ret(0); |
| 4771 | |
| 4772 | // Handling of failure. |
| 4773 | __ bind(&failure_returned); |
| 4774 | |
| 4775 | Label retry; |
| 4776 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 4777 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 4778 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4779 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4780 | |
| 4781 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4782 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4783 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4784 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4785 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4786 | |
| 4787 | // See if we just retrieved an OOM exception. |
| 4788 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 4789 | |
| 4790 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4791 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4792 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 4793 | |
| 4794 | // Special handling of termination exceptions which are uncatchable |
| 4795 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4796 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4797 | __ j(equal, throw_termination_exception); |
| 4798 | |
| 4799 | // Handle normal exception. |
| 4800 | __ jmp(throw_normal_exception); |
| 4801 | |
| 4802 | // Retry. |
| 4803 | __ bind(&retry); |
| 4804 | } |
| 4805 | |
| 4806 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4807 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 4808 | // eax: number of arguments including receiver |
| 4809 | // ebx: pointer to C function (C callee-saved) |
| 4810 | // ebp: frame pointer (restored after C call) |
| 4811 | // esp: stack pointer (restored after C call) |
| 4812 | // esi: current context (C callee-saved) |
| 4813 | // edi: JS function of the caller (C callee-saved) |
| 4814 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4815 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 4816 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4817 | // NOTE: Invocations of builtins may return failure objects instead |
| 4818 | // of a proper result. The builtin entry handles this by performing |
| 4819 | // a garbage collection and retrying the builtin (twice). |
| 4820 | |
| 4821 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4822 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4823 | |
| 4824 | // eax: result parameter for PerformGC, if any (setup below) |
| 4825 | // ebx: pointer to builtin function (C callee-saved) |
| 4826 | // ebp: frame pointer (restored after C call) |
| 4827 | // esp: stack pointer (restored after C call) |
| 4828 | // edi: number of arguments including receiver (C callee-saved) |
| 4829 | // esi: argv pointer (C callee-saved) |
| 4830 | |
| 4831 | Label throw_normal_exception; |
| 4832 | Label throw_termination_exception; |
| 4833 | Label throw_out_of_memory_exception; |
| 4834 | |
| 4835 | // Call into the runtime system. |
| 4836 | GenerateCore(masm, |
| 4837 | &throw_normal_exception, |
| 4838 | &throw_termination_exception, |
| 4839 | &throw_out_of_memory_exception, |
| 4840 | false, |
| 4841 | false); |
| 4842 | |
| 4843 | // Do space-specific GC and retry runtime call. |
| 4844 | GenerateCore(masm, |
| 4845 | &throw_normal_exception, |
| 4846 | &throw_termination_exception, |
| 4847 | &throw_out_of_memory_exception, |
| 4848 | true, |
| 4849 | false); |
| 4850 | |
| 4851 | // Do full GC and retry runtime call one final time. |
| 4852 | Failure* failure = Failure::InternalError(); |
| 4853 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 4854 | GenerateCore(masm, |
| 4855 | &throw_normal_exception, |
| 4856 | &throw_termination_exception, |
| 4857 | &throw_out_of_memory_exception, |
| 4858 | true, |
| 4859 | true); |
| 4860 | |
| 4861 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4862 | // Set external caught exception to false. |
| 4863 | Isolate* isolate = masm->isolate(); |
| 4864 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 4865 | isolate); |
| 4866 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 4867 | |
| 4868 | // Set pending exception and eax to out of memory exception. |
| 4869 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 4870 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4871 | Label already_have_failure; |
| 4872 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 4873 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 4874 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4875 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4876 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4877 | |
| 4878 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4879 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4880 | |
| 4881 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 4882 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4883 | } |
| 4884 | |
| 4885 | |
| 4886 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4887 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4888 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4889 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4890 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 4891 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4892 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4893 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4894 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4895 | |
| 4896 | // Push marker in two places. |
| 4897 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 4898 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 4899 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 4900 | // Save callee-saved registers (C calling conventions). |
| 4901 | __ push(edi); |
| 4902 | __ push(esi); |
| 4903 | __ push(ebx); |
| 4904 | |
| 4905 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4906 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4907 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 4908 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4909 | // 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] | 4910 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4911 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4912 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 4913 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4914 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4915 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 4916 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4917 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4918 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4919 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4920 | // Jump to a faked try block that does the invoke, with a faked catch |
| 4921 | // block that sets the pending exception. |
| 4922 | __ jmp(&invoke); |
| 4923 | __ bind(&handler_entry); |
| 4924 | handler_offset_ = handler_entry.pos(); |
| 4925 | // Caught exception: Store result (exception) in the pending exception |
| 4926 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4927 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4928 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4929 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 4930 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 4931 | __ jmp(&exit); |
| 4932 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4933 | // Invoke: Link this frame into the handler chain. There's only one |
| 4934 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4935 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 4936 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4937 | |
| 4938 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4939 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4940 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 4941 | |
| 4942 | // Fake a receiver (NULL). |
| 4943 | __ push(Immediate(0)); // receiver |
| 4944 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4945 | // Invoke the function by calling through JS entry trampoline builtin and |
| 4946 | // pop the faked function when we return. Notice that we cannot store a |
| 4947 | // reference to the trampoline code directly in this stub, because the |
| 4948 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4949 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4950 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 4951 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4952 | __ mov(edx, Immediate(construct_entry)); |
| 4953 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4954 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4955 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4956 | __ mov(edx, Immediate(entry)); |
| 4957 | } |
| 4958 | __ mov(edx, Operand(edx, 0)); // deref address |
| 4959 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4960 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4961 | |
| 4962 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4963 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4964 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4965 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 4966 | // Check if the current stack frame is marked as the outermost JS frame. |
| 4967 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4968 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4969 | __ j(not_equal, ¬_outermost_js_2); |
| 4970 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 4971 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4972 | |
| 4973 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4974 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 4975 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 4976 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4977 | |
| 4978 | // Restore callee-saved registers (C calling conventions). |
| 4979 | __ pop(ebx); |
| 4980 | __ pop(esi); |
| 4981 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4982 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4983 | |
| 4984 | // Restore frame pointer and return. |
| 4985 | __ pop(ebp); |
| 4986 | __ ret(0); |
| 4987 | } |
| 4988 | |
| 4989 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 4990 | // Generate stub code for instanceof. |
| 4991 | // This code can patch a call site inlined cache of the instance of check, |
| 4992 | // which looks like this. |
| 4993 | // |
| 4994 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 4995 | // 75 0a jne <some near label> |
| 4996 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 4997 | // |
| 4998 | // If call site patching is requested the stack will have the delta from the |
| 4999 | // return address to the cmp instruction just below the return address. This |
| 5000 | // also means that call site patching can only take place with arguments in |
| 5001 | // registers. TOS looks like this when call site patching is requested |
| 5002 | // |
| 5003 | // esp[0] : return address |
| 5004 | // esp[4] : delta from return address to cmp instruction |
| 5005 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5006 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5007 | // Call site inlining and patching implies arguments in registers. |
| 5008 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 5009 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5010 | // Fixed register usage throughout the stub. |
| 5011 | Register object = eax; // Object (lhs). |
| 5012 | Register map = ebx; // Map of the object. |
| 5013 | Register function = edx; // Function (rhs). |
| 5014 | Register prototype = edi; // Prototype of the function. |
| 5015 | Register scratch = ecx; |
| 5016 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5017 | // Constants describing the call site code to patch. |
| 5018 | static const int kDeltaToCmpImmediate = 2; |
| 5019 | static const int kDeltaToMov = 8; |
| 5020 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5021 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 5022 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5023 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 5024 | |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5025 | ExternalReference roots_array_start = |
| 5026 | ExternalReference::roots_array_start(masm->isolate()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5027 | |
| 5028 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 5029 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 5030 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5031 | // Get the object and function - they are always both needed. |
| 5032 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5033 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5034 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 5035 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 5036 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5037 | |
| 5038 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5039 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5040 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5041 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5042 | // If there is a call site cache don't look in the global cache, but do the |
| 5043 | // real lookup and update the call site cache. |
| 5044 | if (!HasCallSiteInlineCheck()) { |
| 5045 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5046 | Label miss; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5047 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5048 | __ cmp(function, Operand::StaticArray(scratch, |
| 5049 | times_pointer_size, |
| 5050 | roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5051 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5052 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
| 5053 | __ cmp(map, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5054 | scratch, times_pointer_size, roots_array_start)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5055 | __ j(not_equal, &miss, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5056 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5057 | __ mov(eax, Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5058 | scratch, times_pointer_size, roots_array_start)); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5059 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 5060 | __ bind(&miss); |
| 5061 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5062 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5063 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5064 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5065 | |
| 5066 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5067 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5068 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5069 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5070 | // Update the global instanceof or call site inlined cache with the current |
| 5071 | // map and function. The cached answer will be set when it is known below. |
| 5072 | if (!HasCallSiteInlineCheck()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5073 | __ mov(scratch, Immediate(Heap::kInstanceofCacheMapRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5074 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
| 5075 | map); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5076 | __ mov(scratch, Immediate(Heap::kInstanceofCacheFunctionRootIndex)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5077 | __ mov(Operand::StaticArray(scratch, times_pointer_size, roots_array_start), |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5078 | function); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5079 | } else { |
| 5080 | // The constants for the code patching are based on no push instructions |
| 5081 | // at the call site. |
| 5082 | ASSERT(HasArgsInRegisters()); |
| 5083 | // Get return address and delta to inlined map check. |
| 5084 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5085 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5086 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5087 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5088 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 1)"); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5089 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5090 | __ Assert(equal, "InstanceofStub unexpected call site cache (cmp 2)"); |
| 5091 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5092 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 5093 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5094 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5095 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5096 | // Loop through the prototype chain of the object looking for the function |
| 5097 | // prototype. |
| 5098 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5099 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5100 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5101 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5102 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5103 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5104 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5105 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5106 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 5107 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5108 | __ jmp(&loop); |
| 5109 | |
| 5110 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5111 | if (!HasCallSiteInlineCheck()) { |
| 5112 | __ Set(eax, Immediate(0)); |
| 5113 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5114 | __ mov(Operand::StaticArray(scratch, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5115 | times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5116 | } else { |
| 5117 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5118 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5119 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5120 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5121 | if (FLAG_debug_code) { |
| 5122 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5123 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5124 | } |
| 5125 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5126 | if (!ReturnTrueFalseObject()) { |
| 5127 | __ Set(eax, Immediate(0)); |
| 5128 | } |
| 5129 | } |
| 5130 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5131 | |
| 5132 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5133 | if (!HasCallSiteInlineCheck()) { |
| 5134 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5135 | __ mov(scratch, Immediate(Heap::kInstanceofCacheAnswerRootIndex)); |
| 5136 | __ mov(Operand::StaticArray( |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5137 | scratch, times_pointer_size, roots_array_start), eax); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5138 | } else { |
| 5139 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5140 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5141 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 5142 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 5143 | if (FLAG_debug_code) { |
| 5144 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
| 5145 | __ Assert(equal, "InstanceofStub unexpected call site cache (mov)"); |
| 5146 | } |
| 5147 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 5148 | if (!ReturnTrueFalseObject()) { |
| 5149 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 5150 | } |
| 5151 | } |
| 5152 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5153 | |
| 5154 | Label object_not_null, object_not_null_or_smi; |
| 5155 | __ bind(¬_js_object); |
| 5156 | // Before null, smi and string value checks, check that the rhs is a function |
| 5157 | // 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] | 5158 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5159 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5160 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5161 | |
| 5162 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5163 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5164 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5165 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5166 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5167 | |
| 5168 | __ bind(&object_not_null); |
| 5169 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5170 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5171 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5172 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5173 | |
| 5174 | __ bind(&object_not_null_or_smi); |
| 5175 | // String values is not instance of anything. |
| 5176 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 5177 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5178 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5179 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5180 | |
| 5181 | // Slow-case: Go through the JavaScript implementation. |
| 5182 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5183 | if (!ReturnTrueFalseObject()) { |
| 5184 | // Tail call the builtin which returns 0 or 1. |
| 5185 | if (HasArgsInRegisters()) { |
| 5186 | // Push arguments below return address. |
| 5187 | __ pop(scratch); |
| 5188 | __ push(object); |
| 5189 | __ push(function); |
| 5190 | __ push(scratch); |
| 5191 | } |
| 5192 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 5193 | } else { |
| 5194 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5195 | { |
| 5196 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5197 | __ push(object); |
| 5198 | __ push(function); |
| 5199 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 5200 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5201 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5202 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5203 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5204 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5205 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5206 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5207 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5208 | __ bind(&done); |
| 5209 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 5210 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 5214 | Register InstanceofStub::left() { return eax; } |
| 5215 | |
| 5216 | |
| 5217 | Register InstanceofStub::right() { return edx; } |
| 5218 | |
| 5219 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5220 | // ------------------------------------------------------------------------- |
| 5221 | // StringCharCodeAtGenerator |
| 5222 | |
| 5223 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5224 | // If the receiver is a smi trigger the non-string case. |
| 5225 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5226 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5227 | |
| 5228 | // Fetch the instance type of the receiver into result register. |
| 5229 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5230 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5231 | // If the receiver is not a string trigger the non-string case. |
| 5232 | __ test(result_, Immediate(kIsNotStringMask)); |
| 5233 | __ j(not_zero, receiver_not_string_); |
| 5234 | |
| 5235 | // If the index is non-smi trigger the non-smi case. |
| 5236 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5237 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5238 | __ bind(&got_smi_index_); |
| 5239 | |
| 5240 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5241 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5242 | __ j(above_equal, index_out_of_range_); |
| 5243 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5244 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5245 | |
| 5246 | Factory* factory = masm->isolate()->factory(); |
| 5247 | StringCharLoadGenerator::Generate( |
| 5248 | masm, factory, object_, index_, result_, &call_runtime_); |
| 5249 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5250 | __ SmiTag(result_); |
| 5251 | __ bind(&exit_); |
| 5252 | } |
| 5253 | |
| 5254 | |
| 5255 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5256 | MacroAssembler* masm, |
| 5257 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5258 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 5259 | |
| 5260 | // Index is not a smi. |
| 5261 | __ bind(&index_not_smi_); |
| 5262 | // 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] | 5263 | __ CheckMap(index_, |
| 5264 | masm->isolate()->factory()->heap_number_map(), |
| 5265 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 5266 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5267 | call_helper.BeforeCall(masm); |
| 5268 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5269 | __ push(index_); // Consumed by runtime conversion function. |
| 5270 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 5271 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 5272 | } else { |
| 5273 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 5274 | // NumberToSmi discards numbers that are not exact integers. |
| 5275 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 5276 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5277 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5278 | // Save the conversion result before the pop instructions below |
| 5279 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5280 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5281 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5282 | __ pop(object_); |
| 5283 | // Reload the instance type. |
| 5284 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 5285 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 5286 | call_helper.AfterCall(masm); |
| 5287 | // If index is still not a smi, it must be out of range. |
| 5288 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 5289 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5290 | // Otherwise, return to the fast path. |
| 5291 | __ jmp(&got_smi_index_); |
| 5292 | |
| 5293 | // Call runtime. We get here when the receiver is a string and the |
| 5294 | // index is a number, but the code of getting the actual character |
| 5295 | // is too complex (e.g., when the string needs to be flattened). |
| 5296 | __ bind(&call_runtime_); |
| 5297 | call_helper.BeforeCall(masm); |
| 5298 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 5299 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5300 | __ push(index_); |
| 5301 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 5302 | if (!result_.is(eax)) { |
| 5303 | __ mov(result_, eax); |
| 5304 | } |
| 5305 | call_helper.AfterCall(masm); |
| 5306 | __ jmp(&exit_); |
| 5307 | |
| 5308 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 5309 | } |
| 5310 | |
| 5311 | |
| 5312 | // ------------------------------------------------------------------------- |
| 5313 | // StringCharFromCodeGenerator |
| 5314 | |
| 5315 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 5316 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 5317 | STATIC_ASSERT(kSmiTag == 0); |
| 5318 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5319 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5320 | __ test(code_, |
| 5321 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 5322 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5323 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5324 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5325 | Factory* factory = masm->isolate()->factory(); |
| 5326 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5327 | STATIC_ASSERT(kSmiTag == 0); |
| 5328 | STATIC_ASSERT(kSmiTagSize == 1); |
| 5329 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5330 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5331 | __ mov(result_, FieldOperand(result_, |
| 5332 | code_, times_half_pointer_size, |
| 5333 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5334 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5335 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5336 | __ bind(&exit_); |
| 5337 | } |
| 5338 | |
| 5339 | |
| 5340 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5341 | MacroAssembler* masm, |
| 5342 | const RuntimeCallHelper& call_helper) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5343 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5344 | |
| 5345 | __ bind(&slow_case_); |
| 5346 | call_helper.BeforeCall(masm); |
| 5347 | __ push(code_); |
| 5348 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5349 | if (!result_.is(eax)) { |
| 5350 | __ mov(result_, eax); |
| 5351 | } |
| 5352 | call_helper.AfterCall(masm); |
| 5353 | __ jmp(&exit_); |
| 5354 | |
| 5355 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5356 | } |
| 5357 | |
| 5358 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5359 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5360 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5361 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5362 | |
| 5363 | // Load the two arguments. |
| 5364 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5365 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5366 | |
| 5367 | // 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] | 5368 | // Otherwise, at least one of the arguments is definitely a string, |
| 5369 | // and we convert the one that is not known to be a string. |
| 5370 | if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) { |
| 5371 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT); |
| 5372 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5373 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5374 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5375 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5376 | |
| 5377 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5378 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5379 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5380 | __ j(above_equal, &call_runtime); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5381 | } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) { |
| 5382 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0); |
| 5383 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 5384 | &call_builtin); |
| 5385 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5386 | } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) { |
| 5387 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0); |
| 5388 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 5389 | &call_builtin); |
| 5390 | builtin_id = Builtins::STRING_ADD_LEFT; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5391 | } |
| 5392 | |
| 5393 | // Both arguments are strings. |
| 5394 | // eax: first string |
| 5395 | // edx: second string |
| 5396 | // 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] | 5397 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5398 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 5399 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5400 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5401 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5402 | // 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] | 5403 | Counters* counters = masm->isolate()->counters(); |
| 5404 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5405 | __ ret(2 * kPointerSize); |
| 5406 | __ bind(&second_not_zero_length); |
| 5407 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 5408 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5409 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5410 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5411 | // First string is empty, result is second string which is in edx. |
| 5412 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5413 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5414 | __ ret(2 * kPointerSize); |
| 5415 | |
| 5416 | // Both strings are non-empty. |
| 5417 | // eax: first string |
| 5418 | // ebx: length of first string as a smi |
| 5419 | // ecx: length of second string as a smi |
| 5420 | // edx: second string |
| 5421 | // Look at the length of the result of adding the two strings. |
| 5422 | Label string_add_flat_result, longer_than_two; |
| 5423 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5424 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5425 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 5426 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5427 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5428 | // Use the string table when adding two one character strings, as it |
| 5429 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5430 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5431 | __ j(not_equal, &longer_than_two); |
| 5432 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5433 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5434 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5435 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5436 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5437 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5438 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5439 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5440 | // 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] | 5441 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5442 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5443 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5444 | masm, ebx, ecx, eax, edx, edi, |
| 5445 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5446 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5447 | __ ret(2 * kPointerSize); |
| 5448 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5449 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5450 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5451 | // Reload the arguments. |
| 5452 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 5453 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 5454 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5455 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 5456 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5457 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5458 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5459 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5460 | // Pack both characters in ebx. |
| 5461 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5462 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5463 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5464 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5465 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5466 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5467 | |
| 5468 | __ bind(&longer_than_two); |
| 5469 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5470 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5471 | __ j(below, &string_add_flat_result); |
| 5472 | |
| 5473 | // 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] | 5474 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5475 | Label non_ascii, allocated, ascii_data; |
| 5476 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5477 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5478 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5479 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5480 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 5481 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 5482 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 5483 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5484 | __ j(zero, &non_ascii); |
| 5485 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5486 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5487 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5488 | __ bind(&allocated); |
| 5489 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 5490 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5491 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 5492 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 5493 | Immediate(String::kEmptyHashField)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5494 | |
| 5495 | Label skip_write_barrier, after_writing; |
| 5496 | ExternalReference high_promotion_mode = ExternalReference:: |
| 5497 | new_space_high_promotion_mode_active_address(masm->isolate()); |
| 5498 | __ test(Operand::StaticVariable(high_promotion_mode), Immediate(1)); |
| 5499 | __ j(zero, &skip_write_barrier); |
| 5500 | |
| 5501 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5502 | __ RecordWriteField(ecx, |
| 5503 | ConsString::kFirstOffset, |
| 5504 | eax, |
| 5505 | ebx, |
| 5506 | kDontSaveFPRegs); |
| 5507 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 5508 | __ RecordWriteField(ecx, |
| 5509 | ConsString::kSecondOffset, |
| 5510 | edx, |
| 5511 | ebx, |
| 5512 | kDontSaveFPRegs); |
| 5513 | __ jmp(&after_writing); |
| 5514 | |
| 5515 | __ bind(&skip_write_barrier); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5516 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 5517 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 5518 | |
| 5519 | __ bind(&after_writing); |
| 5520 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5521 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5522 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5523 | __ ret(2 * kPointerSize); |
| 5524 | __ bind(&non_ascii); |
| 5525 | // 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] | 5526 | // to contain only one byte characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5527 | // ecx: first instance type AND second instance type. |
| 5528 | // edi: second instance type. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5529 | __ test(ecx, Immediate(kOneByteDataHintMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5530 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5531 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5532 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 5533 | __ xor_(edi, ecx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5534 | STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0); |
| 5535 | __ and_(edi, kOneByteStringTag | kOneByteDataHintTag); |
| 5536 | __ cmp(edi, kOneByteStringTag | kOneByteDataHintTag); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 5537 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5538 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5539 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5540 | __ jmp(&allocated); |
| 5541 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5542 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5543 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5544 | // Handle creating a flat result from either external or sequential strings. |
| 5545 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5546 | // eax: first string |
| 5547 | // ebx: length of resulting flat string as a smi |
| 5548 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5549 | Label first_prepared, second_prepared; |
| 5550 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5551 | __ bind(&string_add_flat_result); |
| 5552 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 5553 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5554 | // ecx: instance type of first string |
| 5555 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5556 | __ test_b(ecx, kStringRepresentationMask); |
| 5557 | __ j(zero, &first_is_sequential, Label::kNear); |
| 5558 | // Rule out short external string and load string resource. |
| 5559 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5560 | __ test_b(ecx, kShortExternalStringMask); |
| 5561 | __ j(not_zero, &call_runtime); |
| 5562 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5563 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5564 | __ jmp(&first_prepared, Label::kNear); |
| 5565 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5566 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5567 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5568 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5569 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 5570 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 5571 | // Check whether both strings have same encoding. |
| 5572 | // edi: instance type of second string |
| 5573 | __ xor_(ecx, edi); |
| 5574 | __ test_b(ecx, kStringEncodingMask); |
| 5575 | __ j(not_zero, &call_runtime); |
| 5576 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5577 | __ test_b(edi, kStringRepresentationMask); |
| 5578 | __ j(zero, &second_is_sequential, Label::kNear); |
| 5579 | // Rule out short external string and load string resource. |
| 5580 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 5581 | __ test_b(edi, kShortExternalStringMask); |
| 5582 | __ j(not_zero, &call_runtime); |
| 5583 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5584 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5585 | __ jmp(&second_prepared, Label::kNear); |
| 5586 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5587 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5588 | __ bind(&second_prepared); |
| 5589 | |
| 5590 | // Push the addresses of both strings' first characters onto the stack. |
| 5591 | __ push(edx); |
| 5592 | __ push(eax); |
| 5593 | |
| 5594 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 5595 | // edi: instance type of second string |
| 5596 | // First string and second string have the same encoding. |
| 5597 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5598 | __ test_b(edi, kStringEncodingMask); |
| 5599 | __ j(zero, &non_ascii_string_add_flat_result); |
| 5600 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5601 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5602 | // ebx: length of resulting flat string as a smi |
| 5603 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5604 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5605 | // eax: result string |
| 5606 | __ mov(ecx, eax); |
| 5607 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5608 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5609 | // Load first argument's length and first character location. Account for |
| 5610 | // values currently on the stack when fetching arguments from it. |
| 5611 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5612 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5613 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5614 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5615 | // eax: result string |
| 5616 | // ecx: first character of result |
| 5617 | // edx: first char of first argument |
| 5618 | // edi: length of first argument |
| 5619 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5620 | // Load second argument's length and first character location. Account for |
| 5621 | // values currently on the stack when fetching arguments from it. |
| 5622 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5623 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5624 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5625 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5626 | // eax: result string |
| 5627 | // ecx: next character of result |
| 5628 | // edx: first char of second argument |
| 5629 | // edi: length of second argument |
| 5630 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5631 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5632 | __ ret(2 * kPointerSize); |
| 5633 | |
| 5634 | // Handle creating a flat two byte result. |
| 5635 | // eax: first string - known to be two byte |
| 5636 | // ebx: length of resulting flat string as a smi |
| 5637 | // edx: second string |
| 5638 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5639 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5640 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5641 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5642 | // eax: result string |
| 5643 | __ mov(ecx, eax); |
| 5644 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5645 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5646 | // Load second argument's length and first character location. Account for |
| 5647 | // values currently on the stack when fetching arguments from it. |
| 5648 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5649 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5650 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5651 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5652 | // eax: result string |
| 5653 | // ecx: first character of result |
| 5654 | // edx: first char of first argument |
| 5655 | // edi: length of first argument |
| 5656 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5657 | // Load second argument's length and first character location. Account for |
| 5658 | // values currently on the stack when fetching arguments from it. |
| 5659 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5660 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 5661 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5662 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5663 | // eax: result string |
| 5664 | // ecx: next character of result |
| 5665 | // edx: first char of second argument |
| 5666 | // edi: length of second argument |
| 5667 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 5668 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5669 | __ ret(2 * kPointerSize); |
| 5670 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5671 | // Recover stack pointer before jumping to runtime. |
| 5672 | __ bind(&call_runtime_drop_two); |
| 5673 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5674 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 5675 | __ bind(&call_runtime); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5676 | if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) { |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5677 | GenerateRegisterArgsPop(masm, ecx); |
| 5678 | // Build a frame |
| 5679 | { |
| 5680 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5681 | GenerateRegisterArgsPush(masm); |
| 5682 | __ CallRuntime(Runtime::kStringAdd, 2); |
| 5683 | } |
| 5684 | __ ret(0); |
| 5685 | } else { |
| 5686 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
| 5687 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5688 | |
| 5689 | if (call_builtin.is_linked()) { |
| 5690 | __ bind(&call_builtin); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 5691 | if ((flags_ & STRING_ADD_ERECT_FRAME) != 0) { |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5692 | GenerateRegisterArgsPop(masm, ecx); |
| 5693 | // Build a frame |
| 5694 | { |
| 5695 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 5696 | GenerateRegisterArgsPush(masm); |
| 5697 | __ InvokeBuiltin(builtin_id, CALL_FUNCTION); |
| 5698 | } |
| 5699 | __ ret(0); |
| 5700 | } else { |
| 5701 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
| 5702 | } |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5703 | } |
| 5704 | } |
| 5705 | |
| 5706 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 5707 | void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
| 5708 | __ push(eax); |
| 5709 | __ push(edx); |
| 5710 | } |
| 5711 | |
| 5712 | |
| 5713 | void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm, |
| 5714 | Register temp) { |
| 5715 | __ pop(temp); |
| 5716 | __ pop(edx); |
| 5717 | __ pop(eax); |
| 5718 | __ push(temp); |
| 5719 | } |
| 5720 | |
| 5721 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5722 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 5723 | int stack_offset, |
| 5724 | Register arg, |
| 5725 | Register scratch1, |
| 5726 | Register scratch2, |
| 5727 | Register scratch3, |
| 5728 | Label* slow) { |
| 5729 | // First check if the argument is already a string. |
| 5730 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5731 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5732 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 5733 | __ j(below, &done); |
| 5734 | |
| 5735 | // Check the number to string cache. |
| 5736 | Label not_cached; |
| 5737 | __ bind(¬_string); |
| 5738 | // Puts the cached result into scratch1. |
| 5739 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 5740 | arg, |
| 5741 | scratch1, |
| 5742 | scratch2, |
| 5743 | scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5744 | ¬_cached); |
| 5745 | __ mov(arg, scratch1); |
| 5746 | __ mov(Operand(esp, stack_offset), arg); |
| 5747 | __ jmp(&done); |
| 5748 | |
| 5749 | // Check if the argument is a safe string wrapper. |
| 5750 | __ bind(¬_cached); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 5751 | __ JumpIfSmi(arg, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5752 | __ CmpObjectType(arg, JS_VALUE_TYPE, scratch1); // map -> scratch1. |
| 5753 | __ j(not_equal, slow); |
| 5754 | __ test_b(FieldOperand(scratch1, Map::kBitField2Offset), |
| 5755 | 1 << Map::kStringWrapperSafeForDefaultValueOf); |
| 5756 | __ j(zero, slow); |
| 5757 | __ mov(arg, FieldOperand(arg, JSValue::kValueOffset)); |
| 5758 | __ mov(Operand(esp, stack_offset), arg); |
| 5759 | |
| 5760 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5761 | } |
| 5762 | |
| 5763 | |
| 5764 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5765 | Register dest, |
| 5766 | Register src, |
| 5767 | Register count, |
| 5768 | Register scratch, |
| 5769 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5770 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5771 | __ bind(&loop); |
| 5772 | // This loop just copies one character at a time, as it is only used for very |
| 5773 | // short strings. |
| 5774 | if (ascii) { |
| 5775 | __ mov_b(scratch, Operand(src, 0)); |
| 5776 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5777 | __ add(src, Immediate(1)); |
| 5778 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5779 | } else { |
| 5780 | __ mov_w(scratch, Operand(src, 0)); |
| 5781 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5782 | __ add(src, Immediate(2)); |
| 5783 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5784 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5785 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5786 | __ j(not_zero, &loop); |
| 5787 | } |
| 5788 | |
| 5789 | |
| 5790 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 5791 | Register dest, |
| 5792 | Register src, |
| 5793 | Register count, |
| 5794 | Register scratch, |
| 5795 | bool ascii) { |
| 5796 | // Copy characters using rep movs of doublewords. |
| 5797 | // The destination is aligned on a 4 byte boundary because we are |
| 5798 | // copying to the beginning of a newly allocated string. |
| 5799 | ASSERT(dest.is(edi)); // rep movs destination |
| 5800 | ASSERT(src.is(esi)); // rep movs source |
| 5801 | ASSERT(count.is(ecx)); // rep movs count |
| 5802 | ASSERT(!scratch.is(dest)); |
| 5803 | ASSERT(!scratch.is(src)); |
| 5804 | ASSERT(!scratch.is(count)); |
| 5805 | |
| 5806 | // Nothing to do for zero characters. |
| 5807 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5808 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5809 | __ j(zero, &done); |
| 5810 | |
| 5811 | // Make count the number of bytes to copy. |
| 5812 | if (!ascii) { |
| 5813 | __ shl(count, 1); |
| 5814 | } |
| 5815 | |
| 5816 | // 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] | 5817 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5818 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5819 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5820 | |
| 5821 | // Copy from edi to esi using rep movs instruction. |
| 5822 | __ mov(scratch, count); |
| 5823 | __ sar(count, 2); // Number of doublewords to copy. |
| 5824 | __ cld(); |
| 5825 | __ rep_movs(); |
| 5826 | |
| 5827 | // Find number of bytes left. |
| 5828 | __ mov(count, scratch); |
| 5829 | __ and_(count, 3); |
| 5830 | |
| 5831 | // Check if there are more bytes to copy. |
| 5832 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5833 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5834 | __ j(zero, &done); |
| 5835 | |
| 5836 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5837 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5838 | __ bind(&loop); |
| 5839 | __ mov_b(scratch, Operand(src, 0)); |
| 5840 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5841 | __ add(src, Immediate(1)); |
| 5842 | __ add(dest, Immediate(1)); |
| 5843 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5844 | __ j(not_zero, &loop); |
| 5845 | |
| 5846 | __ bind(&done); |
| 5847 | } |
| 5848 | |
| 5849 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5850 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5851 | Register c1, |
| 5852 | Register c2, |
| 5853 | Register scratch1, |
| 5854 | Register scratch2, |
| 5855 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5856 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5857 | Label* not_found) { |
| 5858 | // Register scratch3 is the general scratch register in this function. |
| 5859 | Register scratch = scratch3; |
| 5860 | |
| 5861 | // 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] | 5862 | // 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] | 5863 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5864 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5865 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5866 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 5867 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5868 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5869 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 5870 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 5871 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5872 | |
| 5873 | __ bind(¬_array_index); |
| 5874 | // Calculate the two character string hash. |
| 5875 | Register hash = scratch1; |
| 5876 | GenerateHashInit(masm, hash, c1, scratch); |
| 5877 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 5878 | GenerateHashGetHash(masm, hash, scratch); |
| 5879 | |
| 5880 | // Collect the two characters in a register. |
| 5881 | Register chars = c1; |
| 5882 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5883 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5884 | |
| 5885 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5886 | // hash: hash of two character string. |
| 5887 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5888 | // Load the string table. |
| 5889 | Register string_table = c2; |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5890 | ExternalReference roots_array_start = |
| 5891 | ExternalReference::roots_array_start(masm->isolate()); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5892 | __ mov(scratch, Immediate(Heap::kStringTableRootIndex)); |
| 5893 | __ mov(string_table, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5894 | Operand::StaticArray(scratch, times_pointer_size, roots_array_start)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5895 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5896 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5897 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5898 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5899 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5900 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5901 | |
| 5902 | // Registers |
| 5903 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5904 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5905 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5906 | // mask: capacity mask |
| 5907 | // scratch: - |
| 5908 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5909 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5910 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5911 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5912 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5913 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5914 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5915 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5916 | __ mov(scratch, hash); |
| 5917 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5918 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5919 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5920 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5921 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5922 | // Load the entry from the string table. |
| 5923 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5924 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5925 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5926 | scratch, |
| 5927 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5928 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5929 | |
| 5930 | // 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] | 5931 | Factory* factory = masm->isolate()->factory(); |
| 5932 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5933 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5934 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 5935 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5936 | |
| 5937 | // If length is not 2 the string is not a candidate. |
| 5938 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 5939 | Immediate(Smi::FromInt(2))); |
| 5940 | __ j(not_equal, &next_probe[i]); |
| 5941 | |
| 5942 | // As we are out of registers save the mask on the stack and use that |
| 5943 | // register as a temporary. |
| 5944 | __ push(mask); |
| 5945 | Register temp = mask; |
| 5946 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5947 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5948 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 5949 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 5950 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 5951 | temp, temp, &next_probe_pop_mask[i]); |
| 5952 | |
| 5953 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 5954 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5955 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5956 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5957 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5958 | __ bind(&next_probe_pop_mask[i]); |
| 5959 | __ pop(mask); |
| 5960 | __ bind(&next_probe[i]); |
| 5961 | } |
| 5962 | |
| 5963 | // No matching 2 character string found by probing. |
| 5964 | __ jmp(not_found); |
| 5965 | |
| 5966 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 5967 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 5968 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5969 | __ pop(mask); // Pop saved mask from the stack. |
| 5970 | if (!result.is(eax)) { |
| 5971 | __ mov(eax, result); |
| 5972 | } |
| 5973 | } |
| 5974 | |
| 5975 | |
| 5976 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 5977 | Register hash, |
| 5978 | Register character, |
| 5979 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5980 | // hash = (seed + character) + ((seed + character) << 10); |
| 5981 | if (Serializer::enabled()) { |
| 5982 | ExternalReference roots_array_start = |
| 5983 | ExternalReference::roots_array_start(masm->isolate()); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5984 | __ mov(scratch, Immediate(Heap::kHashSeedRootIndex)); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5985 | __ mov(scratch, Operand::StaticArray(scratch, |
| 5986 | times_pointer_size, |
| 5987 | roots_array_start)); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 5988 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5989 | __ add(scratch, character); |
| 5990 | __ mov(hash, scratch); |
| 5991 | __ shl(scratch, 10); |
| 5992 | __ add(hash, scratch); |
| 5993 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 5994 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 5995 | __ lea(scratch, Operand(character, seed)); |
| 5996 | __ shl(scratch, 10); |
| 5997 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 5998 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5999 | // hash ^= hash >> 6; |
| 6000 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6001 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6002 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6003 | } |
| 6004 | |
| 6005 | |
| 6006 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 6007 | Register hash, |
| 6008 | Register character, |
| 6009 | Register scratch) { |
| 6010 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6011 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6012 | // hash += hash << 10; |
| 6013 | __ mov(scratch, hash); |
| 6014 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6015 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6016 | // hash ^= hash >> 6; |
| 6017 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6018 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6019 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6020 | } |
| 6021 | |
| 6022 | |
| 6023 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 6024 | Register hash, |
| 6025 | Register scratch) { |
| 6026 | // hash += hash << 3; |
| 6027 | __ mov(scratch, hash); |
| 6028 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6029 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6030 | // hash ^= hash >> 11; |
| 6031 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6032 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6033 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6034 | // hash += hash << 15; |
| 6035 | __ mov(scratch, hash); |
| 6036 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6037 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6038 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6039 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 6040 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6041 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6042 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6043 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 6044 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6045 | __ bind(&hash_not_zero); |
| 6046 | } |
| 6047 | |
| 6048 | |
| 6049 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 6050 | Label runtime; |
| 6051 | |
| 6052 | // Stack frame on entry. |
| 6053 | // esp[0]: return address |
| 6054 | // esp[4]: to |
| 6055 | // esp[8]: from |
| 6056 | // esp[12]: string |
| 6057 | |
| 6058 | // Make sure first argument is a string. |
| 6059 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 6060 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6061 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6062 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 6063 | __ j(NegateCondition(is_string), &runtime); |
| 6064 | |
| 6065 | // eax: string |
| 6066 | // ebx: instance type |
| 6067 | |
| 6068 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6069 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6070 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6071 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6072 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6073 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6074 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6075 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 6076 | // Shorter than original string's length: an actual substring. |
| 6077 | __ j(below, ¬_original_string, Label::kNear); |
| 6078 | // Longer than original string's length or negative: unsafe arguments. |
| 6079 | __ j(above, &runtime); |
| 6080 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6081 | Counters* counters = masm->isolate()->counters(); |
| 6082 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6083 | __ ret(3 * kPointerSize); |
| 6084 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6085 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6086 | Label single_char; |
| 6087 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 6088 | __ j(equal, &single_char); |
| 6089 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6090 | // eax: string |
| 6091 | // ebx: instance type |
| 6092 | // ecx: sub string length (smi) |
| 6093 | // edx: from index (smi) |
| 6094 | // Deal with different string types: update the index if necessary |
| 6095 | // and put the underlying string into edi. |
| 6096 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 6097 | // If the string is not indirect, it can only be sequential or external. |
| 6098 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 6099 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 6100 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 6101 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 6102 | |
| 6103 | Factory* factory = masm->isolate()->factory(); |
| 6104 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 6105 | __ j(not_zero, &sliced_string, Label::kNear); |
| 6106 | // Cons string. Check whether it is flat, then fetch first part. |
| 6107 | // Flat cons strings have an empty second part. |
| 6108 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 6109 | factory->empty_string()); |
| 6110 | __ j(not_equal, &runtime); |
| 6111 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 6112 | // Update instance type. |
| 6113 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6114 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6115 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6116 | |
| 6117 | __ bind(&sliced_string); |
| 6118 | // Sliced string. Fetch parent and adjust start index by offset. |
| 6119 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 6120 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 6121 | // Update instance type. |
| 6122 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 6123 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 6124 | __ jmp(&underlying_unpacked, Label::kNear); |
| 6125 | |
| 6126 | __ bind(&seq_or_external_string); |
| 6127 | // Sequential or external string. Just move string to the expected register. |
| 6128 | __ mov(edi, eax); |
| 6129 | |
| 6130 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6131 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6132 | if (FLAG_string_slices) { |
| 6133 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6134 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6135 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6136 | // edx: adjusted start index (smi) |
| 6137 | // ecx: length (smi) |
| 6138 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 6139 | // Short slice. Copy instead of slicing. |
| 6140 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6141 | // Allocate new sliced string. At this point we do not reload the instance |
| 6142 | // type including the string encoding because we simply rely on the info |
| 6143 | // provided by the original string. It does not matter if the original |
| 6144 | // string's encoding is wrong because we always have to recheck encoding of |
| 6145 | // the newly created string's parent anyways due to externalized strings. |
| 6146 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6147 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6148 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 6149 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6150 | __ j(zero, &two_byte_slice, Label::kNear); |
| 6151 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 6152 | __ jmp(&set_slice_header, Label::kNear); |
| 6153 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 6154 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6155 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6156 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6157 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 6158 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 6159 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 6160 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6161 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 6162 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6163 | |
| 6164 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 6165 | } |
| 6166 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6167 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 6168 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6169 | // edx: adjusted start index (smi) |
| 6170 | // ecx: length (smi) |
| 6171 | // The subject string can only be external or sequential string of either |
| 6172 | // encoding at this point. |
| 6173 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 6174 | STATIC_ASSERT(kExternalStringTag != 0); |
| 6175 | STATIC_ASSERT(kSeqStringTag == 0); |
| 6176 | __ test_b(ebx, kExternalStringTag); |
| 6177 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6178 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6179 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6180 | // Rule out short external strings. |
| 6181 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 6182 | __ test_b(ebx, kShortExternalStringMask); |
| 6183 | __ j(not_zero, &runtime); |
| 6184 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 6185 | // 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] | 6186 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6187 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6188 | |
| 6189 | __ bind(&sequential_string); |
| 6190 | // Stash away (adjusted) index and (underlying) string. |
| 6191 | __ push(edx); |
| 6192 | __ push(edi); |
| 6193 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 6194 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6195 | __ test_b(ebx, kStringEncodingMask); |
| 6196 | __ j(zero, &two_byte_sequential); |
| 6197 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6198 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6199 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6200 | |
| 6201 | // eax: result string |
| 6202 | // ecx: result string length |
| 6203 | __ mov(edx, esi); // esi used by following code. |
| 6204 | // Locate first character of result. |
| 6205 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6206 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6207 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6208 | __ pop(esi); |
| 6209 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6210 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6211 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6212 | |
| 6213 | // eax: result string |
| 6214 | // ecx: result length |
| 6215 | // edx: original value of esi |
| 6216 | // edi: first character of result |
| 6217 | // esi: character of sub string start |
| 6218 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 6219 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6220 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6221 | __ ret(3 * kPointerSize); |
| 6222 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6223 | __ bind(&two_byte_sequential); |
| 6224 | // Sequential two-byte string. Allocate the result. |
| 6225 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6226 | |
| 6227 | // eax: result string |
| 6228 | // ecx: result string length |
| 6229 | __ mov(edx, esi); // esi used by following code. |
| 6230 | // Locate first character of result. |
| 6231 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6232 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6233 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6234 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6235 | __ pop(esi); |
| 6236 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6237 | // As from is a smi it is 2 times the value which matches the size of a two |
| 6238 | // byte character. |
| 6239 | STATIC_ASSERT(kSmiTag == 0); |
| 6240 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6241 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6242 | |
| 6243 | // eax: result string |
| 6244 | // ecx: result length |
| 6245 | // edx: original value of esi |
| 6246 | // edi: first character of result |
| 6247 | // esi: character of sub string start |
| 6248 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 6249 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6250 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6251 | __ ret(3 * kPointerSize); |
| 6252 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6253 | // Drop pushed values on the stack before tail call. |
| 6254 | __ bind(&runtime_drop_two); |
| 6255 | __ Drop(2); |
| 6256 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6257 | // Just jump to runtime to create the sub string. |
| 6258 | __ bind(&runtime); |
| 6259 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 6260 | |
| 6261 | __ bind(&single_char); |
| 6262 | // eax: string |
| 6263 | // ebx: instance type |
| 6264 | // ecx: sub string length (smi) |
| 6265 | // edx: from index (smi) |
| 6266 | StringCharAtGenerator generator( |
| 6267 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 6268 | generator.GenerateFast(masm); |
| 6269 | __ ret(3 * kPointerSize); |
| 6270 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6271 | } |
| 6272 | |
| 6273 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6274 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 6275 | Register left, |
| 6276 | Register right, |
| 6277 | Register scratch1, |
| 6278 | Register scratch2) { |
| 6279 | Register length = scratch1; |
| 6280 | |
| 6281 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6282 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6283 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 6284 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6285 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6286 | __ bind(&strings_not_equal); |
| 6287 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 6288 | __ ret(0); |
| 6289 | |
| 6290 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6291 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6292 | __ bind(&check_zero_length); |
| 6293 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6294 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6295 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6296 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6297 | __ ret(0); |
| 6298 | |
| 6299 | // Compare characters. |
| 6300 | __ bind(&compare_chars); |
| 6301 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6302 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6303 | |
| 6304 | // Characters are equal. |
| 6305 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6306 | __ ret(0); |
| 6307 | } |
| 6308 | |
| 6309 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6310 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 6311 | Register left, |
| 6312 | Register right, |
| 6313 | Register scratch1, |
| 6314 | Register scratch2, |
| 6315 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6316 | Counters* counters = masm->isolate()->counters(); |
| 6317 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6318 | |
| 6319 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6320 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6321 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 6322 | __ mov(scratch3, scratch1); |
| 6323 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 6324 | |
| 6325 | Register length_delta = scratch3; |
| 6326 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6327 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6328 | // 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] | 6329 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6330 | __ bind(&left_shorter); |
| 6331 | |
| 6332 | Register min_length = scratch1; |
| 6333 | |
| 6334 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6335 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6336 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6337 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6338 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6339 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6340 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6341 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6342 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6343 | |
| 6344 | // Compare lengths - strings up to min-length are equal. |
| 6345 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6346 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6347 | Label length_not_equal; |
| 6348 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6349 | |
| 6350 | // Result is EQUAL. |
| 6351 | STATIC_ASSERT(EQUAL == 0); |
| 6352 | STATIC_ASSERT(kSmiTag == 0); |
| 6353 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6354 | __ ret(0); |
| 6355 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6356 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6357 | Label result_less; |
| 6358 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6359 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6360 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6361 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 6362 | __ j(above, &result_greater, Label::kNear); |
| 6363 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6364 | |
| 6365 | // Result is LESS. |
| 6366 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 6367 | __ ret(0); |
| 6368 | |
| 6369 | // Result is GREATER. |
| 6370 | __ bind(&result_greater); |
| 6371 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 6372 | __ ret(0); |
| 6373 | } |
| 6374 | |
| 6375 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6376 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 6377 | MacroAssembler* masm, |
| 6378 | Register left, |
| 6379 | Register right, |
| 6380 | Register length, |
| 6381 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6382 | Label* chars_not_equal, |
| 6383 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6384 | // Change index to run from -length to -1 by adding length to string |
| 6385 | // start. This means that loop ends when index reaches zero, which |
| 6386 | // doesn't need an additional compare. |
| 6387 | __ SmiUntag(length); |
| 6388 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6389 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6390 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6391 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6392 | __ neg(length); |
| 6393 | Register index = length; // index = -length; |
| 6394 | |
| 6395 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6396 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6397 | __ bind(&loop); |
| 6398 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 6399 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6400 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6401 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6402 | __ j(not_zero, &loop); |
| 6403 | } |
| 6404 | |
| 6405 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6406 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 6407 | Label runtime; |
| 6408 | |
| 6409 | // Stack frame on entry. |
| 6410 | // esp[0]: return address |
| 6411 | // esp[4]: right string |
| 6412 | // esp[8]: left string |
| 6413 | |
| 6414 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 6415 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 6416 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6417 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6418 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6419 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6420 | STATIC_ASSERT(EQUAL == 0); |
| 6421 | STATIC_ASSERT(kSmiTag == 0); |
| 6422 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 6423 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6424 | __ ret(2 * kPointerSize); |
| 6425 | |
| 6426 | __ bind(¬_same); |
| 6427 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6428 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6429 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 6430 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 6431 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6432 | // Drop arguments from the stack. |
| 6433 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6434 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 6435 | __ push(ecx); |
| 6436 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 6437 | |
| 6438 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 6439 | // tagged as a small integer. |
| 6440 | __ bind(&runtime); |
| 6441 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6442 | } |
| 6443 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6444 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6445 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6446 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6447 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6448 | __ mov(ecx, edx); |
| 6449 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6450 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6451 | |
| 6452 | if (GetCondition() == equal) { |
| 6453 | // 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] | 6454 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6455 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6456 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6457 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6458 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6459 | // Correct sign of result in case of overflow. |
| 6460 | __ not_(edx); |
| 6461 | __ bind(&done); |
| 6462 | __ mov(eax, edx); |
| 6463 | } |
| 6464 | __ ret(0); |
| 6465 | |
| 6466 | __ bind(&miss); |
| 6467 | GenerateMiss(masm); |
| 6468 | } |
| 6469 | |
| 6470 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6471 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 6472 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6473 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6474 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6475 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6476 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6477 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6478 | if (left_ == CompareIC::SMI) { |
| 6479 | __ JumpIfNotSmi(edx, &miss); |
| 6480 | } |
| 6481 | if (right_ == CompareIC::SMI) { |
| 6482 | __ JumpIfNotSmi(eax, &miss); |
| 6483 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6484 | |
| 6485 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6486 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 6487 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6488 | CpuFeatureScope scope1(masm, SSE2); |
| 6489 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6490 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6491 | // Load left and right operand. |
| 6492 | Label done, left, left_smi, right_smi; |
| 6493 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 6494 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6495 | masm->isolate()->factory()->heap_number_map()); |
| 6496 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6497 | __ movdbl(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6498 | __ jmp(&left, Label::kNear); |
| 6499 | __ bind(&right_smi); |
| 6500 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 6501 | __ SmiUntag(ecx); |
| 6502 | __ cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6503 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6504 | __ bind(&left); |
| 6505 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 6506 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6507 | masm->isolate()->factory()->heap_number_map()); |
| 6508 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6509 | __ movdbl(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
| 6510 | __ jmp(&done); |
| 6511 | __ bind(&left_smi); |
| 6512 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 6513 | __ SmiUntag(ecx); |
| 6514 | __ cvtsi2sd(xmm0, ecx); |
| 6515 | |
| 6516 | __ bind(&done); |
| 6517 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6518 | __ ucomisd(xmm0, xmm1); |
| 6519 | |
| 6520 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6521 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6522 | |
| 6523 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 6524 | // Performing mov, because xor would destroy the flag register. |
| 6525 | __ mov(eax, 0); // equal |
| 6526 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6527 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6528 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6529 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6530 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6531 | } else { |
| 6532 | __ mov(ecx, edx); |
| 6533 | __ and_(ecx, eax); |
| 6534 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 6535 | |
| 6536 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 6537 | masm->isolate()->factory()->heap_number_map()); |
| 6538 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 6539 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 6540 | masm->isolate()->factory()->heap_number_map()); |
| 6541 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6542 | } |
| 6543 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6544 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6545 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6546 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 6547 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 6548 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6549 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6550 | __ bind(&maybe_undefined1); |
| 6551 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6552 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6553 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6554 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 6555 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 6556 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 6557 | __ jmp(&unordered); |
| 6558 | } |
| 6559 | |
| 6560 | __ bind(&maybe_undefined2); |
| 6561 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 6562 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 6563 | __ j(equal, &unordered); |
| 6564 | } |
| 6565 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6566 | __ bind(&miss); |
| 6567 | GenerateMiss(masm); |
| 6568 | } |
| 6569 | |
| 6570 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6571 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 6572 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6573 | ASSERT(GetCondition() == equal); |
| 6574 | |
| 6575 | // Registers containing left and right operands respectively. |
| 6576 | Register left = edx; |
| 6577 | Register right = eax; |
| 6578 | Register tmp1 = ecx; |
| 6579 | Register tmp2 = ebx; |
| 6580 | |
| 6581 | // Check that both operands are heap objects. |
| 6582 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6583 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6584 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6585 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6586 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6587 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6588 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6589 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6590 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6591 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6592 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 6593 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 6594 | __ or_(tmp1, tmp2); |
| 6595 | __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 6596 | __ j(not_zero, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6597 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6598 | // Internalized strings are compared by identity. |
| 6599 | Label done; |
| 6600 | __ cmp(left, right); |
| 6601 | // Make sure eax is non-zero. At this point input operands are |
| 6602 | // guaranteed to be non-zero. |
| 6603 | ASSERT(right.is(eax)); |
| 6604 | __ j(not_equal, &done, Label::kNear); |
| 6605 | STATIC_ASSERT(EQUAL == 0); |
| 6606 | STATIC_ASSERT(kSmiTag == 0); |
| 6607 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6608 | __ bind(&done); |
| 6609 | __ ret(0); |
| 6610 | |
| 6611 | __ bind(&miss); |
| 6612 | GenerateMiss(masm); |
| 6613 | } |
| 6614 | |
| 6615 | |
| 6616 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 6617 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 6618 | ASSERT(GetCondition() == equal); |
| 6619 | |
| 6620 | // Registers containing left and right operands respectively. |
| 6621 | Register left = edx; |
| 6622 | Register right = eax; |
| 6623 | Register tmp1 = ecx; |
| 6624 | Register tmp2 = ebx; |
| 6625 | |
| 6626 | // Check that both operands are heap objects. |
| 6627 | Label miss; |
| 6628 | __ mov(tmp1, left); |
| 6629 | STATIC_ASSERT(kSmiTag == 0); |
| 6630 | __ and_(tmp1, right); |
| 6631 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 6632 | |
| 6633 | // Check that both operands are unique names. This leaves the instance |
| 6634 | // types loaded in tmp1 and tmp2. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6635 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6636 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6637 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6638 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6639 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6640 | __ JumpIfNotUniqueName(tmp1, &miss, Label::kNear); |
| 6641 | __ JumpIfNotUniqueName(tmp2, &miss, Label::kNear); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6642 | |
| 6643 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6644 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6645 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6646 | // Make sure eax is non-zero. At this point input operands are |
| 6647 | // guaranteed to be non-zero. |
| 6648 | ASSERT(right.is(eax)); |
| 6649 | __ j(not_equal, &done, Label::kNear); |
| 6650 | STATIC_ASSERT(EQUAL == 0); |
| 6651 | STATIC_ASSERT(kSmiTag == 0); |
| 6652 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6653 | __ bind(&done); |
| 6654 | __ ret(0); |
| 6655 | |
| 6656 | __ bind(&miss); |
| 6657 | GenerateMiss(masm); |
| 6658 | } |
| 6659 | |
| 6660 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6661 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6662 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6663 | Label miss; |
| 6664 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6665 | bool equality = Token::IsEqualityOp(op_); |
| 6666 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6667 | // Registers containing left and right operands respectively. |
| 6668 | Register left = edx; |
| 6669 | Register right = eax; |
| 6670 | Register tmp1 = ecx; |
| 6671 | Register tmp2 = ebx; |
| 6672 | Register tmp3 = edi; |
| 6673 | |
| 6674 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6675 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6676 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6677 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6678 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6679 | |
| 6680 | // Check that both operands are strings. This leaves the instance |
| 6681 | // types loaded in tmp1 and tmp2. |
| 6682 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 6683 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 6684 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6685 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6686 | __ mov(tmp3, tmp1); |
| 6687 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6688 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6689 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 6690 | __ j(not_zero, &miss); |
| 6691 | |
| 6692 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6693 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6694 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6695 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6696 | STATIC_ASSERT(EQUAL == 0); |
| 6697 | STATIC_ASSERT(kSmiTag == 0); |
| 6698 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 6699 | __ ret(0); |
| 6700 | |
| 6701 | // Handle not identical strings. |
| 6702 | __ bind(¬_same); |
| 6703 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 6704 | // 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] | 6705 | // 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] | 6706 | // non-equality compare, we still need to determine the order. We |
| 6707 | // also know they are both strings. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6708 | if (equality) { |
| 6709 | Label do_compare; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 6710 | STATIC_ASSERT(kInternalizedTag == 0); |
| 6711 | __ or_(tmp1, tmp2); |
| 6712 | __ test(tmp1, Immediate(kIsNotInternalizedMask)); |
| 6713 | __ j(not_zero, &do_compare, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6714 | // Make sure eax is non-zero. At this point input operands are |
| 6715 | // guaranteed to be non-zero. |
| 6716 | ASSERT(right.is(eax)); |
| 6717 | __ ret(0); |
| 6718 | __ bind(&do_compare); |
| 6719 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6720 | |
| 6721 | // Check that both strings are sequential ASCII. |
| 6722 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6723 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 6724 | |
| 6725 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6726 | if (equality) { |
| 6727 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6728 | masm, left, right, tmp1, tmp2); |
| 6729 | } else { |
| 6730 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 6731 | masm, left, right, tmp1, tmp2, tmp3); |
| 6732 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6733 | |
| 6734 | // Handle more complex cases in runtime. |
| 6735 | __ bind(&runtime); |
| 6736 | __ pop(tmp1); // Return address. |
| 6737 | __ push(left); |
| 6738 | __ push(right); |
| 6739 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 6740 | if (equality) { |
| 6741 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6742 | } else { |
| 6743 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 6744 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6745 | |
| 6746 | __ bind(&miss); |
| 6747 | GenerateMiss(masm); |
| 6748 | } |
| 6749 | |
| 6750 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6751 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 6752 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 6753 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6754 | __ mov(ecx, edx); |
| 6755 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 6756 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6757 | |
| 6758 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6759 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6760 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6761 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6762 | |
| 6763 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6764 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6765 | __ ret(0); |
| 6766 | |
| 6767 | __ bind(&miss); |
| 6768 | GenerateMiss(masm); |
| 6769 | } |
| 6770 | |
| 6771 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6772 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 6773 | Label miss; |
| 6774 | __ mov(ecx, edx); |
| 6775 | __ and_(ecx, eax); |
| 6776 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6777 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6778 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 6779 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 6780 | __ cmp(ecx, known_map_); |
| 6781 | __ j(not_equal, &miss, Label::kNear); |
| 6782 | __ cmp(ebx, known_map_); |
| 6783 | __ j(not_equal, &miss, Label::kNear); |
| 6784 | |
| 6785 | __ sub(eax, edx); |
| 6786 | __ ret(0); |
| 6787 | |
| 6788 | __ bind(&miss); |
| 6789 | GenerateMiss(masm); |
| 6790 | } |
| 6791 | |
| 6792 | |
| 6793 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6794 | { |
| 6795 | // Call the runtime system in a fresh internal frame. |
| 6796 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 6797 | masm->isolate()); |
| 6798 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6799 | __ push(edx); // Preserve edx and eax. |
| 6800 | __ push(eax); |
| 6801 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6802 | __ push(eax); |
| 6803 | __ push(Immediate(Smi::FromInt(op_))); |
| 6804 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 6805 | // Compute the entry point of the rewritten stub. |
| 6806 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 6807 | __ pop(eax); |
| 6808 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6809 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6810 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6811 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6812 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 6813 | } |
| 6814 | |
| 6815 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6816 | // Helper function used to check that the dictionary doesn't contain |
| 6817 | // the property. This function may return false negatives, so miss_label |
| 6818 | // must always call a backup property check that is complete. |
| 6819 | // 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] | 6820 | // Name must be a unique name and receiver must be a heap object. |
| 6821 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 6822 | Label* miss, |
| 6823 | Label* done, |
| 6824 | Register properties, |
| 6825 | Handle<Name> name, |
| 6826 | Register r0) { |
| 6827 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6828 | |
| 6829 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6830 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6831 | // undefined value), it guarantees the hash table doesn't contain the |
| 6832 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6833 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6834 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6835 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6836 | Register index = r0; |
| 6837 | // Capacity is smi 2^n. |
| 6838 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 6839 | __ dec(index); |
| 6840 | __ and_(index, |
| 6841 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6842 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6843 | |
| 6844 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6845 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6846 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 6847 | Register entity_name = r0; |
| 6848 | // Having undefined at this place means the name is not contained. |
| 6849 | ASSERT_EQ(kSmiTagSize, 1); |
| 6850 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 6851 | kElementsStartOffset - kHeapObjectTag)); |
| 6852 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 6853 | __ j(equal, done); |
| 6854 | |
| 6855 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6856 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6857 | __ j(equal, miss); |
| 6858 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6859 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6860 | // Check for the hole and skip. |
| 6861 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6862 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 6863 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6864 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6865 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 6866 | __ JumpIfNotUniqueName(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 6867 | miss); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6868 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6869 | } |
| 6870 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6871 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 6872 | __ push(Immediate(Handle<Object>(name))); |
| 6873 | __ push(Immediate(name->Hash())); |
| 6874 | __ CallStub(&stub); |
| 6875 | __ test(r0, r0); |
| 6876 | __ j(not_zero, miss); |
| 6877 | __ jmp(done); |
| 6878 | } |
| 6879 | |
| 6880 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6881 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6882 | // |done| label if a property with the given name is found leaving the |
| 6883 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 6884 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6885 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6886 | Label* miss, |
| 6887 | Label* done, |
| 6888 | Register elements, |
| 6889 | Register name, |
| 6890 | Register r0, |
| 6891 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 6892 | ASSERT(!elements.is(r0)); |
| 6893 | ASSERT(!elements.is(r1)); |
| 6894 | ASSERT(!name.is(r0)); |
| 6895 | ASSERT(!name.is(r1)); |
| 6896 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6897 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6898 | |
| 6899 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 6900 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 6901 | __ dec(r1); |
| 6902 | |
| 6903 | // Generate an unrolled loop that performs a few probes before |
| 6904 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6905 | // cover ~93% of loads from dictionaries. |
| 6906 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6907 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6908 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 6909 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6910 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6911 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6912 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6913 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6914 | |
| 6915 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6916 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6917 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 6918 | |
| 6919 | // Check if the key is identical to the name. |
| 6920 | __ cmp(name, Operand(elements, |
| 6921 | r0, |
| 6922 | times_4, |
| 6923 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 6924 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6925 | } |
| 6926 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6927 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6928 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6929 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 6930 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6931 | __ push(r0); |
| 6932 | __ CallStub(&stub); |
| 6933 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6934 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6935 | __ j(zero, miss); |
| 6936 | __ jmp(done); |
| 6937 | } |
| 6938 | |
| 6939 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6940 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 6941 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 6942 | // 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] | 6943 | // Stack frame on entry: |
| 6944 | // esp[0 * kPointerSize]: return address. |
| 6945 | // esp[1 * kPointerSize]: key's hash. |
| 6946 | // esp[2 * kPointerSize]: key. |
| 6947 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6948 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6949 | // result_: used as scratch. |
| 6950 | // index_: will hold an index of entry if lookup is successful. |
| 6951 | // might alias with result_. |
| 6952 | // Returns: |
| 6953 | // result_ is zero if lookup failed, non zero otherwise. |
| 6954 | |
| 6955 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 6956 | |
| 6957 | Register scratch = result_; |
| 6958 | |
| 6959 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 6960 | __ dec(scratch); |
| 6961 | __ SmiUntag(scratch); |
| 6962 | __ push(scratch); |
| 6963 | |
| 6964 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6965 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6966 | // undefined value), it guarantees the hash table doesn't contain the |
| 6967 | // property. It's true even if some slots represent deleted properties |
| 6968 | // (their names are the null value). |
| 6969 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 6970 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6971 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 6972 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6973 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6974 | } |
| 6975 | __ and_(scratch, Operand(esp, 0)); |
| 6976 | |
| 6977 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6978 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 6979 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 6980 | |
| 6981 | // Having undefined at this place means the name is not contained. |
| 6982 | ASSERT_EQ(kSmiTagSize, 1); |
| 6983 | __ mov(scratch, Operand(dictionary_, |
| 6984 | index_, |
| 6985 | times_pointer_size, |
| 6986 | kElementsStartOffset - kHeapObjectTag)); |
| 6987 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 6988 | __ j(equal, ¬_in_dictionary); |
| 6989 | |
| 6990 | // Stop if found the property. |
| 6991 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 6992 | __ j(equal, &in_dictionary); |
| 6993 | |
| 6994 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6995 | // 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] | 6996 | // 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] | 6997 | // key we are looking for. |
| 6998 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 6999 | // Check if the entry name is not a unique name. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7000 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7001 | __ JumpIfNotUniqueName(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 7002 | &maybe_in_dictionary); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 7003 | } |
| 7004 | } |
| 7005 | |
| 7006 | __ bind(&maybe_in_dictionary); |
| 7007 | // If we are doing negative lookup then probing failure should be |
| 7008 | // treated as a lookup success. For positive lookup probing failure |
| 7009 | // should be treated as lookup failure. |
| 7010 | if (mode_ == POSITIVE_LOOKUP) { |
| 7011 | __ mov(result_, Immediate(0)); |
| 7012 | __ Drop(1); |
| 7013 | __ ret(2 * kPointerSize); |
| 7014 | } |
| 7015 | |
| 7016 | __ bind(&in_dictionary); |
| 7017 | __ mov(result_, Immediate(1)); |
| 7018 | __ Drop(1); |
| 7019 | __ ret(2 * kPointerSize); |
| 7020 | |
| 7021 | __ bind(¬_in_dictionary); |
| 7022 | __ mov(result_, Immediate(0)); |
| 7023 | __ Drop(1); |
| 7024 | __ ret(2 * kPointerSize); |
| 7025 | } |
| 7026 | |
| 7027 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7028 | struct AheadOfTimeWriteBarrierStubList { |
| 7029 | Register object, value, address; |
| 7030 | RememberedSetAction action; |
| 7031 | }; |
| 7032 | |
| 7033 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7034 | #define REG(Name) { kRegister_ ## Name ## _Code } |
| 7035 | |
| 7036 | static const AheadOfTimeWriteBarrierStubList kAheadOfTime[] = { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7037 | // Used in RegExpExecStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7038 | { REG(ebx), REG(eax), REG(edi), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7039 | // Used in CompileArrayPushCall. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7040 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
| 7041 | { REG(ebx), REG(edi), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7042 | // Used in CompileStoreGlobal and CallFunctionStub. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7043 | { REG(ebx), REG(ecx), REG(edx), OMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7044 | // Used in StoreStubCompiler::CompileStoreField and |
| 7045 | // KeyedStoreStubCompiler::CompileStoreField via GenerateStoreField. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7046 | { REG(edx), REG(ecx), REG(ebx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7047 | // GenerateStoreField calls the stub with two different permutations of |
| 7048 | // registers. This is the second. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7049 | { REG(ebx), REG(ecx), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7050 | // StoreIC::GenerateNormal via GenerateDictionaryStore |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7051 | { REG(ebx), REG(edi), REG(edx), EMIT_REMEMBERED_SET }, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7052 | // KeyedStoreIC::GenerateGeneric. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7053 | { REG(ebx), REG(edx), REG(ecx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7054 | // KeyedStoreStubCompiler::GenerateStoreFastElement. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7055 | { REG(edi), REG(ebx), REG(ecx), EMIT_REMEMBERED_SET}, |
| 7056 | { REG(edx), REG(edi), REG(ebx), EMIT_REMEMBERED_SET}, |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7057 | // ElementsTransitionGenerator::GenerateMapChangeElementTransition |
| 7058 | // and ElementsTransitionGenerator::GenerateSmiToDouble |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7059 | // and ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7060 | { REG(edx), REG(ebx), REG(edi), EMIT_REMEMBERED_SET}, |
| 7061 | { REG(edx), REG(ebx), REG(edi), OMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 7062 | // ElementsTransitionGenerator::GenerateDoubleToObject |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7063 | { REG(eax), REG(edx), REG(esi), EMIT_REMEMBERED_SET}, |
| 7064 | { REG(edx), REG(eax), REG(edi), EMIT_REMEMBERED_SET}, |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7065 | // StoreArrayLiteralElementStub::Generate |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7066 | { REG(ebx), REG(eax), REG(ecx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7067 | // FastNewClosureStub and StringAddStub::Generate |
yangguo@chromium.org | 5a11aaf | 2012-06-20 11:29:00 +0000 | [diff] [blame] | 7068 | { REG(ecx), REG(edx), REG(ebx), EMIT_REMEMBERED_SET}, |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 7069 | // StringAddStub::Generate |
| 7070 | { REG(ecx), REG(eax), REG(ebx), EMIT_REMEMBERED_SET}, |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7071 | // Null termination. |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7072 | { 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] | 7073 | }; |
| 7074 | |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7075 | #undef REG |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7076 | |
| 7077 | bool RecordWriteStub::IsPregenerated() { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7078 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7079 | !entry->object.is(no_reg); |
| 7080 | entry++) { |
| 7081 | if (object_.is(entry->object) && |
| 7082 | value_.is(entry->value) && |
| 7083 | address_.is(entry->address) && |
| 7084 | remembered_set_action_ == entry->action && |
| 7085 | save_fp_regs_mode_ == kDontSaveFPRegs) { |
| 7086 | return true; |
| 7087 | } |
| 7088 | } |
| 7089 | return false; |
| 7090 | } |
| 7091 | |
| 7092 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7093 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 7094 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 7095 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
| 7096 | stub.GetCode(isolate)->set_is_pregenerated(true); |
| 7097 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7098 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7099 | stub2.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7100 | } |
| 7101 | } |
| 7102 | |
| 7103 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7104 | void RecordWriteStub::GenerateFixedRegStubsAheadOfTime(Isolate* isolate) { |
jkummerow@chromium.org | 1456e70 | 2012-03-30 08:38:13 +0000 | [diff] [blame] | 7105 | for (const AheadOfTimeWriteBarrierStubList* entry = kAheadOfTime; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7106 | !entry->object.is(no_reg); |
| 7107 | entry++) { |
| 7108 | RecordWriteStub stub(entry->object, |
| 7109 | entry->value, |
| 7110 | entry->address, |
| 7111 | entry->action, |
| 7112 | kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7113 | stub.GetCode(isolate)->set_is_pregenerated(true); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7114 | } |
| 7115 | } |
| 7116 | |
| 7117 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7118 | bool CodeStub::CanUseFPRegisters() { |
| 7119 | return CpuFeatures::IsSupported(SSE2); |
| 7120 | } |
| 7121 | |
| 7122 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7123 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 7124 | // the value has just been written into the object, now this stub makes sure |
| 7125 | // we keep the GC informed. The word in the object where the value has been |
| 7126 | // written is in the address register. |
| 7127 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 7128 | Label skip_to_incremental_noncompacting; |
| 7129 | Label skip_to_incremental_compacting; |
| 7130 | |
| 7131 | // The first two instructions are generated with labels so as to get the |
| 7132 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 7133 | // forth between a compare instructions (a nop in this position) and the |
| 7134 | // real branch when we start and stop incremental heap marking. |
| 7135 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 7136 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 7137 | |
| 7138 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7139 | __ RememberedSetHelper(object_, |
| 7140 | address_, |
| 7141 | value_, |
| 7142 | save_fp_regs_mode_, |
| 7143 | MacroAssembler::kReturnAtEnd); |
| 7144 | } else { |
| 7145 | __ ret(0); |
| 7146 | } |
| 7147 | |
| 7148 | __ bind(&skip_to_incremental_noncompacting); |
| 7149 | GenerateIncremental(masm, INCREMENTAL); |
| 7150 | |
| 7151 | __ bind(&skip_to_incremental_compacting); |
| 7152 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 7153 | |
| 7154 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 7155 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 7156 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 7157 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 7158 | } |
| 7159 | |
| 7160 | |
| 7161 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 7162 | regs_.Save(masm); |
| 7163 | |
| 7164 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 7165 | Label dont_need_remembered_set; |
| 7166 | |
| 7167 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7168 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 7169 | regs_.scratch0(), |
| 7170 | &dont_need_remembered_set); |
| 7171 | |
| 7172 | __ CheckPageFlag(regs_.object(), |
| 7173 | regs_.scratch0(), |
| 7174 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 7175 | not_zero, |
| 7176 | &dont_need_remembered_set); |
| 7177 | |
| 7178 | // First notify the incremental marker if necessary, then update the |
| 7179 | // remembered set. |
| 7180 | CheckNeedsToInformIncrementalMarker( |
| 7181 | masm, |
| 7182 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 7183 | mode); |
| 7184 | InformIncrementalMarker(masm, mode); |
| 7185 | regs_.Restore(masm); |
| 7186 | __ RememberedSetHelper(object_, |
| 7187 | address_, |
| 7188 | value_, |
| 7189 | save_fp_regs_mode_, |
| 7190 | MacroAssembler::kReturnAtEnd); |
| 7191 | |
| 7192 | __ bind(&dont_need_remembered_set); |
| 7193 | } |
| 7194 | |
| 7195 | CheckNeedsToInformIncrementalMarker( |
| 7196 | masm, |
| 7197 | kReturnOnNoNeedToInformIncrementalMarker, |
| 7198 | mode); |
| 7199 | InformIncrementalMarker(masm, mode); |
| 7200 | regs_.Restore(masm); |
| 7201 | __ ret(0); |
| 7202 | } |
| 7203 | |
| 7204 | |
| 7205 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 7206 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7207 | int argument_count = 3; |
| 7208 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 7209 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 7210 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7211 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 7212 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7213 | |
| 7214 | AllowExternalCallThatCantCauseGC scope(masm); |
| 7215 | if (mode == INCREMENTAL_COMPACTION) { |
| 7216 | __ CallCFunction( |
| 7217 | ExternalReference::incremental_evacuation_record_write_function( |
| 7218 | masm->isolate()), |
| 7219 | argument_count); |
| 7220 | } else { |
| 7221 | ASSERT(mode == INCREMENTAL); |
| 7222 | __ CallCFunction( |
| 7223 | ExternalReference::incremental_marking_record_write_function( |
| 7224 | masm->isolate()), |
| 7225 | argument_count); |
| 7226 | } |
| 7227 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 7228 | } |
| 7229 | |
| 7230 | |
| 7231 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 7232 | MacroAssembler* masm, |
| 7233 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 7234 | Mode mode) { |
| 7235 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 7236 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 7237 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 7238 | __ and_(regs_.scratch0(), regs_.object()); |
| 7239 | __ mov(regs_.scratch1(), |
| 7240 | Operand(regs_.scratch0(), |
| 7241 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 7242 | __ sub(regs_.scratch1(), Immediate(1)); |
| 7243 | __ mov(Operand(regs_.scratch0(), |
| 7244 | MemoryChunk::kWriteBarrierCounterOffset), |
| 7245 | regs_.scratch1()); |
| 7246 | __ j(negative, &need_incremental); |
| 7247 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 7248 | // Let's look at the color of the object: If it is not black we don't have |
| 7249 | // to inform the incremental marker. |
| 7250 | __ JumpIfBlack(regs_.object(), |
| 7251 | regs_.scratch0(), |
| 7252 | regs_.scratch1(), |
| 7253 | &object_is_black, |
| 7254 | Label::kNear); |
| 7255 | |
| 7256 | regs_.Restore(masm); |
| 7257 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7258 | __ RememberedSetHelper(object_, |
| 7259 | address_, |
| 7260 | value_, |
| 7261 | save_fp_regs_mode_, |
| 7262 | MacroAssembler::kReturnAtEnd); |
| 7263 | } else { |
| 7264 | __ ret(0); |
| 7265 | } |
| 7266 | |
| 7267 | __ bind(&object_is_black); |
| 7268 | |
| 7269 | // Get the value from the slot. |
| 7270 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 7271 | |
| 7272 | if (mode == INCREMENTAL_COMPACTION) { |
| 7273 | Label ensure_not_white; |
| 7274 | |
| 7275 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 7276 | regs_.scratch1(), // Scratch. |
| 7277 | MemoryChunk::kEvacuationCandidateMask, |
| 7278 | zero, |
| 7279 | &ensure_not_white, |
| 7280 | Label::kNear); |
| 7281 | |
| 7282 | __ CheckPageFlag(regs_.object(), |
| 7283 | regs_.scratch1(), // Scratch. |
| 7284 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 7285 | not_zero, |
| 7286 | &ensure_not_white, |
| 7287 | Label::kNear); |
| 7288 | |
| 7289 | __ jmp(&need_incremental); |
| 7290 | |
| 7291 | __ bind(&ensure_not_white); |
| 7292 | } |
| 7293 | |
| 7294 | // We need an extra register for this, so we push the object register |
| 7295 | // temporarily. |
| 7296 | __ push(regs_.object()); |
| 7297 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 7298 | regs_.scratch1(), // Scratch. |
| 7299 | regs_.object(), // Scratch. |
| 7300 | &need_incremental_pop_object, |
| 7301 | Label::kNear); |
| 7302 | __ pop(regs_.object()); |
| 7303 | |
| 7304 | regs_.Restore(masm); |
| 7305 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 7306 | __ RememberedSetHelper(object_, |
| 7307 | address_, |
| 7308 | value_, |
| 7309 | save_fp_regs_mode_, |
| 7310 | MacroAssembler::kReturnAtEnd); |
| 7311 | } else { |
| 7312 | __ ret(0); |
| 7313 | } |
| 7314 | |
| 7315 | __ bind(&need_incremental_pop_object); |
| 7316 | __ pop(regs_.object()); |
| 7317 | |
| 7318 | __ bind(&need_incremental); |
| 7319 | |
| 7320 | // Fall through when we need to inform the incremental marker. |
| 7321 | } |
| 7322 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7323 | |
| 7324 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 7325 | // ----------- S t a t e ------------- |
| 7326 | // -- eax : element value to store |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7327 | // -- ecx : element index as smi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7328 | // -- esp[0] : return address |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7329 | // -- esp[4] : array literal index in function |
| 7330 | // -- esp[8] : array literal |
| 7331 | // clobbers ebx, edx, edi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7332 | // ----------------------------------- |
| 7333 | |
| 7334 | Label element_done; |
| 7335 | Label double_elements; |
| 7336 | Label smi_element; |
| 7337 | Label slow_elements; |
| 7338 | Label slow_elements_from_double; |
| 7339 | Label fast_elements; |
| 7340 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 7341 | // Get array literal index, array literal and its map. |
| 7342 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 7343 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 7344 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 7345 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7346 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7347 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7348 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7349 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7350 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7351 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7352 | // Store into the array literal requires a elements transition. Call into |
| 7353 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7354 | |
| 7355 | __ bind(&slow_elements); |
| 7356 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 7357 | // call. |
| 7358 | __ push(ebx); |
| 7359 | __ push(ecx); |
| 7360 | __ push(eax); |
| 7361 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 7362 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 7363 | __ push(edx); |
| 7364 | __ push(edi); // Return return address so that tail call returns to right |
| 7365 | // place. |
| 7366 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 7367 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7368 | __ bind(&slow_elements_from_double); |
| 7369 | __ pop(edx); |
| 7370 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7371 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7372 | // 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] | 7373 | __ bind(&fast_elements); |
| 7374 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7375 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7376 | FixedArrayBase::kHeaderSize)); |
| 7377 | __ mov(Operand(ecx, 0), eax); |
| 7378 | // Update the write barrier for the array store. |
| 7379 | __ RecordWrite(ebx, ecx, eax, |
| 7380 | kDontSaveFPRegs, |
| 7381 | EMIT_REMEMBERED_SET, |
| 7382 | OMIT_SMI_CHECK); |
| 7383 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7384 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7385 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 7386 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7387 | __ bind(&smi_element); |
| 7388 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7389 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 7390 | FixedArrayBase::kHeaderSize), eax); |
| 7391 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7392 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 7393 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7394 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7395 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 7396 | __ push(edx); |
| 7397 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 7398 | __ StoreNumberToDoubleElements(eax, |
| 7399 | edx, |
| 7400 | ecx, |
| 7401 | edi, |
| 7402 | xmm0, |
| 7403 | &slow_elements_from_double, |
| 7404 | false); |
| 7405 | __ pop(edx); |
| 7406 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 7407 | } |
| 7408 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7409 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7410 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 7411 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 7412 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7413 | int parameter_count_offset = |
| 7414 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 7415 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7416 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7417 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 7418 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 7419 | ? kPointerSize |
| 7420 | : 0; |
| 7421 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 7422 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 7423 | } |
| 7424 | |
| 7425 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7426 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7427 | if (masm->isolate()->function_entry_hook() != NULL) { |
| 7428 | // It's always safe to call the entry hook stub, as the hook itself |
| 7429 | // is not allowed to call back to V8. |
| 7430 | AllowStubCallsScope allow_stub_calls(masm, true); |
| 7431 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7432 | ProfileEntryHookStub stub; |
| 7433 | masm->CallStub(&stub); |
| 7434 | } |
| 7435 | } |
| 7436 | |
| 7437 | |
| 7438 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7439 | // Save volatile registers. |
| 7440 | const int kNumSavedRegisters = 3; |
| 7441 | __ push(eax); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7442 | __ push(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7443 | __ push(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7444 | |
| 7445 | // Calculate and push the original stack pointer. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7446 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7447 | __ push(eax); |
| 7448 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 7449 | // Retrieve our return address and use it to calculate the calling |
| 7450 | // function's address. |
| 7451 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7452 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 7453 | __ push(eax); |
| 7454 | |
| 7455 | // Call the entry hook. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7456 | ASSERT(masm->isolate()->function_entry_hook() != NULL); |
| 7457 | __ call(FUNCTION_ADDR(masm->isolate()->function_entry_hook()), |
| 7458 | RelocInfo::RUNTIME_ENTRY); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7459 | __ add(esp, Immediate(2 * kPointerSize)); |
| 7460 | |
| 7461 | // Restore ecx. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7462 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7463 | __ pop(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7464 | __ pop(eax); |
| 7465 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 7466 | __ ret(0); |
| 7467 | } |
| 7468 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7469 | |
| 7470 | template<class T> |
| 7471 | static void CreateArrayDispatch(MacroAssembler* masm) { |
| 7472 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7473 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7474 | for (int i = 0; i <= last_index; ++i) { |
| 7475 | Label next; |
| 7476 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7477 | __ cmp(edx, kind); |
| 7478 | __ j(not_equal, &next); |
| 7479 | T stub(kind); |
| 7480 | __ TailCallStub(&stub); |
| 7481 | __ bind(&next); |
| 7482 | } |
| 7483 | |
| 7484 | // If we reached this point there is a problem. |
| 7485 | __ Abort("Unexpected ElementsKind in array constructor"); |
| 7486 | } |
| 7487 | |
| 7488 | |
| 7489 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm) { |
| 7490 | // ebx - type info cell |
| 7491 | // edx - kind |
| 7492 | // eax - number of arguments |
| 7493 | // edi - constructor? |
| 7494 | // esp[0] - return address |
| 7495 | // esp[4] - last argument |
| 7496 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 7497 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 7498 | ASSERT(FAST_ELEMENTS == 2); |
| 7499 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 7500 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 7501 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 7502 | |
| 7503 | Handle<Object> undefined_sentinel( |
| 7504 | masm->isolate()->heap()->undefined_value(), |
| 7505 | masm->isolate()); |
| 7506 | |
| 7507 | // is the low bit set? If so, we are holey and that is good. |
| 7508 | __ test_b(edx, 1); |
| 7509 | Label normal_sequence; |
| 7510 | __ j(not_zero, &normal_sequence); |
| 7511 | |
| 7512 | // look at the first argument |
| 7513 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7514 | __ test(ecx, ecx); |
| 7515 | __ j(zero, &normal_sequence); |
| 7516 | |
| 7517 | // We are going to create a holey array, but our kind is non-holey. |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7518 | // Fix kind and retry (only if we have an allocation site in the cell). |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7519 | __ inc(edx); |
| 7520 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7521 | __ j(equal, &normal_sequence); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7522 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
| 7523 | Handle<Map> allocation_site_map( |
| 7524 | masm->isolate()->heap()->allocation_site_map(), |
| 7525 | masm->isolate()); |
| 7526 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 7527 | __ j(not_equal, &normal_sequence); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7528 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7529 | // Save the resulting elements kind in type info |
| 7530 | __ SmiTag(edx); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7531 | __ mov(FieldOperand(ecx, AllocationSite::kTransitionInfoOffset), edx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7532 | __ SmiUntag(edx); |
| 7533 | |
| 7534 | __ bind(&normal_sequence); |
| 7535 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 7536 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7537 | for (int i = 0; i <= last_index; ++i) { |
| 7538 | Label next; |
| 7539 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 7540 | __ cmp(edx, kind); |
| 7541 | __ j(not_equal, &next); |
| 7542 | ArraySingleArgumentConstructorStub stub(kind); |
| 7543 | __ TailCallStub(&stub); |
| 7544 | __ bind(&next); |
| 7545 | } |
| 7546 | |
| 7547 | // If we reached this point there is a problem. |
| 7548 | __ Abort("Unexpected ElementsKind in array constructor"); |
| 7549 | } |
| 7550 | |
| 7551 | |
| 7552 | template<class T> |
| 7553 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 7554 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 7555 | TERMINAL_FAST_ELEMENTS_KIND); |
| 7556 | for (int i = 0; i <= to_index; ++i) { |
| 7557 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7558 | T stub(kind); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7559 | stub.GetCode(isolate)->set_is_pregenerated(true); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7560 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7561 | T stub1(kind, CONTEXT_CHECK_REQUIRED, DISABLE_ALLOCATION_SITES); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7562 | stub1.GetCode(isolate)->set_is_pregenerated(true); |
| 7563 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7564 | } |
| 7565 | } |
| 7566 | |
| 7567 | |
| 7568 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 7569 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 7570 | isolate); |
| 7571 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 7572 | isolate); |
| 7573 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 7574 | isolate); |
| 7575 | } |
| 7576 | |
| 7577 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7578 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 7579 | Isolate* isolate) { |
| 7580 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 7581 | for (int i = 0; i < 2; i++) { |
| 7582 | // For internal arrays we only need a few things |
| 7583 | InternalArrayNoArgumentConstructorStub stubh1(kinds[i]); |
| 7584 | stubh1.GetCode(isolate)->set_is_pregenerated(true); |
| 7585 | InternalArraySingleArgumentConstructorStub stubh2(kinds[i]); |
| 7586 | stubh2.GetCode(isolate)->set_is_pregenerated(true); |
| 7587 | InternalArrayNArgumentsConstructorStub stubh3(kinds[i]); |
| 7588 | stubh3.GetCode(isolate)->set_is_pregenerated(true); |
| 7589 | } |
| 7590 | } |
| 7591 | |
| 7592 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7593 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7594 | // ----------- S t a t e ------------- |
| 7595 | // -- eax : argc (only if argument_count_ == ANY) |
| 7596 | // -- ebx : type info cell |
| 7597 | // -- edi : constructor |
| 7598 | // -- esp[0] : return address |
| 7599 | // -- esp[4] : last argument |
| 7600 | // ----------------------------------- |
| 7601 | Handle<Object> undefined_sentinel( |
| 7602 | masm->isolate()->heap()->undefined_value(), |
| 7603 | masm->isolate()); |
| 7604 | |
| 7605 | if (FLAG_debug_code) { |
| 7606 | // The array construct code is only set for the global and natives |
| 7607 | // builtin Array functions which always have maps. |
| 7608 | |
| 7609 | // Initial map for the builtin Array function should be a map. |
| 7610 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7611 | // Will both indicate a NULL and a Smi. |
| 7612 | __ test(ecx, Immediate(kSmiTagMask)); |
| 7613 | __ Assert(not_zero, "Unexpected initial map for Array function"); |
| 7614 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 7615 | __ Assert(equal, "Unexpected initial map for Array function"); |
| 7616 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7617 | // We should either have undefined in ebx or a valid cell |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7618 | Label okay_here; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7619 | Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7620 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7621 | __ j(equal, &okay_here); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 7622 | __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7623 | __ Assert(equal, "Expected property cell in register ebx"); |
| 7624 | __ bind(&okay_here); |
| 7625 | } |
| 7626 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7627 | Label no_info, switch_ready; |
| 7628 | // Get the elements kind and case on that. |
| 7629 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 7630 | __ j(equal, &no_info); |
| 7631 | __ mov(edx, FieldOperand(ebx, Cell::kValueOffset)); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 7632 | |
| 7633 | // The type cell may have undefined in its value. |
| 7634 | __ cmp(edx, Immediate(undefined_sentinel)); |
| 7635 | __ j(equal, &no_info); |
| 7636 | |
| 7637 | // The type cell has either an AllocationSite or a JSFunction |
| 7638 | __ cmp(FieldOperand(edx, 0), Immediate(Handle<Map>( |
| 7639 | masm->isolate()->heap()->allocation_site_map()))); |
| 7640 | __ j(not_equal, &no_info); |
| 7641 | |
| 7642 | __ mov(edx, FieldOperand(edx, AllocationSite::kTransitionInfoOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7643 | __ SmiUntag(edx); |
| 7644 | __ jmp(&switch_ready); |
| 7645 | __ bind(&no_info); |
| 7646 | __ mov(edx, Immediate(GetInitialFastElementsKind())); |
| 7647 | __ bind(&switch_ready); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7648 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7649 | if (argument_count_ == ANY) { |
| 7650 | Label not_zero_case, not_one_case; |
| 7651 | __ test(eax, eax); |
| 7652 | __ j(not_zero, ¬_zero_case); |
| 7653 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7654 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7655 | __ bind(¬_zero_case); |
| 7656 | __ cmp(eax, 1); |
| 7657 | __ j(greater, ¬_one_case); |
| 7658 | CreateArrayDispatchOneArgument(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7659 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7660 | __ bind(¬_one_case); |
| 7661 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
| 7662 | } else if (argument_count_ == NONE) { |
| 7663 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm); |
| 7664 | } else if (argument_count_ == ONE) { |
| 7665 | CreateArrayDispatchOneArgument(masm); |
| 7666 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 7667 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7668 | } else { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7669 | UNREACHABLE(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 7670 | } |
| 7671 | } |
| 7672 | |
| 7673 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7674 | void InternalArrayConstructorStub::GenerateCase( |
| 7675 | MacroAssembler* masm, ElementsKind kind) { |
| 7676 | Label not_zero_case, not_one_case; |
| 7677 | Label normal_sequence; |
| 7678 | |
| 7679 | __ test(eax, eax); |
| 7680 | __ j(not_zero, ¬_zero_case); |
| 7681 | InternalArrayNoArgumentConstructorStub stub0(kind); |
| 7682 | __ TailCallStub(&stub0); |
| 7683 | |
| 7684 | __ bind(¬_zero_case); |
| 7685 | __ cmp(eax, 1); |
| 7686 | __ j(greater, ¬_one_case); |
| 7687 | |
| 7688 | if (IsFastPackedElementsKind(kind)) { |
| 7689 | // We might need to create a holey array |
| 7690 | // look at the first argument |
| 7691 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 7692 | __ test(ecx, ecx); |
| 7693 | __ j(zero, &normal_sequence); |
| 7694 | |
| 7695 | InternalArraySingleArgumentConstructorStub |
| 7696 | stub1_holey(GetHoleyElementsKind(kind)); |
| 7697 | __ TailCallStub(&stub1_holey); |
| 7698 | } |
| 7699 | |
| 7700 | __ bind(&normal_sequence); |
| 7701 | InternalArraySingleArgumentConstructorStub stub1(kind); |
| 7702 | __ TailCallStub(&stub1); |
| 7703 | |
| 7704 | __ bind(¬_one_case); |
| 7705 | InternalArrayNArgumentsConstructorStub stubN(kind); |
| 7706 | __ TailCallStub(&stubN); |
| 7707 | } |
| 7708 | |
| 7709 | |
| 7710 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 7711 | // ----------- S t a t e ------------- |
| 7712 | // -- eax : argc |
| 7713 | // -- ebx : type info cell |
| 7714 | // -- edi : constructor |
| 7715 | // -- esp[0] : return address |
| 7716 | // -- esp[4] : last argument |
| 7717 | // ----------------------------------- |
| 7718 | |
| 7719 | if (FLAG_debug_code) { |
| 7720 | // The array construct code is only set for the global and natives |
| 7721 | // builtin Array functions which always have maps. |
| 7722 | |
| 7723 | // Initial map for the builtin Array function should be a map. |
| 7724 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 7725 | // Will both indicate a NULL and a Smi. |
| 7726 | __ test(ecx, Immediate(kSmiTagMask)); |
| 7727 | __ Assert(not_zero, "Unexpected initial map for Array function"); |
| 7728 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
| 7729 | __ Assert(equal, "Unexpected initial map for Array function"); |
| 7730 | } |
| 7731 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7732 | // Figure out the right elements kind |
| 7733 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7734 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7735 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 7736 | // but the following masking takes care of that anyway. |
| 7737 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 7738 | // Retrieve elements_kind from bit field 2. |
| 7739 | __ and_(ecx, Map::kElementsKindMask); |
| 7740 | __ shr(ecx, Map::kElementsKindShift); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7741 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7742 | if (FLAG_debug_code) { |
| 7743 | Label done; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7744 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7745 | __ j(equal, &done); |
| 7746 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 7747 | __ Assert(equal, |
| 7748 | "Invalid ElementsKind for InternalArray or InternalPackedArray"); |
| 7749 | __ bind(&done); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7750 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 7751 | |
| 7752 | Label fast_elements_case; |
| 7753 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 7754 | __ j(equal, &fast_elements_case); |
| 7755 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 7756 | |
| 7757 | __ bind(&fast_elements_case); |
| 7758 | GenerateCase(masm, FAST_ELEMENTS); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 7759 | } |
| 7760 | |
| 7761 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 7762 | #undef __ |
| 7763 | |
| 7764 | } } // namespace v8::internal |
| 7765 | |
| 7766 | #endif // V8_TARGET_ARCH_IA32 |