yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 30 | #if V8_TARGET_ARCH_IA32 |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 31 | |
| 32 | #include "bootstrapper.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 33 | #include "code-stubs.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 34 | #include "isolate.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 35 | #include "jsregexp.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 36 | #include "regexp-macro-assembler.h" |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 37 | #include "runtime.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 38 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 39 | #include "codegen.h" |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 40 | #include "runtime.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 41 | |
| 42 | namespace v8 { |
| 43 | namespace internal { |
| 44 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 45 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 46 | void FastNewClosureStub::InitializeInterfaceDescriptor( |
| 47 | Isolate* isolate, |
| 48 | CodeStubInterfaceDescriptor* descriptor) { |
| 49 | static Register registers[] = { ebx }; |
| 50 | descriptor->register_param_count_ = 1; |
| 51 | descriptor->register_params_ = registers; |
| 52 | descriptor->deoptimization_handler_ = |
| 53 | Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry; |
| 54 | } |
| 55 | |
| 56 | |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 57 | void FastNewContextStub::InitializeInterfaceDescriptor( |
| 58 | Isolate* isolate, |
| 59 | CodeStubInterfaceDescriptor* descriptor) { |
| 60 | static Register registers[] = { edi }; |
| 61 | descriptor->register_param_count_ = 1; |
| 62 | descriptor->register_params_ = registers; |
| 63 | descriptor->deoptimization_handler_ = NULL; |
| 64 | } |
| 65 | |
| 66 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 67 | void ToNumberStub::InitializeInterfaceDescriptor( |
| 68 | Isolate* isolate, |
| 69 | CodeStubInterfaceDescriptor* descriptor) { |
| 70 | static Register registers[] = { eax }; |
| 71 | descriptor->register_param_count_ = 1; |
| 72 | descriptor->register_params_ = registers; |
| 73 | descriptor->deoptimization_handler_ = NULL; |
| 74 | } |
| 75 | |
| 76 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 77 | void NumberToStringStub::InitializeInterfaceDescriptor( |
| 78 | Isolate* isolate, |
| 79 | CodeStubInterfaceDescriptor* descriptor) { |
| 80 | static Register registers[] = { eax }; |
| 81 | descriptor->register_param_count_ = 1; |
| 82 | descriptor->register_params_ = registers; |
bmeurer@chromium.org | e7a0745 | 2013-10-21 13:27:29 +0000 | [diff] [blame] | 83 | descriptor->deoptimization_handler_ = |
| 84 | Runtime::FunctionForId(Runtime::kNumberToString)->entry; |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 88 | void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( |
| 89 | Isolate* isolate, |
| 90 | CodeStubInterfaceDescriptor* descriptor) { |
| 91 | static Register registers[] = { eax, ebx, ecx }; |
| 92 | descriptor->register_param_count_ = 3; |
| 93 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 94 | descriptor->deoptimization_handler_ = |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 95 | Runtime::FunctionForId(Runtime::kCreateArrayLiteralStubBailout)->entry; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 99 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 100 | Isolate* isolate, |
| 101 | CodeStubInterfaceDescriptor* descriptor) { |
| 102 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 103 | descriptor->register_param_count_ = 4; |
| 104 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 105 | descriptor->deoptimization_handler_ = |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 106 | Runtime::FunctionForId(Runtime::kCreateObjectLiteral)->entry; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 110 | void CreateAllocationSiteStub::InitializeInterfaceDescriptor( |
| 111 | Isolate* isolate, |
| 112 | CodeStubInterfaceDescriptor* descriptor) { |
| 113 | static Register registers[] = { ebx }; |
| 114 | descriptor->register_param_count_ = 1; |
| 115 | descriptor->register_params_ = registers; |
| 116 | descriptor->deoptimization_handler_ = NULL; |
| 117 | } |
| 118 | |
| 119 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 120 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 121 | Isolate* isolate, |
| 122 | CodeStubInterfaceDescriptor* descriptor) { |
| 123 | static Register registers[] = { edx, ecx }; |
| 124 | descriptor->register_param_count_ = 2; |
| 125 | descriptor->register_params_ = registers; |
| 126 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 127 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 131 | void KeyedLoadDictionaryElementStub::InitializeInterfaceDescriptor( |
| 132 | Isolate* isolate, |
| 133 | CodeStubInterfaceDescriptor* descriptor) { |
| 134 | static Register registers[] = { edx, ecx }; |
| 135 | descriptor->register_param_count_ = 2; |
| 136 | descriptor->register_params_ = registers; |
| 137 | descriptor->deoptimization_handler_ = |
| 138 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
| 139 | } |
| 140 | |
| 141 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 142 | void LoadFieldStub::InitializeInterfaceDescriptor( |
| 143 | Isolate* isolate, |
| 144 | CodeStubInterfaceDescriptor* descriptor) { |
| 145 | static Register registers[] = { edx }; |
| 146 | descriptor->register_param_count_ = 1; |
| 147 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 148 | descriptor->deoptimization_handler_ = NULL; |
| 149 | } |
| 150 | |
| 151 | |
| 152 | void KeyedLoadFieldStub::InitializeInterfaceDescriptor( |
| 153 | Isolate* isolate, |
| 154 | CodeStubInterfaceDescriptor* descriptor) { |
| 155 | static Register registers[] = { edx }; |
| 156 | descriptor->register_param_count_ = 1; |
| 157 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 158 | descriptor->deoptimization_handler_ = NULL; |
| 159 | } |
| 160 | |
| 161 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 162 | void KeyedArrayCallStub::InitializeInterfaceDescriptor( |
| 163 | Isolate* isolate, |
| 164 | CodeStubInterfaceDescriptor* descriptor) { |
| 165 | static Register registers[] = { ecx }; |
| 166 | descriptor->register_param_count_ = 1; |
| 167 | descriptor->register_params_ = registers; |
| 168 | descriptor->continuation_type_ = TAIL_CALL_CONTINUATION; |
| 169 | descriptor->handler_arguments_mode_ = PASS_ARGUMENTS; |
| 170 | descriptor->deoptimization_handler_ = |
| 171 | FUNCTION_ADDR(KeyedCallIC_MissFromStubFailure); |
| 172 | } |
| 173 | |
| 174 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 175 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 176 | Isolate* isolate, |
| 177 | CodeStubInterfaceDescriptor* descriptor) { |
| 178 | static Register registers[] = { edx, ecx, eax }; |
| 179 | descriptor->register_param_count_ = 3; |
| 180 | descriptor->register_params_ = registers; |
| 181 | descriptor->deoptimization_handler_ = |
| 182 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 183 | } |
| 184 | |
| 185 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 186 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 187 | Isolate* isolate, |
| 188 | CodeStubInterfaceDescriptor* descriptor) { |
| 189 | static Register registers[] = { eax, ebx }; |
| 190 | descriptor->register_param_count_ = 2; |
| 191 | descriptor->register_params_ = registers; |
| 192 | descriptor->deoptimization_handler_ = |
| 193 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 194 | } |
| 195 | |
| 196 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 197 | static void InitializeArrayConstructorDescriptor( |
| 198 | Isolate* isolate, |
| 199 | CodeStubInterfaceDescriptor* descriptor, |
| 200 | int constant_stack_parameter_count) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 201 | // register state |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 202 | // eax -- number of arguments |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 203 | // edi -- function |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 204 | // ebx -- allocation site with elements kind |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 205 | static Register registers_variable_args[] = { edi, ebx, eax }; |
| 206 | static Register registers_no_args[] = { edi, ebx }; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 207 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 208 | if (constant_stack_parameter_count == 0) { |
| 209 | descriptor->register_param_count_ = 2; |
| 210 | descriptor->register_params_ = registers_no_args; |
| 211 | } else { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 212 | // stack param count needs (constructor pointer, and single argument) |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 213 | descriptor->handler_arguments_mode_ = PASS_ARGUMENTS; |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 214 | descriptor->stack_parameter_count_ = eax; |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 215 | descriptor->register_param_count_ = 3; |
| 216 | descriptor->register_params_ = registers_variable_args; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 217 | } |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 218 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 219 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 220 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 221 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 222 | Runtime::FunctionForId(Runtime::kArrayConstructor)->entry; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 226 | static void InitializeInternalArrayConstructorDescriptor( |
| 227 | Isolate* isolate, |
| 228 | CodeStubInterfaceDescriptor* descriptor, |
| 229 | int constant_stack_parameter_count) { |
| 230 | // register state |
| 231 | // eax -- number of arguments |
| 232 | // edi -- constructor function |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 233 | static Register registers_variable_args[] = { edi, eax }; |
| 234 | static Register registers_no_args[] = { edi }; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 235 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 236 | if (constant_stack_parameter_count == 0) { |
| 237 | descriptor->register_param_count_ = 1; |
| 238 | descriptor->register_params_ = registers_no_args; |
| 239 | } else { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 240 | // stack param count needs (constructor pointer, and single argument) |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 241 | descriptor->handler_arguments_mode_ = PASS_ARGUMENTS; |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 242 | descriptor->stack_parameter_count_ = eax; |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 243 | descriptor->register_param_count_ = 2; |
| 244 | descriptor->register_params_ = registers_variable_args; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 245 | } |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 246 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 247 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 248 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
| 249 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 250 | Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 254 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 255 | Isolate* isolate, |
| 256 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 257 | InitializeArrayConstructorDescriptor(isolate, descriptor, 0); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | |
| 261 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 262 | Isolate* isolate, |
| 263 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 264 | InitializeArrayConstructorDescriptor(isolate, descriptor, 1); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | |
| 268 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 269 | Isolate* isolate, |
| 270 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 271 | InitializeArrayConstructorDescriptor(isolate, descriptor, -1); |
| 272 | } |
| 273 | |
| 274 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 275 | void InternalArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 276 | Isolate* isolate, |
| 277 | CodeStubInterfaceDescriptor* descriptor) { |
| 278 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 0); |
| 279 | } |
| 280 | |
| 281 | |
| 282 | void InternalArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 283 | Isolate* isolate, |
| 284 | CodeStubInterfaceDescriptor* descriptor) { |
| 285 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 1); |
| 286 | } |
| 287 | |
| 288 | |
| 289 | void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 290 | Isolate* isolate, |
| 291 | CodeStubInterfaceDescriptor* descriptor) { |
| 292 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, -1); |
| 293 | } |
| 294 | |
| 295 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 296 | void CompareNilICStub::InitializeInterfaceDescriptor( |
| 297 | Isolate* isolate, |
| 298 | CodeStubInterfaceDescriptor* descriptor) { |
| 299 | static Register registers[] = { eax }; |
| 300 | descriptor->register_param_count_ = 1; |
| 301 | descriptor->register_params_ = registers; |
| 302 | descriptor->deoptimization_handler_ = |
| 303 | FUNCTION_ADDR(CompareNilIC_Miss); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 304 | descriptor->SetMissHandler( |
| 305 | ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 306 | } |
| 307 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 308 | void ToBooleanStub::InitializeInterfaceDescriptor( |
| 309 | Isolate* isolate, |
| 310 | CodeStubInterfaceDescriptor* descriptor) { |
| 311 | static Register registers[] = { eax }; |
| 312 | descriptor->register_param_count_ = 1; |
| 313 | descriptor->register_params_ = registers; |
| 314 | descriptor->deoptimization_handler_ = |
| 315 | FUNCTION_ADDR(ToBooleanIC_Miss); |
| 316 | descriptor->SetMissHandler( |
| 317 | ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate)); |
| 318 | } |
| 319 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 320 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 321 | void StoreGlobalStub::InitializeInterfaceDescriptor( |
| 322 | Isolate* isolate, |
| 323 | CodeStubInterfaceDescriptor* descriptor) { |
| 324 | static Register registers[] = { edx, ecx, eax }; |
| 325 | descriptor->register_param_count_ = 3; |
| 326 | descriptor->register_params_ = registers; |
| 327 | descriptor->deoptimization_handler_ = |
| 328 | FUNCTION_ADDR(StoreIC_MissFromStubFailure); |
| 329 | } |
| 330 | |
| 331 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 332 | void ElementsTransitionAndStoreStub::InitializeInterfaceDescriptor( |
| 333 | Isolate* isolate, |
| 334 | CodeStubInterfaceDescriptor* descriptor) { |
| 335 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 336 | descriptor->register_param_count_ = 4; |
| 337 | descriptor->register_params_ = registers; |
| 338 | descriptor->deoptimization_handler_ = |
| 339 | FUNCTION_ADDR(ElementsTransitionAndStoreIC_Miss); |
| 340 | } |
| 341 | |
| 342 | |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 343 | void BinaryOpICStub::InitializeInterfaceDescriptor( |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 344 | Isolate* isolate, |
| 345 | CodeStubInterfaceDescriptor* descriptor) { |
| 346 | static Register registers[] = { edx, eax }; |
| 347 | descriptor->register_param_count_ = 2; |
| 348 | descriptor->register_params_ = registers; |
| 349 | descriptor->deoptimization_handler_ = FUNCTION_ADDR(BinaryOpIC_Miss); |
| 350 | descriptor->SetMissHandler( |
| 351 | ExternalReference(IC_Utility(IC::kBinaryOpIC_Miss), isolate)); |
| 352 | } |
| 353 | |
| 354 | |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 355 | void BinaryOpWithAllocationSiteStub::InitializeInterfaceDescriptor( |
| 356 | Isolate* isolate, |
| 357 | CodeStubInterfaceDescriptor* descriptor) { |
| 358 | static Register registers[] = { ecx, edx, eax }; |
| 359 | descriptor->register_param_count_ = 3; |
| 360 | descriptor->register_params_ = registers; |
| 361 | descriptor->deoptimization_handler_ = |
| 362 | FUNCTION_ADDR(BinaryOpIC_MissWithAllocationSite); |
| 363 | } |
| 364 | |
| 365 | |
machenbach@chromium.org | bbbda92 | 2014-01-23 09:38:20 +0000 | [diff] [blame] | 366 | void StringAddStub::InitializeInterfaceDescriptor( |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 367 | Isolate* isolate, |
| 368 | CodeStubInterfaceDescriptor* descriptor) { |
| 369 | static Register registers[] = { edx, eax }; |
| 370 | descriptor->register_param_count_ = 2; |
| 371 | descriptor->register_params_ = registers; |
| 372 | descriptor->deoptimization_handler_ = |
| 373 | Runtime::FunctionForId(Runtime::kStringAdd)->entry; |
| 374 | } |
| 375 | |
| 376 | |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 377 | void CallDescriptors::InitializeForIsolate(Isolate* isolate) { |
| 378 | { |
| 379 | CallInterfaceDescriptor* descriptor = |
| 380 | isolate->call_descriptor(Isolate::ArgumentAdaptorCall); |
| 381 | static Register registers[] = { edi, // JSFunction |
| 382 | esi, // context |
| 383 | eax, // actual number of arguments |
| 384 | ebx, // expected number of arguments |
| 385 | }; |
| 386 | static Representation representations[] = { |
| 387 | Representation::Tagged(), // JSFunction |
| 388 | Representation::Tagged(), // context |
| 389 | Representation::Integer32(), // actual number of arguments |
| 390 | Representation::Integer32(), // expected number of arguments |
| 391 | }; |
| 392 | descriptor->register_param_count_ = 4; |
| 393 | descriptor->register_params_ = registers; |
| 394 | descriptor->param_representations_ = representations; |
| 395 | } |
| 396 | { |
| 397 | CallInterfaceDescriptor* descriptor = |
| 398 | isolate->call_descriptor(Isolate::KeyedCall); |
| 399 | static Register registers[] = { esi, // context |
| 400 | ecx, // key |
| 401 | }; |
| 402 | static Representation representations[] = { |
| 403 | Representation::Tagged(), // context |
| 404 | Representation::Tagged(), // key |
| 405 | }; |
| 406 | descriptor->register_param_count_ = 2; |
| 407 | descriptor->register_params_ = registers; |
| 408 | descriptor->param_representations_ = representations; |
| 409 | } |
| 410 | { |
| 411 | CallInterfaceDescriptor* descriptor = |
| 412 | isolate->call_descriptor(Isolate::NamedCall); |
| 413 | static Register registers[] = { esi, // context |
| 414 | ecx, // name |
| 415 | }; |
| 416 | static Representation representations[] = { |
| 417 | Representation::Tagged(), // context |
| 418 | Representation::Tagged(), // name |
| 419 | }; |
| 420 | descriptor->register_param_count_ = 2; |
| 421 | descriptor->register_params_ = registers; |
| 422 | descriptor->param_representations_ = representations; |
| 423 | } |
machenbach@chromium.org | af4fba3 | 2014-01-27 01:05:32 +0000 | [diff] [blame^] | 424 | { |
| 425 | CallInterfaceDescriptor* descriptor = |
| 426 | isolate->call_descriptor(Isolate::CallHandler); |
| 427 | static Register registers[] = { esi, // context |
| 428 | edx, // receiver |
| 429 | }; |
| 430 | static Representation representations[] = { |
| 431 | Representation::Tagged(), // context |
| 432 | Representation::Tagged(), // receiver |
| 433 | }; |
| 434 | descriptor->register_param_count_ = 2; |
| 435 | descriptor->register_params_ = registers; |
| 436 | descriptor->param_representations_ = representations; |
| 437 | } |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 441 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 442 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 443 | |
| 444 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
| 445 | // Update the static counter each time a new code stub is generated. |
| 446 | Isolate* isolate = masm->isolate(); |
| 447 | isolate->counters()->code_stubs()->Increment(); |
| 448 | |
| 449 | CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
| 450 | int param_count = descriptor->register_param_count_; |
| 451 | { |
| 452 | // Call the runtime system in a fresh internal frame. |
| 453 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 454 | ASSERT(descriptor->register_param_count_ == 0 || |
| 455 | eax.is(descriptor->register_params_[param_count - 1])); |
| 456 | // Push arguments |
| 457 | for (int i = 0; i < param_count; ++i) { |
| 458 | __ push(descriptor->register_params_[i]); |
| 459 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 460 | ExternalReference miss = descriptor->miss_handler(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 461 | __ CallExternalReference(miss, descriptor->register_param_count_); |
| 462 | } |
| 463 | |
| 464 | __ ret(0); |
| 465 | } |
| 466 | |
| 467 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 468 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 469 | // Stack layout on entry: |
| 470 | // |
| 471 | // [esp + (1 * kPointerSize)]: function |
| 472 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 473 | |
| 474 | // Try to allocate the context in new space. |
| 475 | Label gc; |
| 476 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 477 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 478 | |
| 479 | // Get the function or sentinel from the stack. |
| 480 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 481 | |
| 482 | // Get the serialized scope info from the stack. |
| 483 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 484 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 485 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 486 | Factory* factory = masm->isolate()->factory(); |
| 487 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 488 | factory->block_context_map()); |
| 489 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 490 | Immediate(Smi::FromInt(length))); |
| 491 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 492 | // 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] | 493 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 494 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 495 | // we still have to look up. |
| 496 | Label after_sentinel; |
| 497 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 498 | if (FLAG_debug_code) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 499 | __ cmp(ecx, 0); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 500 | __ Assert(equal, kExpected0AsASmiSentinel); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 501 | } |
| 502 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 503 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 504 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 505 | __ bind(&after_sentinel); |
| 506 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 507 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 508 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 509 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 510 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 511 | |
| 512 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 513 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 514 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 515 | |
| 516 | // Initialize the rest of the slots to the hole value. |
| 517 | if (slots_ == 1) { |
| 518 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 519 | factory->the_hole_value()); |
| 520 | } else { |
| 521 | __ mov(ebx, factory->the_hole_value()); |
| 522 | for (int i = 0; i < slots_; i++) { |
| 523 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | // Return and remove the on-stack parameters. |
| 528 | __ mov(esi, eax); |
| 529 | __ ret(2 * kPointerSize); |
| 530 | |
| 531 | // Need to collect. Call into runtime system. |
| 532 | __ bind(&gc); |
| 533 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 534 | } |
| 535 | |
| 536 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 537 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 538 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 539 | // store the registers in any particular way, but we do have to store and |
| 540 | // restore them. |
| 541 | __ pushad(); |
| 542 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 543 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 544 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 545 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 546 | XMMRegister reg = XMMRegister::from_code(i); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 547 | __ movsd(Operand(esp, i * kDoubleSize), reg); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 548 | } |
| 549 | } |
| 550 | const int argument_count = 1; |
| 551 | |
| 552 | AllowExternalCallThatCantCauseGC scope(masm); |
| 553 | __ PrepareCallCFunction(argument_count, ecx); |
| 554 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 555 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 556 | __ CallCFunction( |
| 557 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 558 | argument_count); |
| 559 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 560 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 561 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 562 | XMMRegister reg = XMMRegister::from_code(i); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 563 | __ movsd(reg, Operand(esp, i * kDoubleSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 564 | } |
| 565 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 566 | } |
| 567 | __ popad(); |
| 568 | __ ret(0); |
| 569 | } |
| 570 | |
| 571 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 572 | class FloatingPointHelper : public AllStatic { |
| 573 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 574 | enum ArgLocation { |
| 575 | ARGS_ON_STACK, |
| 576 | ARGS_IN_REGISTERS |
| 577 | }; |
| 578 | |
| 579 | // Code pattern for loading a floating point value. Input value must |
| 580 | // be either a smi or a heap number object (fp value). Requirements: |
| 581 | // operand in register number. Returns operand as floating point number |
| 582 | // on FPU stack. |
| 583 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 584 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 585 | // Test if operands are smi or number objects (fp). Requirements: |
| 586 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 587 | // operands, jumps to the non_float label otherwise. |
| 588 | static void CheckFloatOperands(MacroAssembler* masm, |
| 589 | Label* non_float, |
| 590 | Register scratch); |
| 591 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 592 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 593 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 594 | // either operand is not a number. Operands are in edx and eax. |
| 595 | // Leaves operands unchanged. |
| 596 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 597 | }; |
| 598 | |
| 599 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 600 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 601 | Register input_reg = this->source(); |
| 602 | Register final_result_reg = this->destination(); |
| 603 | ASSERT(is_truncating()); |
| 604 | |
| 605 | Label check_negative, process_64_bits, done, done_no_stash; |
| 606 | |
| 607 | int double_offset = offset(); |
| 608 | |
| 609 | // Account for return address and saved regs if input is esp. |
| 610 | if (input_reg.is(esp)) double_offset += 3 * kPointerSize; |
| 611 | |
| 612 | MemOperand mantissa_operand(MemOperand(input_reg, double_offset)); |
| 613 | MemOperand exponent_operand(MemOperand(input_reg, |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 614 | double_offset + kDoubleSize / 2)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 615 | |
| 616 | Register scratch1; |
| 617 | { |
| 618 | Register scratch_candidates[3] = { ebx, edx, edi }; |
| 619 | for (int i = 0; i < 3; i++) { |
| 620 | scratch1 = scratch_candidates[i]; |
| 621 | if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break; |
| 622 | } |
| 623 | } |
| 624 | // Since we must use ecx for shifts below, use some other register (eax) |
| 625 | // to calculate the result if ecx is the requested return register. |
| 626 | Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg; |
| 627 | // Save ecx if it isn't the return register and therefore volatile, or if it |
| 628 | // is the return register, then save the temp register we use in its stead for |
| 629 | // the result. |
| 630 | Register save_reg = final_result_reg.is(ecx) ? eax : ecx; |
| 631 | __ push(scratch1); |
| 632 | __ push(save_reg); |
| 633 | |
| 634 | bool stash_exponent_copy = !input_reg.is(esp); |
| 635 | __ mov(scratch1, mantissa_operand); |
| 636 | if (CpuFeatures::IsSupported(SSE3)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 637 | CpuFeatureScope scope(masm, SSE3); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 638 | // Load x87 register with heap number. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 639 | __ fld_d(mantissa_operand); |
| 640 | } |
| 641 | __ mov(ecx, exponent_operand); |
| 642 | if (stash_exponent_copy) __ push(ecx); |
| 643 | |
| 644 | __ and_(ecx, HeapNumber::kExponentMask); |
| 645 | __ shr(ecx, HeapNumber::kExponentShift); |
| 646 | __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias)); |
| 647 | __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits)); |
| 648 | __ j(below, &process_64_bits); |
| 649 | |
| 650 | // Result is entirely in lower 32-bits of mantissa |
| 651 | int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize; |
| 652 | if (CpuFeatures::IsSupported(SSE3)) { |
| 653 | __ fstp(0); |
| 654 | } |
| 655 | __ sub(ecx, Immediate(delta)); |
| 656 | __ xor_(result_reg, result_reg); |
| 657 | __ cmp(ecx, Immediate(31)); |
| 658 | __ j(above, &done); |
| 659 | __ shl_cl(scratch1); |
| 660 | __ jmp(&check_negative); |
| 661 | |
| 662 | __ bind(&process_64_bits); |
| 663 | if (CpuFeatures::IsSupported(SSE3)) { |
| 664 | CpuFeatureScope scope(masm, SSE3); |
| 665 | if (stash_exponent_copy) { |
| 666 | // Already a copy of the exponent on the stack, overwrite it. |
| 667 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 668 | __ sub(esp, Immediate(kDoubleSize / 2)); |
| 669 | } else { |
| 670 | // Reserve space for 64 bit answer. |
| 671 | __ sub(esp, Immediate(kDoubleSize)); // Nolint. |
| 672 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 673 | // Do conversion, which cannot fail because we checked the exponent. |
| 674 | __ fisttp_d(Operand(esp, 0)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 675 | __ mov(result_reg, Operand(esp, 0)); // Load low word of answer as result |
| 676 | __ add(esp, Immediate(kDoubleSize)); |
| 677 | __ jmp(&done_no_stash); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 678 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 679 | // Result must be extracted from shifted 32-bit mantissa |
| 680 | __ sub(ecx, Immediate(delta)); |
| 681 | __ neg(ecx); |
| 682 | if (stash_exponent_copy) { |
| 683 | __ mov(result_reg, MemOperand(esp, 0)); |
| 684 | } else { |
| 685 | __ mov(result_reg, exponent_operand); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 686 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 687 | __ and_(result_reg, |
| 688 | Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32))); |
| 689 | __ add(result_reg, |
| 690 | Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32))); |
| 691 | __ shrd(result_reg, scratch1); |
| 692 | __ shr_cl(result_reg); |
| 693 | __ test(ecx, Immediate(32)); |
| 694 | if (CpuFeatures::IsSupported(CMOV)) { |
| 695 | CpuFeatureScope use_cmov(masm, CMOV); |
| 696 | __ cmov(not_equal, scratch1, result_reg); |
| 697 | } else { |
| 698 | Label skip_mov; |
| 699 | __ j(equal, &skip_mov, Label::kNear); |
| 700 | __ mov(scratch1, result_reg); |
| 701 | __ bind(&skip_mov); |
| 702 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 703 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 704 | |
| 705 | // If the double was negative, negate the integer result. |
| 706 | __ bind(&check_negative); |
| 707 | __ mov(result_reg, scratch1); |
| 708 | __ neg(result_reg); |
| 709 | if (stash_exponent_copy) { |
| 710 | __ cmp(MemOperand(esp, 0), Immediate(0)); |
| 711 | } else { |
| 712 | __ cmp(exponent_operand, Immediate(0)); |
| 713 | } |
| 714 | if (CpuFeatures::IsSupported(CMOV)) { |
| 715 | CpuFeatureScope use_cmov(masm, CMOV); |
| 716 | __ cmov(greater, result_reg, scratch1); |
| 717 | } else { |
| 718 | Label skip_mov; |
| 719 | __ j(less_equal, &skip_mov, Label::kNear); |
| 720 | __ mov(result_reg, scratch1); |
| 721 | __ bind(&skip_mov); |
| 722 | } |
| 723 | |
| 724 | // Restore registers |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 725 | __ bind(&done); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 726 | if (stash_exponent_copy) { |
| 727 | __ add(esp, Immediate(kDoubleSize / 2)); |
| 728 | } |
| 729 | __ bind(&done_no_stash); |
| 730 | if (!final_result_reg.is(result_reg)) { |
| 731 | ASSERT(final_result_reg.is(ecx)); |
| 732 | __ mov(final_result_reg, result_reg); |
| 733 | } |
| 734 | __ pop(save_reg); |
| 735 | __ pop(scratch1); |
| 736 | __ ret(0); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 737 | } |
| 738 | |
| 739 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 740 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 741 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 742 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 743 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 744 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 745 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 746 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 747 | |
| 748 | __ bind(&load_smi); |
| 749 | __ SmiUntag(number); |
| 750 | __ push(number); |
| 751 | __ fild_s(Operand(esp, 0)); |
| 752 | __ pop(number); |
| 753 | |
| 754 | __ bind(&done); |
| 755 | } |
| 756 | |
| 757 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 758 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 759 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 760 | 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] | 761 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 762 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 763 | Factory* factory = masm->isolate()->factory(); |
| 764 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 765 | __ j(not_equal, not_numbers); // Argument in edx is not a number. |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 766 | __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 767 | __ bind(&load_eax); |
| 768 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 769 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 770 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 771 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 772 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 773 | __ bind(&load_smi_edx); |
| 774 | __ SmiUntag(edx); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 775 | __ Cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 776 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 777 | __ jmp(&load_eax); |
| 778 | __ bind(&load_smi_eax); |
| 779 | __ SmiUntag(eax); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 780 | __ Cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 781 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 782 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 783 | __ bind(&load_float_eax); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 784 | __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 785 | __ bind(&done); |
| 786 | } |
| 787 | |
| 788 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 789 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 790 | Label* non_float, |
| 791 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 792 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 793 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 794 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 795 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 796 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 797 | Factory* factory = masm->isolate()->factory(); |
| 798 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 799 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 800 | |
| 801 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 802 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 803 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 804 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 805 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 806 | |
| 807 | // Fall-through: Both operands are numbers. |
| 808 | __ bind(&done); |
| 809 | } |
| 810 | |
| 811 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 812 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 813 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 814 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 815 | const Register exponent = eax; |
| 816 | const Register base = edx; |
| 817 | const Register scratch = ecx; |
| 818 | const XMMRegister double_result = xmm3; |
| 819 | const XMMRegister double_base = xmm2; |
| 820 | const XMMRegister double_exponent = xmm1; |
| 821 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 822 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 823 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 824 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 825 | // Save 1 in double_result - we need this several times later on. |
| 826 | __ mov(scratch, Immediate(1)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 827 | __ Cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 828 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 829 | if (exponent_type_ == ON_STACK) { |
| 830 | Label base_is_smi, unpack_exponent; |
| 831 | // The exponent and base are supplied as arguments on the stack. |
| 832 | // This can only happen if the stub is called from non-optimized code. |
| 833 | // Load input parameters from stack. |
| 834 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 835 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 836 | |
| 837 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 838 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 839 | factory->heap_number_map()); |
| 840 | __ j(not_equal, &call_runtime); |
| 841 | |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 842 | __ movsd(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 843 | __ jmp(&unpack_exponent, Label::kNear); |
| 844 | |
| 845 | __ bind(&base_is_smi); |
| 846 | __ SmiUntag(base); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 847 | __ Cvtsi2sd(double_base, base); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 848 | |
| 849 | __ bind(&unpack_exponent); |
| 850 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 851 | __ SmiUntag(exponent); |
| 852 | __ jmp(&int_exponent); |
| 853 | |
| 854 | __ bind(&exponent_not_smi); |
| 855 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 856 | factory->heap_number_map()); |
| 857 | __ j(not_equal, &call_runtime); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 858 | __ movsd(double_exponent, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 859 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 860 | } else if (exponent_type_ == TAGGED) { |
| 861 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 862 | __ SmiUntag(exponent); |
| 863 | __ jmp(&int_exponent); |
| 864 | |
| 865 | __ bind(&exponent_not_smi); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 866 | __ movsd(double_exponent, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 867 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 868 | } |
| 869 | |
| 870 | if (exponent_type_ != INTEGER) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 871 | Label fast_power, try_arithmetic_simplification; |
| 872 | __ DoubleToI(exponent, double_exponent, double_scratch, |
| 873 | TREAT_MINUS_ZERO_AS_ZERO, &try_arithmetic_simplification); |
| 874 | __ jmp(&int_exponent); |
| 875 | |
| 876 | __ bind(&try_arithmetic_simplification); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 877 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 878 | __ cvttsd2si(exponent, Operand(double_exponent)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 879 | __ cmp(exponent, Immediate(0x80000000u)); |
| 880 | __ j(equal, &call_runtime); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 881 | |
| 882 | if (exponent_type_ == ON_STACK) { |
| 883 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 884 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 885 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 886 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 887 | // Test for 0.5. |
| 888 | // Load double_scratch with 0.5. |
| 889 | __ mov(scratch, Immediate(0x3F000000u)); |
| 890 | __ movd(double_scratch, scratch); |
| 891 | __ cvtss2sd(double_scratch, double_scratch); |
| 892 | // Already ruled out NaNs for exponent. |
| 893 | __ ucomisd(double_scratch, double_exponent); |
| 894 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 895 | |
| 896 | // Calculates square root of base. Check for the special case of |
| 897 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 898 | // According to IEEE-754, single-precision -Infinity has the highest |
| 899 | // 9 bits set and the lowest 23 bits cleared. |
| 900 | __ mov(scratch, 0xFF800000u); |
| 901 | __ movd(double_scratch, scratch); |
| 902 | __ cvtss2sd(double_scratch, double_scratch); |
| 903 | __ ucomisd(double_base, double_scratch); |
| 904 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 905 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 906 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 907 | __ j(carry, &continue_sqrt, Label::kNear); |
| 908 | |
| 909 | // Set result to Infinity in the special case. |
| 910 | __ xorps(double_result, double_result); |
| 911 | __ subsd(double_result, double_scratch); |
| 912 | __ jmp(&done); |
| 913 | |
| 914 | __ bind(&continue_sqrt); |
| 915 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 916 | __ xorps(double_scratch, double_scratch); |
| 917 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 918 | __ sqrtsd(double_result, double_scratch); |
| 919 | __ jmp(&done); |
| 920 | |
| 921 | // Test for -0.5. |
| 922 | __ bind(¬_plus_half); |
| 923 | // Load double_exponent with -0.5 by substracting 1. |
| 924 | __ subsd(double_scratch, double_result); |
| 925 | // Already ruled out NaNs for exponent. |
| 926 | __ ucomisd(double_scratch, double_exponent); |
| 927 | __ j(not_equal, &fast_power, Label::kNear); |
| 928 | |
| 929 | // Calculates reciprocal of square root of base. Check for the special |
| 930 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 931 | // According to IEEE-754, single-precision -Infinity has the highest |
| 932 | // 9 bits set and the lowest 23 bits cleared. |
| 933 | __ mov(scratch, 0xFF800000u); |
| 934 | __ movd(double_scratch, scratch); |
| 935 | __ cvtss2sd(double_scratch, double_scratch); |
| 936 | __ ucomisd(double_base, double_scratch); |
| 937 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 938 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 939 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 940 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 941 | |
| 942 | // Set result to 0 in the special case. |
| 943 | __ xorps(double_result, double_result); |
| 944 | __ jmp(&done); |
| 945 | |
| 946 | __ bind(&continue_rsqrt); |
| 947 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 948 | __ xorps(double_exponent, double_exponent); |
| 949 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 950 | __ sqrtsd(double_exponent, double_exponent); |
| 951 | __ divsd(double_result, double_exponent); |
| 952 | __ jmp(&done); |
| 953 | } |
| 954 | |
| 955 | // Using FPU instructions to calculate power. |
| 956 | Label fast_power_failed; |
| 957 | __ bind(&fast_power); |
| 958 | __ fnclex(); // Clear flags to catch exceptions later. |
| 959 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 960 | __ sub(esp, Immediate(kDoubleSize)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 961 | __ movsd(Operand(esp, 0), double_exponent); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 962 | __ fld_d(Operand(esp, 0)); // E |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 963 | __ movsd(Operand(esp, 0), double_base); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 964 | __ fld_d(Operand(esp, 0)); // B, E |
| 965 | |
| 966 | // Exponent is in st(1) and base is in st(0) |
| 967 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 968 | // FYL2X calculates st(1) * log2(st(0)) |
| 969 | __ fyl2x(); // X |
| 970 | __ fld(0); // X, X |
| 971 | __ frndint(); // rnd(X), X |
| 972 | __ fsub(1); // rnd(X), X-rnd(X) |
| 973 | __ fxch(1); // X - rnd(X), rnd(X) |
| 974 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 975 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 976 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 977 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 978 | // FSCALE calculates st(0) * 2^st(1) |
| 979 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 980 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 981 | // Bail out to runtime in case of exceptions in the status word. |
| 982 | __ fnstsw_ax(); |
| 983 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 984 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 985 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 986 | __ movsd(double_result, Operand(esp, 0)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 987 | __ add(esp, Immediate(kDoubleSize)); |
| 988 | __ jmp(&done); |
| 989 | |
| 990 | __ bind(&fast_power_failed); |
| 991 | __ fninit(); |
| 992 | __ add(esp, Immediate(kDoubleSize)); |
| 993 | __ jmp(&call_runtime); |
| 994 | } |
| 995 | |
| 996 | // Calculate power with integer exponent. |
| 997 | __ bind(&int_exponent); |
| 998 | const XMMRegister double_scratch2 = double_exponent; |
| 999 | __ mov(scratch, exponent); // Back up exponent. |
| 1000 | __ movsd(double_scratch, double_base); // Back up base. |
| 1001 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1002 | |
| 1003 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1004 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1005 | __ test(scratch, scratch); |
| 1006 | __ j(positive, &no_neg, Label::kNear); |
| 1007 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1008 | __ bind(&no_neg); |
| 1009 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1010 | __ j(zero, &while_false, Label::kNear); |
| 1011 | __ shr(scratch, 1); |
| 1012 | // Above condition means CF==0 && ZF==0. This means that the |
| 1013 | // bit that has been shifted out is 0 and the result is not 0. |
| 1014 | __ j(above, &while_true, Label::kNear); |
| 1015 | __ movsd(double_result, double_scratch); |
| 1016 | __ j(zero, &while_false, Label::kNear); |
| 1017 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1018 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1019 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1020 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1021 | __ j(above, &while_true, Label::kNear); |
| 1022 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1023 | __ j(not_zero, &while_true); |
| 1024 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1025 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1026 | // scratch has the original value of the exponent - if the exponent is |
| 1027 | // negative, return 1/result. |
| 1028 | __ test(exponent, exponent); |
| 1029 | __ j(positive, &done); |
| 1030 | __ divsd(double_scratch2, double_result); |
| 1031 | __ movsd(double_result, double_scratch2); |
| 1032 | // Test whether result is zero. Bail out to check for subnormal result. |
| 1033 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 1034 | __ xorps(double_scratch2, double_scratch2); |
| 1035 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 1036 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 1037 | // and may not have contained the exponent value in the first place when the |
| 1038 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 1039 | __ j(not_equal, &done); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1040 | __ Cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1041 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1042 | // Returning or bailing out. |
| 1043 | Counters* counters = masm->isolate()->counters(); |
| 1044 | if (exponent_type_ == ON_STACK) { |
| 1045 | // The arguments are still on the stack. |
| 1046 | __ bind(&call_runtime); |
| 1047 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1048 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1049 | // The stub is called from non-optimized code, which expects the result |
| 1050 | // as heap number in exponent. |
| 1051 | __ bind(&done); |
| 1052 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1053 | __ movsd(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1054 | __ IncrementCounter(counters->math_pow(), 1); |
| 1055 | __ ret(2 * kPointerSize); |
| 1056 | } else { |
| 1057 | __ bind(&call_runtime); |
| 1058 | { |
| 1059 | AllowExternalCallThatCantCauseGC scope(masm); |
| 1060 | __ PrepareCallCFunction(4, scratch); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1061 | __ movsd(Operand(esp, 0 * kDoubleSize), double_base); |
| 1062 | __ movsd(Operand(esp, 1 * kDoubleSize), double_exponent); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1063 | __ CallCFunction( |
| 1064 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 1065 | } |
| 1066 | // Return value is in st(0) on ia32. |
| 1067 | // Store it into the (fixed) result register. |
| 1068 | __ sub(esp, Immediate(kDoubleSize)); |
| 1069 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1070 | __ movsd(double_result, Operand(esp, 0)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1071 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1072 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1073 | __ bind(&done); |
| 1074 | __ IncrementCounter(counters->math_pow(), 1); |
| 1075 | __ ret(0); |
| 1076 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1080 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 1081 | // ----------- S t a t e ------------- |
| 1082 | // -- ecx : name |
| 1083 | // -- edx : receiver |
| 1084 | // -- esp[0] : return address |
| 1085 | // ----------------------------------- |
| 1086 | Label miss; |
| 1087 | |
| 1088 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1089 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1090 | __ j(not_equal, &miss); |
| 1091 | } |
| 1092 | |
| 1093 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 1094 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1095 | StubCompiler::TailCallBuiltin( |
| 1096 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
| 1099 | |
| 1100 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 1101 | // ----------- S t a t e ------------- |
| 1102 | // -- ecx : name |
| 1103 | // -- edx : receiver |
| 1104 | // -- esp[0] : return address |
| 1105 | // ----------------------------------- |
| 1106 | Label miss; |
| 1107 | |
| 1108 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1109 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1110 | __ j(not_equal, &miss); |
| 1111 | } |
| 1112 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1113 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1114 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1115 | StubCompiler::TailCallBuiltin( |
| 1116 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1120 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 1121 | // ----------- S t a t e ------------- |
| 1122 | // -- eax : value |
| 1123 | // -- ecx : name |
| 1124 | // -- edx : receiver |
| 1125 | // -- esp[0] : return address |
| 1126 | // ----------------------------------- |
| 1127 | // |
| 1128 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 1129 | // (currently anything except for external arrays which means anything with |
| 1130 | // elements of FixedArray type). Value must be a number, but only smis are |
| 1131 | // accepted as the most common case. |
| 1132 | |
| 1133 | Label miss; |
| 1134 | |
| 1135 | Register receiver = edx; |
| 1136 | Register value = eax; |
| 1137 | Register scratch = ebx; |
| 1138 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1139 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1140 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1141 | __ j(not_equal, &miss); |
| 1142 | } |
| 1143 | |
| 1144 | // Check that the receiver isn't a smi. |
| 1145 | __ JumpIfSmi(receiver, &miss); |
| 1146 | |
| 1147 | // Check that the object is a JS array. |
| 1148 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 1149 | __ j(not_equal, &miss); |
| 1150 | |
| 1151 | // Check that elements are FixedArray. |
| 1152 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 1153 | // fast elements (including COW). |
| 1154 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 1155 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 1156 | __ j(not_equal, &miss); |
| 1157 | |
| 1158 | // Check that the array has fast properties, otherwise the length |
| 1159 | // property might have been redefined. |
| 1160 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 1161 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 1162 | Heap::kHashTableMapRootIndex); |
| 1163 | __ j(equal, &miss); |
| 1164 | |
| 1165 | // Check that value is a smi. |
| 1166 | __ JumpIfNotSmi(value, &miss); |
| 1167 | |
| 1168 | // Prepare tail call to StoreIC_ArrayLength. |
| 1169 | __ pop(scratch); |
| 1170 | __ push(receiver); |
| 1171 | __ push(value); |
| 1172 | __ push(scratch); // return address |
| 1173 | |
| 1174 | ExternalReference ref = |
| 1175 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 1176 | __ TailCallExternalReference(ref, 2, 1); |
| 1177 | |
| 1178 | __ bind(&miss); |
| 1179 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1180 | StubCompiler::TailCallBuiltin( |
| 1181 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1185 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 1186 | // The key is in edx and the parameter count is in eax. |
| 1187 | |
| 1188 | // The displacement is used for skipping the frame pointer on the |
| 1189 | // stack. It is the offset of the last parameter (if any) relative |
| 1190 | // to the frame pointer. |
| 1191 | static const int kDisplacement = 1 * kPointerSize; |
| 1192 | |
| 1193 | // Check that the key is a smi. |
| 1194 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1195 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1196 | |
| 1197 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1198 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1199 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1200 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1201 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1202 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1203 | |
| 1204 | // Check index against formal parameters count limit passed in |
| 1205 | // through register eax. Use unsigned comparison to get negative |
| 1206 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1207 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1208 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1209 | |
| 1210 | // Read the argument from the stack and return it. |
| 1211 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1212 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 1213 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 1214 | __ neg(edx); |
| 1215 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 1216 | __ ret(0); |
| 1217 | |
| 1218 | // Arguments adaptor case: Check index against actual arguments |
| 1219 | // limit found in the arguments adaptor frame. Use unsigned |
| 1220 | // comparison to get negative check for free. |
| 1221 | __ bind(&adaptor); |
| 1222 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1223 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1224 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1225 | |
| 1226 | // Read the argument from the stack and return it. |
| 1227 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1228 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 1229 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 1230 | __ neg(edx); |
| 1231 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 1232 | __ ret(0); |
| 1233 | |
| 1234 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 1235 | // by calling the runtime system. |
| 1236 | __ bind(&slow); |
| 1237 | __ pop(ebx); // Return address. |
| 1238 | __ push(edx); |
| 1239 | __ push(ebx); |
| 1240 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 1241 | } |
| 1242 | |
| 1243 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1244 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1245 | // esp[0] : return address |
| 1246 | // esp[4] : number of parameters |
| 1247 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1248 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1249 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1250 | // Check if the calling frame is an arguments adaptor frame. |
| 1251 | Label runtime; |
| 1252 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1253 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1254 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1255 | __ j(not_equal, &runtime, Label::kNear); |
| 1256 | |
| 1257 | // Patch the arguments.length and the parameters pointer. |
| 1258 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1259 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 1260 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1261 | StandardFrameConstants::kCallerSPOffset)); |
| 1262 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1263 | |
| 1264 | __ bind(&runtime); |
| 1265 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 1266 | } |
| 1267 | |
| 1268 | |
| 1269 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1270 | Isolate* isolate = masm->isolate(); |
| 1271 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1272 | // esp[0] : return address |
| 1273 | // esp[4] : number of parameters (tagged) |
| 1274 | // esp[8] : receiver displacement |
| 1275 | // esp[12] : function |
| 1276 | |
| 1277 | // ebx = parameter count (tagged) |
| 1278 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1279 | |
| 1280 | // Check if the calling frame is an arguments adaptor frame. |
| 1281 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 1282 | // Generate* functions. |
| 1283 | Label runtime; |
| 1284 | Label adaptor_frame, try_allocate; |
| 1285 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1286 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1287 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1288 | __ j(equal, &adaptor_frame, Label::kNear); |
| 1289 | |
| 1290 | // No adaptor, parameter count = argument count. |
| 1291 | __ mov(ecx, ebx); |
| 1292 | __ jmp(&try_allocate, Label::kNear); |
| 1293 | |
| 1294 | // We have an adaptor frame. Patch the parameters pointer. |
| 1295 | __ bind(&adaptor_frame); |
| 1296 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1297 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1298 | StandardFrameConstants::kCallerSPOffset)); |
| 1299 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1300 | |
| 1301 | // ebx = parameter count (tagged) |
| 1302 | // ecx = argument count (tagged) |
| 1303 | // esp[4] = parameter count (tagged) |
| 1304 | // esp[8] = address of receiver argument |
| 1305 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1306 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1307 | __ j(less_equal, &try_allocate, Label::kNear); |
| 1308 | __ mov(ebx, ecx); |
| 1309 | |
| 1310 | __ bind(&try_allocate); |
| 1311 | |
| 1312 | // Save mapped parameter count. |
| 1313 | __ push(ebx); |
| 1314 | |
| 1315 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 1316 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 1317 | const int kParameterMapHeaderSize = |
| 1318 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 1319 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1320 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1321 | __ j(zero, &no_parameter_map, Label::kNear); |
| 1322 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 1323 | __ bind(&no_parameter_map); |
| 1324 | |
| 1325 | // 2. Backing store. |
| 1326 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 1327 | |
| 1328 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1329 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1330 | |
| 1331 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1332 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1333 | |
| 1334 | // eax = address of new object(s) (tagged) |
| 1335 | // ecx = argument count (tagged) |
| 1336 | // esp[0] = mapped parameter count (tagged) |
| 1337 | // esp[8] = parameter count (tagged) |
| 1338 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1339 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1340 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1341 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 1342 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1343 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1344 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1345 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 1346 | __ mov(edi, Operand(edi, |
| 1347 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 1348 | __ jmp(©, Label::kNear); |
| 1349 | |
| 1350 | __ bind(&has_mapped_parameters); |
| 1351 | __ mov(edi, Operand(edi, |
| 1352 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 1353 | __ bind(©); |
| 1354 | |
| 1355 | // eax = address of new object (tagged) |
| 1356 | // ebx = mapped parameter count (tagged) |
| 1357 | // ecx = argument count (tagged) |
| 1358 | // edi = address of boilerplate object (tagged) |
| 1359 | // esp[0] = mapped parameter count (tagged) |
| 1360 | // esp[8] = parameter count (tagged) |
| 1361 | // esp[12] = address of receiver argument |
| 1362 | // Copy the JS object part. |
| 1363 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 1364 | __ mov(edx, FieldOperand(edi, i)); |
| 1365 | __ mov(FieldOperand(eax, i), edx); |
| 1366 | } |
| 1367 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1368 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1369 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 1370 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 1371 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 1372 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 1373 | edx); |
| 1374 | |
| 1375 | // Use the length (smi tagged) and set that as an in-object property too. |
| 1376 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 1377 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 1378 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 1379 | ecx); |
| 1380 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1381 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1382 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 1383 | // backing store. |
| 1384 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 1385 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 1386 | |
| 1387 | // eax = address of new object (tagged) |
| 1388 | // ebx = mapped parameter count (tagged) |
| 1389 | // ecx = argument count (tagged) |
| 1390 | // edi = address of parameter map or backing store (tagged) |
| 1391 | // esp[0] = mapped parameter count (tagged) |
| 1392 | // esp[8] = parameter count (tagged) |
| 1393 | // esp[12] = address of receiver argument |
| 1394 | // Free a register. |
| 1395 | __ push(eax); |
| 1396 | |
| 1397 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 1398 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1399 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1400 | __ j(zero, &skip_parameter_map); |
| 1401 | |
| 1402 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1403 | Immediate(isolate->factory()->non_strict_arguments_elements_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1404 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 1405 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 1406 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 1407 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 1408 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 1409 | |
| 1410 | // Copy the parameter slots and the holes in the arguments. |
| 1411 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 1412 | // where parameters are stored in reverse order, at |
| 1413 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 1414 | // The mapped parameter thus need to get indices |
| 1415 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 1416 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 1417 | // We loop from right to left. |
| 1418 | Label parameters_loop, parameters_test; |
| 1419 | __ push(ecx); |
| 1420 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 1421 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 1422 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1423 | __ sub(ebx, eax); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1424 | __ mov(ecx, isolate->factory()->the_hole_value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1425 | __ mov(edx, edi); |
| 1426 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 1427 | // eax = loop variable (tagged) |
| 1428 | // ebx = mapping index (tagged) |
| 1429 | // ecx = the hole value |
| 1430 | // edx = address of parameter map (tagged) |
| 1431 | // edi = address of backing store (tagged) |
| 1432 | // esp[0] = argument count (tagged) |
| 1433 | // esp[4] = address of new object (tagged) |
| 1434 | // esp[8] = mapped parameter count (tagged) |
| 1435 | // esp[16] = parameter count (tagged) |
| 1436 | // esp[20] = address of receiver argument |
| 1437 | __ jmp(¶meters_test, Label::kNear); |
| 1438 | |
| 1439 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1440 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1441 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 1442 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1443 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1444 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1445 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1446 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 1447 | __ pop(ecx); |
| 1448 | |
| 1449 | __ bind(&skip_parameter_map); |
| 1450 | |
| 1451 | // ecx = argument count (tagged) |
| 1452 | // edi = address of backing store (tagged) |
| 1453 | // esp[0] = address of new object (tagged) |
| 1454 | // esp[4] = mapped parameter count (tagged) |
| 1455 | // esp[12] = parameter count (tagged) |
| 1456 | // esp[16] = address of receiver argument |
| 1457 | // Copy arguments header and remaining slots (if there are any). |
| 1458 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1459 | Immediate(isolate->factory()->fixed_array_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1460 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 1461 | |
| 1462 | Label arguments_loop, arguments_test; |
| 1463 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1464 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1465 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 1466 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1467 | __ jmp(&arguments_test, Label::kNear); |
| 1468 | |
| 1469 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1470 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1471 | __ mov(eax, Operand(edx, 0)); |
| 1472 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1473 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1474 | |
| 1475 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1476 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1477 | __ j(less, &arguments_loop, Label::kNear); |
| 1478 | |
| 1479 | // Restore. |
| 1480 | __ pop(eax); // Address of arguments object. |
| 1481 | __ pop(ebx); // Parameter count. |
| 1482 | |
| 1483 | // Return and remove the on-stack parameters. |
| 1484 | __ ret(3 * kPointerSize); |
| 1485 | |
| 1486 | // Do the runtime call to allocate the arguments object. |
| 1487 | __ bind(&runtime); |
| 1488 | __ pop(eax); // Remove saved parameter count. |
| 1489 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 1490 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | |
| 1494 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1495 | Isolate* isolate = masm->isolate(); |
| 1496 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1497 | // esp[0] : return address |
| 1498 | // esp[4] : number of parameters |
| 1499 | // esp[8] : receiver displacement |
| 1500 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1501 | |
| 1502 | // Check if the calling frame is an arguments adaptor frame. |
| 1503 | Label adaptor_frame, try_allocate, runtime; |
| 1504 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1505 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1506 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1507 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1508 | |
| 1509 | // Get the length from the frame. |
| 1510 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1511 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1512 | |
| 1513 | // Patch the arguments.length and the parameters pointer. |
| 1514 | __ bind(&adaptor_frame); |
| 1515 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1516 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1517 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1518 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1519 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1520 | |
| 1521 | // Try the new space allocation. Start out with computing the size of |
| 1522 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1523 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1524 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1525 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1526 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1527 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 1528 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1529 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1530 | |
| 1531 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1532 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1533 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1534 | // Get the arguments boilerplate from the current native context. |
| 1535 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 1536 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1537 | const int offset = |
| 1538 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 1539 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1540 | |
| 1541 | // Copy the JS object part. |
| 1542 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 1543 | __ mov(ebx, FieldOperand(edi, i)); |
| 1544 | __ mov(FieldOperand(eax, i), ebx); |
| 1545 | } |
| 1546 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1547 | // 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] | 1548 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1549 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1550 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1551 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1552 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1553 | |
| 1554 | // If there are no actual arguments, we're done. |
| 1555 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1556 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1557 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1558 | |
| 1559 | // Get the parameters pointer from the stack. |
| 1560 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 1561 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1562 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1563 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1564 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1565 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 1566 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1567 | Immediate(isolate->factory()->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1568 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1569 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 1570 | // Untag the length for the loop below. |
| 1571 | __ SmiUntag(ecx); |
| 1572 | |
| 1573 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1574 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1575 | __ bind(&loop); |
| 1576 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 1577 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1578 | __ add(edi, Immediate(kPointerSize)); |
| 1579 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1580 | __ dec(ecx); |
| 1581 | __ j(not_zero, &loop); |
| 1582 | |
| 1583 | // Return and remove the on-stack parameters. |
| 1584 | __ bind(&done); |
| 1585 | __ ret(3 * kPointerSize); |
| 1586 | |
| 1587 | // Do the runtime call to allocate the arguments object. |
| 1588 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1589 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | |
| 1593 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 1594 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 1595 | // time or if regexp entry in generated code is turned off runtime switch or |
| 1596 | // at compilation. |
| 1597 | #ifdef V8_INTERPRETED_REGEXP |
| 1598 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 1599 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1600 | |
| 1601 | // Stack frame on entry. |
| 1602 | // esp[0]: return address |
| 1603 | // esp[4]: last_match_info (expected JSArray) |
| 1604 | // esp[8]: previous index |
| 1605 | // esp[12]: subject string |
| 1606 | // esp[16]: JSRegExp object |
| 1607 | |
| 1608 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 1609 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 1610 | static const int kSubjectOffset = 3 * kPointerSize; |
| 1611 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 1612 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1613 | Label runtime; |
| 1614 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1615 | |
| 1616 | // Ensure that a RegExp stack is allocated. |
| 1617 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1618 | ExternalReference::address_of_regexp_stack_memory_address( |
| 1619 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1620 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1621 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1622 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1623 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1624 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1625 | |
| 1626 | // Check that the first argument is a JSRegExp object. |
| 1627 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 1628 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1629 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1630 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 1631 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1632 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1633 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 1634 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 1635 | if (FLAG_debug_code) { |
| 1636 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1637 | __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1638 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1639 | __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | // ecx: RegExp data (FixedArray) |
| 1643 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 1644 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1645 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1646 | __ j(not_equal, &runtime); |
| 1647 | |
| 1648 | // ecx: RegExp data (FixedArray) |
| 1649 | // Check that the number of captures fit in the static offsets vector buffer. |
| 1650 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1651 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 1652 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 1653 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1654 | STATIC_ASSERT(kSmiTag == 0); |
| 1655 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1656 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 1657 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1658 | __ j(above, &runtime); |
| 1659 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1660 | // Reset offset for possibly sliced string. |
| 1661 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1662 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1663 | __ JumpIfSmi(eax, &runtime); |
| 1664 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1665 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1666 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1667 | |
| 1668 | // eax: subject string |
| 1669 | // edx: subject string |
| 1670 | // ebx: subject string instance type |
| 1671 | // ecx: RegExp data (FixedArray) |
| 1672 | // Handle subject string according to its encoding and representation: |
| 1673 | // (1) Sequential two byte? If yes, go to (9). |
| 1674 | // (2) Sequential one byte? If yes, go to (6). |
| 1675 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 1676 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 1677 | // Otherwise bailout. |
| 1678 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 1679 | // (5b) Is subject external? If yes, go to (8). |
| 1680 | // (6) One byte sequential. Load regexp code for one byte. |
| 1681 | // (E) Carry on. |
| 1682 | /// [...] |
| 1683 | |
| 1684 | // Deferred code at the end of the stub: |
| 1685 | // (7) Not a long external string? If yes, go to (10). |
| 1686 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 1687 | // (8a) Is the external string one byte? If yes, go to (6). |
| 1688 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 1689 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 1690 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 1691 | |
| 1692 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 1693 | external_string /* 8 */, check_underlying /* 5a */, |
| 1694 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 1695 | not_long_external /* 10 */; |
| 1696 | |
| 1697 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1698 | __ and_(ebx, kIsNotStringMask | |
| 1699 | kStringRepresentationMask | |
| 1700 | kStringEncodingMask | |
| 1701 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1702 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1703 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 1704 | |
| 1705 | // (2) Sequential one byte? If yes, go to (6). |
| 1706 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1707 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 1708 | kStringRepresentationMask | |
| 1709 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1710 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1711 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1712 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 1713 | // We check whether the subject string is a cons, since sequential strings |
| 1714 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1715 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 1716 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1717 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 1718 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1719 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1720 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1721 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1722 | // (4) Cons string. Check that it's flat. |
| 1723 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1724 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1725 | __ j(not_equal, &runtime); |
| 1726 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1727 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1728 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1729 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 1730 | |
| 1731 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 1732 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1733 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1734 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 1735 | // (5b) Is subject external? If yes, go to (8). |
| 1736 | __ test_b(ebx, kStringRepresentationMask); |
| 1737 | // The underlying external string is never a short external string. |
| 1738 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 1739 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 1740 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1741 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1742 | // eax: sequential subject string (or look-alike, external string) |
| 1743 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1744 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1745 | // (6) One byte sequential. Load regexp code for one byte. |
| 1746 | __ bind(&seq_one_byte_string); |
| 1747 | // Load previous index and check range before edx is overwritten. We have |
| 1748 | // to use edx instead of eax here because it might have been only made to |
| 1749 | // look like a sequential string when it actually is an external string. |
| 1750 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 1751 | __ JumpIfNotSmi(ebx, &runtime); |
| 1752 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 1753 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1754 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1755 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1756 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1757 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1758 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1759 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1760 | // Check that the irregexp code has been generated for the actual string |
| 1761 | // 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] | 1762 | // a smi (code flushing support). |
| 1763 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1764 | |
| 1765 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1766 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1767 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1768 | // 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] | 1769 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1770 | Counters* counters = masm->isolate()->counters(); |
| 1771 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1772 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1773 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1774 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1775 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1776 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1777 | // Argument 9: Pass current isolate address. |
| 1778 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1779 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1780 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1781 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 1782 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1783 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1784 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1785 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 1786 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1787 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 1788 | |
| 1789 | // Argument 6: Set the number of capture registers to zero to force global |
| 1790 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 1791 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1792 | |
| 1793 | // Argument 5: static offsets vector buffer. |
| 1794 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1795 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 1796 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1797 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1798 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1799 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1800 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1801 | |
| 1802 | // Argument 1: Original subject string. |
| 1803 | // The original subject is in the previous stack frame. Therefore we have to |
| 1804 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 1805 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 1806 | // and thereby moves up esp by one kPointerSize.) |
| 1807 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 1808 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 1809 | |
| 1810 | // esi: original subject string |
| 1811 | // eax: underlying subject string |
| 1812 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1813 | // 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] | 1814 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1815 | // Argument 4: End of string data |
| 1816 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1817 | // Prepare start and end index of the input. |
| 1818 | // Load the length from the original sliced string if that is the case. |
| 1819 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1820 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1821 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1822 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1823 | |
| 1824 | // ebx: start index of the input string |
| 1825 | // esi: end index of the input string |
| 1826 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1827 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1828 | __ j(zero, &setup_two_byte, Label::kNear); |
| 1829 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1830 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1831 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1832 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1833 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1834 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1835 | |
| 1836 | __ bind(&setup_two_byte); |
| 1837 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1838 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 1839 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1840 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 1841 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 1842 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 1843 | |
| 1844 | __ bind(&setup_rest); |
| 1845 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1846 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1847 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1848 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1849 | |
| 1850 | // Drop arguments and come back to JS mode. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1851 | __ LeaveApiExitFrame(true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1852 | |
| 1853 | // Check the result. |
| 1854 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1855 | __ cmp(eax, 1); |
| 1856 | // We expect exactly one result since we force the called regexp to behave |
| 1857 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1858 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1859 | Label failure; |
| 1860 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1861 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1862 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 1863 | // If not exception it can only be retry. Handle that in the runtime system. |
| 1864 | __ j(not_equal, &runtime); |
| 1865 | // Result must now be exception. If there is no pending exception already a |
| 1866 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 1867 | // haven't created the exception yet. Handle that in the runtime system. |
| 1868 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1869 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1870 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1871 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1872 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1873 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1874 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1875 | // For exception, throw the exception again. |
| 1876 | |
| 1877 | // Clear the pending exception variable. |
| 1878 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 1879 | |
| 1880 | // Special handling of termination exceptions which are uncatchable |
| 1881 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1882 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1883 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1884 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1885 | |
| 1886 | // Handle normal exception by following handler chain. |
| 1887 | __ Throw(eax); |
| 1888 | |
| 1889 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1890 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1891 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1892 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1893 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1894 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1895 | __ ret(4 * kPointerSize); |
| 1896 | |
| 1897 | // Load RegExp data. |
| 1898 | __ bind(&success); |
| 1899 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 1900 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 1901 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 1902 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 1903 | STATIC_ASSERT(kSmiTag == 0); |
| 1904 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1905 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1906 | |
| 1907 | // edx: Number of capture registers |
| 1908 | // 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] | 1909 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1910 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1911 | __ JumpIfSmi(eax, &runtime); |
| 1912 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 1913 | __ j(not_equal, &runtime); |
| 1914 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1915 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1916 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 1917 | __ cmp(eax, factory->fixed_array_map()); |
| 1918 | __ j(not_equal, &runtime); |
| 1919 | // Check that the last match info has space for the capture registers and the |
| 1920 | // additional information. |
| 1921 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 1922 | __ SmiUntag(eax); |
| 1923 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 1924 | __ cmp(edx, eax); |
| 1925 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1926 | |
| 1927 | // ebx: last_match_info backing store (FixedArray) |
| 1928 | // edx: number of capture registers |
| 1929 | // Store the capture count. |
| 1930 | __ SmiTag(edx); // Number of capture registers to smi. |
| 1931 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 1932 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 1933 | // Store last subject and last input. |
| 1934 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1935 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1936 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1937 | __ RecordWriteField(ebx, |
| 1938 | RegExpImpl::kLastSubjectOffset, |
| 1939 | eax, |
| 1940 | edi, |
| 1941 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1942 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1943 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1944 | __ RecordWriteField(ebx, |
| 1945 | RegExpImpl::kLastInputOffset, |
| 1946 | eax, |
| 1947 | edi, |
| 1948 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1949 | |
| 1950 | // Get the static offsets vector filled by the native regexp code. |
| 1951 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1952 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1953 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 1954 | |
| 1955 | // ebx: last_match_info backing store (FixedArray) |
| 1956 | // ecx: offsets vector |
| 1957 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1958 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1959 | // Capture register counter starts from number of capture registers and |
| 1960 | // counts down until wraping after zero. |
| 1961 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1962 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1963 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1964 | // Read the value from the static offsets vector buffer. |
| 1965 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 1966 | __ SmiTag(edi); |
| 1967 | // Store the smi value in the last match info. |
| 1968 | __ mov(FieldOperand(ebx, |
| 1969 | edx, |
| 1970 | times_pointer_size, |
| 1971 | RegExpImpl::kFirstCaptureOffset), |
| 1972 | edi); |
| 1973 | __ jmp(&next_capture); |
| 1974 | __ bind(&done); |
| 1975 | |
| 1976 | // Return last match info. |
| 1977 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 1978 | __ ret(4 * kPointerSize); |
| 1979 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1980 | // Do the runtime call to execute the regexp. |
| 1981 | __ bind(&runtime); |
| 1982 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 1983 | |
| 1984 | // Deferred code for string handling. |
| 1985 | // (7) Not a long external string? If yes, go to (10). |
| 1986 | __ bind(¬_seq_nor_cons); |
| 1987 | // Compare flags are still set from (3). |
| 1988 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 1989 | |
| 1990 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1991 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1992 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1993 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1994 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 1995 | if (FLAG_debug_code) { |
| 1996 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 1997 | // Sequential strings have already been ruled out. |
| 1998 | __ test_b(ebx, kIsIndirectStringMask); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1999 | __ Assert(zero, kExternalStringExpectedButNotFound); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2000 | } |
| 2001 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 2002 | // 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] | 2003 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2004 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 2005 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 2006 | // (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] | 2007 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 2008 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2009 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 2010 | // eax: sequential subject string (or look-alike, external string) |
| 2011 | // edx: original subject string |
| 2012 | // ecx: RegExp data (FixedArray) |
| 2013 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 2014 | __ bind(&seq_two_byte_string); |
| 2015 | // Load previous index and check range before edx is overwritten. We have |
| 2016 | // to use edx instead of eax here because it might have been only made to |
| 2017 | // look like a sequential string when it actually is an external string. |
| 2018 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 2019 | __ JumpIfNotSmi(ebx, &runtime); |
| 2020 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 2021 | __ j(above_equal, &runtime); |
| 2022 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 2023 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 2024 | __ jmp(&check_code); // Go to (E). |
| 2025 | |
| 2026 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 2027 | __ bind(¬_long_external); |
| 2028 | // Catch non-string subject or short external string. |
| 2029 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 2030 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 2031 | __ j(not_zero, &runtime); |
| 2032 | |
| 2033 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 2034 | // Load offset into edi and replace subject string with parent. |
| 2035 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 2036 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 2037 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2038 | #endif // V8_INTERPRETED_REGEXP |
| 2039 | } |
| 2040 | |
| 2041 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2042 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 2043 | const int kMaxInlineLength = 100; |
| 2044 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2045 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2046 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2047 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2048 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2049 | __ j(above, &slowcase); |
| 2050 | // Smi-tagging is equivalent to multiplying by 2. |
| 2051 | STATIC_ASSERT(kSmiTag == 0); |
| 2052 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2053 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 2054 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 2055 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2056 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 2057 | times_pointer_size, |
| 2058 | ebx, // In: Number of elements as a smi |
| 2059 | REGISTER_VALUE_IS_SMI, |
| 2060 | eax, // Out: Start of allocation (tagged). |
| 2061 | ecx, // Out: End of allocation. |
| 2062 | edx, // Scratch register |
| 2063 | &slowcase, |
| 2064 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2065 | // eax: Start of allocated area, object-tagged. |
| 2066 | |
| 2067 | // Set JSArray map to global.regexp_result_map(). |
| 2068 | // Set empty properties FixedArray. |
| 2069 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 2070 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2071 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2072 | Factory* factory = masm->isolate()->factory(); |
| 2073 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2074 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2075 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2076 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 2077 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 2078 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 2079 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 2080 | |
| 2081 | // Set input, index and length fields from arguments. |
| 2082 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 2083 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 2084 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 2085 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 2086 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 2087 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 2088 | |
| 2089 | // Fill out the elements FixedArray. |
| 2090 | // eax: JSArray. |
| 2091 | // ebx: FixedArray. |
| 2092 | // ecx: Number of elements in array, as smi. |
| 2093 | |
| 2094 | // Set map. |
| 2095 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2096 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2097 | // Set length. |
| 2098 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2099 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2100 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2101 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2102 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2103 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2104 | // eax: JSArray. |
| 2105 | // ecx: Number of elements to fill. |
| 2106 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2107 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2108 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2109 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2110 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2111 | __ 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] | 2112 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2113 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 2114 | __ jmp(&loop); |
| 2115 | |
| 2116 | __ bind(&done); |
| 2117 | __ ret(3 * kPointerSize); |
| 2118 | |
| 2119 | __ bind(&slowcase); |
| 2120 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 2121 | } |
| 2122 | |
| 2123 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2124 | static int NegativeComparisonResult(Condition cc) { |
| 2125 | ASSERT(cc != equal); |
| 2126 | ASSERT((cc == less) || (cc == less_equal) |
| 2127 | || (cc == greater) || (cc == greater_equal)); |
| 2128 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 2129 | } |
| 2130 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2131 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2132 | static void CheckInputType(MacroAssembler* masm, |
| 2133 | Register input, |
| 2134 | CompareIC::State expected, |
| 2135 | Label* fail) { |
| 2136 | Label ok; |
| 2137 | if (expected == CompareIC::SMI) { |
| 2138 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2139 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2140 | __ JumpIfSmi(input, &ok); |
| 2141 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 2142 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 2143 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2144 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2145 | // 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] | 2146 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 2147 | __ bind(&ok); |
| 2148 | } |
| 2149 | |
| 2150 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2151 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 2152 | Label* label, |
| 2153 | Register object, |
| 2154 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2155 | __ JumpIfSmi(object, label); |
| 2156 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 2157 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 2158 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 2159 | __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 2160 | __ j(not_zero, label); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | |
| 2164 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 2165 | Label check_unequal_objects; |
| 2166 | Condition cc = GetCondition(); |
| 2167 | |
| 2168 | Label miss; |
| 2169 | CheckInputType(masm, edx, left_, &miss); |
| 2170 | CheckInputType(masm, eax, right_, &miss); |
| 2171 | |
| 2172 | // Compare two smis. |
| 2173 | Label non_smi, smi_done; |
| 2174 | __ mov(ecx, edx); |
| 2175 | __ or_(ecx, eax); |
| 2176 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 2177 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 2178 | __ j(no_overflow, &smi_done, Label::kNear); |
| 2179 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 2180 | __ bind(&smi_done); |
| 2181 | __ mov(eax, edx); |
| 2182 | __ ret(0); |
| 2183 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2184 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2185 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 2186 | // it is certain that at least one operand isn't a smi. |
| 2187 | |
| 2188 | // Identical objects can be compared fast, but there are some tricky cases |
| 2189 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2190 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2191 | { |
| 2192 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2193 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2194 | __ j(not_equal, ¬_identical); |
| 2195 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2196 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2197 | // Check for undefined. undefined OP undefined is false even though |
| 2198 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2199 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2200 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2201 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2202 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2203 | __ ret(0); |
| 2204 | __ bind(&check_for_nan); |
| 2205 | } |
| 2206 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2207 | // Test for NaN. Compare heap numbers in a general way, |
| 2208 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2209 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 2210 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2211 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2212 | if (cc != equal) { |
| 2213 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 2214 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 2215 | __ j(above_equal, ¬_identical); |
| 2216 | } |
| 2217 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 2218 | __ ret(0); |
| 2219 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2220 | |
| 2221 | __ bind(¬_identical); |
| 2222 | } |
| 2223 | |
| 2224 | // Strict equality can quickly decide whether objects are equal. |
| 2225 | // 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] | 2226 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2227 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2228 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2229 | // If we're doing a strict equality comparison, we don't have to do |
| 2230 | // type conversion, so we generate code to do fast comparison for objects |
| 2231 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 2232 | // slow-case code. |
| 2233 | // If either is a Smi (we know that not both are), then they can only |
| 2234 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 2235 | STATIC_ASSERT(kSmiTag == 0); |
| 2236 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 2237 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2238 | __ and_(ecx, eax); |
| 2239 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2240 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2241 | // One operand is a smi. |
| 2242 | |
| 2243 | // Check whether the non-smi is a heap number. |
| 2244 | STATIC_ASSERT(kSmiTagMask == 1); |
| 2245 | // 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] | 2246 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2247 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2248 | __ xor_(ebx, eax); |
| 2249 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 2250 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2251 | // if eax was smi, ebx is now edx, else eax. |
| 2252 | |
| 2253 | // Check if the non-smi operand is a heap number. |
| 2254 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2255 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2256 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2257 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2258 | // Return non-equal (ebx is not zero) |
| 2259 | __ mov(eax, ebx); |
| 2260 | __ ret(0); |
| 2261 | |
| 2262 | __ bind(¬_smis); |
| 2263 | // If either operand is a JSObject or an oddball value, then they are not |
| 2264 | // equal since their pointers are different |
| 2265 | // There is no test for undetectability in strict equality. |
| 2266 | |
| 2267 | // Get the type of the first operand. |
| 2268 | // 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] | 2269 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2270 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 2271 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2272 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2273 | |
| 2274 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2275 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2276 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 2277 | __ bind(&return_not_equal); |
| 2278 | __ ret(0); |
| 2279 | |
| 2280 | __ bind(&first_non_object); |
| 2281 | // Check for oddballs: true, false, null, undefined. |
| 2282 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 2283 | __ j(equal, &return_not_equal); |
| 2284 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2285 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2286 | __ j(above_equal, &return_not_equal); |
| 2287 | |
| 2288 | // Check for oddballs: true, false, null, undefined. |
| 2289 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 2290 | __ j(equal, &return_not_equal); |
| 2291 | |
| 2292 | // Fall through to the general case. |
| 2293 | __ bind(&slow); |
| 2294 | } |
| 2295 | |
| 2296 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2297 | Label non_number_comparison; |
| 2298 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2299 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2300 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2301 | CpuFeatureScope use_sse2(masm, SSE2); |
| 2302 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2303 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2304 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 2305 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2306 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2307 | // Don't base result on EFLAGS when a NaN is involved. |
| 2308 | __ j(parity_even, &unordered, Label::kNear); |
| 2309 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 2310 | __ mov(eax, 0); // equal |
| 2311 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 2312 | __ cmov(above, eax, ecx); |
| 2313 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 2314 | __ cmov(below, eax, ecx); |
| 2315 | __ ret(0); |
| 2316 | } else { |
| 2317 | FloatingPointHelper::CheckFloatOperands( |
| 2318 | masm, &non_number_comparison, ebx); |
| 2319 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 2320 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 2321 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2322 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2323 | // Don't base result on EFLAGS when a NaN is involved. |
| 2324 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2325 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2326 | Label below_label, above_label; |
| 2327 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 2328 | __ j(below, &below_label, Label::kNear); |
| 2329 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2330 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2331 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2332 | __ ret(0); |
| 2333 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2334 | __ bind(&below_label); |
| 2335 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 2336 | __ ret(0); |
| 2337 | |
| 2338 | __ bind(&above_label); |
| 2339 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 2340 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2343 | // If one of the numbers was NaN, then the result is always false. |
| 2344 | // The cc is never not-equal. |
| 2345 | __ bind(&unordered); |
| 2346 | ASSERT(cc != not_equal); |
| 2347 | if (cc == less || cc == less_equal) { |
| 2348 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 2349 | } else { |
| 2350 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 2351 | } |
| 2352 | __ ret(0); |
| 2353 | |
| 2354 | // The number comparison code did not provide a valid result. |
| 2355 | __ bind(&non_number_comparison); |
| 2356 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2357 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2358 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2359 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2360 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 2361 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2362 | |
| 2363 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2364 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2365 | // non-zero value, which indicates not equal, so just return. |
| 2366 | __ ret(0); |
| 2367 | } |
| 2368 | |
| 2369 | __ bind(&check_for_strings); |
| 2370 | |
| 2371 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 2372 | &check_unequal_objects); |
| 2373 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2374 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2375 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2376 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2377 | edx, |
| 2378 | eax, |
| 2379 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2380 | ebx); |
| 2381 | } else { |
| 2382 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 2383 | edx, |
| 2384 | eax, |
| 2385 | ecx, |
| 2386 | ebx, |
| 2387 | edi); |
| 2388 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2389 | #ifdef DEBUG |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2390 | __ Abort(kUnexpectedFallThroughFromStringComparison); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2391 | #endif |
| 2392 | |
| 2393 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2394 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2395 | // Non-strict equality. Objects are unequal if |
| 2396 | // they are both JSObjects and not undetectable, |
| 2397 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2398 | Label not_both_objects; |
| 2399 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2400 | // At most one is a smi, so we can test for smi by adding the two. |
| 2401 | // A smi plus a heap object has the low bit set, a heap object plus |
| 2402 | // a heap object has the low bit clear. |
| 2403 | STATIC_ASSERT(kSmiTag == 0); |
| 2404 | STATIC_ASSERT(kSmiTagMask == 1); |
| 2405 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 2406 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2407 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2408 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2409 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2410 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2411 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2412 | // We do not bail out after this point. Both are JSObjects, and |
| 2413 | // they are equal if and only if both are undetectable. |
| 2414 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 2415 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 2416 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2417 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2418 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 2419 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2420 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2421 | // The objects are both undetectable, so they both compare as the value |
| 2422 | // undefined, and are equal. |
| 2423 | __ Set(eax, Immediate(EQUAL)); |
| 2424 | __ bind(&return_unequal); |
| 2425 | // Return non-equal by returning the non-zero object pointer in eax, |
| 2426 | // or return equal if we fell through to here. |
| 2427 | __ ret(0); // rax, rdx were pushed |
| 2428 | __ bind(¬_both_objects); |
| 2429 | } |
| 2430 | |
| 2431 | // Push arguments below the return address. |
| 2432 | __ pop(ecx); |
| 2433 | __ push(edx); |
| 2434 | __ push(eax); |
| 2435 | |
| 2436 | // Figure out which native to call and setup the arguments. |
| 2437 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2438 | if (cc == equal) { |
| 2439 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2440 | } else { |
| 2441 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2442 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | // Restore return address on the stack. |
| 2446 | __ push(ecx); |
| 2447 | |
| 2448 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 2449 | // tagged as a small integer. |
| 2450 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2451 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2452 | __ bind(&miss); |
| 2453 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2454 | } |
| 2455 | |
| 2456 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2457 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 2458 | // Cache the called function in a global property cell. Cache states |
| 2459 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 2460 | // megamorphic. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2461 | // eax : number of arguments to the construct function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2462 | // ebx : cache cell for call target |
| 2463 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2464 | Isolate* isolate = masm->isolate(); |
| 2465 | Label initialize, done, miss, megamorphic, not_array_function; |
| 2466 | |
| 2467 | // Load the cache state into ecx. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2468 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2469 | |
| 2470 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 2471 | // function without changing the state. |
| 2472 | __ cmp(ecx, edi); |
| 2473 | __ j(equal, &done); |
| 2474 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 2475 | __ j(equal, &done); |
| 2476 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2477 | // If we came here, we need to see if we are the array function. |
| 2478 | // If we didn't have a matching function, and we didn't find the megamorph |
| 2479 | // sentinel, then we have in the cell either some other function or an |
| 2480 | // AllocationSite. Do a map check on the object in ecx. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2481 | Handle<Map> allocation_site_map = |
| 2482 | masm->isolate()->factory()->allocation_site_map(); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2483 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 2484 | __ j(not_equal, &miss); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2485 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2486 | // Load the global or builtins object from the current context |
| 2487 | __ LoadGlobalContext(ecx); |
| 2488 | // Make sure the function is the Array() function |
| 2489 | __ cmp(edi, Operand(ecx, |
| 2490 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 2491 | __ j(not_equal, &megamorphic); |
| 2492 | __ jmp(&done); |
| 2493 | |
| 2494 | __ bind(&miss); |
| 2495 | |
| 2496 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 2497 | // megamorphic. |
| 2498 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 2499 | __ j(equal, &initialize); |
| 2500 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 2501 | // write-barrier is needed. |
| 2502 | __ bind(&megamorphic); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2503 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2504 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 2505 | __ jmp(&done, Label::kNear); |
| 2506 | |
| 2507 | // An uninitialized cache is patched with the function or sentinel to |
| 2508 | // indicate the ElementsKind if function is the Array constructor. |
| 2509 | __ bind(&initialize); |
| 2510 | __ LoadGlobalContext(ecx); |
| 2511 | // Make sure the function is the Array() function |
| 2512 | __ cmp(edi, Operand(ecx, |
| 2513 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 2514 | __ j(not_equal, ¬_array_function); |
| 2515 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2516 | // The target function is the Array constructor, |
| 2517 | // Create an AllocationSite if we don't already have it, store it in the cell |
| 2518 | { |
| 2519 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2520 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2521 | // Arguments register must be smi-tagged to call out. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2522 | __ SmiTag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2523 | __ push(eax); |
| 2524 | __ push(edi); |
| 2525 | __ push(ebx); |
| 2526 | |
| 2527 | CreateAllocationSiteStub create_stub; |
| 2528 | __ CallStub(&create_stub); |
| 2529 | |
| 2530 | __ pop(ebx); |
| 2531 | __ pop(edi); |
| 2532 | __ pop(eax); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2533 | __ SmiUntag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2534 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2535 | __ jmp(&done); |
| 2536 | |
| 2537 | __ bind(¬_array_function); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2538 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2539 | // No need for a write barrier here - cells are rescanned. |
| 2540 | |
| 2541 | __ bind(&done); |
| 2542 | } |
| 2543 | |
| 2544 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2545 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2546 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2547 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2548 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2549 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2550 | |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame] | 2551 | // Check that the function really is a JavaScript function. |
| 2552 | __ JumpIfSmi(edi, &non_function); |
| 2553 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2554 | // Goto slow case if we do not have a function. |
| 2555 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2556 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2557 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2558 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2559 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2560 | } |
| 2561 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2562 | // Fast-case: Just invoke the function. |
| 2563 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2564 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2565 | __ InvokeFunction(edi, actual, JUMP_FUNCTION, NullCallWrapper()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2566 | |
| 2567 | // Slow-case: Non-function called. |
| 2568 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2569 | if (RecordCallTarget()) { |
| 2570 | // 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] | 2571 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 2572 | // object (undefined) so no write barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2573 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2574 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2575 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2576 | // Check for function proxy. |
| 2577 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 2578 | __ j(not_equal, &non_function); |
| 2579 | __ pop(ecx); |
| 2580 | __ push(edi); // put proxy as additional argument under return address |
| 2581 | __ push(ecx); |
| 2582 | __ Set(eax, Immediate(argc_ + 1)); |
| 2583 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2584 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 2585 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2586 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2587 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 2588 | } |
| 2589 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2590 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 2591 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2592 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2593 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 2594 | __ Set(eax, Immediate(argc_)); |
| 2595 | __ Set(ebx, Immediate(0)); |
| 2596 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2597 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2598 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 2599 | } |
| 2600 | |
| 2601 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2602 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 2603 | // eax : number of arguments |
| 2604 | // ebx : cache cell for call target |
| 2605 | // edi : constructor function |
| 2606 | Label slow, non_function_call; |
| 2607 | |
| 2608 | // Check that function is not a smi. |
| 2609 | __ JumpIfSmi(edi, &non_function_call); |
| 2610 | // Check that function is a JSFunction. |
| 2611 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2612 | __ j(not_equal, &slow); |
| 2613 | |
| 2614 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2615 | GenerateRecordCallTarget(masm); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2616 | } |
| 2617 | |
| 2618 | // Jump to the function-specific construct stub. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2619 | Register jmp_reg = ecx; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2620 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2621 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 2622 | SharedFunctionInfo::kConstructStubOffset)); |
| 2623 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 2624 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2625 | |
| 2626 | // edi: called object |
| 2627 | // eax: number of arguments |
| 2628 | // ecx: object map |
| 2629 | Label do_call; |
| 2630 | __ bind(&slow); |
| 2631 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 2632 | __ j(not_equal, &non_function_call); |
| 2633 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 2634 | __ jmp(&do_call); |
| 2635 | |
| 2636 | __ bind(&non_function_call); |
| 2637 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 2638 | __ bind(&do_call); |
| 2639 | // Set expected number of arguments to zero (not changing eax). |
| 2640 | __ Set(ebx, Immediate(0)); |
| 2641 | Handle<Code> arguments_adaptor = |
| 2642 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2643 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 2644 | } |
| 2645 | |
| 2646 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2647 | bool CEntryStub::NeedsImmovableCode() { |
| 2648 | return false; |
| 2649 | } |
| 2650 | |
| 2651 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2652 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 2653 | CEntryStub::GenerateAheadOfTime(isolate); |
| 2654 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2655 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2656 | // It is important that the store buffer overflow stubs are generated first. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2657 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2658 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2659 | if (Serializer::enabled()) { |
| 2660 | PlatformFeatureScope sse2(SSE2); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2661 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 2662 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2663 | } else { |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2664 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 2665 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2666 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2667 | } |
| 2668 | |
| 2669 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2670 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2671 | if (CpuFeatures::IsSupported(SSE2)) { |
| 2672 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 2673 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 2674 | // which would lead to code stub initialization state being messed up. |
| 2675 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2676 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 2677 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2678 | } |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2679 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2680 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2684 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2685 | CEntryStub stub(1, kDontSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2686 | stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2690 | static void JumpIfOOM(MacroAssembler* masm, |
| 2691 | Register value, |
| 2692 | Register scratch, |
| 2693 | Label* oom_label) { |
| 2694 | __ mov(scratch, value); |
| 2695 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 2696 | STATIC_ASSERT(kFailureTag == 3); |
| 2697 | __ and_(scratch, 0xf); |
| 2698 | __ cmp(scratch, 0xf); |
| 2699 | __ j(equal, oom_label); |
| 2700 | } |
| 2701 | |
| 2702 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2703 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 2704 | Label* throw_normal_exception, |
| 2705 | Label* throw_termination_exception, |
| 2706 | Label* throw_out_of_memory_exception, |
| 2707 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2708 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2709 | // eax: result parameter for PerformGC, if any |
| 2710 | // ebx: pointer to C function (C callee-saved) |
| 2711 | // ebp: frame pointer (restored after C call) |
| 2712 | // esp: stack pointer (restored after C call) |
| 2713 | // edi: number of arguments including receiver (C callee-saved) |
| 2714 | // esi: pointer to the first argument (C callee-saved) |
| 2715 | |
| 2716 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 2717 | |
| 2718 | // Check stack alignment. |
| 2719 | if (FLAG_debug_code) { |
| 2720 | __ CheckStackAlignment(); |
| 2721 | } |
| 2722 | |
| 2723 | if (do_gc) { |
| 2724 | // Pass failure code returned from last attempt as first argument to |
| 2725 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 2726 | // stack alignment is known to be correct. This function takes one argument |
| 2727 | // which is passed on the stack, and we know that the stack has been |
| 2728 | // prepared to pass at least one argument. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2729 | __ mov(Operand(esp, 1 * kPointerSize), |
| 2730 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2731 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 2732 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 2733 | } |
| 2734 | |
| 2735 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2736 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2737 | if (always_allocate_scope) { |
| 2738 | __ inc(Operand::StaticVariable(scope_depth)); |
| 2739 | } |
| 2740 | |
| 2741 | // Call C function. |
| 2742 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 2743 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2744 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2745 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2746 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2747 | // Result is in eax or edx:eax - do not destroy these registers! |
| 2748 | |
| 2749 | if (always_allocate_scope) { |
| 2750 | __ dec(Operand::StaticVariable(scope_depth)); |
| 2751 | } |
| 2752 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2753 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 2754 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2755 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2756 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2757 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2758 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2759 | __ int3(); |
| 2760 | __ bind(&okay); |
| 2761 | } |
| 2762 | |
| 2763 | // Check for failure result. |
| 2764 | Label failure_returned; |
| 2765 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 2766 | __ lea(ecx, Operand(eax, 1)); |
| 2767 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 2768 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2769 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2770 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2771 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2772 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2773 | |
| 2774 | // Check that there is no pending exception, otherwise we |
| 2775 | // should have returned some failure value. |
| 2776 | if (FLAG_debug_code) { |
| 2777 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2778 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2779 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2780 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 2781 | // 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] | 2782 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2783 | __ int3(); |
| 2784 | __ bind(&okay); |
| 2785 | __ pop(edx); |
| 2786 | } |
| 2787 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2788 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2789 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2790 | __ ret(0); |
| 2791 | |
| 2792 | // Handling of failure. |
| 2793 | __ bind(&failure_returned); |
| 2794 | |
| 2795 | Label retry; |
| 2796 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 2797 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 2798 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2799 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2800 | |
| 2801 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2802 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2803 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2804 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2805 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2806 | |
| 2807 | // See if we just retrieved an OOM exception. |
| 2808 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 2809 | |
| 2810 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2811 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2812 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 2813 | |
| 2814 | // Special handling of termination exceptions which are uncatchable |
| 2815 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2816 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2817 | __ j(equal, throw_termination_exception); |
| 2818 | |
| 2819 | // Handle normal exception. |
| 2820 | __ jmp(throw_normal_exception); |
| 2821 | |
| 2822 | // Retry. |
| 2823 | __ bind(&retry); |
| 2824 | } |
| 2825 | |
| 2826 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2827 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 2828 | // eax: number of arguments including receiver |
| 2829 | // ebx: pointer to C function (C callee-saved) |
| 2830 | // ebp: frame pointer (restored after C call) |
| 2831 | // esp: stack pointer (restored after C call) |
| 2832 | // esi: current context (C callee-saved) |
| 2833 | // edi: JS function of the caller (C callee-saved) |
| 2834 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2835 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 2836 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2837 | // NOTE: Invocations of builtins may return failure objects instead |
| 2838 | // of a proper result. The builtin entry handles this by performing |
| 2839 | // a garbage collection and retrying the builtin (twice). |
| 2840 | |
| 2841 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2842 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2843 | |
| 2844 | // eax: result parameter for PerformGC, if any (setup below) |
| 2845 | // ebx: pointer to builtin function (C callee-saved) |
| 2846 | // ebp: frame pointer (restored after C call) |
| 2847 | // esp: stack pointer (restored after C call) |
| 2848 | // edi: number of arguments including receiver (C callee-saved) |
| 2849 | // esi: argv pointer (C callee-saved) |
| 2850 | |
| 2851 | Label throw_normal_exception; |
| 2852 | Label throw_termination_exception; |
| 2853 | Label throw_out_of_memory_exception; |
| 2854 | |
| 2855 | // Call into the runtime system. |
| 2856 | GenerateCore(masm, |
| 2857 | &throw_normal_exception, |
| 2858 | &throw_termination_exception, |
| 2859 | &throw_out_of_memory_exception, |
| 2860 | false, |
| 2861 | false); |
| 2862 | |
| 2863 | // Do space-specific GC and retry runtime call. |
| 2864 | GenerateCore(masm, |
| 2865 | &throw_normal_exception, |
| 2866 | &throw_termination_exception, |
| 2867 | &throw_out_of_memory_exception, |
| 2868 | true, |
| 2869 | false); |
| 2870 | |
| 2871 | // Do full GC and retry runtime call one final time. |
| 2872 | Failure* failure = Failure::InternalError(); |
| 2873 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 2874 | GenerateCore(masm, |
| 2875 | &throw_normal_exception, |
| 2876 | &throw_termination_exception, |
| 2877 | &throw_out_of_memory_exception, |
| 2878 | true, |
| 2879 | true); |
| 2880 | |
| 2881 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2882 | // Set external caught exception to false. |
| 2883 | Isolate* isolate = masm->isolate(); |
| 2884 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 2885 | isolate); |
| 2886 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 2887 | |
| 2888 | // Set pending exception and eax to out of memory exception. |
| 2889 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 2890 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2891 | Label already_have_failure; |
| 2892 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 2893 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 2894 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2895 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 2896 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2897 | |
| 2898 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2899 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2900 | |
| 2901 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2902 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | |
| 2906 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2907 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2908 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2909 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2910 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 2911 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2912 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2913 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2914 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2915 | |
| 2916 | // Push marker in two places. |
| 2917 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 2918 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 2919 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 2920 | // Save callee-saved registers (C calling conventions). |
| 2921 | __ push(edi); |
| 2922 | __ push(esi); |
| 2923 | __ push(ebx); |
| 2924 | |
| 2925 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2926 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2927 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 2928 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2929 | // 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] | 2930 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2931 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2932 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2933 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2934 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2935 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 2936 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2937 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2938 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2939 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2940 | // Jump to a faked try block that does the invoke, with a faked catch |
| 2941 | // block that sets the pending exception. |
| 2942 | __ jmp(&invoke); |
| 2943 | __ bind(&handler_entry); |
| 2944 | handler_offset_ = handler_entry.pos(); |
| 2945 | // Caught exception: Store result (exception) in the pending exception |
| 2946 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2947 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2948 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2949 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 2950 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 2951 | __ jmp(&exit); |
| 2952 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2953 | // Invoke: Link this frame into the handler chain. There's only one |
| 2954 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2955 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 2956 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2957 | |
| 2958 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2959 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2960 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 2961 | |
| 2962 | // Fake a receiver (NULL). |
| 2963 | __ push(Immediate(0)); // receiver |
| 2964 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2965 | // Invoke the function by calling through JS entry trampoline builtin and |
| 2966 | // pop the faked function when we return. Notice that we cannot store a |
| 2967 | // reference to the trampoline code directly in this stub, because the |
| 2968 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2969 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2970 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 2971 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2972 | __ mov(edx, Immediate(construct_entry)); |
| 2973 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2974 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2975 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2976 | __ mov(edx, Immediate(entry)); |
| 2977 | } |
| 2978 | __ mov(edx, Operand(edx, 0)); // deref address |
| 2979 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2980 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2981 | |
| 2982 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2983 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2984 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2985 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2986 | // Check if the current stack frame is marked as the outermost JS frame. |
| 2987 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2988 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2989 | __ j(not_equal, ¬_outermost_js_2); |
| 2990 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 2991 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2992 | |
| 2993 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2994 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2995 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2996 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2997 | |
| 2998 | // Restore callee-saved registers (C calling conventions). |
| 2999 | __ pop(ebx); |
| 3000 | __ pop(esi); |
| 3001 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3002 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3003 | |
| 3004 | // Restore frame pointer and return. |
| 3005 | __ pop(ebp); |
| 3006 | __ ret(0); |
| 3007 | } |
| 3008 | |
| 3009 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3010 | // Generate stub code for instanceof. |
| 3011 | // This code can patch a call site inlined cache of the instance of check, |
| 3012 | // which looks like this. |
| 3013 | // |
| 3014 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 3015 | // 75 0a jne <some near label> |
| 3016 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 3017 | // |
| 3018 | // If call site patching is requested the stack will have the delta from the |
| 3019 | // return address to the cmp instruction just below the return address. This |
| 3020 | // also means that call site patching can only take place with arguments in |
| 3021 | // registers. TOS looks like this when call site patching is requested |
| 3022 | // |
| 3023 | // esp[0] : return address |
| 3024 | // esp[4] : delta from return address to cmp instruction |
| 3025 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3026 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3027 | // Call site inlining and patching implies arguments in registers. |
| 3028 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 3029 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3030 | // Fixed register usage throughout the stub. |
| 3031 | Register object = eax; // Object (lhs). |
| 3032 | Register map = ebx; // Map of the object. |
| 3033 | Register function = edx; // Function (rhs). |
| 3034 | Register prototype = edi; // Prototype of the function. |
| 3035 | Register scratch = ecx; |
| 3036 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3037 | // Constants describing the call site code to patch. |
| 3038 | static const int kDeltaToCmpImmediate = 2; |
| 3039 | static const int kDeltaToMov = 8; |
| 3040 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3041 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 3042 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3043 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 3044 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3045 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 3046 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 3047 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3048 | // Get the object and function - they are always both needed. |
| 3049 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3050 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3051 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 3052 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 3053 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3054 | |
| 3055 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3056 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3057 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3058 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3059 | // If there is a call site cache don't look in the global cache, but do the |
| 3060 | // real lookup and update the call site cache. |
| 3061 | if (!HasCallSiteInlineCheck()) { |
| 3062 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3063 | Label miss; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3064 | __ CompareRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3065 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3066 | __ CompareRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3067 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3068 | __ LoadRoot(eax, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3069 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 3070 | __ bind(&miss); |
| 3071 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3072 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3073 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3074 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3075 | |
| 3076 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3077 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3078 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3079 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3080 | // Update the global instanceof or call site inlined cache with the current |
| 3081 | // map and function. The cached answer will be set when it is known below. |
| 3082 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3083 | __ StoreRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
| 3084 | __ StoreRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3085 | } else { |
| 3086 | // The constants for the code patching are based on no push instructions |
| 3087 | // at the call site. |
| 3088 | ASSERT(HasArgsInRegisters()); |
| 3089 | // Get return address and delta to inlined map check. |
| 3090 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3091 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3092 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3093 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3094 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp1); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3095 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3096 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3097 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3098 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 3099 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3100 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3101 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3102 | // Loop through the prototype chain of the object looking for the function |
| 3103 | // prototype. |
| 3104 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3105 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3106 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3107 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3108 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3109 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3110 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3111 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3112 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 3113 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3114 | __ jmp(&loop); |
| 3115 | |
| 3116 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3117 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3118 | __ mov(eax, Immediate(0)); |
| 3119 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3120 | } else { |
| 3121 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3122 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3123 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3124 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3125 | if (FLAG_debug_code) { |
| 3126 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3127 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3128 | } |
| 3129 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 3130 | if (!ReturnTrueFalseObject()) { |
| 3131 | __ Set(eax, Immediate(0)); |
| 3132 | } |
| 3133 | } |
| 3134 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3135 | |
| 3136 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3137 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3138 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 3139 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3140 | } else { |
| 3141 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3142 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3143 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3144 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3145 | if (FLAG_debug_code) { |
| 3146 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3147 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3148 | } |
| 3149 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 3150 | if (!ReturnTrueFalseObject()) { |
| 3151 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 3152 | } |
| 3153 | } |
| 3154 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3155 | |
| 3156 | Label object_not_null, object_not_null_or_smi; |
| 3157 | __ bind(¬_js_object); |
| 3158 | // Before null, smi and string value checks, check that the rhs is a function |
| 3159 | // 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] | 3160 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3161 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3162 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3163 | |
| 3164 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3165 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3166 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3167 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3168 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3169 | |
| 3170 | __ bind(&object_not_null); |
| 3171 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3172 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3173 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3174 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3175 | |
| 3176 | __ bind(&object_not_null_or_smi); |
| 3177 | // String values is not instance of anything. |
| 3178 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3179 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3180 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3181 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3182 | |
| 3183 | // Slow-case: Go through the JavaScript implementation. |
| 3184 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3185 | if (!ReturnTrueFalseObject()) { |
| 3186 | // Tail call the builtin which returns 0 or 1. |
| 3187 | if (HasArgsInRegisters()) { |
| 3188 | // Push arguments below return address. |
| 3189 | __ pop(scratch); |
| 3190 | __ push(object); |
| 3191 | __ push(function); |
| 3192 | __ push(scratch); |
| 3193 | } |
| 3194 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 3195 | } else { |
| 3196 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3197 | { |
| 3198 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3199 | __ push(object); |
| 3200 | __ push(function); |
| 3201 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 3202 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3203 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3204 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3205 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3206 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3207 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3208 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3209 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3210 | __ bind(&done); |
| 3211 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3212 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3216 | Register InstanceofStub::left() { return eax; } |
| 3217 | |
| 3218 | |
| 3219 | Register InstanceofStub::right() { return edx; } |
| 3220 | |
| 3221 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3222 | // ------------------------------------------------------------------------- |
| 3223 | // StringCharCodeAtGenerator |
| 3224 | |
| 3225 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3226 | // If the receiver is a smi trigger the non-string case. |
| 3227 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3228 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3229 | |
| 3230 | // Fetch the instance type of the receiver into result register. |
| 3231 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 3232 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 3233 | // If the receiver is not a string trigger the non-string case. |
| 3234 | __ test(result_, Immediate(kIsNotStringMask)); |
| 3235 | __ j(not_zero, receiver_not_string_); |
| 3236 | |
| 3237 | // If the index is non-smi trigger the non-smi case. |
| 3238 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3239 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3240 | __ bind(&got_smi_index_); |
| 3241 | |
| 3242 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3243 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3244 | __ j(above_equal, index_out_of_range_); |
| 3245 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3246 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3247 | |
| 3248 | Factory* factory = masm->isolate()->factory(); |
| 3249 | StringCharLoadGenerator::Generate( |
| 3250 | masm, factory, object_, index_, result_, &call_runtime_); |
| 3251 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3252 | __ SmiTag(result_); |
| 3253 | __ bind(&exit_); |
| 3254 | } |
| 3255 | |
| 3256 | |
| 3257 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3258 | MacroAssembler* masm, |
| 3259 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3260 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3261 | |
| 3262 | // Index is not a smi. |
| 3263 | __ bind(&index_not_smi_); |
| 3264 | // 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] | 3265 | __ CheckMap(index_, |
| 3266 | masm->isolate()->factory()->heap_number_map(), |
| 3267 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3268 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3269 | call_helper.BeforeCall(masm); |
| 3270 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3271 | __ push(index_); // Consumed by runtime conversion function. |
| 3272 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 3273 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 3274 | } else { |
| 3275 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 3276 | // NumberToSmi discards numbers that are not exact integers. |
| 3277 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 3278 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3279 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3280 | // Save the conversion result before the pop instructions below |
| 3281 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3282 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3283 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3284 | __ pop(object_); |
| 3285 | // Reload the instance type. |
| 3286 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 3287 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 3288 | call_helper.AfterCall(masm); |
| 3289 | // If index is still not a smi, it must be out of range. |
| 3290 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3291 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3292 | // Otherwise, return to the fast path. |
| 3293 | __ jmp(&got_smi_index_); |
| 3294 | |
| 3295 | // Call runtime. We get here when the receiver is a string and the |
| 3296 | // index is a number, but the code of getting the actual character |
| 3297 | // is too complex (e.g., when the string needs to be flattened). |
| 3298 | __ bind(&call_runtime_); |
| 3299 | call_helper.BeforeCall(masm); |
| 3300 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3301 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3302 | __ push(index_); |
| 3303 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 3304 | if (!result_.is(eax)) { |
| 3305 | __ mov(result_, eax); |
| 3306 | } |
| 3307 | call_helper.AfterCall(masm); |
| 3308 | __ jmp(&exit_); |
| 3309 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3310 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | |
| 3314 | // ------------------------------------------------------------------------- |
| 3315 | // StringCharFromCodeGenerator |
| 3316 | |
| 3317 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 3318 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 3319 | STATIC_ASSERT(kSmiTag == 0); |
| 3320 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3321 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3322 | __ test(code_, |
| 3323 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3324 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3325 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3326 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3327 | Factory* factory = masm->isolate()->factory(); |
| 3328 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3329 | STATIC_ASSERT(kSmiTag == 0); |
| 3330 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3331 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3332 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3333 | __ mov(result_, FieldOperand(result_, |
| 3334 | code_, times_half_pointer_size, |
| 3335 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3336 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3337 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3338 | __ bind(&exit_); |
| 3339 | } |
| 3340 | |
| 3341 | |
| 3342 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3343 | MacroAssembler* masm, |
| 3344 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3345 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3346 | |
| 3347 | __ bind(&slow_case_); |
| 3348 | call_helper.BeforeCall(masm); |
| 3349 | __ push(code_); |
| 3350 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 3351 | if (!result_.is(eax)) { |
| 3352 | __ mov(result_, eax); |
| 3353 | } |
| 3354 | call_helper.AfterCall(masm); |
| 3355 | __ jmp(&exit_); |
| 3356 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3357 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3361 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 3362 | Register dest, |
| 3363 | Register src, |
| 3364 | Register count, |
| 3365 | Register scratch, |
| 3366 | bool ascii) { |
| 3367 | // Copy characters using rep movs of doublewords. |
| 3368 | // The destination is aligned on a 4 byte boundary because we are |
| 3369 | // copying to the beginning of a newly allocated string. |
| 3370 | ASSERT(dest.is(edi)); // rep movs destination |
| 3371 | ASSERT(src.is(esi)); // rep movs source |
| 3372 | ASSERT(count.is(ecx)); // rep movs count |
| 3373 | ASSERT(!scratch.is(dest)); |
| 3374 | ASSERT(!scratch.is(src)); |
| 3375 | ASSERT(!scratch.is(count)); |
| 3376 | |
| 3377 | // Nothing to do for zero characters. |
| 3378 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3379 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3380 | __ j(zero, &done); |
| 3381 | |
| 3382 | // Make count the number of bytes to copy. |
| 3383 | if (!ascii) { |
| 3384 | __ shl(count, 1); |
| 3385 | } |
| 3386 | |
| 3387 | // 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] | 3388 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3389 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3390 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3391 | |
| 3392 | // Copy from edi to esi using rep movs instruction. |
| 3393 | __ mov(scratch, count); |
| 3394 | __ sar(count, 2); // Number of doublewords to copy. |
| 3395 | __ cld(); |
| 3396 | __ rep_movs(); |
| 3397 | |
| 3398 | // Find number of bytes left. |
| 3399 | __ mov(count, scratch); |
| 3400 | __ and_(count, 3); |
| 3401 | |
| 3402 | // Check if there are more bytes to copy. |
| 3403 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3404 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3405 | __ j(zero, &done); |
| 3406 | |
| 3407 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3408 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3409 | __ bind(&loop); |
| 3410 | __ mov_b(scratch, Operand(src, 0)); |
| 3411 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3412 | __ add(src, Immediate(1)); |
| 3413 | __ add(dest, Immediate(1)); |
| 3414 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3415 | __ j(not_zero, &loop); |
| 3416 | |
| 3417 | __ bind(&done); |
| 3418 | } |
| 3419 | |
| 3420 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3421 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 3422 | Register hash, |
| 3423 | Register character, |
| 3424 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3425 | // hash = (seed + character) + ((seed + character) << 10); |
| 3426 | if (Serializer::enabled()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3427 | __ LoadRoot(scratch, Heap::kHashSeedRootIndex); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3428 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3429 | __ add(scratch, character); |
| 3430 | __ mov(hash, scratch); |
| 3431 | __ shl(scratch, 10); |
| 3432 | __ add(hash, scratch); |
| 3433 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3434 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3435 | __ lea(scratch, Operand(character, seed)); |
| 3436 | __ shl(scratch, 10); |
| 3437 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 3438 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3439 | // hash ^= hash >> 6; |
| 3440 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3441 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3442 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | |
| 3446 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 3447 | Register hash, |
| 3448 | Register character, |
| 3449 | Register scratch) { |
| 3450 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3451 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3452 | // hash += hash << 10; |
| 3453 | __ mov(scratch, hash); |
| 3454 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3455 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3456 | // hash ^= hash >> 6; |
| 3457 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3458 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3459 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | |
| 3463 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 3464 | Register hash, |
| 3465 | Register scratch) { |
| 3466 | // hash += hash << 3; |
| 3467 | __ mov(scratch, hash); |
| 3468 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3469 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3470 | // hash ^= hash >> 11; |
| 3471 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3472 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3473 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3474 | // hash += hash << 15; |
| 3475 | __ mov(scratch, hash); |
| 3476 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3477 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3478 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3479 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3480 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3481 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3482 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3483 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3484 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3485 | __ bind(&hash_not_zero); |
| 3486 | } |
| 3487 | |
| 3488 | |
| 3489 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 3490 | Label runtime; |
| 3491 | |
| 3492 | // Stack frame on entry. |
| 3493 | // esp[0]: return address |
| 3494 | // esp[4]: to |
| 3495 | // esp[8]: from |
| 3496 | // esp[12]: string |
| 3497 | |
| 3498 | // Make sure first argument is a string. |
| 3499 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 3500 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3501 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3502 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 3503 | __ j(NegateCondition(is_string), &runtime); |
| 3504 | |
| 3505 | // eax: string |
| 3506 | // ebx: instance type |
| 3507 | |
| 3508 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3509 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3510 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3511 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3512 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3513 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3514 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3515 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 3516 | // Shorter than original string's length: an actual substring. |
| 3517 | __ j(below, ¬_original_string, Label::kNear); |
| 3518 | // Longer than original string's length or negative: unsafe arguments. |
| 3519 | __ j(above, &runtime); |
| 3520 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3521 | Counters* counters = masm->isolate()->counters(); |
| 3522 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 3523 | __ ret(3 * kPointerSize); |
| 3524 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3525 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3526 | Label single_char; |
| 3527 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 3528 | __ j(equal, &single_char); |
| 3529 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3530 | // eax: string |
| 3531 | // ebx: instance type |
| 3532 | // ecx: sub string length (smi) |
| 3533 | // edx: from index (smi) |
| 3534 | // Deal with different string types: update the index if necessary |
| 3535 | // and put the underlying string into edi. |
| 3536 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 3537 | // If the string is not indirect, it can only be sequential or external. |
| 3538 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 3539 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 3540 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 3541 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 3542 | |
| 3543 | Factory* factory = masm->isolate()->factory(); |
| 3544 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 3545 | __ j(not_zero, &sliced_string, Label::kNear); |
| 3546 | // Cons string. Check whether it is flat, then fetch first part. |
| 3547 | // Flat cons strings have an empty second part. |
| 3548 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 3549 | factory->empty_string()); |
| 3550 | __ j(not_equal, &runtime); |
| 3551 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 3552 | // Update instance type. |
| 3553 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 3554 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3555 | __ jmp(&underlying_unpacked, Label::kNear); |
| 3556 | |
| 3557 | __ bind(&sliced_string); |
| 3558 | // Sliced string. Fetch parent and adjust start index by offset. |
| 3559 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3560 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3561 | // Update instance type. |
| 3562 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 3563 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3564 | __ jmp(&underlying_unpacked, Label::kNear); |
| 3565 | |
| 3566 | __ bind(&seq_or_external_string); |
| 3567 | // Sequential or external string. Just move string to the expected register. |
| 3568 | __ mov(edi, eax); |
| 3569 | |
| 3570 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3571 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3572 | if (FLAG_string_slices) { |
| 3573 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3574 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3575 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3576 | // edx: adjusted start index (smi) |
| 3577 | // ecx: length (smi) |
| 3578 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 3579 | // Short slice. Copy instead of slicing. |
| 3580 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3581 | // Allocate new sliced string. At this point we do not reload the instance |
| 3582 | // type including the string encoding because we simply rely on the info |
| 3583 | // provided by the original string. It does not matter if the original |
| 3584 | // string's encoding is wrong because we always have to recheck encoding of |
| 3585 | // the newly created string's parent anyways due to externalized strings. |
| 3586 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3587 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3588 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 3589 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3590 | __ j(zero, &two_byte_slice, Label::kNear); |
| 3591 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 3592 | __ jmp(&set_slice_header, Label::kNear); |
| 3593 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3594 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3595 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3596 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3597 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 3598 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3599 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 3600 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3601 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 3602 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3603 | |
| 3604 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3605 | } |
| 3606 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3607 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3608 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3609 | // edx: adjusted start index (smi) |
| 3610 | // ecx: length (smi) |
| 3611 | // The subject string can only be external or sequential string of either |
| 3612 | // encoding at this point. |
| 3613 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 3614 | STATIC_ASSERT(kExternalStringTag != 0); |
| 3615 | STATIC_ASSERT(kSeqStringTag == 0); |
| 3616 | __ test_b(ebx, kExternalStringTag); |
| 3617 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3618 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3619 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3620 | // Rule out short external strings. |
| 3621 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 3622 | __ test_b(ebx, kShortExternalStringMask); |
| 3623 | __ j(not_zero, &runtime); |
| 3624 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 3625 | // 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] | 3626 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3627 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3628 | |
| 3629 | __ bind(&sequential_string); |
| 3630 | // Stash away (adjusted) index and (underlying) string. |
| 3631 | __ push(edx); |
| 3632 | __ push(edi); |
| 3633 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3634 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3635 | __ test_b(ebx, kStringEncodingMask); |
| 3636 | __ j(zero, &two_byte_sequential); |
| 3637 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3638 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3639 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3640 | |
| 3641 | // eax: result string |
| 3642 | // ecx: result string length |
| 3643 | __ mov(edx, esi); // esi used by following code. |
| 3644 | // Locate first character of result. |
| 3645 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3646 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3647 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3648 | __ pop(esi); |
| 3649 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3650 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3651 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3652 | |
| 3653 | // eax: result string |
| 3654 | // ecx: result length |
| 3655 | // edx: original value of esi |
| 3656 | // edi: first character of result |
| 3657 | // esi: character of sub string start |
| 3658 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 3659 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3660 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3661 | __ ret(3 * kPointerSize); |
| 3662 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3663 | __ bind(&two_byte_sequential); |
| 3664 | // Sequential two-byte string. Allocate the result. |
| 3665 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3666 | |
| 3667 | // eax: result string |
| 3668 | // ecx: result string length |
| 3669 | __ mov(edx, esi); // esi used by following code. |
| 3670 | // Locate first character of result. |
| 3671 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3672 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3673 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3674 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3675 | __ pop(esi); |
| 3676 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3677 | // As from is a smi it is 2 times the value which matches the size of a two |
| 3678 | // byte character. |
| 3679 | STATIC_ASSERT(kSmiTag == 0); |
| 3680 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3681 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3682 | |
| 3683 | // eax: result string |
| 3684 | // ecx: result length |
| 3685 | // edx: original value of esi |
| 3686 | // edi: first character of result |
| 3687 | // esi: character of sub string start |
| 3688 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 3689 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3690 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3691 | __ ret(3 * kPointerSize); |
| 3692 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3693 | // Drop pushed values on the stack before tail call. |
| 3694 | __ bind(&runtime_drop_two); |
| 3695 | __ Drop(2); |
| 3696 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3697 | // Just jump to runtime to create the sub string. |
| 3698 | __ bind(&runtime); |
| 3699 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3700 | |
| 3701 | __ bind(&single_char); |
| 3702 | // eax: string |
| 3703 | // ebx: instance type |
| 3704 | // ecx: sub string length (smi) |
| 3705 | // edx: from index (smi) |
| 3706 | StringCharAtGenerator generator( |
| 3707 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 3708 | generator.GenerateFast(masm); |
| 3709 | __ ret(3 * kPointerSize); |
| 3710 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3714 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 3715 | Register left, |
| 3716 | Register right, |
| 3717 | Register scratch1, |
| 3718 | Register scratch2) { |
| 3719 | Register length = scratch1; |
| 3720 | |
| 3721 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3722 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3723 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 3724 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3725 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3726 | __ bind(&strings_not_equal); |
| 3727 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 3728 | __ ret(0); |
| 3729 | |
| 3730 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3731 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3732 | __ bind(&check_zero_length); |
| 3733 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3734 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3735 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3736 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3737 | __ ret(0); |
| 3738 | |
| 3739 | // Compare characters. |
| 3740 | __ bind(&compare_chars); |
| 3741 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3742 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3743 | |
| 3744 | // Characters are equal. |
| 3745 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3746 | __ ret(0); |
| 3747 | } |
| 3748 | |
| 3749 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3750 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 3751 | Register left, |
| 3752 | Register right, |
| 3753 | Register scratch1, |
| 3754 | Register scratch2, |
| 3755 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3756 | Counters* counters = masm->isolate()->counters(); |
| 3757 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3758 | |
| 3759 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3760 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3761 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 3762 | __ mov(scratch3, scratch1); |
| 3763 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 3764 | |
| 3765 | Register length_delta = scratch3; |
| 3766 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3767 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3768 | // 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] | 3769 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3770 | __ bind(&left_shorter); |
| 3771 | |
| 3772 | Register min_length = scratch1; |
| 3773 | |
| 3774 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3775 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3776 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3777 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3778 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3779 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3780 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3781 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3782 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3783 | |
| 3784 | // Compare lengths - strings up to min-length are equal. |
| 3785 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3786 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3787 | Label length_not_equal; |
| 3788 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3789 | |
| 3790 | // Result is EQUAL. |
| 3791 | STATIC_ASSERT(EQUAL == 0); |
| 3792 | STATIC_ASSERT(kSmiTag == 0); |
| 3793 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3794 | __ ret(0); |
| 3795 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3796 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3797 | Label result_less; |
| 3798 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3799 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3800 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3801 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3802 | __ j(above, &result_greater, Label::kNear); |
| 3803 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3804 | |
| 3805 | // Result is LESS. |
| 3806 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 3807 | __ ret(0); |
| 3808 | |
| 3809 | // Result is GREATER. |
| 3810 | __ bind(&result_greater); |
| 3811 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 3812 | __ ret(0); |
| 3813 | } |
| 3814 | |
| 3815 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3816 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 3817 | MacroAssembler* masm, |
| 3818 | Register left, |
| 3819 | Register right, |
| 3820 | Register length, |
| 3821 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3822 | Label* chars_not_equal, |
| 3823 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3824 | // Change index to run from -length to -1 by adding length to string |
| 3825 | // start. This means that loop ends when index reaches zero, which |
| 3826 | // doesn't need an additional compare. |
| 3827 | __ SmiUntag(length); |
| 3828 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3829 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3830 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3831 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3832 | __ neg(length); |
| 3833 | Register index = length; // index = -length; |
| 3834 | |
| 3835 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3836 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3837 | __ bind(&loop); |
| 3838 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 3839 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3840 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3841 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3842 | __ j(not_zero, &loop); |
| 3843 | } |
| 3844 | |
| 3845 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3846 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 3847 | Label runtime; |
| 3848 | |
| 3849 | // Stack frame on entry. |
| 3850 | // esp[0]: return address |
| 3851 | // esp[4]: right string |
| 3852 | // esp[8]: left string |
| 3853 | |
| 3854 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 3855 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 3856 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3857 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3858 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3859 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3860 | STATIC_ASSERT(EQUAL == 0); |
| 3861 | STATIC_ASSERT(kSmiTag == 0); |
| 3862 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3863 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3864 | __ ret(2 * kPointerSize); |
| 3865 | |
| 3866 | __ bind(¬_same); |
| 3867 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3868 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3869 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 3870 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3871 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3872 | // Drop arguments from the stack. |
| 3873 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3874 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3875 | __ push(ecx); |
| 3876 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 3877 | |
| 3878 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 3879 | // tagged as a small integer. |
| 3880 | __ bind(&runtime); |
| 3881 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 3882 | } |
| 3883 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3884 | |
machenbach@chromium.org | c8cbc43 | 2014-01-21 09:01:57 +0000 | [diff] [blame] | 3885 | void ArrayPushStub::Generate(MacroAssembler* masm) { |
| 3886 | int argc = arguments_count(); |
| 3887 | |
| 3888 | if (argc == 0) { |
| 3889 | // Noop, return the length. |
| 3890 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 3891 | __ ret((argc + 1) * kPointerSize); |
| 3892 | return; |
| 3893 | } |
| 3894 | |
| 3895 | Isolate* isolate = masm->isolate(); |
| 3896 | |
| 3897 | if (argc != 1) { |
| 3898 | __ TailCallExternalReference( |
| 3899 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 3900 | return; |
| 3901 | } |
| 3902 | |
| 3903 | Label call_builtin, attempt_to_grow_elements, with_write_barrier; |
| 3904 | |
| 3905 | // Get the elements array of the object. |
| 3906 | __ mov(edi, FieldOperand(edx, JSArray::kElementsOffset)); |
| 3907 | |
| 3908 | if (IsFastSmiOrObjectElementsKind(elements_kind())) { |
| 3909 | // Check that the elements are in fast mode and writable. |
| 3910 | __ cmp(FieldOperand(edi, HeapObject::kMapOffset), |
| 3911 | isolate->factory()->fixed_array_map()); |
| 3912 | __ j(not_equal, &call_builtin); |
| 3913 | } |
| 3914 | |
| 3915 | // Get the array's length into eax and calculate new length. |
| 3916 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 3917 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3918 | STATIC_ASSERT(kSmiTag == 0); |
| 3919 | __ add(eax, Immediate(Smi::FromInt(argc))); |
| 3920 | |
| 3921 | // Get the elements' length into ecx. |
| 3922 | __ mov(ecx, FieldOperand(edi, FixedArray::kLengthOffset)); |
| 3923 | |
| 3924 | // Check if we could survive without allocation. |
| 3925 | __ cmp(eax, ecx); |
| 3926 | |
| 3927 | if (IsFastSmiOrObjectElementsKind(elements_kind())) { |
| 3928 | __ j(greater, &attempt_to_grow_elements); |
| 3929 | |
| 3930 | // Check if value is a smi. |
| 3931 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 3932 | __ JumpIfNotSmi(ecx, &with_write_barrier); |
| 3933 | |
| 3934 | // Store the value. |
| 3935 | __ mov(FieldOperand(edi, eax, times_half_pointer_size, |
| 3936 | FixedArray::kHeaderSize - argc * kPointerSize), |
| 3937 | ecx); |
| 3938 | } else { |
| 3939 | __ j(greater, &call_builtin); |
| 3940 | |
| 3941 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 3942 | __ StoreNumberToDoubleElements( |
| 3943 | ecx, edi, eax, ecx, xmm0, &call_builtin, true, argc * kDoubleSize); |
| 3944 | } |
| 3945 | |
| 3946 | // Save new length. |
| 3947 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 3948 | __ ret((argc + 1) * kPointerSize); |
| 3949 | |
| 3950 | if (IsFastDoubleElementsKind(elements_kind())) { |
| 3951 | __ bind(&call_builtin); |
| 3952 | __ TailCallExternalReference( |
| 3953 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 3954 | return; |
| 3955 | } |
| 3956 | |
| 3957 | __ bind(&with_write_barrier); |
| 3958 | |
| 3959 | if (IsFastSmiElementsKind(elements_kind())) { |
| 3960 | if (FLAG_trace_elements_transitions) __ jmp(&call_builtin); |
| 3961 | |
| 3962 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 3963 | isolate->factory()->heap_number_map()); |
| 3964 | __ j(equal, &call_builtin); |
| 3965 | |
| 3966 | ElementsKind target_kind = IsHoleyElementsKind(elements_kind()) |
| 3967 | ? FAST_HOLEY_ELEMENTS : FAST_ELEMENTS; |
| 3968 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 3969 | __ mov(ebx, FieldOperand(ebx, GlobalObject::kNativeContextOffset)); |
| 3970 | __ mov(ebx, ContextOperand(ebx, Context::JS_ARRAY_MAPS_INDEX)); |
| 3971 | const int header_size = FixedArrayBase::kHeaderSize; |
| 3972 | // Verify that the object can be transitioned in place. |
| 3973 | const int origin_offset = header_size + elements_kind() * kPointerSize; |
| 3974 | __ mov(edi, FieldOperand(ebx, origin_offset)); |
| 3975 | __ cmp(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 3976 | __ j(not_equal, &call_builtin); |
| 3977 | |
| 3978 | const int target_offset = header_size + target_kind * kPointerSize; |
| 3979 | __ mov(ebx, FieldOperand(ebx, target_offset)); |
| 3980 | ElementsTransitionGenerator::GenerateMapChangeElementsTransition( |
| 3981 | masm, DONT_TRACK_ALLOCATION_SITE, NULL); |
| 3982 | // Restore edi used as a scratch register for the write barrier used while |
| 3983 | // setting the map. |
| 3984 | __ mov(edi, FieldOperand(edx, JSArray::kElementsOffset)); |
| 3985 | } |
| 3986 | |
| 3987 | // Save new length. |
| 3988 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 3989 | |
| 3990 | // Store the value. |
| 3991 | __ lea(edx, FieldOperand(edi, eax, times_half_pointer_size, |
| 3992 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 3993 | __ mov(Operand(edx, 0), ecx); |
| 3994 | |
| 3995 | __ RecordWrite(edi, edx, ecx, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
| 3996 | OMIT_SMI_CHECK); |
| 3997 | |
| 3998 | __ ret((argc + 1) * kPointerSize); |
| 3999 | |
| 4000 | __ bind(&attempt_to_grow_elements); |
| 4001 | if (!FLAG_inline_new) { |
| 4002 | __ bind(&call_builtin); |
| 4003 | __ TailCallExternalReference( |
| 4004 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 4005 | return; |
| 4006 | } |
| 4007 | |
| 4008 | __ mov(ebx, Operand(esp, argc * kPointerSize)); |
| 4009 | // Growing elements that are SMI-only requires special handling in case the |
| 4010 | // new element is non-Smi. For now, delegate to the builtin. |
| 4011 | if (IsFastSmiElementsKind(elements_kind())) { |
| 4012 | __ JumpIfNotSmi(ebx, &call_builtin); |
| 4013 | } |
| 4014 | |
| 4015 | // We could be lucky and the elements array could be at the top of new-space. |
| 4016 | // In this case we can just grow it in place by moving the allocation pointer |
| 4017 | // up. |
| 4018 | ExternalReference new_space_allocation_top = |
| 4019 | ExternalReference::new_space_allocation_top_address(isolate); |
| 4020 | ExternalReference new_space_allocation_limit = |
| 4021 | ExternalReference::new_space_allocation_limit_address(isolate); |
| 4022 | |
| 4023 | const int kAllocationDelta = 4; |
| 4024 | ASSERT(kAllocationDelta >= argc); |
| 4025 | // Load top. |
| 4026 | __ mov(ecx, Operand::StaticVariable(new_space_allocation_top)); |
| 4027 | |
| 4028 | // Check if it's the end of elements. |
| 4029 | __ lea(edx, FieldOperand(edi, eax, times_half_pointer_size, |
| 4030 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 4031 | __ cmp(edx, ecx); |
| 4032 | __ j(not_equal, &call_builtin); |
| 4033 | __ add(ecx, Immediate(kAllocationDelta * kPointerSize)); |
| 4034 | __ cmp(ecx, Operand::StaticVariable(new_space_allocation_limit)); |
| 4035 | __ j(above, &call_builtin); |
| 4036 | |
| 4037 | // We fit and could grow elements. |
| 4038 | __ mov(Operand::StaticVariable(new_space_allocation_top), ecx); |
| 4039 | |
| 4040 | // Push the argument... |
| 4041 | __ mov(Operand(edx, 0), ebx); |
| 4042 | // ... and fill the rest with holes. |
| 4043 | for (int i = 1; i < kAllocationDelta; i++) { |
| 4044 | __ mov(Operand(edx, i * kPointerSize), |
| 4045 | isolate->factory()->the_hole_value()); |
| 4046 | } |
| 4047 | |
| 4048 | if (IsFastObjectElementsKind(elements_kind())) { |
| 4049 | // We know the elements array is in new space so we don't need the |
| 4050 | // remembered set, but we just pushed a value onto it so we may have to tell |
| 4051 | // the incremental marker to rescan the object that we just grew. We don't |
| 4052 | // need to worry about the holes because they are in old space and already |
| 4053 | // marked black. |
| 4054 | __ RecordWrite(edi, edx, ebx, kDontSaveFPRegs, OMIT_REMEMBERED_SET); |
| 4055 | } |
| 4056 | |
| 4057 | // Restore receiver to edx as finish sequence assumes it's here. |
| 4058 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 4059 | |
| 4060 | // Increment element's and array's sizes. |
| 4061 | __ add(FieldOperand(edi, FixedArray::kLengthOffset), |
| 4062 | Immediate(Smi::FromInt(kAllocationDelta))); |
| 4063 | |
| 4064 | // NOTE: This only happen in new-space, where we don't care about the |
| 4065 | // black-byte-count on pages. Otherwise we should update that too if the |
| 4066 | // object is black. |
| 4067 | |
| 4068 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 4069 | __ ret((argc + 1) * kPointerSize); |
| 4070 | |
| 4071 | __ bind(&call_builtin); |
| 4072 | __ TailCallExternalReference( |
| 4073 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 4074 | } |
| 4075 | |
| 4076 | |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 4077 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 4078 | // ----------- S t a t e ------------- |
| 4079 | // -- edx : left |
| 4080 | // -- eax : right |
| 4081 | // -- esp[0] : return address |
| 4082 | // ----------------------------------- |
| 4083 | Isolate* isolate = masm->isolate(); |
| 4084 | |
| 4085 | // Load ecx with the allocation site. We stick an undefined dummy value here |
| 4086 | // and replace it with the real allocation site later when we instantiate this |
| 4087 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
| 4088 | __ mov(ecx, handle(isolate->heap()->undefined_value())); |
| 4089 | |
| 4090 | // Make sure that we actually patched the allocation site. |
| 4091 | if (FLAG_debug_code) { |
| 4092 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4093 | __ Assert(not_equal, kExpectedAllocationSite); |
| 4094 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 4095 | isolate->factory()->allocation_site_map()); |
| 4096 | __ Assert(equal, kExpectedAllocationSite); |
| 4097 | } |
| 4098 | |
| 4099 | // Tail call into the stub that handles binary operations with allocation |
| 4100 | // sites. |
| 4101 | BinaryOpWithAllocationSiteStub stub(state_); |
| 4102 | __ TailCallStub(&stub); |
| 4103 | } |
| 4104 | |
| 4105 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4106 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4107 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4108 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4109 | __ mov(ecx, edx); |
| 4110 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4111 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4112 | |
| 4113 | if (GetCondition() == equal) { |
| 4114 | // 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] | 4115 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4116 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4117 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4118 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4119 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4120 | // Correct sign of result in case of overflow. |
| 4121 | __ not_(edx); |
| 4122 | __ bind(&done); |
| 4123 | __ mov(eax, edx); |
| 4124 | } |
| 4125 | __ ret(0); |
| 4126 | |
| 4127 | __ bind(&miss); |
| 4128 | GenerateMiss(masm); |
| 4129 | } |
| 4130 | |
| 4131 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4132 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 4133 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4134 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4135 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4136 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4137 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4138 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4139 | if (left_ == CompareIC::SMI) { |
| 4140 | __ JumpIfNotSmi(edx, &miss); |
| 4141 | } |
| 4142 | if (right_ == CompareIC::SMI) { |
| 4143 | __ JumpIfNotSmi(eax, &miss); |
| 4144 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4145 | |
| 4146 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4147 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4148 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4149 | CpuFeatureScope scope1(masm, SSE2); |
| 4150 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4151 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4152 | // Load left and right operand. |
| 4153 | Label done, left, left_smi, right_smi; |
| 4154 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 4155 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 4156 | masm->isolate()->factory()->heap_number_map()); |
| 4157 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4158 | __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4159 | __ jmp(&left, Label::kNear); |
| 4160 | __ bind(&right_smi); |
| 4161 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 4162 | __ SmiUntag(ecx); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4163 | __ Cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4164 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4165 | __ bind(&left); |
| 4166 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 4167 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4168 | masm->isolate()->factory()->heap_number_map()); |
| 4169 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4170 | __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4171 | __ jmp(&done); |
| 4172 | __ bind(&left_smi); |
| 4173 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 4174 | __ SmiUntag(ecx); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4175 | __ Cvtsi2sd(xmm0, ecx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4176 | |
| 4177 | __ bind(&done); |
| 4178 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4179 | __ ucomisd(xmm0, xmm1); |
| 4180 | |
| 4181 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4182 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4183 | |
| 4184 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4185 | // Performing mov, because xor would destroy the flag register. |
| 4186 | __ mov(eax, 0); // equal |
| 4187 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4188 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4189 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4190 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4191 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4192 | } else { |
| 4193 | __ mov(ecx, edx); |
| 4194 | __ and_(ecx, eax); |
| 4195 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 4196 | |
| 4197 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 4198 | masm->isolate()->factory()->heap_number_map()); |
| 4199 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 4200 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4201 | masm->isolate()->factory()->heap_number_map()); |
| 4202 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4203 | } |
| 4204 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4205 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4206 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4207 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 4208 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4209 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4210 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4211 | __ bind(&maybe_undefined1); |
| 4212 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 4213 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 4214 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4215 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4216 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 4217 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 4218 | __ jmp(&unordered); |
| 4219 | } |
| 4220 | |
| 4221 | __ bind(&maybe_undefined2); |
| 4222 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 4223 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 4224 | __ j(equal, &unordered); |
| 4225 | } |
| 4226 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4227 | __ bind(&miss); |
| 4228 | GenerateMiss(masm); |
| 4229 | } |
| 4230 | |
| 4231 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4232 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 4233 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4234 | ASSERT(GetCondition() == equal); |
| 4235 | |
| 4236 | // Registers containing left and right operands respectively. |
| 4237 | Register left = edx; |
| 4238 | Register right = eax; |
| 4239 | Register tmp1 = ecx; |
| 4240 | Register tmp2 = ebx; |
| 4241 | |
| 4242 | // Check that both operands are heap objects. |
| 4243 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4244 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4245 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4246 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4247 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4248 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4249 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4250 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4251 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4252 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4253 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4254 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 4255 | __ or_(tmp1, tmp2); |
| 4256 | __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 4257 | __ j(not_zero, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4258 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4259 | // Internalized strings are compared by identity. |
| 4260 | Label done; |
| 4261 | __ cmp(left, right); |
| 4262 | // Make sure eax is non-zero. At this point input operands are |
| 4263 | // guaranteed to be non-zero. |
| 4264 | ASSERT(right.is(eax)); |
| 4265 | __ j(not_equal, &done, Label::kNear); |
| 4266 | STATIC_ASSERT(EQUAL == 0); |
| 4267 | STATIC_ASSERT(kSmiTag == 0); |
| 4268 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4269 | __ bind(&done); |
| 4270 | __ ret(0); |
| 4271 | |
| 4272 | __ bind(&miss); |
| 4273 | GenerateMiss(masm); |
| 4274 | } |
| 4275 | |
| 4276 | |
| 4277 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 4278 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 4279 | ASSERT(GetCondition() == equal); |
| 4280 | |
| 4281 | // Registers containing left and right operands respectively. |
| 4282 | Register left = edx; |
| 4283 | Register right = eax; |
| 4284 | Register tmp1 = ecx; |
| 4285 | Register tmp2 = ebx; |
| 4286 | |
| 4287 | // Check that both operands are heap objects. |
| 4288 | Label miss; |
| 4289 | __ mov(tmp1, left); |
| 4290 | STATIC_ASSERT(kSmiTag == 0); |
| 4291 | __ and_(tmp1, right); |
| 4292 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 4293 | |
| 4294 | // Check that both operands are unique names. This leaves the instance |
| 4295 | // types loaded in tmp1 and tmp2. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4296 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4297 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4298 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4299 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 4300 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4301 | __ JumpIfNotUniqueName(tmp1, &miss, Label::kNear); |
| 4302 | __ JumpIfNotUniqueName(tmp2, &miss, Label::kNear); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4303 | |
| 4304 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4305 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4306 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4307 | // Make sure eax is non-zero. At this point input operands are |
| 4308 | // guaranteed to be non-zero. |
| 4309 | ASSERT(right.is(eax)); |
| 4310 | __ j(not_equal, &done, Label::kNear); |
| 4311 | STATIC_ASSERT(EQUAL == 0); |
| 4312 | STATIC_ASSERT(kSmiTag == 0); |
| 4313 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4314 | __ bind(&done); |
| 4315 | __ ret(0); |
| 4316 | |
| 4317 | __ bind(&miss); |
| 4318 | GenerateMiss(masm); |
| 4319 | } |
| 4320 | |
| 4321 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4322 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4323 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4324 | Label miss; |
| 4325 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4326 | bool equality = Token::IsEqualityOp(op_); |
| 4327 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4328 | // Registers containing left and right operands respectively. |
| 4329 | Register left = edx; |
| 4330 | Register right = eax; |
| 4331 | Register tmp1 = ecx; |
| 4332 | Register tmp2 = ebx; |
| 4333 | Register tmp3 = edi; |
| 4334 | |
| 4335 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4336 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4337 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4338 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4339 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4340 | |
| 4341 | // Check that both operands are strings. This leaves the instance |
| 4342 | // types loaded in tmp1 and tmp2. |
| 4343 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4344 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4345 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4346 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 4347 | __ mov(tmp3, tmp1); |
| 4348 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4349 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4350 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 4351 | __ j(not_zero, &miss); |
| 4352 | |
| 4353 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4354 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4355 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4356 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4357 | STATIC_ASSERT(EQUAL == 0); |
| 4358 | STATIC_ASSERT(kSmiTag == 0); |
| 4359 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4360 | __ ret(0); |
| 4361 | |
| 4362 | // Handle not identical strings. |
| 4363 | __ bind(¬_same); |
| 4364 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4365 | // 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] | 4366 | // 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] | 4367 | // non-equality compare, we still need to determine the order. We |
| 4368 | // also know they are both strings. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4369 | if (equality) { |
| 4370 | Label do_compare; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4371 | STATIC_ASSERT(kInternalizedTag == 0); |
| 4372 | __ or_(tmp1, tmp2); |
| 4373 | __ test(tmp1, Immediate(kIsNotInternalizedMask)); |
| 4374 | __ j(not_zero, &do_compare, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4375 | // Make sure eax is non-zero. At this point input operands are |
| 4376 | // guaranteed to be non-zero. |
| 4377 | ASSERT(right.is(eax)); |
| 4378 | __ ret(0); |
| 4379 | __ bind(&do_compare); |
| 4380 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4381 | |
| 4382 | // Check that both strings are sequential ASCII. |
| 4383 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4384 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 4385 | |
| 4386 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4387 | if (equality) { |
| 4388 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 4389 | masm, left, right, tmp1, tmp2); |
| 4390 | } else { |
| 4391 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 4392 | masm, left, right, tmp1, tmp2, tmp3); |
| 4393 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4394 | |
| 4395 | // Handle more complex cases in runtime. |
| 4396 | __ bind(&runtime); |
| 4397 | __ pop(tmp1); // Return address. |
| 4398 | __ push(left); |
| 4399 | __ push(right); |
| 4400 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4401 | if (equality) { |
| 4402 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 4403 | } else { |
| 4404 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 4405 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4406 | |
| 4407 | __ bind(&miss); |
| 4408 | GenerateMiss(masm); |
| 4409 | } |
| 4410 | |
| 4411 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4412 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4413 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4414 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4415 | __ mov(ecx, edx); |
| 4416 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4417 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4418 | |
| 4419 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4420 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4421 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4422 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4423 | |
| 4424 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4425 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4426 | __ ret(0); |
| 4427 | |
| 4428 | __ bind(&miss); |
| 4429 | GenerateMiss(masm); |
| 4430 | } |
| 4431 | |
| 4432 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4433 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 4434 | Label miss; |
| 4435 | __ mov(ecx, edx); |
| 4436 | __ and_(ecx, eax); |
| 4437 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4438 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4439 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4440 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 4441 | __ cmp(ecx, known_map_); |
| 4442 | __ j(not_equal, &miss, Label::kNear); |
| 4443 | __ cmp(ebx, known_map_); |
| 4444 | __ j(not_equal, &miss, Label::kNear); |
| 4445 | |
| 4446 | __ sub(eax, edx); |
| 4447 | __ ret(0); |
| 4448 | |
| 4449 | __ bind(&miss); |
| 4450 | GenerateMiss(masm); |
| 4451 | } |
| 4452 | |
| 4453 | |
| 4454 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4455 | { |
| 4456 | // Call the runtime system in a fresh internal frame. |
| 4457 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 4458 | masm->isolate()); |
| 4459 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4460 | __ push(edx); // Preserve edx and eax. |
| 4461 | __ push(eax); |
| 4462 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4463 | __ push(eax); |
| 4464 | __ push(Immediate(Smi::FromInt(op_))); |
| 4465 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4466 | // Compute the entry point of the rewritten stub. |
| 4467 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 4468 | __ pop(eax); |
| 4469 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4470 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4471 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4472 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4473 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4474 | } |
| 4475 | |
| 4476 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4477 | // Helper function used to check that the dictionary doesn't contain |
| 4478 | // the property. This function may return false negatives, so miss_label |
| 4479 | // must always call a backup property check that is complete. |
| 4480 | // 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] | 4481 | // Name must be a unique name and receiver must be a heap object. |
| 4482 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 4483 | Label* miss, |
| 4484 | Label* done, |
| 4485 | Register properties, |
| 4486 | Handle<Name> name, |
| 4487 | Register r0) { |
| 4488 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4489 | |
| 4490 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 4491 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 4492 | // undefined value), it guarantees the hash table doesn't contain the |
| 4493 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4494 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4495 | for (int i = 0; i < kInlinedProbes; i++) { |
| 4496 | // Compute the masked index: (hash + i + i * i) & mask. |
| 4497 | Register index = r0; |
| 4498 | // Capacity is smi 2^n. |
| 4499 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 4500 | __ dec(index); |
| 4501 | __ and_(index, |
| 4502 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4503 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4504 | |
| 4505 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4506 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4507 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 4508 | Register entity_name = r0; |
| 4509 | // Having undefined at this place means the name is not contained. |
| 4510 | ASSERT_EQ(kSmiTagSize, 1); |
| 4511 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 4512 | kElementsStartOffset - kHeapObjectTag)); |
| 4513 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 4514 | __ j(equal, done); |
| 4515 | |
| 4516 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4517 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4518 | __ j(equal, miss); |
| 4519 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4520 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4521 | // Check for the hole and skip. |
| 4522 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4523 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4524 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4525 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4526 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4527 | __ JumpIfNotUniqueName(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 4528 | miss); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4529 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4530 | } |
| 4531 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4532 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4533 | __ push(Immediate(Handle<Object>(name))); |
| 4534 | __ push(Immediate(name->Hash())); |
| 4535 | __ CallStub(&stub); |
| 4536 | __ test(r0, r0); |
| 4537 | __ j(not_zero, miss); |
| 4538 | __ jmp(done); |
| 4539 | } |
| 4540 | |
| 4541 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4542 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4543 | // |done| label if a property with the given name is found leaving the |
| 4544 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 4545 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4546 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 4547 | Label* miss, |
| 4548 | Label* done, |
| 4549 | Register elements, |
| 4550 | Register name, |
| 4551 | Register r0, |
| 4552 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 4553 | ASSERT(!elements.is(r0)); |
| 4554 | ASSERT(!elements.is(r1)); |
| 4555 | ASSERT(!name.is(r0)); |
| 4556 | ASSERT(!name.is(r1)); |
| 4557 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4558 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4559 | |
| 4560 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 4561 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 4562 | __ dec(r1); |
| 4563 | |
| 4564 | // Generate an unrolled loop that performs a few probes before |
| 4565 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 4566 | // cover ~93% of loads from dictionaries. |
| 4567 | for (int i = 0; i < kInlinedProbes; i++) { |
| 4568 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4569 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 4570 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4571 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4572 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4573 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4574 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4575 | |
| 4576 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4577 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4578 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 4579 | |
| 4580 | // Check if the key is identical to the name. |
| 4581 | __ cmp(name, Operand(elements, |
| 4582 | r0, |
| 4583 | times_4, |
| 4584 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4585 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4586 | } |
| 4587 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4588 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4589 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4590 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 4591 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4592 | __ push(r0); |
| 4593 | __ CallStub(&stub); |
| 4594 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4595 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4596 | __ j(zero, miss); |
| 4597 | __ jmp(done); |
| 4598 | } |
| 4599 | |
| 4600 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4601 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4602 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 4603 | // 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] | 4604 | // Stack frame on entry: |
| 4605 | // esp[0 * kPointerSize]: return address. |
| 4606 | // esp[1 * kPointerSize]: key's hash. |
| 4607 | // esp[2 * kPointerSize]: key. |
| 4608 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4609 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4610 | // result_: used as scratch. |
| 4611 | // index_: will hold an index of entry if lookup is successful. |
| 4612 | // might alias with result_. |
| 4613 | // Returns: |
| 4614 | // result_ is zero if lookup failed, non zero otherwise. |
| 4615 | |
| 4616 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 4617 | |
| 4618 | Register scratch = result_; |
| 4619 | |
| 4620 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 4621 | __ dec(scratch); |
| 4622 | __ SmiUntag(scratch); |
| 4623 | __ push(scratch); |
| 4624 | |
| 4625 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 4626 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 4627 | // undefined value), it guarantees the hash table doesn't contain the |
| 4628 | // property. It's true even if some slots represent deleted properties |
| 4629 | // (their names are the null value). |
| 4630 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 4631 | // Compute the masked index: (hash + i + i * i) & mask. |
| 4632 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 4633 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4634 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4635 | } |
| 4636 | __ and_(scratch, Operand(esp, 0)); |
| 4637 | |
| 4638 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4639 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4640 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 4641 | |
| 4642 | // Having undefined at this place means the name is not contained. |
| 4643 | ASSERT_EQ(kSmiTagSize, 1); |
| 4644 | __ mov(scratch, Operand(dictionary_, |
| 4645 | index_, |
| 4646 | times_pointer_size, |
| 4647 | kElementsStartOffset - kHeapObjectTag)); |
| 4648 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 4649 | __ j(equal, ¬_in_dictionary); |
| 4650 | |
| 4651 | // Stop if found the property. |
| 4652 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 4653 | __ j(equal, &in_dictionary); |
| 4654 | |
| 4655 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4656 | // 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] | 4657 | // 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] | 4658 | // key we are looking for. |
| 4659 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4660 | // Check if the entry name is not a unique name. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4661 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4662 | __ JumpIfNotUniqueName(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 4663 | &maybe_in_dictionary); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4664 | } |
| 4665 | } |
| 4666 | |
| 4667 | __ bind(&maybe_in_dictionary); |
| 4668 | // If we are doing negative lookup then probing failure should be |
| 4669 | // treated as a lookup success. For positive lookup probing failure |
| 4670 | // should be treated as lookup failure. |
| 4671 | if (mode_ == POSITIVE_LOOKUP) { |
| 4672 | __ mov(result_, Immediate(0)); |
| 4673 | __ Drop(1); |
| 4674 | __ ret(2 * kPointerSize); |
| 4675 | } |
| 4676 | |
| 4677 | __ bind(&in_dictionary); |
| 4678 | __ mov(result_, Immediate(1)); |
| 4679 | __ Drop(1); |
| 4680 | __ ret(2 * kPointerSize); |
| 4681 | |
| 4682 | __ bind(¬_in_dictionary); |
| 4683 | __ mov(result_, Immediate(0)); |
| 4684 | __ Drop(1); |
| 4685 | __ ret(2 * kPointerSize); |
| 4686 | } |
| 4687 | |
| 4688 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4689 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 4690 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4691 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 4692 | stub.GetCode(isolate); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4693 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4694 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 4695 | stub2.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4696 | } |
| 4697 | } |
| 4698 | |
| 4699 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4700 | bool CodeStub::CanUseFPRegisters() { |
| 4701 | return CpuFeatures::IsSupported(SSE2); |
| 4702 | } |
| 4703 | |
| 4704 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4705 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 4706 | // the value has just been written into the object, now this stub makes sure |
| 4707 | // we keep the GC informed. The word in the object where the value has been |
| 4708 | // written is in the address register. |
| 4709 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 4710 | Label skip_to_incremental_noncompacting; |
| 4711 | Label skip_to_incremental_compacting; |
| 4712 | |
| 4713 | // The first two instructions are generated with labels so as to get the |
| 4714 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 4715 | // forth between a compare instructions (a nop in this position) and the |
| 4716 | // real branch when we start and stop incremental heap marking. |
| 4717 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 4718 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 4719 | |
| 4720 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 4721 | __ RememberedSetHelper(object_, |
| 4722 | address_, |
| 4723 | value_, |
| 4724 | save_fp_regs_mode_, |
| 4725 | MacroAssembler::kReturnAtEnd); |
| 4726 | } else { |
| 4727 | __ ret(0); |
| 4728 | } |
| 4729 | |
| 4730 | __ bind(&skip_to_incremental_noncompacting); |
| 4731 | GenerateIncremental(masm, INCREMENTAL); |
| 4732 | |
| 4733 | __ bind(&skip_to_incremental_compacting); |
| 4734 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 4735 | |
| 4736 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 4737 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 4738 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 4739 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 4740 | } |
| 4741 | |
| 4742 | |
| 4743 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 4744 | regs_.Save(masm); |
| 4745 | |
| 4746 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 4747 | Label dont_need_remembered_set; |
| 4748 | |
| 4749 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 4750 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 4751 | regs_.scratch0(), |
| 4752 | &dont_need_remembered_set); |
| 4753 | |
| 4754 | __ CheckPageFlag(regs_.object(), |
| 4755 | regs_.scratch0(), |
| 4756 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 4757 | not_zero, |
| 4758 | &dont_need_remembered_set); |
| 4759 | |
| 4760 | // First notify the incremental marker if necessary, then update the |
| 4761 | // remembered set. |
| 4762 | CheckNeedsToInformIncrementalMarker( |
| 4763 | masm, |
| 4764 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 4765 | mode); |
| 4766 | InformIncrementalMarker(masm, mode); |
| 4767 | regs_.Restore(masm); |
| 4768 | __ RememberedSetHelper(object_, |
| 4769 | address_, |
| 4770 | value_, |
| 4771 | save_fp_regs_mode_, |
| 4772 | MacroAssembler::kReturnAtEnd); |
| 4773 | |
| 4774 | __ bind(&dont_need_remembered_set); |
| 4775 | } |
| 4776 | |
| 4777 | CheckNeedsToInformIncrementalMarker( |
| 4778 | masm, |
| 4779 | kReturnOnNoNeedToInformIncrementalMarker, |
| 4780 | mode); |
| 4781 | InformIncrementalMarker(masm, mode); |
| 4782 | regs_.Restore(masm); |
| 4783 | __ ret(0); |
| 4784 | } |
| 4785 | |
| 4786 | |
| 4787 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 4788 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 4789 | int argument_count = 3; |
| 4790 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 4791 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 4792 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4793 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4794 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4795 | |
| 4796 | AllowExternalCallThatCantCauseGC scope(masm); |
| 4797 | if (mode == INCREMENTAL_COMPACTION) { |
| 4798 | __ CallCFunction( |
| 4799 | ExternalReference::incremental_evacuation_record_write_function( |
| 4800 | masm->isolate()), |
| 4801 | argument_count); |
| 4802 | } else { |
| 4803 | ASSERT(mode == INCREMENTAL); |
| 4804 | __ CallCFunction( |
| 4805 | ExternalReference::incremental_marking_record_write_function( |
| 4806 | masm->isolate()), |
| 4807 | argument_count); |
| 4808 | } |
| 4809 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 4810 | } |
| 4811 | |
| 4812 | |
| 4813 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 4814 | MacroAssembler* masm, |
| 4815 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 4816 | Mode mode) { |
| 4817 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 4818 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4819 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 4820 | __ and_(regs_.scratch0(), regs_.object()); |
| 4821 | __ mov(regs_.scratch1(), |
| 4822 | Operand(regs_.scratch0(), |
| 4823 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 4824 | __ sub(regs_.scratch1(), Immediate(1)); |
| 4825 | __ mov(Operand(regs_.scratch0(), |
| 4826 | MemoryChunk::kWriteBarrierCounterOffset), |
| 4827 | regs_.scratch1()); |
| 4828 | __ j(negative, &need_incremental); |
| 4829 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4830 | // Let's look at the color of the object: If it is not black we don't have |
| 4831 | // to inform the incremental marker. |
| 4832 | __ JumpIfBlack(regs_.object(), |
| 4833 | regs_.scratch0(), |
| 4834 | regs_.scratch1(), |
| 4835 | &object_is_black, |
| 4836 | Label::kNear); |
| 4837 | |
| 4838 | regs_.Restore(masm); |
| 4839 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 4840 | __ RememberedSetHelper(object_, |
| 4841 | address_, |
| 4842 | value_, |
| 4843 | save_fp_regs_mode_, |
| 4844 | MacroAssembler::kReturnAtEnd); |
| 4845 | } else { |
| 4846 | __ ret(0); |
| 4847 | } |
| 4848 | |
| 4849 | __ bind(&object_is_black); |
| 4850 | |
| 4851 | // Get the value from the slot. |
| 4852 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 4853 | |
| 4854 | if (mode == INCREMENTAL_COMPACTION) { |
| 4855 | Label ensure_not_white; |
| 4856 | |
| 4857 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 4858 | regs_.scratch1(), // Scratch. |
| 4859 | MemoryChunk::kEvacuationCandidateMask, |
| 4860 | zero, |
| 4861 | &ensure_not_white, |
| 4862 | Label::kNear); |
| 4863 | |
| 4864 | __ CheckPageFlag(regs_.object(), |
| 4865 | regs_.scratch1(), // Scratch. |
| 4866 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 4867 | not_zero, |
| 4868 | &ensure_not_white, |
| 4869 | Label::kNear); |
| 4870 | |
| 4871 | __ jmp(&need_incremental); |
| 4872 | |
| 4873 | __ bind(&ensure_not_white); |
| 4874 | } |
| 4875 | |
| 4876 | // We need an extra register for this, so we push the object register |
| 4877 | // temporarily. |
| 4878 | __ push(regs_.object()); |
| 4879 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 4880 | regs_.scratch1(), // Scratch. |
| 4881 | regs_.object(), // Scratch. |
| 4882 | &need_incremental_pop_object, |
| 4883 | Label::kNear); |
| 4884 | __ pop(regs_.object()); |
| 4885 | |
| 4886 | regs_.Restore(masm); |
| 4887 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 4888 | __ RememberedSetHelper(object_, |
| 4889 | address_, |
| 4890 | value_, |
| 4891 | save_fp_regs_mode_, |
| 4892 | MacroAssembler::kReturnAtEnd); |
| 4893 | } else { |
| 4894 | __ ret(0); |
| 4895 | } |
| 4896 | |
| 4897 | __ bind(&need_incremental_pop_object); |
| 4898 | __ pop(regs_.object()); |
| 4899 | |
| 4900 | __ bind(&need_incremental); |
| 4901 | |
| 4902 | // Fall through when we need to inform the incremental marker. |
| 4903 | } |
| 4904 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4905 | |
| 4906 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 4907 | // ----------- S t a t e ------------- |
| 4908 | // -- eax : element value to store |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4909 | // -- ecx : element index as smi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4910 | // -- esp[0] : return address |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 4911 | // -- esp[4] : array literal index in function |
| 4912 | // -- esp[8] : array literal |
| 4913 | // clobbers ebx, edx, edi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4914 | // ----------------------------------- |
| 4915 | |
| 4916 | Label element_done; |
| 4917 | Label double_elements; |
| 4918 | Label smi_element; |
| 4919 | Label slow_elements; |
| 4920 | Label slow_elements_from_double; |
| 4921 | Label fast_elements; |
| 4922 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 4923 | // Get array literal index, array literal and its map. |
| 4924 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 4925 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 4926 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 4927 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4928 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4929 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4930 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4931 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4932 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4933 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4934 | // Store into the array literal requires a elements transition. Call into |
| 4935 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4936 | |
| 4937 | __ bind(&slow_elements); |
| 4938 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 4939 | // call. |
| 4940 | __ push(ebx); |
| 4941 | __ push(ecx); |
| 4942 | __ push(eax); |
| 4943 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4944 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 4945 | __ push(edx); |
| 4946 | __ push(edi); // Return return address so that tail call returns to right |
| 4947 | // place. |
| 4948 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 4949 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4950 | __ bind(&slow_elements_from_double); |
| 4951 | __ pop(edx); |
| 4952 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4953 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4954 | // 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] | 4955 | __ bind(&fast_elements); |
| 4956 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 4957 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 4958 | FixedArrayBase::kHeaderSize)); |
| 4959 | __ mov(Operand(ecx, 0), eax); |
| 4960 | // Update the write barrier for the array store. |
| 4961 | __ RecordWrite(ebx, ecx, eax, |
| 4962 | kDontSaveFPRegs, |
| 4963 | EMIT_REMEMBERED_SET, |
| 4964 | OMIT_SMI_CHECK); |
| 4965 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4966 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4967 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 4968 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4969 | __ bind(&smi_element); |
| 4970 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 4971 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 4972 | FixedArrayBase::kHeaderSize), eax); |
| 4973 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4974 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4975 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4976 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4977 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4978 | __ push(edx); |
| 4979 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 4980 | __ StoreNumberToDoubleElements(eax, |
| 4981 | edx, |
| 4982 | ecx, |
| 4983 | edi, |
| 4984 | xmm0, |
| 4985 | &slow_elements_from_double, |
| 4986 | false); |
| 4987 | __ pop(edx); |
| 4988 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4989 | } |
| 4990 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4991 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 4992 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4993 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4994 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 4995 | int parameter_count_offset = |
| 4996 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 4997 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 4998 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 4999 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5000 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 5001 | ? kPointerSize |
| 5002 | : 0; |
| 5003 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 5004 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5008 | void StubFailureTailCallTrampolineStub::Generate(MacroAssembler* masm) { |
| 5009 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
| 5010 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
| 5011 | __ mov(edi, eax); |
| 5012 | int parameter_count_offset = |
| 5013 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 5014 | __ mov(eax, MemOperand(ebp, parameter_count_offset)); |
| 5015 | // The parameter count above includes the receiver for the arguments passed to |
| 5016 | // the deoptimization handler. Subtract the receiver for the parameter count |
| 5017 | // for the call. |
| 5018 | __ sub(eax, Immediate(1)); |
| 5019 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 5020 | ParameterCount argument_count(eax); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 5021 | __ InvokeFunction(edi, argument_count, JUMP_FUNCTION, NullCallWrapper()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5022 | } |
| 5023 | |
| 5024 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5025 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5026 | if (masm->isolate()->function_entry_hook() != NULL) { |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5027 | ProfileEntryHookStub stub; |
| 5028 | masm->CallStub(&stub); |
| 5029 | } |
| 5030 | } |
| 5031 | |
| 5032 | |
| 5033 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5034 | // Save volatile registers. |
| 5035 | const int kNumSavedRegisters = 3; |
| 5036 | __ push(eax); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5037 | __ push(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5038 | __ push(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5039 | |
| 5040 | // Calculate and push the original stack pointer. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 5041 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5042 | __ push(eax); |
| 5043 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 5044 | // Retrieve our return address and use it to calculate the calling |
| 5045 | // function's address. |
| 5046 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5047 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 5048 | __ push(eax); |
| 5049 | |
| 5050 | // Call the entry hook. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5051 | ASSERT(masm->isolate()->function_entry_hook() != NULL); |
| 5052 | __ call(FUNCTION_ADDR(masm->isolate()->function_entry_hook()), |
| 5053 | RelocInfo::RUNTIME_ENTRY); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5054 | __ add(esp, Immediate(2 * kPointerSize)); |
| 5055 | |
| 5056 | // Restore ecx. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5057 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5058 | __ pop(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5059 | __ pop(eax); |
| 5060 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5061 | __ ret(0); |
| 5062 | } |
| 5063 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5064 | |
| 5065 | template<class T> |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5066 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 5067 | AllocationSiteOverrideMode mode) { |
| 5068 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 5069 | T stub(GetInitialFastElementsKind(), |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5070 | mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5071 | __ TailCallStub(&stub); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5072 | } else if (mode == DONT_OVERRIDE) { |
| 5073 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 5074 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5075 | for (int i = 0; i <= last_index; ++i) { |
| 5076 | Label next; |
| 5077 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 5078 | __ cmp(edx, kind); |
| 5079 | __ j(not_equal, &next); |
| 5080 | T stub(kind); |
| 5081 | __ TailCallStub(&stub); |
| 5082 | __ bind(&next); |
| 5083 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5084 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5085 | // If we reached this point there is a problem. |
| 5086 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 5087 | } else { |
| 5088 | UNREACHABLE(); |
| 5089 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5090 | } |
| 5091 | |
| 5092 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5093 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 5094 | AllocationSiteOverrideMode mode) { |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5095 | // ebx - allocation site (if mode != DISABLE_ALLOCATION_SITES) |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5096 | // edx - kind (if mode != DISABLE_ALLOCATION_SITES) |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5097 | // eax - number of arguments |
| 5098 | // edi - constructor? |
| 5099 | // esp[0] - return address |
| 5100 | // esp[4] - last argument |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5101 | Label normal_sequence; |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5102 | if (mode == DONT_OVERRIDE) { |
| 5103 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 5104 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 5105 | ASSERT(FAST_ELEMENTS == 2); |
| 5106 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 5107 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 5108 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 5109 | |
| 5110 | // is the low bit set? If so, we are holey and that is good. |
| 5111 | __ test_b(edx, 1); |
| 5112 | __ j(not_zero, &normal_sequence); |
| 5113 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5114 | |
| 5115 | // look at the first argument |
| 5116 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 5117 | __ test(ecx, ecx); |
| 5118 | __ j(zero, &normal_sequence); |
| 5119 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5120 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 5121 | ElementsKind initial = GetInitialFastElementsKind(); |
| 5122 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5123 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5124 | ArraySingleArgumentConstructorStub stub_holey(holey_initial, |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5125 | DISABLE_ALLOCATION_SITES); |
| 5126 | __ TailCallStub(&stub_holey); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5127 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5128 | __ bind(&normal_sequence); |
| 5129 | ArraySingleArgumentConstructorStub stub(initial, |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5130 | DISABLE_ALLOCATION_SITES); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5131 | __ TailCallStub(&stub); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5132 | } else if (mode == DONT_OVERRIDE) { |
| 5133 | // We are going to create a holey array, but our kind is non-holey. |
| 5134 | // Fix kind and retry. |
| 5135 | __ inc(edx); |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5136 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5137 | if (FLAG_debug_code) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5138 | Handle<Map> allocation_site_map = |
| 5139 | masm->isolate()->factory()->allocation_site_map(); |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5140 | __ cmp(FieldOperand(ebx, 0), Immediate(allocation_site_map)); |
| 5141 | __ Assert(equal, kExpectedAllocationSite); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5142 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5143 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5144 | // Save the resulting elements kind in type info. We can't just store r3 |
| 5145 | // in the AllocationSite::transition_info field because elements kind is |
| 5146 | // restricted to a portion of the field...upper bits need to be left alone. |
| 5147 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5148 | __ add(FieldOperand(ebx, AllocationSite::kTransitionInfoOffset), |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5149 | Immediate(Smi::FromInt(kFastElementsKindPackedToHoley))); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5150 | |
| 5151 | __ bind(&normal_sequence); |
| 5152 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 5153 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5154 | for (int i = 0; i <= last_index; ++i) { |
| 5155 | Label next; |
| 5156 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 5157 | __ cmp(edx, kind); |
| 5158 | __ j(not_equal, &next); |
| 5159 | ArraySingleArgumentConstructorStub stub(kind); |
| 5160 | __ TailCallStub(&stub); |
| 5161 | __ bind(&next); |
| 5162 | } |
| 5163 | |
| 5164 | // If we reached this point there is a problem. |
| 5165 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 5166 | } else { |
| 5167 | UNREACHABLE(); |
| 5168 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5169 | } |
| 5170 | |
| 5171 | |
| 5172 | template<class T> |
| 5173 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 5174 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 5175 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5176 | for (int i = 0; i <= to_index; ++i) { |
| 5177 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5178 | T stub(kind); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5179 | stub.GetCode(isolate); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 5180 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 5181 | T stub1(kind, DISABLE_ALLOCATION_SITES); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5182 | stub1.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5183 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5184 | } |
| 5185 | } |
| 5186 | |
| 5187 | |
| 5188 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 5189 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 5190 | isolate); |
| 5191 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 5192 | isolate); |
| 5193 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 5194 | isolate); |
| 5195 | } |
| 5196 | |
| 5197 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5198 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 5199 | Isolate* isolate) { |
| 5200 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 5201 | for (int i = 0; i < 2; i++) { |
| 5202 | // For internal arrays we only need a few things |
| 5203 | InternalArrayNoArgumentConstructorStub stubh1(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5204 | stubh1.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5205 | InternalArraySingleArgumentConstructorStub stubh2(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5206 | stubh2.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5207 | InternalArrayNArgumentsConstructorStub stubh3(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5208 | stubh3.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5209 | } |
| 5210 | } |
| 5211 | |
| 5212 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5213 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 5214 | MacroAssembler* masm, |
| 5215 | AllocationSiteOverrideMode mode) { |
| 5216 | if (argument_count_ == ANY) { |
| 5217 | Label not_zero_case, not_one_case; |
| 5218 | __ test(eax, eax); |
| 5219 | __ j(not_zero, ¬_zero_case); |
| 5220 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 5221 | |
| 5222 | __ bind(¬_zero_case); |
| 5223 | __ cmp(eax, 1); |
| 5224 | __ j(greater, ¬_one_case); |
| 5225 | CreateArrayDispatchOneArgument(masm, mode); |
| 5226 | |
| 5227 | __ bind(¬_one_case); |
| 5228 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 5229 | } else if (argument_count_ == NONE) { |
| 5230 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 5231 | } else if (argument_count_ == ONE) { |
| 5232 | CreateArrayDispatchOneArgument(masm, mode); |
| 5233 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 5234 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 5235 | } else { |
| 5236 | UNREACHABLE(); |
| 5237 | } |
| 5238 | } |
| 5239 | |
| 5240 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5241 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 5242 | // ----------- S t a t e ------------- |
| 5243 | // -- eax : argc (only if argument_count_ == ANY) |
| 5244 | // -- ebx : type info cell |
| 5245 | // -- edi : constructor |
| 5246 | // -- esp[0] : return address |
| 5247 | // -- esp[4] : last argument |
| 5248 | // ----------------------------------- |
| 5249 | Handle<Object> undefined_sentinel( |
| 5250 | masm->isolate()->heap()->undefined_value(), |
| 5251 | masm->isolate()); |
| 5252 | |
| 5253 | if (FLAG_debug_code) { |
| 5254 | // The array construct code is only set for the global and natives |
| 5255 | // builtin Array functions which always have maps. |
| 5256 | |
| 5257 | // Initial map for the builtin Array function should be a map. |
| 5258 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5259 | // Will both indicate a NULL and a Smi. |
| 5260 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5261 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5262 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5263 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5264 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5265 | // We should either have undefined in ebx or a valid cell |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5266 | Label okay_here; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5267 | Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5268 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 5269 | __ j(equal, &okay_here); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5270 | __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5271 | __ Assert(equal, kExpectedPropertyCellInRegisterEbx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5272 | __ bind(&okay_here); |
| 5273 | } |
| 5274 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5275 | Label no_info; |
| 5276 | // If the type cell is undefined, or contains anything other than an |
| 5277 | // AllocationSite, call an array constructor that doesn't use AllocationSites. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5278 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 5279 | __ j(equal, &no_info); |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5280 | __ mov(ebx, FieldOperand(ebx, Cell::kValueOffset)); |
| 5281 | __ cmp(FieldOperand(ebx, 0), Immediate( |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5282 | masm->isolate()->factory()->allocation_site_map())); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 5283 | __ j(not_equal, &no_info); |
| 5284 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5285 | // Only look at the lower 16 bits of the transition info. |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5286 | __ mov(edx, FieldOperand(ebx, AllocationSite::kTransitionInfoOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5287 | __ SmiUntag(edx); |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5288 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 5289 | __ and_(edx, Immediate(AllocationSite::ElementsKindBits::kMask)); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5290 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 5291 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5292 | __ bind(&no_info); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5293 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5294 | } |
| 5295 | |
| 5296 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5297 | void InternalArrayConstructorStub::GenerateCase( |
| 5298 | MacroAssembler* masm, ElementsKind kind) { |
| 5299 | Label not_zero_case, not_one_case; |
| 5300 | Label normal_sequence; |
| 5301 | |
| 5302 | __ test(eax, eax); |
| 5303 | __ j(not_zero, ¬_zero_case); |
| 5304 | InternalArrayNoArgumentConstructorStub stub0(kind); |
| 5305 | __ TailCallStub(&stub0); |
| 5306 | |
| 5307 | __ bind(¬_zero_case); |
| 5308 | __ cmp(eax, 1); |
| 5309 | __ j(greater, ¬_one_case); |
| 5310 | |
| 5311 | if (IsFastPackedElementsKind(kind)) { |
| 5312 | // We might need to create a holey array |
| 5313 | // look at the first argument |
| 5314 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 5315 | __ test(ecx, ecx); |
| 5316 | __ j(zero, &normal_sequence); |
| 5317 | |
| 5318 | InternalArraySingleArgumentConstructorStub |
| 5319 | stub1_holey(GetHoleyElementsKind(kind)); |
| 5320 | __ TailCallStub(&stub1_holey); |
| 5321 | } |
| 5322 | |
| 5323 | __ bind(&normal_sequence); |
| 5324 | InternalArraySingleArgumentConstructorStub stub1(kind); |
| 5325 | __ TailCallStub(&stub1); |
| 5326 | |
| 5327 | __ bind(¬_one_case); |
| 5328 | InternalArrayNArgumentsConstructorStub stubN(kind); |
| 5329 | __ TailCallStub(&stubN); |
| 5330 | } |
| 5331 | |
| 5332 | |
| 5333 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 5334 | // ----------- S t a t e ------------- |
| 5335 | // -- eax : argc |
| 5336 | // -- ebx : type info cell |
| 5337 | // -- edi : constructor |
| 5338 | // -- esp[0] : return address |
| 5339 | // -- esp[4] : last argument |
| 5340 | // ----------------------------------- |
| 5341 | |
| 5342 | if (FLAG_debug_code) { |
| 5343 | // The array construct code is only set for the global and natives |
| 5344 | // builtin Array functions which always have maps. |
| 5345 | |
| 5346 | // Initial map for the builtin Array function should be a map. |
| 5347 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5348 | // Will both indicate a NULL and a Smi. |
| 5349 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5350 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5351 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5352 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5353 | } |
| 5354 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5355 | // Figure out the right elements kind |
| 5356 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5357 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5358 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 5359 | // but the following masking takes care of that anyway. |
| 5360 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 5361 | // Retrieve elements_kind from bit field 2. |
| 5362 | __ and_(ecx, Map::kElementsKindMask); |
| 5363 | __ shr(ecx, Map::kElementsKindShift); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5364 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5365 | if (FLAG_debug_code) { |
| 5366 | Label done; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5367 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5368 | __ j(equal, &done); |
| 5369 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 5370 | __ Assert(equal, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5371 | kInvalidElementsKindForInternalArrayOrInternalPackedArray); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5372 | __ bind(&done); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5373 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5374 | |
| 5375 | Label fast_elements_case; |
| 5376 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 5377 | __ j(equal, &fast_elements_case); |
| 5378 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 5379 | |
| 5380 | __ bind(&fast_elements_case); |
| 5381 | GenerateCase(masm, FAST_ELEMENTS); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5382 | } |
| 5383 | |
| 5384 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5385 | #undef __ |
| 5386 | |
| 5387 | } } // namespace v8::internal |
| 5388 | |
| 5389 | #endif // V8_TARGET_ARCH_IA32 |