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 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 468 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 469 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 470 | // store the registers in any particular way, but we do have to store and |
| 471 | // restore them. |
| 472 | __ pushad(); |
| 473 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 474 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 475 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 476 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 477 | XMMRegister reg = XMMRegister::from_code(i); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 478 | __ movsd(Operand(esp, i * kDoubleSize), reg); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 479 | } |
| 480 | } |
| 481 | const int argument_count = 1; |
| 482 | |
| 483 | AllowExternalCallThatCantCauseGC scope(masm); |
| 484 | __ PrepareCallCFunction(argument_count, ecx); |
| 485 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 486 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 487 | __ CallCFunction( |
| 488 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 489 | argument_count); |
| 490 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 491 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 492 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 493 | XMMRegister reg = XMMRegister::from_code(i); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 494 | __ movsd(reg, Operand(esp, i * kDoubleSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 495 | } |
| 496 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 497 | } |
| 498 | __ popad(); |
| 499 | __ ret(0); |
| 500 | } |
| 501 | |
| 502 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 503 | class FloatingPointHelper : public AllStatic { |
| 504 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 505 | enum ArgLocation { |
| 506 | ARGS_ON_STACK, |
| 507 | ARGS_IN_REGISTERS |
| 508 | }; |
| 509 | |
| 510 | // Code pattern for loading a floating point value. Input value must |
| 511 | // be either a smi or a heap number object (fp value). Requirements: |
| 512 | // operand in register number. Returns operand as floating point number |
| 513 | // on FPU stack. |
| 514 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 515 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 516 | // Test if operands are smi or number objects (fp). Requirements: |
| 517 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 518 | // operands, jumps to the non_float label otherwise. |
| 519 | static void CheckFloatOperands(MacroAssembler* masm, |
| 520 | Label* non_float, |
| 521 | Register scratch); |
| 522 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 523 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 524 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 525 | // either operand is not a number. Operands are in edx and eax. |
| 526 | // Leaves operands unchanged. |
| 527 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 528 | }; |
| 529 | |
| 530 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 531 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 532 | Register input_reg = this->source(); |
| 533 | Register final_result_reg = this->destination(); |
| 534 | ASSERT(is_truncating()); |
| 535 | |
| 536 | Label check_negative, process_64_bits, done, done_no_stash; |
| 537 | |
| 538 | int double_offset = offset(); |
| 539 | |
| 540 | // Account for return address and saved regs if input is esp. |
| 541 | if (input_reg.is(esp)) double_offset += 3 * kPointerSize; |
| 542 | |
| 543 | MemOperand mantissa_operand(MemOperand(input_reg, double_offset)); |
| 544 | MemOperand exponent_operand(MemOperand(input_reg, |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 545 | double_offset + kDoubleSize / 2)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 546 | |
| 547 | Register scratch1; |
| 548 | { |
| 549 | Register scratch_candidates[3] = { ebx, edx, edi }; |
| 550 | for (int i = 0; i < 3; i++) { |
| 551 | scratch1 = scratch_candidates[i]; |
| 552 | if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break; |
| 553 | } |
| 554 | } |
| 555 | // Since we must use ecx for shifts below, use some other register (eax) |
| 556 | // to calculate the result if ecx is the requested return register. |
| 557 | Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg; |
| 558 | // Save ecx if it isn't the return register and therefore volatile, or if it |
| 559 | // is the return register, then save the temp register we use in its stead for |
| 560 | // the result. |
| 561 | Register save_reg = final_result_reg.is(ecx) ? eax : ecx; |
| 562 | __ push(scratch1); |
| 563 | __ push(save_reg); |
| 564 | |
| 565 | bool stash_exponent_copy = !input_reg.is(esp); |
| 566 | __ mov(scratch1, mantissa_operand); |
| 567 | if (CpuFeatures::IsSupported(SSE3)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 568 | CpuFeatureScope scope(masm, SSE3); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 569 | // Load x87 register with heap number. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 570 | __ fld_d(mantissa_operand); |
| 571 | } |
| 572 | __ mov(ecx, exponent_operand); |
| 573 | if (stash_exponent_copy) __ push(ecx); |
| 574 | |
| 575 | __ and_(ecx, HeapNumber::kExponentMask); |
| 576 | __ shr(ecx, HeapNumber::kExponentShift); |
| 577 | __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias)); |
| 578 | __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits)); |
| 579 | __ j(below, &process_64_bits); |
| 580 | |
| 581 | // Result is entirely in lower 32-bits of mantissa |
| 582 | int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize; |
| 583 | if (CpuFeatures::IsSupported(SSE3)) { |
| 584 | __ fstp(0); |
| 585 | } |
| 586 | __ sub(ecx, Immediate(delta)); |
| 587 | __ xor_(result_reg, result_reg); |
| 588 | __ cmp(ecx, Immediate(31)); |
| 589 | __ j(above, &done); |
| 590 | __ shl_cl(scratch1); |
| 591 | __ jmp(&check_negative); |
| 592 | |
| 593 | __ bind(&process_64_bits); |
| 594 | if (CpuFeatures::IsSupported(SSE3)) { |
| 595 | CpuFeatureScope scope(masm, SSE3); |
| 596 | if (stash_exponent_copy) { |
| 597 | // Already a copy of the exponent on the stack, overwrite it. |
| 598 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 599 | __ sub(esp, Immediate(kDoubleSize / 2)); |
| 600 | } else { |
| 601 | // Reserve space for 64 bit answer. |
| 602 | __ sub(esp, Immediate(kDoubleSize)); // Nolint. |
| 603 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 604 | // Do conversion, which cannot fail because we checked the exponent. |
| 605 | __ fisttp_d(Operand(esp, 0)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 606 | __ mov(result_reg, Operand(esp, 0)); // Load low word of answer as result |
| 607 | __ add(esp, Immediate(kDoubleSize)); |
| 608 | __ jmp(&done_no_stash); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 609 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 610 | // Result must be extracted from shifted 32-bit mantissa |
| 611 | __ sub(ecx, Immediate(delta)); |
| 612 | __ neg(ecx); |
| 613 | if (stash_exponent_copy) { |
| 614 | __ mov(result_reg, MemOperand(esp, 0)); |
| 615 | } else { |
| 616 | __ mov(result_reg, exponent_operand); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 617 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 618 | __ and_(result_reg, |
| 619 | Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32))); |
| 620 | __ add(result_reg, |
| 621 | Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32))); |
| 622 | __ shrd(result_reg, scratch1); |
| 623 | __ shr_cl(result_reg); |
| 624 | __ test(ecx, Immediate(32)); |
| 625 | if (CpuFeatures::IsSupported(CMOV)) { |
| 626 | CpuFeatureScope use_cmov(masm, CMOV); |
| 627 | __ cmov(not_equal, scratch1, result_reg); |
| 628 | } else { |
| 629 | Label skip_mov; |
| 630 | __ j(equal, &skip_mov, Label::kNear); |
| 631 | __ mov(scratch1, result_reg); |
| 632 | __ bind(&skip_mov); |
| 633 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 634 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 635 | |
| 636 | // If the double was negative, negate the integer result. |
| 637 | __ bind(&check_negative); |
| 638 | __ mov(result_reg, scratch1); |
| 639 | __ neg(result_reg); |
| 640 | if (stash_exponent_copy) { |
| 641 | __ cmp(MemOperand(esp, 0), Immediate(0)); |
| 642 | } else { |
| 643 | __ cmp(exponent_operand, Immediate(0)); |
| 644 | } |
| 645 | if (CpuFeatures::IsSupported(CMOV)) { |
| 646 | CpuFeatureScope use_cmov(masm, CMOV); |
| 647 | __ cmov(greater, result_reg, scratch1); |
| 648 | } else { |
| 649 | Label skip_mov; |
| 650 | __ j(less_equal, &skip_mov, Label::kNear); |
| 651 | __ mov(result_reg, scratch1); |
| 652 | __ bind(&skip_mov); |
| 653 | } |
| 654 | |
| 655 | // Restore registers |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 656 | __ bind(&done); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 657 | if (stash_exponent_copy) { |
| 658 | __ add(esp, Immediate(kDoubleSize / 2)); |
| 659 | } |
| 660 | __ bind(&done_no_stash); |
| 661 | if (!final_result_reg.is(result_reg)) { |
| 662 | ASSERT(final_result_reg.is(ecx)); |
| 663 | __ mov(final_result_reg, result_reg); |
| 664 | } |
| 665 | __ pop(save_reg); |
| 666 | __ pop(scratch1); |
| 667 | __ ret(0); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 671 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 672 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 673 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 674 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 675 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 676 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 677 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 678 | |
| 679 | __ bind(&load_smi); |
| 680 | __ SmiUntag(number); |
| 681 | __ push(number); |
| 682 | __ fild_s(Operand(esp, 0)); |
| 683 | __ pop(number); |
| 684 | |
| 685 | __ bind(&done); |
| 686 | } |
| 687 | |
| 688 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 689 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 690 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 691 | 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] | 692 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 693 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 694 | Factory* factory = masm->isolate()->factory(); |
| 695 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 696 | __ 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] | 697 | __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 698 | __ bind(&load_eax); |
| 699 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 700 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 701 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 702 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 703 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 704 | __ bind(&load_smi_edx); |
| 705 | __ SmiUntag(edx); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 706 | __ Cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 707 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 708 | __ jmp(&load_eax); |
| 709 | __ bind(&load_smi_eax); |
| 710 | __ SmiUntag(eax); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 711 | __ Cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 712 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 713 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 714 | __ bind(&load_float_eax); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 715 | __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 716 | __ bind(&done); |
| 717 | } |
| 718 | |
| 719 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 720 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 721 | Label* non_float, |
| 722 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 723 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 724 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 725 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 726 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 727 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 728 | Factory* factory = masm->isolate()->factory(); |
| 729 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 730 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 731 | |
| 732 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 733 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 734 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 735 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 736 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 737 | |
| 738 | // Fall-through: Both operands are numbers. |
| 739 | __ bind(&done); |
| 740 | } |
| 741 | |
| 742 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 743 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 744 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 745 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 746 | const Register exponent = eax; |
| 747 | const Register base = edx; |
| 748 | const Register scratch = ecx; |
| 749 | const XMMRegister double_result = xmm3; |
| 750 | const XMMRegister double_base = xmm2; |
| 751 | const XMMRegister double_exponent = xmm1; |
| 752 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 753 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 754 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 755 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 756 | // Save 1 in double_result - we need this several times later on. |
| 757 | __ mov(scratch, Immediate(1)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 758 | __ Cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 759 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 760 | if (exponent_type_ == ON_STACK) { |
| 761 | Label base_is_smi, unpack_exponent; |
| 762 | // The exponent and base are supplied as arguments on the stack. |
| 763 | // This can only happen if the stub is called from non-optimized code. |
| 764 | // Load input parameters from stack. |
| 765 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 766 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 767 | |
| 768 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 769 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 770 | factory->heap_number_map()); |
| 771 | __ j(not_equal, &call_runtime); |
| 772 | |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 773 | __ movsd(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 774 | __ jmp(&unpack_exponent, Label::kNear); |
| 775 | |
| 776 | __ bind(&base_is_smi); |
| 777 | __ SmiUntag(base); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 778 | __ Cvtsi2sd(double_base, base); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 779 | |
| 780 | __ bind(&unpack_exponent); |
| 781 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 782 | __ SmiUntag(exponent); |
| 783 | __ jmp(&int_exponent); |
| 784 | |
| 785 | __ bind(&exponent_not_smi); |
| 786 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 787 | factory->heap_number_map()); |
| 788 | __ j(not_equal, &call_runtime); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 789 | __ movsd(double_exponent, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 790 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 791 | } else if (exponent_type_ == TAGGED) { |
| 792 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 793 | __ SmiUntag(exponent); |
| 794 | __ jmp(&int_exponent); |
| 795 | |
| 796 | __ bind(&exponent_not_smi); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 797 | __ movsd(double_exponent, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 798 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 799 | } |
| 800 | |
| 801 | if (exponent_type_ != INTEGER) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 802 | Label fast_power, try_arithmetic_simplification; |
| 803 | __ DoubleToI(exponent, double_exponent, double_scratch, |
| 804 | TREAT_MINUS_ZERO_AS_ZERO, &try_arithmetic_simplification); |
| 805 | __ jmp(&int_exponent); |
| 806 | |
| 807 | __ bind(&try_arithmetic_simplification); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 808 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 809 | __ cvttsd2si(exponent, Operand(double_exponent)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 810 | __ cmp(exponent, Immediate(0x80000000u)); |
| 811 | __ j(equal, &call_runtime); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 812 | |
| 813 | if (exponent_type_ == ON_STACK) { |
| 814 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 815 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 816 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 817 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 818 | // Test for 0.5. |
| 819 | // Load double_scratch with 0.5. |
| 820 | __ mov(scratch, Immediate(0x3F000000u)); |
| 821 | __ movd(double_scratch, scratch); |
| 822 | __ cvtss2sd(double_scratch, double_scratch); |
| 823 | // Already ruled out NaNs for exponent. |
| 824 | __ ucomisd(double_scratch, double_exponent); |
| 825 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 826 | |
| 827 | // Calculates square root of base. Check for the special case of |
| 828 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 829 | // According to IEEE-754, single-precision -Infinity has the highest |
| 830 | // 9 bits set and the lowest 23 bits cleared. |
| 831 | __ mov(scratch, 0xFF800000u); |
| 832 | __ movd(double_scratch, scratch); |
| 833 | __ cvtss2sd(double_scratch, double_scratch); |
| 834 | __ ucomisd(double_base, double_scratch); |
| 835 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 836 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 837 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 838 | __ j(carry, &continue_sqrt, Label::kNear); |
| 839 | |
| 840 | // Set result to Infinity in the special case. |
| 841 | __ xorps(double_result, double_result); |
| 842 | __ subsd(double_result, double_scratch); |
| 843 | __ jmp(&done); |
| 844 | |
| 845 | __ bind(&continue_sqrt); |
| 846 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 847 | __ xorps(double_scratch, double_scratch); |
| 848 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 849 | __ sqrtsd(double_result, double_scratch); |
| 850 | __ jmp(&done); |
| 851 | |
| 852 | // Test for -0.5. |
| 853 | __ bind(¬_plus_half); |
| 854 | // Load double_exponent with -0.5 by substracting 1. |
| 855 | __ subsd(double_scratch, double_result); |
| 856 | // Already ruled out NaNs for exponent. |
| 857 | __ ucomisd(double_scratch, double_exponent); |
| 858 | __ j(not_equal, &fast_power, Label::kNear); |
| 859 | |
| 860 | // Calculates reciprocal of square root of base. Check for the special |
| 861 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 862 | // According to IEEE-754, single-precision -Infinity has the highest |
| 863 | // 9 bits set and the lowest 23 bits cleared. |
| 864 | __ mov(scratch, 0xFF800000u); |
| 865 | __ movd(double_scratch, scratch); |
| 866 | __ cvtss2sd(double_scratch, double_scratch); |
| 867 | __ ucomisd(double_base, double_scratch); |
| 868 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 869 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 870 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 871 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 872 | |
| 873 | // Set result to 0 in the special case. |
| 874 | __ xorps(double_result, double_result); |
| 875 | __ jmp(&done); |
| 876 | |
| 877 | __ bind(&continue_rsqrt); |
| 878 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 879 | __ xorps(double_exponent, double_exponent); |
| 880 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 881 | __ sqrtsd(double_exponent, double_exponent); |
| 882 | __ divsd(double_result, double_exponent); |
| 883 | __ jmp(&done); |
| 884 | } |
| 885 | |
| 886 | // Using FPU instructions to calculate power. |
| 887 | Label fast_power_failed; |
| 888 | __ bind(&fast_power); |
| 889 | __ fnclex(); // Clear flags to catch exceptions later. |
| 890 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 891 | __ sub(esp, Immediate(kDoubleSize)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 892 | __ movsd(Operand(esp, 0), double_exponent); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 893 | __ fld_d(Operand(esp, 0)); // E |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 894 | __ movsd(Operand(esp, 0), double_base); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 895 | __ fld_d(Operand(esp, 0)); // B, E |
| 896 | |
| 897 | // Exponent is in st(1) and base is in st(0) |
| 898 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 899 | // FYL2X calculates st(1) * log2(st(0)) |
| 900 | __ fyl2x(); // X |
| 901 | __ fld(0); // X, X |
| 902 | __ frndint(); // rnd(X), X |
| 903 | __ fsub(1); // rnd(X), X-rnd(X) |
| 904 | __ fxch(1); // X - rnd(X), rnd(X) |
| 905 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 906 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 907 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 908 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 909 | // FSCALE calculates st(0) * 2^st(1) |
| 910 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 911 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 912 | // Bail out to runtime in case of exceptions in the status word. |
| 913 | __ fnstsw_ax(); |
| 914 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 915 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 916 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 917 | __ movsd(double_result, Operand(esp, 0)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 918 | __ add(esp, Immediate(kDoubleSize)); |
| 919 | __ jmp(&done); |
| 920 | |
| 921 | __ bind(&fast_power_failed); |
| 922 | __ fninit(); |
| 923 | __ add(esp, Immediate(kDoubleSize)); |
| 924 | __ jmp(&call_runtime); |
| 925 | } |
| 926 | |
| 927 | // Calculate power with integer exponent. |
| 928 | __ bind(&int_exponent); |
| 929 | const XMMRegister double_scratch2 = double_exponent; |
| 930 | __ mov(scratch, exponent); // Back up exponent. |
| 931 | __ movsd(double_scratch, double_base); // Back up base. |
| 932 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 933 | |
| 934 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 935 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 936 | __ test(scratch, scratch); |
| 937 | __ j(positive, &no_neg, Label::kNear); |
| 938 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 939 | __ bind(&no_neg); |
| 940 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 941 | __ j(zero, &while_false, Label::kNear); |
| 942 | __ shr(scratch, 1); |
| 943 | // Above condition means CF==0 && ZF==0. This means that the |
| 944 | // bit that has been shifted out is 0 and the result is not 0. |
| 945 | __ j(above, &while_true, Label::kNear); |
| 946 | __ movsd(double_result, double_scratch); |
| 947 | __ j(zero, &while_false, Label::kNear); |
| 948 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 949 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 950 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 951 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 952 | __ j(above, &while_true, Label::kNear); |
| 953 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 954 | __ j(not_zero, &while_true); |
| 955 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 956 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 957 | // scratch has the original value of the exponent - if the exponent is |
| 958 | // negative, return 1/result. |
| 959 | __ test(exponent, exponent); |
| 960 | __ j(positive, &done); |
| 961 | __ divsd(double_scratch2, double_result); |
| 962 | __ movsd(double_result, double_scratch2); |
| 963 | // Test whether result is zero. Bail out to check for subnormal result. |
| 964 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 965 | __ xorps(double_scratch2, double_scratch2); |
| 966 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 967 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 968 | // and may not have contained the exponent value in the first place when the |
| 969 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 970 | __ j(not_equal, &done); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 971 | __ Cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 972 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 973 | // Returning or bailing out. |
| 974 | Counters* counters = masm->isolate()->counters(); |
| 975 | if (exponent_type_ == ON_STACK) { |
| 976 | // The arguments are still on the stack. |
| 977 | __ bind(&call_runtime); |
| 978 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 979 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 980 | // The stub is called from non-optimized code, which expects the result |
| 981 | // as heap number in exponent. |
| 982 | __ bind(&done); |
| 983 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 984 | __ movsd(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 985 | __ IncrementCounter(counters->math_pow(), 1); |
| 986 | __ ret(2 * kPointerSize); |
| 987 | } else { |
| 988 | __ bind(&call_runtime); |
| 989 | { |
| 990 | AllowExternalCallThatCantCauseGC scope(masm); |
| 991 | __ PrepareCallCFunction(4, scratch); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 992 | __ movsd(Operand(esp, 0 * kDoubleSize), double_base); |
| 993 | __ movsd(Operand(esp, 1 * kDoubleSize), double_exponent); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 994 | __ CallCFunction( |
| 995 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 996 | } |
| 997 | // Return value is in st(0) on ia32. |
| 998 | // Store it into the (fixed) result register. |
| 999 | __ sub(esp, Immediate(kDoubleSize)); |
| 1000 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1001 | __ movsd(double_result, Operand(esp, 0)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1002 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1003 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1004 | __ bind(&done); |
| 1005 | __ IncrementCounter(counters->math_pow(), 1); |
| 1006 | __ ret(0); |
| 1007 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1011 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 1012 | // ----------- S t a t e ------------- |
| 1013 | // -- ecx : name |
| 1014 | // -- edx : receiver |
| 1015 | // -- esp[0] : return address |
| 1016 | // ----------------------------------- |
| 1017 | Label miss; |
| 1018 | |
| 1019 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1020 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1021 | __ j(not_equal, &miss); |
| 1022 | } |
| 1023 | |
| 1024 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 1025 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1026 | StubCompiler::TailCallBuiltin( |
| 1027 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | |
| 1031 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 1032 | // ----------- S t a t e ------------- |
| 1033 | // -- ecx : name |
| 1034 | // -- edx : receiver |
| 1035 | // -- esp[0] : return address |
| 1036 | // ----------------------------------- |
| 1037 | Label miss; |
| 1038 | |
| 1039 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1040 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1041 | __ j(not_equal, &miss); |
| 1042 | } |
| 1043 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1044 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1045 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1046 | StubCompiler::TailCallBuiltin( |
| 1047 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1051 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 1052 | // ----------- S t a t e ------------- |
| 1053 | // -- eax : value |
| 1054 | // -- ecx : name |
| 1055 | // -- edx : receiver |
| 1056 | // -- esp[0] : return address |
| 1057 | // ----------------------------------- |
| 1058 | // |
| 1059 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 1060 | // (currently anything except for external arrays which means anything with |
| 1061 | // elements of FixedArray type). Value must be a number, but only smis are |
| 1062 | // accepted as the most common case. |
| 1063 | |
| 1064 | Label miss; |
| 1065 | |
| 1066 | Register receiver = edx; |
| 1067 | Register value = eax; |
| 1068 | Register scratch = ebx; |
| 1069 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1070 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1071 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1072 | __ j(not_equal, &miss); |
| 1073 | } |
| 1074 | |
| 1075 | // Check that the receiver isn't a smi. |
| 1076 | __ JumpIfSmi(receiver, &miss); |
| 1077 | |
| 1078 | // Check that the object is a JS array. |
| 1079 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 1080 | __ j(not_equal, &miss); |
| 1081 | |
| 1082 | // Check that elements are FixedArray. |
| 1083 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 1084 | // fast elements (including COW). |
| 1085 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 1086 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 1087 | __ j(not_equal, &miss); |
| 1088 | |
| 1089 | // Check that the array has fast properties, otherwise the length |
| 1090 | // property might have been redefined. |
| 1091 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 1092 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 1093 | Heap::kHashTableMapRootIndex); |
| 1094 | __ j(equal, &miss); |
| 1095 | |
| 1096 | // Check that value is a smi. |
| 1097 | __ JumpIfNotSmi(value, &miss); |
| 1098 | |
| 1099 | // Prepare tail call to StoreIC_ArrayLength. |
| 1100 | __ pop(scratch); |
| 1101 | __ push(receiver); |
| 1102 | __ push(value); |
| 1103 | __ push(scratch); // return address |
| 1104 | |
| 1105 | ExternalReference ref = |
| 1106 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 1107 | __ TailCallExternalReference(ref, 2, 1); |
| 1108 | |
| 1109 | __ bind(&miss); |
| 1110 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1111 | StubCompiler::TailCallBuiltin( |
| 1112 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1116 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 1117 | // The key is in edx and the parameter count is in eax. |
| 1118 | |
| 1119 | // The displacement is used for skipping the frame pointer on the |
| 1120 | // stack. It is the offset of the last parameter (if any) relative |
| 1121 | // to the frame pointer. |
| 1122 | static const int kDisplacement = 1 * kPointerSize; |
| 1123 | |
| 1124 | // Check that the key is a smi. |
| 1125 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1126 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1127 | |
| 1128 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1129 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1130 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1131 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1132 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1133 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1134 | |
| 1135 | // Check index against formal parameters count limit passed in |
| 1136 | // through register eax. Use unsigned comparison to get negative |
| 1137 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1138 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1139 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1140 | |
| 1141 | // Read the argument from the stack and return it. |
| 1142 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1143 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 1144 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 1145 | __ neg(edx); |
| 1146 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 1147 | __ ret(0); |
| 1148 | |
| 1149 | // Arguments adaptor case: Check index against actual arguments |
| 1150 | // limit found in the arguments adaptor frame. Use unsigned |
| 1151 | // comparison to get negative check for free. |
| 1152 | __ bind(&adaptor); |
| 1153 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1154 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1155 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1156 | |
| 1157 | // Read the argument from the stack and return it. |
| 1158 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1159 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 1160 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 1161 | __ neg(edx); |
| 1162 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 1163 | __ ret(0); |
| 1164 | |
| 1165 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 1166 | // by calling the runtime system. |
| 1167 | __ bind(&slow); |
| 1168 | __ pop(ebx); // Return address. |
| 1169 | __ push(edx); |
| 1170 | __ push(ebx); |
| 1171 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 1172 | } |
| 1173 | |
| 1174 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1175 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1176 | // esp[0] : return address |
| 1177 | // esp[4] : number of parameters |
| 1178 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1179 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1180 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1181 | // Check if the calling frame is an arguments adaptor frame. |
| 1182 | Label runtime; |
| 1183 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1184 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1185 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1186 | __ j(not_equal, &runtime, Label::kNear); |
| 1187 | |
| 1188 | // Patch the arguments.length and the parameters pointer. |
| 1189 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1190 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 1191 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1192 | StandardFrameConstants::kCallerSPOffset)); |
| 1193 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1194 | |
| 1195 | __ bind(&runtime); |
| 1196 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 1197 | } |
| 1198 | |
| 1199 | |
| 1200 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1201 | Isolate* isolate = masm->isolate(); |
| 1202 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1203 | // esp[0] : return address |
| 1204 | // esp[4] : number of parameters (tagged) |
| 1205 | // esp[8] : receiver displacement |
| 1206 | // esp[12] : function |
| 1207 | |
| 1208 | // ebx = parameter count (tagged) |
| 1209 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1210 | |
| 1211 | // Check if the calling frame is an arguments adaptor frame. |
| 1212 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 1213 | // Generate* functions. |
| 1214 | Label runtime; |
| 1215 | Label adaptor_frame, try_allocate; |
| 1216 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1217 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1218 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1219 | __ j(equal, &adaptor_frame, Label::kNear); |
| 1220 | |
| 1221 | // No adaptor, parameter count = argument count. |
| 1222 | __ mov(ecx, ebx); |
| 1223 | __ jmp(&try_allocate, Label::kNear); |
| 1224 | |
| 1225 | // We have an adaptor frame. Patch the parameters pointer. |
| 1226 | __ bind(&adaptor_frame); |
| 1227 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1228 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1229 | StandardFrameConstants::kCallerSPOffset)); |
| 1230 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1231 | |
| 1232 | // ebx = parameter count (tagged) |
| 1233 | // ecx = argument count (tagged) |
| 1234 | // esp[4] = parameter count (tagged) |
| 1235 | // esp[8] = address of receiver argument |
| 1236 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1237 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1238 | __ j(less_equal, &try_allocate, Label::kNear); |
| 1239 | __ mov(ebx, ecx); |
| 1240 | |
| 1241 | __ bind(&try_allocate); |
| 1242 | |
| 1243 | // Save mapped parameter count. |
| 1244 | __ push(ebx); |
| 1245 | |
| 1246 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 1247 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 1248 | const int kParameterMapHeaderSize = |
| 1249 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 1250 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1251 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1252 | __ j(zero, &no_parameter_map, Label::kNear); |
| 1253 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 1254 | __ bind(&no_parameter_map); |
| 1255 | |
| 1256 | // 2. Backing store. |
| 1257 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 1258 | |
| 1259 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1260 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1261 | |
| 1262 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1263 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1264 | |
| 1265 | // eax = address of new object(s) (tagged) |
| 1266 | // ecx = argument count (tagged) |
| 1267 | // esp[0] = mapped parameter count (tagged) |
| 1268 | // esp[8] = parameter count (tagged) |
| 1269 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1270 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1271 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1272 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 1273 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1274 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1275 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1276 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 1277 | __ mov(edi, Operand(edi, |
| 1278 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 1279 | __ jmp(©, Label::kNear); |
| 1280 | |
| 1281 | __ bind(&has_mapped_parameters); |
| 1282 | __ mov(edi, Operand(edi, |
| 1283 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 1284 | __ bind(©); |
| 1285 | |
| 1286 | // eax = address of new object (tagged) |
| 1287 | // ebx = mapped parameter count (tagged) |
| 1288 | // ecx = argument count (tagged) |
| 1289 | // edi = address of boilerplate object (tagged) |
| 1290 | // esp[0] = mapped parameter count (tagged) |
| 1291 | // esp[8] = parameter count (tagged) |
| 1292 | // esp[12] = address of receiver argument |
| 1293 | // Copy the JS object part. |
| 1294 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 1295 | __ mov(edx, FieldOperand(edi, i)); |
| 1296 | __ mov(FieldOperand(eax, i), edx); |
| 1297 | } |
| 1298 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1299 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1300 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 1301 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 1302 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 1303 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 1304 | edx); |
| 1305 | |
| 1306 | // Use the length (smi tagged) and set that as an in-object property too. |
| 1307 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 1308 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 1309 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 1310 | ecx); |
| 1311 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1312 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1313 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 1314 | // backing store. |
| 1315 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 1316 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 1317 | |
| 1318 | // eax = address of new object (tagged) |
| 1319 | // ebx = mapped parameter count (tagged) |
| 1320 | // ecx = argument count (tagged) |
| 1321 | // edi = address of parameter map or backing store (tagged) |
| 1322 | // esp[0] = mapped parameter count (tagged) |
| 1323 | // esp[8] = parameter count (tagged) |
| 1324 | // esp[12] = address of receiver argument |
| 1325 | // Free a register. |
| 1326 | __ push(eax); |
| 1327 | |
| 1328 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 1329 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1330 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1331 | __ j(zero, &skip_parameter_map); |
| 1332 | |
| 1333 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1334 | Immediate(isolate->factory()->non_strict_arguments_elements_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1335 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 1336 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 1337 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 1338 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 1339 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 1340 | |
| 1341 | // Copy the parameter slots and the holes in the arguments. |
| 1342 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 1343 | // where parameters are stored in reverse order, at |
| 1344 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 1345 | // The mapped parameter thus need to get indices |
| 1346 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 1347 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 1348 | // We loop from right to left. |
| 1349 | Label parameters_loop, parameters_test; |
| 1350 | __ push(ecx); |
| 1351 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 1352 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 1353 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1354 | __ sub(ebx, eax); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1355 | __ mov(ecx, isolate->factory()->the_hole_value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1356 | __ mov(edx, edi); |
| 1357 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 1358 | // eax = loop variable (tagged) |
| 1359 | // ebx = mapping index (tagged) |
| 1360 | // ecx = the hole value |
| 1361 | // edx = address of parameter map (tagged) |
| 1362 | // edi = address of backing store (tagged) |
| 1363 | // esp[0] = argument count (tagged) |
| 1364 | // esp[4] = address of new object (tagged) |
| 1365 | // esp[8] = mapped parameter count (tagged) |
| 1366 | // esp[16] = parameter count (tagged) |
| 1367 | // esp[20] = address of receiver argument |
| 1368 | __ jmp(¶meters_test, Label::kNear); |
| 1369 | |
| 1370 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1371 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1372 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 1373 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1374 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1375 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1376 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1377 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 1378 | __ pop(ecx); |
| 1379 | |
| 1380 | __ bind(&skip_parameter_map); |
| 1381 | |
| 1382 | // ecx = argument count (tagged) |
| 1383 | // edi = address of backing store (tagged) |
| 1384 | // esp[0] = address of new object (tagged) |
| 1385 | // esp[4] = mapped parameter count (tagged) |
| 1386 | // esp[12] = parameter count (tagged) |
| 1387 | // esp[16] = address of receiver argument |
| 1388 | // Copy arguments header and remaining slots (if there are any). |
| 1389 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1390 | Immediate(isolate->factory()->fixed_array_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1391 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 1392 | |
| 1393 | Label arguments_loop, arguments_test; |
| 1394 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1395 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1396 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 1397 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1398 | __ jmp(&arguments_test, Label::kNear); |
| 1399 | |
| 1400 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1401 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1402 | __ mov(eax, Operand(edx, 0)); |
| 1403 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1404 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1405 | |
| 1406 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1407 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1408 | __ j(less, &arguments_loop, Label::kNear); |
| 1409 | |
| 1410 | // Restore. |
| 1411 | __ pop(eax); // Address of arguments object. |
| 1412 | __ pop(ebx); // Parameter count. |
| 1413 | |
| 1414 | // Return and remove the on-stack parameters. |
| 1415 | __ ret(3 * kPointerSize); |
| 1416 | |
| 1417 | // Do the runtime call to allocate the arguments object. |
| 1418 | __ bind(&runtime); |
| 1419 | __ pop(eax); // Remove saved parameter count. |
| 1420 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 1421 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | |
| 1425 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1426 | Isolate* isolate = masm->isolate(); |
| 1427 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1428 | // esp[0] : return address |
| 1429 | // esp[4] : number of parameters |
| 1430 | // esp[8] : receiver displacement |
| 1431 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1432 | |
| 1433 | // Check if the calling frame is an arguments adaptor frame. |
| 1434 | Label adaptor_frame, try_allocate, runtime; |
| 1435 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1436 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1437 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1438 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1439 | |
| 1440 | // Get the length from the frame. |
| 1441 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1442 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1443 | |
| 1444 | // Patch the arguments.length and the parameters pointer. |
| 1445 | __ bind(&adaptor_frame); |
| 1446 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1447 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1448 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1449 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1450 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1451 | |
| 1452 | // Try the new space allocation. Start out with computing the size of |
| 1453 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1454 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1455 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1456 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1457 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1458 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 1459 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1460 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1461 | |
| 1462 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1463 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1464 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1465 | // Get the arguments boilerplate from the current native context. |
| 1466 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 1467 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1468 | const int offset = |
| 1469 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 1470 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1471 | |
| 1472 | // Copy the JS object part. |
| 1473 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 1474 | __ mov(ebx, FieldOperand(edi, i)); |
| 1475 | __ mov(FieldOperand(eax, i), ebx); |
| 1476 | } |
| 1477 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1478 | // 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] | 1479 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1480 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1481 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1482 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1483 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1484 | |
| 1485 | // If there are no actual arguments, we're done. |
| 1486 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1487 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1488 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1489 | |
| 1490 | // Get the parameters pointer from the stack. |
| 1491 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 1492 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1493 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1494 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1495 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1496 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 1497 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1498 | Immediate(isolate->factory()->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1499 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1500 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 1501 | // Untag the length for the loop below. |
| 1502 | __ SmiUntag(ecx); |
| 1503 | |
| 1504 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1505 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1506 | __ bind(&loop); |
| 1507 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 1508 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1509 | __ add(edi, Immediate(kPointerSize)); |
| 1510 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1511 | __ dec(ecx); |
| 1512 | __ j(not_zero, &loop); |
| 1513 | |
| 1514 | // Return and remove the on-stack parameters. |
| 1515 | __ bind(&done); |
| 1516 | __ ret(3 * kPointerSize); |
| 1517 | |
| 1518 | // Do the runtime call to allocate the arguments object. |
| 1519 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1520 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | |
| 1524 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 1525 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 1526 | // time or if regexp entry in generated code is turned off runtime switch or |
| 1527 | // at compilation. |
| 1528 | #ifdef V8_INTERPRETED_REGEXP |
| 1529 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 1530 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1531 | |
| 1532 | // Stack frame on entry. |
| 1533 | // esp[0]: return address |
| 1534 | // esp[4]: last_match_info (expected JSArray) |
| 1535 | // esp[8]: previous index |
| 1536 | // esp[12]: subject string |
| 1537 | // esp[16]: JSRegExp object |
| 1538 | |
| 1539 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 1540 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 1541 | static const int kSubjectOffset = 3 * kPointerSize; |
| 1542 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 1543 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1544 | Label runtime; |
| 1545 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1546 | |
| 1547 | // Ensure that a RegExp stack is allocated. |
| 1548 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1549 | ExternalReference::address_of_regexp_stack_memory_address( |
| 1550 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1551 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1552 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1553 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1554 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1555 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1556 | |
| 1557 | // Check that the first argument is a JSRegExp object. |
| 1558 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 1559 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1560 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1561 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 1562 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1563 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1564 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 1565 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 1566 | if (FLAG_debug_code) { |
| 1567 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1568 | __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1569 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1570 | __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1571 | } |
| 1572 | |
| 1573 | // ecx: RegExp data (FixedArray) |
| 1574 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 1575 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1576 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1577 | __ j(not_equal, &runtime); |
| 1578 | |
| 1579 | // ecx: RegExp data (FixedArray) |
| 1580 | // Check that the number of captures fit in the static offsets vector buffer. |
| 1581 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1582 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 1583 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 1584 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1585 | STATIC_ASSERT(kSmiTag == 0); |
| 1586 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1587 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 1588 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1589 | __ j(above, &runtime); |
| 1590 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1591 | // Reset offset for possibly sliced string. |
| 1592 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1593 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1594 | __ JumpIfSmi(eax, &runtime); |
| 1595 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1596 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1597 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1598 | |
| 1599 | // eax: subject string |
| 1600 | // edx: subject string |
| 1601 | // ebx: subject string instance type |
| 1602 | // ecx: RegExp data (FixedArray) |
| 1603 | // Handle subject string according to its encoding and representation: |
| 1604 | // (1) Sequential two byte? If yes, go to (9). |
| 1605 | // (2) Sequential one byte? If yes, go to (6). |
| 1606 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 1607 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 1608 | // Otherwise bailout. |
| 1609 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 1610 | // (5b) Is subject external? If yes, go to (8). |
| 1611 | // (6) One byte sequential. Load regexp code for one byte. |
| 1612 | // (E) Carry on. |
| 1613 | /// [...] |
| 1614 | |
| 1615 | // Deferred code at the end of the stub: |
| 1616 | // (7) Not a long external string? If yes, go to (10). |
| 1617 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 1618 | // (8a) Is the external string one byte? If yes, go to (6). |
| 1619 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 1620 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 1621 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 1622 | |
| 1623 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 1624 | external_string /* 8 */, check_underlying /* 5a */, |
| 1625 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 1626 | not_long_external /* 10 */; |
| 1627 | |
| 1628 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1629 | __ and_(ebx, kIsNotStringMask | |
| 1630 | kStringRepresentationMask | |
| 1631 | kStringEncodingMask | |
| 1632 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1633 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1634 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 1635 | |
| 1636 | // (2) Sequential one byte? If yes, go to (6). |
| 1637 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1638 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 1639 | kStringRepresentationMask | |
| 1640 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1641 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1642 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1643 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 1644 | // We check whether the subject string is a cons, since sequential strings |
| 1645 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1646 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 1647 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1648 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 1649 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1650 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1651 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1652 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1653 | // (4) Cons string. Check that it's flat. |
| 1654 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1655 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1656 | __ j(not_equal, &runtime); |
| 1657 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1658 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1659 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1660 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 1661 | |
| 1662 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 1663 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1664 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1665 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 1666 | // (5b) Is subject external? If yes, go to (8). |
| 1667 | __ test_b(ebx, kStringRepresentationMask); |
| 1668 | // The underlying external string is never a short external string. |
| 1669 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 1670 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 1671 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1672 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1673 | // eax: sequential subject string (or look-alike, external string) |
| 1674 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1675 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1676 | // (6) One byte sequential. Load regexp code for one byte. |
| 1677 | __ bind(&seq_one_byte_string); |
| 1678 | // Load previous index and check range before edx is overwritten. We have |
| 1679 | // to use edx instead of eax here because it might have been only made to |
| 1680 | // look like a sequential string when it actually is an external string. |
| 1681 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 1682 | __ JumpIfNotSmi(ebx, &runtime); |
| 1683 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 1684 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1685 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1686 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1687 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1688 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1689 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1690 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1691 | // Check that the irregexp code has been generated for the actual string |
| 1692 | // 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] | 1693 | // a smi (code flushing support). |
| 1694 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1695 | |
| 1696 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1697 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1698 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1699 | // 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] | 1700 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1701 | Counters* counters = masm->isolate()->counters(); |
| 1702 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1703 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1704 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1705 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1706 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1707 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1708 | // Argument 9: Pass current isolate address. |
| 1709 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1710 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1711 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1712 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 1713 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1714 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1715 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1716 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 1717 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1718 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 1719 | |
| 1720 | // Argument 6: Set the number of capture registers to zero to force global |
| 1721 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 1722 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1723 | |
| 1724 | // Argument 5: static offsets vector buffer. |
| 1725 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1726 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 1727 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1728 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1729 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1730 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1731 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1732 | |
| 1733 | // Argument 1: Original subject string. |
| 1734 | // The original subject is in the previous stack frame. Therefore we have to |
| 1735 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 1736 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 1737 | // and thereby moves up esp by one kPointerSize.) |
| 1738 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 1739 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 1740 | |
| 1741 | // esi: original subject string |
| 1742 | // eax: underlying subject string |
| 1743 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1744 | // 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] | 1745 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1746 | // Argument 4: End of string data |
| 1747 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1748 | // Prepare start and end index of the input. |
| 1749 | // Load the length from the original sliced string if that is the case. |
| 1750 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1751 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1752 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1753 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1754 | |
| 1755 | // ebx: start index of the input string |
| 1756 | // esi: end index of the input string |
| 1757 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1758 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1759 | __ j(zero, &setup_two_byte, Label::kNear); |
| 1760 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1761 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1762 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1763 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1764 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1765 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1766 | |
| 1767 | __ bind(&setup_two_byte); |
| 1768 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1769 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 1770 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1771 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 1772 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 1773 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 1774 | |
| 1775 | __ bind(&setup_rest); |
| 1776 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1777 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1778 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1779 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1780 | |
| 1781 | // Drop arguments and come back to JS mode. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1782 | __ LeaveApiExitFrame(true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1783 | |
| 1784 | // Check the result. |
| 1785 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1786 | __ cmp(eax, 1); |
| 1787 | // We expect exactly one result since we force the called regexp to behave |
| 1788 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1789 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1790 | Label failure; |
| 1791 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1792 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1793 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 1794 | // If not exception it can only be retry. Handle that in the runtime system. |
| 1795 | __ j(not_equal, &runtime); |
| 1796 | // Result must now be exception. If there is no pending exception already a |
| 1797 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 1798 | // haven't created the exception yet. Handle that in the runtime system. |
| 1799 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1800 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1801 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1802 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1803 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1804 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1805 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1806 | // For exception, throw the exception again. |
| 1807 | |
| 1808 | // Clear the pending exception variable. |
| 1809 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 1810 | |
| 1811 | // Special handling of termination exceptions which are uncatchable |
| 1812 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1813 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1814 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1815 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1816 | |
| 1817 | // Handle normal exception by following handler chain. |
| 1818 | __ Throw(eax); |
| 1819 | |
| 1820 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1821 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1822 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1823 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1824 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1825 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1826 | __ ret(4 * kPointerSize); |
| 1827 | |
| 1828 | // Load RegExp data. |
| 1829 | __ bind(&success); |
| 1830 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 1831 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 1832 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 1833 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 1834 | STATIC_ASSERT(kSmiTag == 0); |
| 1835 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1836 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1837 | |
| 1838 | // edx: Number of capture registers |
| 1839 | // 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] | 1840 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1841 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1842 | __ JumpIfSmi(eax, &runtime); |
| 1843 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 1844 | __ j(not_equal, &runtime); |
| 1845 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1846 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1847 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 1848 | __ cmp(eax, factory->fixed_array_map()); |
| 1849 | __ j(not_equal, &runtime); |
| 1850 | // Check that the last match info has space for the capture registers and the |
| 1851 | // additional information. |
| 1852 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 1853 | __ SmiUntag(eax); |
| 1854 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 1855 | __ cmp(edx, eax); |
| 1856 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1857 | |
| 1858 | // ebx: last_match_info backing store (FixedArray) |
| 1859 | // edx: number of capture registers |
| 1860 | // Store the capture count. |
| 1861 | __ SmiTag(edx); // Number of capture registers to smi. |
| 1862 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 1863 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 1864 | // Store last subject and last input. |
| 1865 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1866 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1867 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1868 | __ RecordWriteField(ebx, |
| 1869 | RegExpImpl::kLastSubjectOffset, |
| 1870 | eax, |
| 1871 | edi, |
| 1872 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1873 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1874 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1875 | __ RecordWriteField(ebx, |
| 1876 | RegExpImpl::kLastInputOffset, |
| 1877 | eax, |
| 1878 | edi, |
| 1879 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1880 | |
| 1881 | // Get the static offsets vector filled by the native regexp code. |
| 1882 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1883 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1884 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 1885 | |
| 1886 | // ebx: last_match_info backing store (FixedArray) |
| 1887 | // ecx: offsets vector |
| 1888 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1889 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1890 | // Capture register counter starts from number of capture registers and |
| 1891 | // counts down until wraping after zero. |
| 1892 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1893 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1894 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1895 | // Read the value from the static offsets vector buffer. |
| 1896 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 1897 | __ SmiTag(edi); |
| 1898 | // Store the smi value in the last match info. |
| 1899 | __ mov(FieldOperand(ebx, |
| 1900 | edx, |
| 1901 | times_pointer_size, |
| 1902 | RegExpImpl::kFirstCaptureOffset), |
| 1903 | edi); |
| 1904 | __ jmp(&next_capture); |
| 1905 | __ bind(&done); |
| 1906 | |
| 1907 | // Return last match info. |
| 1908 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 1909 | __ ret(4 * kPointerSize); |
| 1910 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1911 | // Do the runtime call to execute the regexp. |
| 1912 | __ bind(&runtime); |
| 1913 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 1914 | |
| 1915 | // Deferred code for string handling. |
| 1916 | // (7) Not a long external string? If yes, go to (10). |
| 1917 | __ bind(¬_seq_nor_cons); |
| 1918 | // Compare flags are still set from (3). |
| 1919 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 1920 | |
| 1921 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1922 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1923 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1924 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1925 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 1926 | if (FLAG_debug_code) { |
| 1927 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 1928 | // Sequential strings have already been ruled out. |
| 1929 | __ test_b(ebx, kIsIndirectStringMask); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1930 | __ Assert(zero, kExternalStringExpectedButNotFound); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1931 | } |
| 1932 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 1933 | // 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] | 1934 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1935 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 1936 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1937 | // (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] | 1938 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1939 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1940 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1941 | // eax: sequential subject string (or look-alike, external string) |
| 1942 | // edx: original subject string |
| 1943 | // ecx: RegExp data (FixedArray) |
| 1944 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 1945 | __ bind(&seq_two_byte_string); |
| 1946 | // Load previous index and check range before edx is overwritten. We have |
| 1947 | // to use edx instead of eax here because it might have been only made to |
| 1948 | // look like a sequential string when it actually is an external string. |
| 1949 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 1950 | __ JumpIfNotSmi(ebx, &runtime); |
| 1951 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 1952 | __ j(above_equal, &runtime); |
| 1953 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 1954 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 1955 | __ jmp(&check_code); // Go to (E). |
| 1956 | |
| 1957 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 1958 | __ bind(¬_long_external); |
| 1959 | // Catch non-string subject or short external string. |
| 1960 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 1961 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 1962 | __ j(not_zero, &runtime); |
| 1963 | |
| 1964 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 1965 | // Load offset into edi and replace subject string with parent. |
| 1966 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 1967 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 1968 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1969 | #endif // V8_INTERPRETED_REGEXP |
| 1970 | } |
| 1971 | |
| 1972 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1973 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 1974 | const int kMaxInlineLength = 100; |
| 1975 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1976 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1977 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1978 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1979 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1980 | __ j(above, &slowcase); |
| 1981 | // Smi-tagging is equivalent to multiplying by 2. |
| 1982 | STATIC_ASSERT(kSmiTag == 0); |
| 1983 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1984 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 1985 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 1986 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1987 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 1988 | times_pointer_size, |
| 1989 | ebx, // In: Number of elements as a smi |
| 1990 | REGISTER_VALUE_IS_SMI, |
| 1991 | eax, // Out: Start of allocation (tagged). |
| 1992 | ecx, // Out: End of allocation. |
| 1993 | edx, // Scratch register |
| 1994 | &slowcase, |
| 1995 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1996 | // eax: Start of allocated area, object-tagged. |
| 1997 | |
| 1998 | // Set JSArray map to global.regexp_result_map(). |
| 1999 | // Set empty properties FixedArray. |
| 2000 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 2001 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2002 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2003 | Factory* factory = masm->isolate()->factory(); |
| 2004 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2005 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2006 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2007 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 2008 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 2009 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 2010 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 2011 | |
| 2012 | // Set input, index and length fields from arguments. |
| 2013 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 2014 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 2015 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 2016 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 2017 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 2018 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 2019 | |
| 2020 | // Fill out the elements FixedArray. |
| 2021 | // eax: JSArray. |
| 2022 | // ebx: FixedArray. |
| 2023 | // ecx: Number of elements in array, as smi. |
| 2024 | |
| 2025 | // Set map. |
| 2026 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2027 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2028 | // Set length. |
| 2029 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2030 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2031 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2032 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2033 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2034 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2035 | // eax: JSArray. |
| 2036 | // ecx: Number of elements to fill. |
| 2037 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2038 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2039 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2040 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2041 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2042 | __ 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] | 2043 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2044 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 2045 | __ jmp(&loop); |
| 2046 | |
| 2047 | __ bind(&done); |
| 2048 | __ ret(3 * kPointerSize); |
| 2049 | |
| 2050 | __ bind(&slowcase); |
| 2051 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 2052 | } |
| 2053 | |
| 2054 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2055 | static int NegativeComparisonResult(Condition cc) { |
| 2056 | ASSERT(cc != equal); |
| 2057 | ASSERT((cc == less) || (cc == less_equal) |
| 2058 | || (cc == greater) || (cc == greater_equal)); |
| 2059 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 2060 | } |
| 2061 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2062 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2063 | static void CheckInputType(MacroAssembler* masm, |
| 2064 | Register input, |
| 2065 | CompareIC::State expected, |
| 2066 | Label* fail) { |
| 2067 | Label ok; |
| 2068 | if (expected == CompareIC::SMI) { |
| 2069 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2070 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2071 | __ JumpIfSmi(input, &ok); |
| 2072 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 2073 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 2074 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2075 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2076 | // 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] | 2077 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 2078 | __ bind(&ok); |
| 2079 | } |
| 2080 | |
| 2081 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2082 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 2083 | Label* label, |
| 2084 | Register object, |
| 2085 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2086 | __ JumpIfSmi(object, label); |
| 2087 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 2088 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 2089 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 2090 | __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 2091 | __ j(not_zero, label); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2092 | } |
| 2093 | |
| 2094 | |
| 2095 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 2096 | Label check_unequal_objects; |
| 2097 | Condition cc = GetCondition(); |
| 2098 | |
| 2099 | Label miss; |
| 2100 | CheckInputType(masm, edx, left_, &miss); |
| 2101 | CheckInputType(masm, eax, right_, &miss); |
| 2102 | |
| 2103 | // Compare two smis. |
| 2104 | Label non_smi, smi_done; |
| 2105 | __ mov(ecx, edx); |
| 2106 | __ or_(ecx, eax); |
| 2107 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 2108 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 2109 | __ j(no_overflow, &smi_done, Label::kNear); |
| 2110 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 2111 | __ bind(&smi_done); |
| 2112 | __ mov(eax, edx); |
| 2113 | __ ret(0); |
| 2114 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2115 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2116 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 2117 | // it is certain that at least one operand isn't a smi. |
| 2118 | |
| 2119 | // Identical objects can be compared fast, but there are some tricky cases |
| 2120 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2121 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2122 | { |
| 2123 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2124 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2125 | __ j(not_equal, ¬_identical); |
| 2126 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2127 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2128 | // Check for undefined. undefined OP undefined is false even though |
| 2129 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2130 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2131 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2132 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2133 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2134 | __ ret(0); |
| 2135 | __ bind(&check_for_nan); |
| 2136 | } |
| 2137 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2138 | // Test for NaN. Compare heap numbers in a general way, |
| 2139 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2140 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 2141 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2142 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2143 | if (cc != equal) { |
| 2144 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 2145 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 2146 | __ j(above_equal, ¬_identical); |
| 2147 | } |
| 2148 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 2149 | __ ret(0); |
| 2150 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2151 | |
| 2152 | __ bind(¬_identical); |
| 2153 | } |
| 2154 | |
| 2155 | // Strict equality can quickly decide whether objects are equal. |
| 2156 | // 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] | 2157 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2158 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2159 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2160 | // If we're doing a strict equality comparison, we don't have to do |
| 2161 | // type conversion, so we generate code to do fast comparison for objects |
| 2162 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 2163 | // slow-case code. |
| 2164 | // If either is a Smi (we know that not both are), then they can only |
| 2165 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 2166 | STATIC_ASSERT(kSmiTag == 0); |
| 2167 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 2168 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2169 | __ and_(ecx, eax); |
| 2170 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2171 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2172 | // One operand is a smi. |
| 2173 | |
| 2174 | // Check whether the non-smi is a heap number. |
| 2175 | STATIC_ASSERT(kSmiTagMask == 1); |
| 2176 | // 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] | 2177 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2178 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2179 | __ xor_(ebx, eax); |
| 2180 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 2181 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2182 | // if eax was smi, ebx is now edx, else eax. |
| 2183 | |
| 2184 | // Check if the non-smi operand is a heap number. |
| 2185 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2186 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2187 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2188 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2189 | // Return non-equal (ebx is not zero) |
| 2190 | __ mov(eax, ebx); |
| 2191 | __ ret(0); |
| 2192 | |
| 2193 | __ bind(¬_smis); |
| 2194 | // If either operand is a JSObject or an oddball value, then they are not |
| 2195 | // equal since their pointers are different |
| 2196 | // There is no test for undetectability in strict equality. |
| 2197 | |
| 2198 | // Get the type of the first operand. |
| 2199 | // 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] | 2200 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2201 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 2202 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2203 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2204 | |
| 2205 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2206 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2207 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 2208 | __ bind(&return_not_equal); |
| 2209 | __ ret(0); |
| 2210 | |
| 2211 | __ bind(&first_non_object); |
| 2212 | // Check for oddballs: true, false, null, undefined. |
| 2213 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 2214 | __ j(equal, &return_not_equal); |
| 2215 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2216 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2217 | __ j(above_equal, &return_not_equal); |
| 2218 | |
| 2219 | // Check for oddballs: true, false, null, undefined. |
| 2220 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 2221 | __ j(equal, &return_not_equal); |
| 2222 | |
| 2223 | // Fall through to the general case. |
| 2224 | __ bind(&slow); |
| 2225 | } |
| 2226 | |
| 2227 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2228 | Label non_number_comparison; |
| 2229 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2230 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2231 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2232 | CpuFeatureScope use_sse2(masm, SSE2); |
| 2233 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2234 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2235 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 2236 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2237 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2238 | // Don't base result on EFLAGS when a NaN is involved. |
| 2239 | __ j(parity_even, &unordered, Label::kNear); |
| 2240 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 2241 | __ mov(eax, 0); // equal |
| 2242 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 2243 | __ cmov(above, eax, ecx); |
| 2244 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 2245 | __ cmov(below, eax, ecx); |
| 2246 | __ ret(0); |
| 2247 | } else { |
| 2248 | FloatingPointHelper::CheckFloatOperands( |
| 2249 | masm, &non_number_comparison, ebx); |
| 2250 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 2251 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 2252 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2253 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2254 | // Don't base result on EFLAGS when a NaN is involved. |
| 2255 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2256 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2257 | Label below_label, above_label; |
| 2258 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 2259 | __ j(below, &below_label, Label::kNear); |
| 2260 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2261 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2262 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2263 | __ ret(0); |
| 2264 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2265 | __ bind(&below_label); |
| 2266 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 2267 | __ ret(0); |
| 2268 | |
| 2269 | __ bind(&above_label); |
| 2270 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 2271 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2272 | } |
| 2273 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2274 | // If one of the numbers was NaN, then the result is always false. |
| 2275 | // The cc is never not-equal. |
| 2276 | __ bind(&unordered); |
| 2277 | ASSERT(cc != not_equal); |
| 2278 | if (cc == less || cc == less_equal) { |
| 2279 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 2280 | } else { |
| 2281 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 2282 | } |
| 2283 | __ ret(0); |
| 2284 | |
| 2285 | // The number comparison code did not provide a valid result. |
| 2286 | __ bind(&non_number_comparison); |
| 2287 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2288 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2289 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2290 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2291 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 2292 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2293 | |
| 2294 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2295 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2296 | // non-zero value, which indicates not equal, so just return. |
| 2297 | __ ret(0); |
| 2298 | } |
| 2299 | |
| 2300 | __ bind(&check_for_strings); |
| 2301 | |
| 2302 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 2303 | &check_unequal_objects); |
| 2304 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2305 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2306 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2307 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2308 | edx, |
| 2309 | eax, |
| 2310 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2311 | ebx); |
| 2312 | } else { |
| 2313 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 2314 | edx, |
| 2315 | eax, |
| 2316 | ecx, |
| 2317 | ebx, |
| 2318 | edi); |
| 2319 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2320 | #ifdef DEBUG |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2321 | __ Abort(kUnexpectedFallThroughFromStringComparison); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2322 | #endif |
| 2323 | |
| 2324 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2325 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2326 | // Non-strict equality. Objects are unequal if |
| 2327 | // they are both JSObjects and not undetectable, |
| 2328 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2329 | Label not_both_objects; |
| 2330 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2331 | // At most one is a smi, so we can test for smi by adding the two. |
| 2332 | // A smi plus a heap object has the low bit set, a heap object plus |
| 2333 | // a heap object has the low bit clear. |
| 2334 | STATIC_ASSERT(kSmiTag == 0); |
| 2335 | STATIC_ASSERT(kSmiTagMask == 1); |
| 2336 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 2337 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2338 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2339 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2340 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2341 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2342 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2343 | // We do not bail out after this point. Both are JSObjects, and |
| 2344 | // they are equal if and only if both are undetectable. |
| 2345 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 2346 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 2347 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2348 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2349 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 2350 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2351 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2352 | // The objects are both undetectable, so they both compare as the value |
| 2353 | // undefined, and are equal. |
| 2354 | __ Set(eax, Immediate(EQUAL)); |
| 2355 | __ bind(&return_unequal); |
| 2356 | // Return non-equal by returning the non-zero object pointer in eax, |
| 2357 | // or return equal if we fell through to here. |
| 2358 | __ ret(0); // rax, rdx were pushed |
| 2359 | __ bind(¬_both_objects); |
| 2360 | } |
| 2361 | |
| 2362 | // Push arguments below the return address. |
| 2363 | __ pop(ecx); |
| 2364 | __ push(edx); |
| 2365 | __ push(eax); |
| 2366 | |
| 2367 | // Figure out which native to call and setup the arguments. |
| 2368 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2369 | if (cc == equal) { |
| 2370 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2371 | } else { |
| 2372 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2373 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | // Restore return address on the stack. |
| 2377 | __ push(ecx); |
| 2378 | |
| 2379 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 2380 | // tagged as a small integer. |
| 2381 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2382 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2383 | __ bind(&miss); |
| 2384 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2385 | } |
| 2386 | |
| 2387 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2388 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 2389 | // Cache the called function in a global property cell. Cache states |
| 2390 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 2391 | // megamorphic. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2392 | // eax : number of arguments to the construct function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2393 | // ebx : cache cell for call target |
| 2394 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2395 | Isolate* isolate = masm->isolate(); |
| 2396 | Label initialize, done, miss, megamorphic, not_array_function; |
| 2397 | |
| 2398 | // Load the cache state into ecx. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2399 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2400 | |
| 2401 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 2402 | // function without changing the state. |
| 2403 | __ cmp(ecx, edi); |
| 2404 | __ j(equal, &done); |
| 2405 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 2406 | __ j(equal, &done); |
| 2407 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2408 | // If we came here, we need to see if we are the array function. |
| 2409 | // If we didn't have a matching function, and we didn't find the megamorph |
| 2410 | // sentinel, then we have in the cell either some other function or an |
| 2411 | // AllocationSite. Do a map check on the object in ecx. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2412 | Handle<Map> allocation_site_map = |
| 2413 | masm->isolate()->factory()->allocation_site_map(); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2414 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 2415 | __ j(not_equal, &miss); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2416 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2417 | // Load the global or builtins object from the current context |
| 2418 | __ LoadGlobalContext(ecx); |
| 2419 | // Make sure the function is the Array() function |
| 2420 | __ cmp(edi, Operand(ecx, |
| 2421 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 2422 | __ j(not_equal, &megamorphic); |
| 2423 | __ jmp(&done); |
| 2424 | |
| 2425 | __ bind(&miss); |
| 2426 | |
| 2427 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 2428 | // megamorphic. |
| 2429 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 2430 | __ j(equal, &initialize); |
| 2431 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 2432 | // write-barrier is needed. |
| 2433 | __ bind(&megamorphic); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2434 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2435 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 2436 | __ jmp(&done, Label::kNear); |
| 2437 | |
| 2438 | // An uninitialized cache is patched with the function or sentinel to |
| 2439 | // indicate the ElementsKind if function is the Array constructor. |
| 2440 | __ bind(&initialize); |
| 2441 | __ LoadGlobalContext(ecx); |
| 2442 | // Make sure the function is the Array() function |
| 2443 | __ cmp(edi, Operand(ecx, |
| 2444 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 2445 | __ j(not_equal, ¬_array_function); |
| 2446 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2447 | // The target function is the Array constructor, |
| 2448 | // Create an AllocationSite if we don't already have it, store it in the cell |
| 2449 | { |
| 2450 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2451 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2452 | // Arguments register must be smi-tagged to call out. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2453 | __ SmiTag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2454 | __ push(eax); |
| 2455 | __ push(edi); |
| 2456 | __ push(ebx); |
| 2457 | |
| 2458 | CreateAllocationSiteStub create_stub; |
| 2459 | __ CallStub(&create_stub); |
| 2460 | |
| 2461 | __ pop(ebx); |
| 2462 | __ pop(edi); |
| 2463 | __ pop(eax); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2464 | __ SmiUntag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2465 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2466 | __ jmp(&done); |
| 2467 | |
| 2468 | __ bind(¬_array_function); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2469 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2470 | // No need for a write barrier here - cells are rescanned. |
| 2471 | |
| 2472 | __ bind(&done); |
| 2473 | } |
| 2474 | |
| 2475 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2476 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2477 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2478 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2479 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2480 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2481 | |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame] | 2482 | // Check that the function really is a JavaScript function. |
| 2483 | __ JumpIfSmi(edi, &non_function); |
| 2484 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2485 | // Goto slow case if we do not have a function. |
| 2486 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2487 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2488 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2489 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2490 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2491 | } |
| 2492 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2493 | // Fast-case: Just invoke the function. |
| 2494 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2495 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2496 | __ InvokeFunction(edi, actual, JUMP_FUNCTION, NullCallWrapper()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2497 | |
| 2498 | // Slow-case: Non-function called. |
| 2499 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2500 | if (RecordCallTarget()) { |
| 2501 | // 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] | 2502 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 2503 | // object (undefined) so no write barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2504 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2505 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2506 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2507 | // Check for function proxy. |
| 2508 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 2509 | __ j(not_equal, &non_function); |
| 2510 | __ pop(ecx); |
| 2511 | __ push(edi); // put proxy as additional argument under return address |
| 2512 | __ push(ecx); |
| 2513 | __ Set(eax, Immediate(argc_ + 1)); |
| 2514 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2515 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 2516 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2517 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2518 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 2519 | } |
| 2520 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2521 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 2522 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2523 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2524 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 2525 | __ Set(eax, Immediate(argc_)); |
| 2526 | __ Set(ebx, Immediate(0)); |
| 2527 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2528 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2529 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 2530 | } |
| 2531 | |
| 2532 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2533 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 2534 | // eax : number of arguments |
| 2535 | // ebx : cache cell for call target |
| 2536 | // edi : constructor function |
| 2537 | Label slow, non_function_call; |
| 2538 | |
| 2539 | // Check that function is not a smi. |
| 2540 | __ JumpIfSmi(edi, &non_function_call); |
| 2541 | // Check that function is a JSFunction. |
| 2542 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2543 | __ j(not_equal, &slow); |
| 2544 | |
| 2545 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2546 | GenerateRecordCallTarget(masm); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2547 | } |
| 2548 | |
| 2549 | // Jump to the function-specific construct stub. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2550 | Register jmp_reg = ecx; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2551 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2552 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 2553 | SharedFunctionInfo::kConstructStubOffset)); |
| 2554 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 2555 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2556 | |
| 2557 | // edi: called object |
| 2558 | // eax: number of arguments |
| 2559 | // ecx: object map |
| 2560 | Label do_call; |
| 2561 | __ bind(&slow); |
| 2562 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 2563 | __ j(not_equal, &non_function_call); |
| 2564 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 2565 | __ jmp(&do_call); |
| 2566 | |
| 2567 | __ bind(&non_function_call); |
| 2568 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 2569 | __ bind(&do_call); |
| 2570 | // Set expected number of arguments to zero (not changing eax). |
| 2571 | __ Set(ebx, Immediate(0)); |
| 2572 | Handle<Code> arguments_adaptor = |
| 2573 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2574 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 2575 | } |
| 2576 | |
| 2577 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2578 | bool CEntryStub::NeedsImmovableCode() { |
| 2579 | return false; |
| 2580 | } |
| 2581 | |
| 2582 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2583 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 2584 | CEntryStub::GenerateAheadOfTime(isolate); |
| 2585 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2586 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2587 | // 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] | 2588 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2589 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2590 | if (Serializer::enabled()) { |
| 2591 | PlatformFeatureScope sse2(SSE2); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2592 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 2593 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2594 | } else { |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2595 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 2596 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2597 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2601 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2602 | if (CpuFeatures::IsSupported(SSE2)) { |
| 2603 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 2604 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 2605 | // which would lead to code stub initialization state being messed up. |
| 2606 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2607 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 2608 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2609 | } |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2610 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2611 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2612 | } |
| 2613 | |
| 2614 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2615 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2616 | CEntryStub stub(1, kDontSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2617 | stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2618 | } |
| 2619 | |
| 2620 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2621 | static void JumpIfOOM(MacroAssembler* masm, |
| 2622 | Register value, |
| 2623 | Register scratch, |
| 2624 | Label* oom_label) { |
| 2625 | __ mov(scratch, value); |
| 2626 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 2627 | STATIC_ASSERT(kFailureTag == 3); |
| 2628 | __ and_(scratch, 0xf); |
| 2629 | __ cmp(scratch, 0xf); |
| 2630 | __ j(equal, oom_label); |
| 2631 | } |
| 2632 | |
| 2633 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2634 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 2635 | Label* throw_normal_exception, |
| 2636 | Label* throw_termination_exception, |
| 2637 | Label* throw_out_of_memory_exception, |
| 2638 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2639 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2640 | // eax: result parameter for PerformGC, if any |
| 2641 | // ebx: pointer to C function (C callee-saved) |
| 2642 | // ebp: frame pointer (restored after C call) |
| 2643 | // esp: stack pointer (restored after C call) |
| 2644 | // edi: number of arguments including receiver (C callee-saved) |
| 2645 | // esi: pointer to the first argument (C callee-saved) |
| 2646 | |
| 2647 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 2648 | |
| 2649 | // Check stack alignment. |
| 2650 | if (FLAG_debug_code) { |
| 2651 | __ CheckStackAlignment(); |
| 2652 | } |
| 2653 | |
| 2654 | if (do_gc) { |
| 2655 | // Pass failure code returned from last attempt as first argument to |
| 2656 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 2657 | // stack alignment is known to be correct. This function takes one argument |
| 2658 | // which is passed on the stack, and we know that the stack has been |
| 2659 | // prepared to pass at least one argument. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2660 | __ mov(Operand(esp, 1 * kPointerSize), |
| 2661 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2662 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 2663 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 2664 | } |
| 2665 | |
| 2666 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2667 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2668 | if (always_allocate_scope) { |
| 2669 | __ inc(Operand::StaticVariable(scope_depth)); |
| 2670 | } |
| 2671 | |
| 2672 | // Call C function. |
| 2673 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 2674 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2675 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2676 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2677 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2678 | // Result is in eax or edx:eax - do not destroy these registers! |
| 2679 | |
| 2680 | if (always_allocate_scope) { |
| 2681 | __ dec(Operand::StaticVariable(scope_depth)); |
| 2682 | } |
| 2683 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2684 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 2685 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2686 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2687 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2688 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2689 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2690 | __ int3(); |
| 2691 | __ bind(&okay); |
| 2692 | } |
| 2693 | |
| 2694 | // Check for failure result. |
| 2695 | Label failure_returned; |
| 2696 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 2697 | __ lea(ecx, Operand(eax, 1)); |
| 2698 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 2699 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2700 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2701 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2702 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2703 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2704 | |
| 2705 | // Check that there is no pending exception, otherwise we |
| 2706 | // should have returned some failure value. |
| 2707 | if (FLAG_debug_code) { |
| 2708 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2709 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2710 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2711 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 2712 | // 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] | 2713 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2714 | __ int3(); |
| 2715 | __ bind(&okay); |
| 2716 | __ pop(edx); |
| 2717 | } |
| 2718 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2719 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2720 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2721 | __ ret(0); |
| 2722 | |
| 2723 | // Handling of failure. |
| 2724 | __ bind(&failure_returned); |
| 2725 | |
| 2726 | Label retry; |
| 2727 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 2728 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 2729 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2730 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2731 | |
| 2732 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2733 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2734 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2735 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2736 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2737 | |
| 2738 | // See if we just retrieved an OOM exception. |
| 2739 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 2740 | |
| 2741 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2742 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2743 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 2744 | |
| 2745 | // Special handling of termination exceptions which are uncatchable |
| 2746 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2747 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2748 | __ j(equal, throw_termination_exception); |
| 2749 | |
| 2750 | // Handle normal exception. |
| 2751 | __ jmp(throw_normal_exception); |
| 2752 | |
| 2753 | // Retry. |
| 2754 | __ bind(&retry); |
| 2755 | } |
| 2756 | |
| 2757 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2758 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 2759 | // eax: number of arguments including receiver |
| 2760 | // ebx: pointer to C function (C callee-saved) |
| 2761 | // ebp: frame pointer (restored after C call) |
| 2762 | // esp: stack pointer (restored after C call) |
| 2763 | // esi: current context (C callee-saved) |
| 2764 | // edi: JS function of the caller (C callee-saved) |
| 2765 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2766 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 2767 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2768 | // NOTE: Invocations of builtins may return failure objects instead |
| 2769 | // of a proper result. The builtin entry handles this by performing |
| 2770 | // a garbage collection and retrying the builtin (twice). |
| 2771 | |
| 2772 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2773 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2774 | |
| 2775 | // eax: result parameter for PerformGC, if any (setup below) |
| 2776 | // ebx: pointer to builtin function (C callee-saved) |
| 2777 | // ebp: frame pointer (restored after C call) |
| 2778 | // esp: stack pointer (restored after C call) |
| 2779 | // edi: number of arguments including receiver (C callee-saved) |
| 2780 | // esi: argv pointer (C callee-saved) |
| 2781 | |
| 2782 | Label throw_normal_exception; |
| 2783 | Label throw_termination_exception; |
| 2784 | Label throw_out_of_memory_exception; |
| 2785 | |
| 2786 | // Call into the runtime system. |
| 2787 | GenerateCore(masm, |
| 2788 | &throw_normal_exception, |
| 2789 | &throw_termination_exception, |
| 2790 | &throw_out_of_memory_exception, |
| 2791 | false, |
| 2792 | false); |
| 2793 | |
| 2794 | // Do space-specific GC and retry runtime call. |
| 2795 | GenerateCore(masm, |
| 2796 | &throw_normal_exception, |
| 2797 | &throw_termination_exception, |
| 2798 | &throw_out_of_memory_exception, |
| 2799 | true, |
| 2800 | false); |
| 2801 | |
| 2802 | // Do full GC and retry runtime call one final time. |
| 2803 | Failure* failure = Failure::InternalError(); |
| 2804 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 2805 | GenerateCore(masm, |
| 2806 | &throw_normal_exception, |
| 2807 | &throw_termination_exception, |
| 2808 | &throw_out_of_memory_exception, |
| 2809 | true, |
| 2810 | true); |
| 2811 | |
| 2812 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2813 | // Set external caught exception to false. |
| 2814 | Isolate* isolate = masm->isolate(); |
| 2815 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 2816 | isolate); |
| 2817 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 2818 | |
| 2819 | // Set pending exception and eax to out of memory exception. |
| 2820 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 2821 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2822 | Label already_have_failure; |
| 2823 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 2824 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 2825 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2826 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 2827 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2828 | |
| 2829 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2830 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2831 | |
| 2832 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2833 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | |
| 2837 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2838 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2839 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2840 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2841 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 2842 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2843 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2844 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2845 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2846 | |
| 2847 | // Push marker in two places. |
| 2848 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 2849 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 2850 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 2851 | // Save callee-saved registers (C calling conventions). |
| 2852 | __ push(edi); |
| 2853 | __ push(esi); |
| 2854 | __ push(ebx); |
| 2855 | |
| 2856 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2857 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2858 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 2859 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2860 | // 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] | 2861 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2862 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2863 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2864 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2865 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2866 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 2867 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2868 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2869 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2870 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2871 | // Jump to a faked try block that does the invoke, with a faked catch |
| 2872 | // block that sets the pending exception. |
| 2873 | __ jmp(&invoke); |
| 2874 | __ bind(&handler_entry); |
| 2875 | handler_offset_ = handler_entry.pos(); |
| 2876 | // Caught exception: Store result (exception) in the pending exception |
| 2877 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2878 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2879 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2880 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 2881 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 2882 | __ jmp(&exit); |
| 2883 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2884 | // Invoke: Link this frame into the handler chain. There's only one |
| 2885 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2886 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 2887 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2888 | |
| 2889 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2890 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2891 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 2892 | |
| 2893 | // Fake a receiver (NULL). |
| 2894 | __ push(Immediate(0)); // receiver |
| 2895 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2896 | // Invoke the function by calling through JS entry trampoline builtin and |
| 2897 | // pop the faked function when we return. Notice that we cannot store a |
| 2898 | // reference to the trampoline code directly in this stub, because the |
| 2899 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2900 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2901 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 2902 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2903 | __ mov(edx, Immediate(construct_entry)); |
| 2904 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2905 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2906 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2907 | __ mov(edx, Immediate(entry)); |
| 2908 | } |
| 2909 | __ mov(edx, Operand(edx, 0)); // deref address |
| 2910 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2911 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2912 | |
| 2913 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2914 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2915 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2916 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2917 | // Check if the current stack frame is marked as the outermost JS frame. |
| 2918 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2919 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2920 | __ j(not_equal, ¬_outermost_js_2); |
| 2921 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 2922 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2923 | |
| 2924 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2925 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2926 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2927 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2928 | |
| 2929 | // Restore callee-saved registers (C calling conventions). |
| 2930 | __ pop(ebx); |
| 2931 | __ pop(esi); |
| 2932 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2933 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2934 | |
| 2935 | // Restore frame pointer and return. |
| 2936 | __ pop(ebp); |
| 2937 | __ ret(0); |
| 2938 | } |
| 2939 | |
| 2940 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2941 | // Generate stub code for instanceof. |
| 2942 | // This code can patch a call site inlined cache of the instance of check, |
| 2943 | // which looks like this. |
| 2944 | // |
| 2945 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 2946 | // 75 0a jne <some near label> |
| 2947 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 2948 | // |
| 2949 | // If call site patching is requested the stack will have the delta from the |
| 2950 | // return address to the cmp instruction just below the return address. This |
| 2951 | // also means that call site patching can only take place with arguments in |
| 2952 | // registers. TOS looks like this when call site patching is requested |
| 2953 | // |
| 2954 | // esp[0] : return address |
| 2955 | // esp[4] : delta from return address to cmp instruction |
| 2956 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2957 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2958 | // Call site inlining and patching implies arguments in registers. |
| 2959 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 2960 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2961 | // Fixed register usage throughout the stub. |
| 2962 | Register object = eax; // Object (lhs). |
| 2963 | Register map = ebx; // Map of the object. |
| 2964 | Register function = edx; // Function (rhs). |
| 2965 | Register prototype = edi; // Prototype of the function. |
| 2966 | Register scratch = ecx; |
| 2967 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2968 | // Constants describing the call site code to patch. |
| 2969 | static const int kDeltaToCmpImmediate = 2; |
| 2970 | static const int kDeltaToMov = 8; |
| 2971 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2972 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 2973 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2974 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 2975 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2976 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 2977 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 2978 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2979 | // Get the object and function - they are always both needed. |
| 2980 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2981 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2982 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 2983 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 2984 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2985 | |
| 2986 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2987 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 2988 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2989 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 2990 | // If there is a call site cache don't look in the global cache, but do the |
| 2991 | // real lookup and update the call site cache. |
| 2992 | if (!HasCallSiteInlineCheck()) { |
| 2993 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2994 | Label miss; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2995 | __ CompareRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2996 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2997 | __ CompareRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2998 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2999 | __ LoadRoot(eax, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3000 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 3001 | __ bind(&miss); |
| 3002 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3003 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3004 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3005 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3006 | |
| 3007 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3008 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3009 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3010 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3011 | // Update the global instanceof or call site inlined cache with the current |
| 3012 | // map and function. The cached answer will be set when it is known below. |
| 3013 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3014 | __ StoreRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
| 3015 | __ StoreRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3016 | } else { |
| 3017 | // The constants for the code patching are based on no push instructions |
| 3018 | // at the call site. |
| 3019 | ASSERT(HasArgsInRegisters()); |
| 3020 | // Get return address and delta to inlined map check. |
| 3021 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3022 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3023 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3024 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3025 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp1); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3026 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3027 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3028 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3029 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 3030 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3031 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3032 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3033 | // Loop through the prototype chain of the object looking for the function |
| 3034 | // prototype. |
| 3035 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3036 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3037 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3038 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3039 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3040 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3041 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3042 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3043 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 3044 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3045 | __ jmp(&loop); |
| 3046 | |
| 3047 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3048 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3049 | __ mov(eax, Immediate(0)); |
| 3050 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3051 | } else { |
| 3052 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3053 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3054 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3055 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3056 | if (FLAG_debug_code) { |
| 3057 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3058 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3059 | } |
| 3060 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 3061 | if (!ReturnTrueFalseObject()) { |
| 3062 | __ Set(eax, Immediate(0)); |
| 3063 | } |
| 3064 | } |
| 3065 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3066 | |
| 3067 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3068 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3069 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 3070 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3071 | } else { |
| 3072 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3073 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3074 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3075 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3076 | if (FLAG_debug_code) { |
| 3077 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3078 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3079 | } |
| 3080 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 3081 | if (!ReturnTrueFalseObject()) { |
| 3082 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 3083 | } |
| 3084 | } |
| 3085 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3086 | |
| 3087 | Label object_not_null, object_not_null_or_smi; |
| 3088 | __ bind(¬_js_object); |
| 3089 | // Before null, smi and string value checks, check that the rhs is a function |
| 3090 | // 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] | 3091 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3092 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3093 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3094 | |
| 3095 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3096 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3097 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3098 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3099 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3100 | |
| 3101 | __ bind(&object_not_null); |
| 3102 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3103 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3104 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3105 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3106 | |
| 3107 | __ bind(&object_not_null_or_smi); |
| 3108 | // String values is not instance of anything. |
| 3109 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3110 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3111 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3112 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3113 | |
| 3114 | // Slow-case: Go through the JavaScript implementation. |
| 3115 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3116 | if (!ReturnTrueFalseObject()) { |
| 3117 | // Tail call the builtin which returns 0 or 1. |
| 3118 | if (HasArgsInRegisters()) { |
| 3119 | // Push arguments below return address. |
| 3120 | __ pop(scratch); |
| 3121 | __ push(object); |
| 3122 | __ push(function); |
| 3123 | __ push(scratch); |
| 3124 | } |
| 3125 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 3126 | } else { |
| 3127 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3128 | { |
| 3129 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3130 | __ push(object); |
| 3131 | __ push(function); |
| 3132 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 3133 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3134 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3135 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3136 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3137 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3138 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3139 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3140 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3141 | __ bind(&done); |
| 3142 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3143 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3147 | Register InstanceofStub::left() { return eax; } |
| 3148 | |
| 3149 | |
| 3150 | Register InstanceofStub::right() { return edx; } |
| 3151 | |
| 3152 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3153 | // ------------------------------------------------------------------------- |
| 3154 | // StringCharCodeAtGenerator |
| 3155 | |
| 3156 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3157 | // If the receiver is a smi trigger the non-string case. |
| 3158 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3159 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3160 | |
| 3161 | // Fetch the instance type of the receiver into result register. |
| 3162 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 3163 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 3164 | // If the receiver is not a string trigger the non-string case. |
| 3165 | __ test(result_, Immediate(kIsNotStringMask)); |
| 3166 | __ j(not_zero, receiver_not_string_); |
| 3167 | |
| 3168 | // If the index is non-smi trigger the non-smi case. |
| 3169 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3170 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3171 | __ bind(&got_smi_index_); |
| 3172 | |
| 3173 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3174 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3175 | __ j(above_equal, index_out_of_range_); |
| 3176 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3177 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3178 | |
| 3179 | Factory* factory = masm->isolate()->factory(); |
| 3180 | StringCharLoadGenerator::Generate( |
| 3181 | masm, factory, object_, index_, result_, &call_runtime_); |
| 3182 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3183 | __ SmiTag(result_); |
| 3184 | __ bind(&exit_); |
| 3185 | } |
| 3186 | |
| 3187 | |
| 3188 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3189 | MacroAssembler* masm, |
| 3190 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3191 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3192 | |
| 3193 | // Index is not a smi. |
| 3194 | __ bind(&index_not_smi_); |
| 3195 | // 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] | 3196 | __ CheckMap(index_, |
| 3197 | masm->isolate()->factory()->heap_number_map(), |
| 3198 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3199 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3200 | call_helper.BeforeCall(masm); |
| 3201 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3202 | __ push(index_); // Consumed by runtime conversion function. |
| 3203 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 3204 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 3205 | } else { |
| 3206 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 3207 | // NumberToSmi discards numbers that are not exact integers. |
| 3208 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 3209 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3210 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3211 | // Save the conversion result before the pop instructions below |
| 3212 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3213 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3214 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3215 | __ pop(object_); |
| 3216 | // Reload the instance type. |
| 3217 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 3218 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 3219 | call_helper.AfterCall(masm); |
| 3220 | // If index is still not a smi, it must be out of range. |
| 3221 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3222 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3223 | // Otherwise, return to the fast path. |
| 3224 | __ jmp(&got_smi_index_); |
| 3225 | |
| 3226 | // Call runtime. We get here when the receiver is a string and the |
| 3227 | // index is a number, but the code of getting the actual character |
| 3228 | // is too complex (e.g., when the string needs to be flattened). |
| 3229 | __ bind(&call_runtime_); |
| 3230 | call_helper.BeforeCall(masm); |
| 3231 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3232 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3233 | __ push(index_); |
| 3234 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 3235 | if (!result_.is(eax)) { |
| 3236 | __ mov(result_, eax); |
| 3237 | } |
| 3238 | call_helper.AfterCall(masm); |
| 3239 | __ jmp(&exit_); |
| 3240 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3241 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3242 | } |
| 3243 | |
| 3244 | |
| 3245 | // ------------------------------------------------------------------------- |
| 3246 | // StringCharFromCodeGenerator |
| 3247 | |
| 3248 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 3249 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 3250 | STATIC_ASSERT(kSmiTag == 0); |
| 3251 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3252 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3253 | __ test(code_, |
| 3254 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3255 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3256 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3257 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3258 | Factory* factory = masm->isolate()->factory(); |
| 3259 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3260 | STATIC_ASSERT(kSmiTag == 0); |
| 3261 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3262 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3263 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3264 | __ mov(result_, FieldOperand(result_, |
| 3265 | code_, times_half_pointer_size, |
| 3266 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3267 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3268 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3269 | __ bind(&exit_); |
| 3270 | } |
| 3271 | |
| 3272 | |
| 3273 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3274 | MacroAssembler* masm, |
| 3275 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3276 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3277 | |
| 3278 | __ bind(&slow_case_); |
| 3279 | call_helper.BeforeCall(masm); |
| 3280 | __ push(code_); |
| 3281 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 3282 | if (!result_.is(eax)) { |
| 3283 | __ mov(result_, eax); |
| 3284 | } |
| 3285 | call_helper.AfterCall(masm); |
| 3286 | __ jmp(&exit_); |
| 3287 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3288 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3292 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 3293 | Register dest, |
| 3294 | Register src, |
| 3295 | Register count, |
| 3296 | Register scratch, |
| 3297 | bool ascii) { |
| 3298 | // Copy characters using rep movs of doublewords. |
| 3299 | // The destination is aligned on a 4 byte boundary because we are |
| 3300 | // copying to the beginning of a newly allocated string. |
| 3301 | ASSERT(dest.is(edi)); // rep movs destination |
| 3302 | ASSERT(src.is(esi)); // rep movs source |
| 3303 | ASSERT(count.is(ecx)); // rep movs count |
| 3304 | ASSERT(!scratch.is(dest)); |
| 3305 | ASSERT(!scratch.is(src)); |
| 3306 | ASSERT(!scratch.is(count)); |
| 3307 | |
| 3308 | // Nothing to do for zero characters. |
| 3309 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3310 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3311 | __ j(zero, &done); |
| 3312 | |
| 3313 | // Make count the number of bytes to copy. |
| 3314 | if (!ascii) { |
| 3315 | __ shl(count, 1); |
| 3316 | } |
| 3317 | |
| 3318 | // 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] | 3319 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3320 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3321 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3322 | |
| 3323 | // Copy from edi to esi using rep movs instruction. |
| 3324 | __ mov(scratch, count); |
| 3325 | __ sar(count, 2); // Number of doublewords to copy. |
| 3326 | __ cld(); |
| 3327 | __ rep_movs(); |
| 3328 | |
| 3329 | // Find number of bytes left. |
| 3330 | __ mov(count, scratch); |
| 3331 | __ and_(count, 3); |
| 3332 | |
| 3333 | // Check if there are more bytes to copy. |
| 3334 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3335 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3336 | __ j(zero, &done); |
| 3337 | |
| 3338 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3339 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3340 | __ bind(&loop); |
| 3341 | __ mov_b(scratch, Operand(src, 0)); |
| 3342 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3343 | __ add(src, Immediate(1)); |
| 3344 | __ add(dest, Immediate(1)); |
| 3345 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3346 | __ j(not_zero, &loop); |
| 3347 | |
| 3348 | __ bind(&done); |
| 3349 | } |
| 3350 | |
| 3351 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3352 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 3353 | Register hash, |
| 3354 | Register character, |
| 3355 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3356 | // hash = (seed + character) + ((seed + character) << 10); |
| 3357 | if (Serializer::enabled()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3358 | __ LoadRoot(scratch, Heap::kHashSeedRootIndex); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3359 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3360 | __ add(scratch, character); |
| 3361 | __ mov(hash, scratch); |
| 3362 | __ shl(scratch, 10); |
| 3363 | __ add(hash, scratch); |
| 3364 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3365 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3366 | __ lea(scratch, Operand(character, seed)); |
| 3367 | __ shl(scratch, 10); |
| 3368 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 3369 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3370 | // hash ^= hash >> 6; |
| 3371 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3372 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3373 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3374 | } |
| 3375 | |
| 3376 | |
| 3377 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 3378 | Register hash, |
| 3379 | Register character, |
| 3380 | Register scratch) { |
| 3381 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3382 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3383 | // hash += hash << 10; |
| 3384 | __ mov(scratch, hash); |
| 3385 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3386 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3387 | // hash ^= hash >> 6; |
| 3388 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3389 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3390 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | |
| 3394 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 3395 | Register hash, |
| 3396 | Register scratch) { |
| 3397 | // hash += hash << 3; |
| 3398 | __ mov(scratch, hash); |
| 3399 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3400 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3401 | // hash ^= hash >> 11; |
| 3402 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3403 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3404 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3405 | // hash += hash << 15; |
| 3406 | __ mov(scratch, hash); |
| 3407 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3408 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3409 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3410 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3411 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3412 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3413 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3414 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3415 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3416 | __ bind(&hash_not_zero); |
| 3417 | } |
| 3418 | |
| 3419 | |
| 3420 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 3421 | Label runtime; |
| 3422 | |
| 3423 | // Stack frame on entry. |
| 3424 | // esp[0]: return address |
| 3425 | // esp[4]: to |
| 3426 | // esp[8]: from |
| 3427 | // esp[12]: string |
| 3428 | |
| 3429 | // Make sure first argument is a string. |
| 3430 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 3431 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3432 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3433 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 3434 | __ j(NegateCondition(is_string), &runtime); |
| 3435 | |
| 3436 | // eax: string |
| 3437 | // ebx: instance type |
| 3438 | |
| 3439 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3440 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3441 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3442 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3443 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3444 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3445 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3446 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 3447 | // Shorter than original string's length: an actual substring. |
| 3448 | __ j(below, ¬_original_string, Label::kNear); |
| 3449 | // Longer than original string's length or negative: unsafe arguments. |
| 3450 | __ j(above, &runtime); |
| 3451 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3452 | Counters* counters = masm->isolate()->counters(); |
| 3453 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 3454 | __ ret(3 * kPointerSize); |
| 3455 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3456 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3457 | Label single_char; |
| 3458 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 3459 | __ j(equal, &single_char); |
| 3460 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3461 | // eax: string |
| 3462 | // ebx: instance type |
| 3463 | // ecx: sub string length (smi) |
| 3464 | // edx: from index (smi) |
| 3465 | // Deal with different string types: update the index if necessary |
| 3466 | // and put the underlying string into edi. |
| 3467 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 3468 | // If the string is not indirect, it can only be sequential or external. |
| 3469 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 3470 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 3471 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 3472 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 3473 | |
| 3474 | Factory* factory = masm->isolate()->factory(); |
| 3475 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 3476 | __ j(not_zero, &sliced_string, Label::kNear); |
| 3477 | // Cons string. Check whether it is flat, then fetch first part. |
| 3478 | // Flat cons strings have an empty second part. |
| 3479 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 3480 | factory->empty_string()); |
| 3481 | __ j(not_equal, &runtime); |
| 3482 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 3483 | // Update instance type. |
| 3484 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 3485 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3486 | __ jmp(&underlying_unpacked, Label::kNear); |
| 3487 | |
| 3488 | __ bind(&sliced_string); |
| 3489 | // Sliced string. Fetch parent and adjust start index by offset. |
| 3490 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 3491 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 3492 | // Update instance type. |
| 3493 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 3494 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 3495 | __ jmp(&underlying_unpacked, Label::kNear); |
| 3496 | |
| 3497 | __ bind(&seq_or_external_string); |
| 3498 | // Sequential or external string. Just move string to the expected register. |
| 3499 | __ mov(edi, eax); |
| 3500 | |
| 3501 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3502 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3503 | if (FLAG_string_slices) { |
| 3504 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3505 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3506 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3507 | // edx: adjusted start index (smi) |
| 3508 | // ecx: length (smi) |
| 3509 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 3510 | // Short slice. Copy instead of slicing. |
| 3511 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3512 | // Allocate new sliced string. At this point we do not reload the instance |
| 3513 | // type including the string encoding because we simply rely on the info |
| 3514 | // provided by the original string. It does not matter if the original |
| 3515 | // string's encoding is wrong because we always have to recheck encoding of |
| 3516 | // the newly created string's parent anyways due to externalized strings. |
| 3517 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3518 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3519 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 3520 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3521 | __ j(zero, &two_byte_slice, Label::kNear); |
| 3522 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 3523 | __ jmp(&set_slice_header, Label::kNear); |
| 3524 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3525 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3526 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3527 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3528 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 3529 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 3530 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 3531 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3532 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 3533 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3534 | |
| 3535 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 3536 | } |
| 3537 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3538 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3539 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3540 | // edx: adjusted start index (smi) |
| 3541 | // ecx: length (smi) |
| 3542 | // The subject string can only be external or sequential string of either |
| 3543 | // encoding at this point. |
| 3544 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 3545 | STATIC_ASSERT(kExternalStringTag != 0); |
| 3546 | STATIC_ASSERT(kSeqStringTag == 0); |
| 3547 | __ test_b(ebx, kExternalStringTag); |
| 3548 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3549 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3550 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3551 | // Rule out short external strings. |
| 3552 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 3553 | __ test_b(ebx, kShortExternalStringMask); |
| 3554 | __ j(not_zero, &runtime); |
| 3555 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 3556 | // 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] | 3557 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3558 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3559 | |
| 3560 | __ bind(&sequential_string); |
| 3561 | // Stash away (adjusted) index and (underlying) string. |
| 3562 | __ push(edx); |
| 3563 | __ push(edi); |
| 3564 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3565 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3566 | __ test_b(ebx, kStringEncodingMask); |
| 3567 | __ j(zero, &two_byte_sequential); |
| 3568 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3569 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3570 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3571 | |
| 3572 | // eax: result string |
| 3573 | // ecx: result string length |
| 3574 | __ mov(edx, esi); // esi used by following code. |
| 3575 | // Locate first character of result. |
| 3576 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3577 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3578 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3579 | __ pop(esi); |
| 3580 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3581 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3582 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3583 | |
| 3584 | // eax: result string |
| 3585 | // ecx: result length |
| 3586 | // edx: original value of esi |
| 3587 | // edi: first character of result |
| 3588 | // esi: character of sub string start |
| 3589 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 3590 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3591 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3592 | __ ret(3 * kPointerSize); |
| 3593 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3594 | __ bind(&two_byte_sequential); |
| 3595 | // Sequential two-byte string. Allocate the result. |
| 3596 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3597 | |
| 3598 | // eax: result string |
| 3599 | // ecx: result string length |
| 3600 | __ mov(edx, esi); // esi used by following code. |
| 3601 | // Locate first character of result. |
| 3602 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3603 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3604 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3605 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3606 | __ pop(esi); |
| 3607 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3608 | // As from is a smi it is 2 times the value which matches the size of a two |
| 3609 | // byte character. |
| 3610 | STATIC_ASSERT(kSmiTag == 0); |
| 3611 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3612 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3613 | |
| 3614 | // eax: result string |
| 3615 | // ecx: result length |
| 3616 | // edx: original value of esi |
| 3617 | // edi: first character of result |
| 3618 | // esi: character of sub string start |
| 3619 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 3620 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3621 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3622 | __ ret(3 * kPointerSize); |
| 3623 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 3624 | // Drop pushed values on the stack before tail call. |
| 3625 | __ bind(&runtime_drop_two); |
| 3626 | __ Drop(2); |
| 3627 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3628 | // Just jump to runtime to create the sub string. |
| 3629 | __ bind(&runtime); |
| 3630 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 3631 | |
| 3632 | __ bind(&single_char); |
| 3633 | // eax: string |
| 3634 | // ebx: instance type |
| 3635 | // ecx: sub string length (smi) |
| 3636 | // edx: from index (smi) |
| 3637 | StringCharAtGenerator generator( |
| 3638 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 3639 | generator.GenerateFast(masm); |
| 3640 | __ ret(3 * kPointerSize); |
| 3641 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3642 | } |
| 3643 | |
| 3644 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3645 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 3646 | Register left, |
| 3647 | Register right, |
| 3648 | Register scratch1, |
| 3649 | Register scratch2) { |
| 3650 | Register length = scratch1; |
| 3651 | |
| 3652 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3653 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3654 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 3655 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3656 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3657 | __ bind(&strings_not_equal); |
| 3658 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 3659 | __ ret(0); |
| 3660 | |
| 3661 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3662 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3663 | __ bind(&check_zero_length); |
| 3664 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3665 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3666 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3667 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3668 | __ ret(0); |
| 3669 | |
| 3670 | // Compare characters. |
| 3671 | __ bind(&compare_chars); |
| 3672 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3673 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3674 | |
| 3675 | // Characters are equal. |
| 3676 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3677 | __ ret(0); |
| 3678 | } |
| 3679 | |
| 3680 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3681 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 3682 | Register left, |
| 3683 | Register right, |
| 3684 | Register scratch1, |
| 3685 | Register scratch2, |
| 3686 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3687 | Counters* counters = masm->isolate()->counters(); |
| 3688 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3689 | |
| 3690 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3691 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3692 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 3693 | __ mov(scratch3, scratch1); |
| 3694 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 3695 | |
| 3696 | Register length_delta = scratch3; |
| 3697 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3698 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3699 | // 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] | 3700 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3701 | __ bind(&left_shorter); |
| 3702 | |
| 3703 | Register min_length = scratch1; |
| 3704 | |
| 3705 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3706 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3707 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3708 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3709 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3710 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3711 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3712 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3713 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3714 | |
| 3715 | // Compare lengths - strings up to min-length are equal. |
| 3716 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3717 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3718 | Label length_not_equal; |
| 3719 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3720 | |
| 3721 | // Result is EQUAL. |
| 3722 | STATIC_ASSERT(EQUAL == 0); |
| 3723 | STATIC_ASSERT(kSmiTag == 0); |
| 3724 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 3725 | __ ret(0); |
| 3726 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3727 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3728 | Label result_less; |
| 3729 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3730 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3731 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3732 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3733 | __ j(above, &result_greater, Label::kNear); |
| 3734 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3735 | |
| 3736 | // Result is LESS. |
| 3737 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 3738 | __ ret(0); |
| 3739 | |
| 3740 | // Result is GREATER. |
| 3741 | __ bind(&result_greater); |
| 3742 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 3743 | __ ret(0); |
| 3744 | } |
| 3745 | |
| 3746 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3747 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 3748 | MacroAssembler* masm, |
| 3749 | Register left, |
| 3750 | Register right, |
| 3751 | Register length, |
| 3752 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3753 | Label* chars_not_equal, |
| 3754 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3755 | // Change index to run from -length to -1 by adding length to string |
| 3756 | // start. This means that loop ends when index reaches zero, which |
| 3757 | // doesn't need an additional compare. |
| 3758 | __ SmiUntag(length); |
| 3759 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3760 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3761 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3762 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3763 | __ neg(length); |
| 3764 | Register index = length; // index = -length; |
| 3765 | |
| 3766 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3767 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3768 | __ bind(&loop); |
| 3769 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 3770 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3771 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 3772 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 3773 | __ j(not_zero, &loop); |
| 3774 | } |
| 3775 | |
| 3776 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3777 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 3778 | Label runtime; |
| 3779 | |
| 3780 | // Stack frame on entry. |
| 3781 | // esp[0]: return address |
| 3782 | // esp[4]: right string |
| 3783 | // esp[8]: left string |
| 3784 | |
| 3785 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 3786 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 3787 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3788 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3789 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3790 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3791 | STATIC_ASSERT(EQUAL == 0); |
| 3792 | STATIC_ASSERT(kSmiTag == 0); |
| 3793 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3794 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3795 | __ ret(2 * kPointerSize); |
| 3796 | |
| 3797 | __ bind(¬_same); |
| 3798 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3799 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3800 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 3801 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3802 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3803 | // Drop arguments from the stack. |
| 3804 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3805 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3806 | __ push(ecx); |
| 3807 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 3808 | |
| 3809 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 3810 | // tagged as a small integer. |
| 3811 | __ bind(&runtime); |
| 3812 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 3813 | } |
| 3814 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 3815 | |
machenbach@chromium.org | c8cbc43 | 2014-01-21 09:01:57 +0000 | [diff] [blame] | 3816 | void ArrayPushStub::Generate(MacroAssembler* masm) { |
| 3817 | int argc = arguments_count(); |
| 3818 | |
| 3819 | if (argc == 0) { |
| 3820 | // Noop, return the length. |
| 3821 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 3822 | __ ret((argc + 1) * kPointerSize); |
| 3823 | return; |
| 3824 | } |
| 3825 | |
| 3826 | Isolate* isolate = masm->isolate(); |
| 3827 | |
| 3828 | if (argc != 1) { |
| 3829 | __ TailCallExternalReference( |
| 3830 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 3831 | return; |
| 3832 | } |
| 3833 | |
| 3834 | Label call_builtin, attempt_to_grow_elements, with_write_barrier; |
| 3835 | |
| 3836 | // Get the elements array of the object. |
| 3837 | __ mov(edi, FieldOperand(edx, JSArray::kElementsOffset)); |
| 3838 | |
| 3839 | if (IsFastSmiOrObjectElementsKind(elements_kind())) { |
| 3840 | // Check that the elements are in fast mode and writable. |
| 3841 | __ cmp(FieldOperand(edi, HeapObject::kMapOffset), |
| 3842 | isolate->factory()->fixed_array_map()); |
| 3843 | __ j(not_equal, &call_builtin); |
| 3844 | } |
| 3845 | |
| 3846 | // Get the array's length into eax and calculate new length. |
| 3847 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 3848 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3849 | STATIC_ASSERT(kSmiTag == 0); |
| 3850 | __ add(eax, Immediate(Smi::FromInt(argc))); |
| 3851 | |
| 3852 | // Get the elements' length into ecx. |
| 3853 | __ mov(ecx, FieldOperand(edi, FixedArray::kLengthOffset)); |
| 3854 | |
| 3855 | // Check if we could survive without allocation. |
| 3856 | __ cmp(eax, ecx); |
| 3857 | |
| 3858 | if (IsFastSmiOrObjectElementsKind(elements_kind())) { |
| 3859 | __ j(greater, &attempt_to_grow_elements); |
| 3860 | |
| 3861 | // Check if value is a smi. |
| 3862 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 3863 | __ JumpIfNotSmi(ecx, &with_write_barrier); |
| 3864 | |
| 3865 | // Store the value. |
| 3866 | __ mov(FieldOperand(edi, eax, times_half_pointer_size, |
| 3867 | FixedArray::kHeaderSize - argc * kPointerSize), |
| 3868 | ecx); |
| 3869 | } else { |
| 3870 | __ j(greater, &call_builtin); |
| 3871 | |
| 3872 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 3873 | __ StoreNumberToDoubleElements( |
| 3874 | ecx, edi, eax, ecx, xmm0, &call_builtin, true, argc * kDoubleSize); |
| 3875 | } |
| 3876 | |
| 3877 | // Save new length. |
| 3878 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 3879 | __ ret((argc + 1) * kPointerSize); |
| 3880 | |
| 3881 | if (IsFastDoubleElementsKind(elements_kind())) { |
| 3882 | __ bind(&call_builtin); |
| 3883 | __ TailCallExternalReference( |
| 3884 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 3885 | return; |
| 3886 | } |
| 3887 | |
| 3888 | __ bind(&with_write_barrier); |
| 3889 | |
| 3890 | if (IsFastSmiElementsKind(elements_kind())) { |
| 3891 | if (FLAG_trace_elements_transitions) __ jmp(&call_builtin); |
| 3892 | |
| 3893 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 3894 | isolate->factory()->heap_number_map()); |
| 3895 | __ j(equal, &call_builtin); |
| 3896 | |
| 3897 | ElementsKind target_kind = IsHoleyElementsKind(elements_kind()) |
| 3898 | ? FAST_HOLEY_ELEMENTS : FAST_ELEMENTS; |
| 3899 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 3900 | __ mov(ebx, FieldOperand(ebx, GlobalObject::kNativeContextOffset)); |
| 3901 | __ mov(ebx, ContextOperand(ebx, Context::JS_ARRAY_MAPS_INDEX)); |
| 3902 | const int header_size = FixedArrayBase::kHeaderSize; |
| 3903 | // Verify that the object can be transitioned in place. |
| 3904 | const int origin_offset = header_size + elements_kind() * kPointerSize; |
| 3905 | __ mov(edi, FieldOperand(ebx, origin_offset)); |
| 3906 | __ cmp(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 3907 | __ j(not_equal, &call_builtin); |
| 3908 | |
| 3909 | const int target_offset = header_size + target_kind * kPointerSize; |
| 3910 | __ mov(ebx, FieldOperand(ebx, target_offset)); |
| 3911 | ElementsTransitionGenerator::GenerateMapChangeElementsTransition( |
| 3912 | masm, DONT_TRACK_ALLOCATION_SITE, NULL); |
| 3913 | // Restore edi used as a scratch register for the write barrier used while |
| 3914 | // setting the map. |
| 3915 | __ mov(edi, FieldOperand(edx, JSArray::kElementsOffset)); |
| 3916 | } |
| 3917 | |
| 3918 | // Save new length. |
| 3919 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 3920 | |
| 3921 | // Store the value. |
| 3922 | __ lea(edx, FieldOperand(edi, eax, times_half_pointer_size, |
| 3923 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 3924 | __ mov(Operand(edx, 0), ecx); |
| 3925 | |
| 3926 | __ RecordWrite(edi, edx, ecx, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
| 3927 | OMIT_SMI_CHECK); |
| 3928 | |
| 3929 | __ ret((argc + 1) * kPointerSize); |
| 3930 | |
| 3931 | __ bind(&attempt_to_grow_elements); |
| 3932 | if (!FLAG_inline_new) { |
| 3933 | __ bind(&call_builtin); |
| 3934 | __ TailCallExternalReference( |
| 3935 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 3936 | return; |
| 3937 | } |
| 3938 | |
| 3939 | __ mov(ebx, Operand(esp, argc * kPointerSize)); |
| 3940 | // Growing elements that are SMI-only requires special handling in case the |
| 3941 | // new element is non-Smi. For now, delegate to the builtin. |
| 3942 | if (IsFastSmiElementsKind(elements_kind())) { |
| 3943 | __ JumpIfNotSmi(ebx, &call_builtin); |
| 3944 | } |
| 3945 | |
| 3946 | // We could be lucky and the elements array could be at the top of new-space. |
| 3947 | // In this case we can just grow it in place by moving the allocation pointer |
| 3948 | // up. |
| 3949 | ExternalReference new_space_allocation_top = |
| 3950 | ExternalReference::new_space_allocation_top_address(isolate); |
| 3951 | ExternalReference new_space_allocation_limit = |
| 3952 | ExternalReference::new_space_allocation_limit_address(isolate); |
| 3953 | |
| 3954 | const int kAllocationDelta = 4; |
| 3955 | ASSERT(kAllocationDelta >= argc); |
| 3956 | // Load top. |
| 3957 | __ mov(ecx, Operand::StaticVariable(new_space_allocation_top)); |
| 3958 | |
| 3959 | // Check if it's the end of elements. |
| 3960 | __ lea(edx, FieldOperand(edi, eax, times_half_pointer_size, |
| 3961 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 3962 | __ cmp(edx, ecx); |
| 3963 | __ j(not_equal, &call_builtin); |
| 3964 | __ add(ecx, Immediate(kAllocationDelta * kPointerSize)); |
| 3965 | __ cmp(ecx, Operand::StaticVariable(new_space_allocation_limit)); |
| 3966 | __ j(above, &call_builtin); |
| 3967 | |
| 3968 | // We fit and could grow elements. |
| 3969 | __ mov(Operand::StaticVariable(new_space_allocation_top), ecx); |
| 3970 | |
| 3971 | // Push the argument... |
| 3972 | __ mov(Operand(edx, 0), ebx); |
| 3973 | // ... and fill the rest with holes. |
| 3974 | for (int i = 1; i < kAllocationDelta; i++) { |
| 3975 | __ mov(Operand(edx, i * kPointerSize), |
| 3976 | isolate->factory()->the_hole_value()); |
| 3977 | } |
| 3978 | |
| 3979 | if (IsFastObjectElementsKind(elements_kind())) { |
| 3980 | // We know the elements array is in new space so we don't need the |
| 3981 | // remembered set, but we just pushed a value onto it so we may have to tell |
| 3982 | // the incremental marker to rescan the object that we just grew. We don't |
| 3983 | // need to worry about the holes because they are in old space and already |
| 3984 | // marked black. |
| 3985 | __ RecordWrite(edi, edx, ebx, kDontSaveFPRegs, OMIT_REMEMBERED_SET); |
| 3986 | } |
| 3987 | |
| 3988 | // Restore receiver to edx as finish sequence assumes it's here. |
| 3989 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 3990 | |
| 3991 | // Increment element's and array's sizes. |
| 3992 | __ add(FieldOperand(edi, FixedArray::kLengthOffset), |
| 3993 | Immediate(Smi::FromInt(kAllocationDelta))); |
| 3994 | |
| 3995 | // NOTE: This only happen in new-space, where we don't care about the |
| 3996 | // black-byte-count on pages. Otherwise we should update that too if the |
| 3997 | // object is black. |
| 3998 | |
| 3999 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 4000 | __ ret((argc + 1) * kPointerSize); |
| 4001 | |
| 4002 | __ bind(&call_builtin); |
| 4003 | __ TailCallExternalReference( |
| 4004 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 4005 | } |
| 4006 | |
| 4007 | |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 4008 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 4009 | // ----------- S t a t e ------------- |
| 4010 | // -- edx : left |
| 4011 | // -- eax : right |
| 4012 | // -- esp[0] : return address |
| 4013 | // ----------------------------------- |
| 4014 | Isolate* isolate = masm->isolate(); |
| 4015 | |
| 4016 | // Load ecx with the allocation site. We stick an undefined dummy value here |
| 4017 | // and replace it with the real allocation site later when we instantiate this |
| 4018 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
| 4019 | __ mov(ecx, handle(isolate->heap()->undefined_value())); |
| 4020 | |
| 4021 | // Make sure that we actually patched the allocation site. |
| 4022 | if (FLAG_debug_code) { |
| 4023 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4024 | __ Assert(not_equal, kExpectedAllocationSite); |
| 4025 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 4026 | isolate->factory()->allocation_site_map()); |
| 4027 | __ Assert(equal, kExpectedAllocationSite); |
| 4028 | } |
| 4029 | |
| 4030 | // Tail call into the stub that handles binary operations with allocation |
| 4031 | // sites. |
| 4032 | BinaryOpWithAllocationSiteStub stub(state_); |
| 4033 | __ TailCallStub(&stub); |
| 4034 | } |
| 4035 | |
| 4036 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4037 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4038 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4039 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4040 | __ mov(ecx, edx); |
| 4041 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4042 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4043 | |
| 4044 | if (GetCondition() == equal) { |
| 4045 | // 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] | 4046 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4047 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4048 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4049 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4050 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4051 | // Correct sign of result in case of overflow. |
| 4052 | __ not_(edx); |
| 4053 | __ bind(&done); |
| 4054 | __ mov(eax, edx); |
| 4055 | } |
| 4056 | __ ret(0); |
| 4057 | |
| 4058 | __ bind(&miss); |
| 4059 | GenerateMiss(masm); |
| 4060 | } |
| 4061 | |
| 4062 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4063 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 4064 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4065 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4066 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4067 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4068 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4069 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4070 | if (left_ == CompareIC::SMI) { |
| 4071 | __ JumpIfNotSmi(edx, &miss); |
| 4072 | } |
| 4073 | if (right_ == CompareIC::SMI) { |
| 4074 | __ JumpIfNotSmi(eax, &miss); |
| 4075 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4076 | |
| 4077 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4078 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4079 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4080 | CpuFeatureScope scope1(masm, SSE2); |
| 4081 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4082 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4083 | // Load left and right operand. |
| 4084 | Label done, left, left_smi, right_smi; |
| 4085 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 4086 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 4087 | masm->isolate()->factory()->heap_number_map()); |
| 4088 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4089 | __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4090 | __ jmp(&left, Label::kNear); |
| 4091 | __ bind(&right_smi); |
| 4092 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 4093 | __ SmiUntag(ecx); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4094 | __ Cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4095 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4096 | __ bind(&left); |
| 4097 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 4098 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4099 | masm->isolate()->factory()->heap_number_map()); |
| 4100 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4101 | __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4102 | __ jmp(&done); |
| 4103 | __ bind(&left_smi); |
| 4104 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 4105 | __ SmiUntag(ecx); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4106 | __ Cvtsi2sd(xmm0, ecx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4107 | |
| 4108 | __ bind(&done); |
| 4109 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4110 | __ ucomisd(xmm0, xmm1); |
| 4111 | |
| 4112 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4113 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4114 | |
| 4115 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4116 | // Performing mov, because xor would destroy the flag register. |
| 4117 | __ mov(eax, 0); // equal |
| 4118 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4119 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4120 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4121 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4122 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4123 | } else { |
| 4124 | __ mov(ecx, edx); |
| 4125 | __ and_(ecx, eax); |
| 4126 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 4127 | |
| 4128 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 4129 | masm->isolate()->factory()->heap_number_map()); |
| 4130 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 4131 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4132 | masm->isolate()->factory()->heap_number_map()); |
| 4133 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4134 | } |
| 4135 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4136 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4137 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4138 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 4139 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4140 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4141 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4142 | __ bind(&maybe_undefined1); |
| 4143 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 4144 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 4145 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4146 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4147 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 4148 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 4149 | __ jmp(&unordered); |
| 4150 | } |
| 4151 | |
| 4152 | __ bind(&maybe_undefined2); |
| 4153 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 4154 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 4155 | __ j(equal, &unordered); |
| 4156 | } |
| 4157 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4158 | __ bind(&miss); |
| 4159 | GenerateMiss(masm); |
| 4160 | } |
| 4161 | |
| 4162 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4163 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 4164 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4165 | ASSERT(GetCondition() == equal); |
| 4166 | |
| 4167 | // Registers containing left and right operands respectively. |
| 4168 | Register left = edx; |
| 4169 | Register right = eax; |
| 4170 | Register tmp1 = ecx; |
| 4171 | Register tmp2 = ebx; |
| 4172 | |
| 4173 | // Check that both operands are heap objects. |
| 4174 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4175 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4176 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4177 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4178 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4179 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4180 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4181 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4182 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4183 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4184 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4185 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 4186 | __ or_(tmp1, tmp2); |
| 4187 | __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 4188 | __ j(not_zero, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4189 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4190 | // Internalized strings are compared by identity. |
| 4191 | Label done; |
| 4192 | __ cmp(left, right); |
| 4193 | // Make sure eax is non-zero. At this point input operands are |
| 4194 | // guaranteed to be non-zero. |
| 4195 | ASSERT(right.is(eax)); |
| 4196 | __ j(not_equal, &done, Label::kNear); |
| 4197 | STATIC_ASSERT(EQUAL == 0); |
| 4198 | STATIC_ASSERT(kSmiTag == 0); |
| 4199 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4200 | __ bind(&done); |
| 4201 | __ ret(0); |
| 4202 | |
| 4203 | __ bind(&miss); |
| 4204 | GenerateMiss(masm); |
| 4205 | } |
| 4206 | |
| 4207 | |
| 4208 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 4209 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 4210 | ASSERT(GetCondition() == equal); |
| 4211 | |
| 4212 | // Registers containing left and right operands respectively. |
| 4213 | Register left = edx; |
| 4214 | Register right = eax; |
| 4215 | Register tmp1 = ecx; |
| 4216 | Register tmp2 = ebx; |
| 4217 | |
| 4218 | // Check that both operands are heap objects. |
| 4219 | Label miss; |
| 4220 | __ mov(tmp1, left); |
| 4221 | STATIC_ASSERT(kSmiTag == 0); |
| 4222 | __ and_(tmp1, right); |
| 4223 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 4224 | |
| 4225 | // Check that both operands are unique names. This leaves the instance |
| 4226 | // types loaded in tmp1 and tmp2. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4227 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4228 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4229 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4230 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 4231 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4232 | __ JumpIfNotUniqueName(tmp1, &miss, Label::kNear); |
| 4233 | __ JumpIfNotUniqueName(tmp2, &miss, Label::kNear); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4234 | |
| 4235 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4236 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4237 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4238 | // Make sure eax is non-zero. At this point input operands are |
| 4239 | // guaranteed to be non-zero. |
| 4240 | ASSERT(right.is(eax)); |
| 4241 | __ j(not_equal, &done, Label::kNear); |
| 4242 | STATIC_ASSERT(EQUAL == 0); |
| 4243 | STATIC_ASSERT(kSmiTag == 0); |
| 4244 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4245 | __ bind(&done); |
| 4246 | __ ret(0); |
| 4247 | |
| 4248 | __ bind(&miss); |
| 4249 | GenerateMiss(masm); |
| 4250 | } |
| 4251 | |
| 4252 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4253 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4254 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4255 | Label miss; |
| 4256 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4257 | bool equality = Token::IsEqualityOp(op_); |
| 4258 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4259 | // Registers containing left and right operands respectively. |
| 4260 | Register left = edx; |
| 4261 | Register right = eax; |
| 4262 | Register tmp1 = ecx; |
| 4263 | Register tmp2 = ebx; |
| 4264 | Register tmp3 = edi; |
| 4265 | |
| 4266 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4267 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4268 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4269 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4270 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4271 | |
| 4272 | // Check that both operands are strings. This leaves the instance |
| 4273 | // types loaded in tmp1 and tmp2. |
| 4274 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4275 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4276 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4277 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 4278 | __ mov(tmp3, tmp1); |
| 4279 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4280 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4281 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 4282 | __ j(not_zero, &miss); |
| 4283 | |
| 4284 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4285 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4286 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4287 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4288 | STATIC_ASSERT(EQUAL == 0); |
| 4289 | STATIC_ASSERT(kSmiTag == 0); |
| 4290 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4291 | __ ret(0); |
| 4292 | |
| 4293 | // Handle not identical strings. |
| 4294 | __ bind(¬_same); |
| 4295 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4296 | // 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] | 4297 | // 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] | 4298 | // non-equality compare, we still need to determine the order. We |
| 4299 | // also know they are both strings. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4300 | if (equality) { |
| 4301 | Label do_compare; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4302 | STATIC_ASSERT(kInternalizedTag == 0); |
| 4303 | __ or_(tmp1, tmp2); |
| 4304 | __ test(tmp1, Immediate(kIsNotInternalizedMask)); |
| 4305 | __ j(not_zero, &do_compare, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4306 | // Make sure eax is non-zero. At this point input operands are |
| 4307 | // guaranteed to be non-zero. |
| 4308 | ASSERT(right.is(eax)); |
| 4309 | __ ret(0); |
| 4310 | __ bind(&do_compare); |
| 4311 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4312 | |
| 4313 | // Check that both strings are sequential ASCII. |
| 4314 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4315 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 4316 | |
| 4317 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4318 | if (equality) { |
| 4319 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 4320 | masm, left, right, tmp1, tmp2); |
| 4321 | } else { |
| 4322 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 4323 | masm, left, right, tmp1, tmp2, tmp3); |
| 4324 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4325 | |
| 4326 | // Handle more complex cases in runtime. |
| 4327 | __ bind(&runtime); |
| 4328 | __ pop(tmp1); // Return address. |
| 4329 | __ push(left); |
| 4330 | __ push(right); |
| 4331 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4332 | if (equality) { |
| 4333 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 4334 | } else { |
| 4335 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 4336 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4337 | |
| 4338 | __ bind(&miss); |
| 4339 | GenerateMiss(masm); |
| 4340 | } |
| 4341 | |
| 4342 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4343 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4344 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4345 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4346 | __ mov(ecx, edx); |
| 4347 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4348 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4349 | |
| 4350 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4351 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4352 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4353 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4354 | |
| 4355 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4356 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4357 | __ ret(0); |
| 4358 | |
| 4359 | __ bind(&miss); |
| 4360 | GenerateMiss(masm); |
| 4361 | } |
| 4362 | |
| 4363 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4364 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 4365 | Label miss; |
| 4366 | __ mov(ecx, edx); |
| 4367 | __ and_(ecx, eax); |
| 4368 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4369 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4370 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4371 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 4372 | __ cmp(ecx, known_map_); |
| 4373 | __ j(not_equal, &miss, Label::kNear); |
| 4374 | __ cmp(ebx, known_map_); |
| 4375 | __ j(not_equal, &miss, Label::kNear); |
| 4376 | |
| 4377 | __ sub(eax, edx); |
| 4378 | __ ret(0); |
| 4379 | |
| 4380 | __ bind(&miss); |
| 4381 | GenerateMiss(masm); |
| 4382 | } |
| 4383 | |
| 4384 | |
| 4385 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4386 | { |
| 4387 | // Call the runtime system in a fresh internal frame. |
| 4388 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 4389 | masm->isolate()); |
| 4390 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4391 | __ push(edx); // Preserve edx and eax. |
| 4392 | __ push(eax); |
| 4393 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4394 | __ push(eax); |
| 4395 | __ push(Immediate(Smi::FromInt(op_))); |
| 4396 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4397 | // Compute the entry point of the rewritten stub. |
| 4398 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 4399 | __ pop(eax); |
| 4400 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4401 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4402 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4403 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4404 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4405 | } |
| 4406 | |
| 4407 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4408 | // Helper function used to check that the dictionary doesn't contain |
| 4409 | // the property. This function may return false negatives, so miss_label |
| 4410 | // must always call a backup property check that is complete. |
| 4411 | // 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] | 4412 | // Name must be a unique name and receiver must be a heap object. |
| 4413 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 4414 | Label* miss, |
| 4415 | Label* done, |
| 4416 | Register properties, |
| 4417 | Handle<Name> name, |
| 4418 | Register r0) { |
| 4419 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4420 | |
| 4421 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 4422 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 4423 | // undefined value), it guarantees the hash table doesn't contain the |
| 4424 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4425 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4426 | for (int i = 0; i < kInlinedProbes; i++) { |
| 4427 | // Compute the masked index: (hash + i + i * i) & mask. |
| 4428 | Register index = r0; |
| 4429 | // Capacity is smi 2^n. |
| 4430 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 4431 | __ dec(index); |
| 4432 | __ and_(index, |
| 4433 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4434 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4435 | |
| 4436 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4437 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4438 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 4439 | Register entity_name = r0; |
| 4440 | // Having undefined at this place means the name is not contained. |
| 4441 | ASSERT_EQ(kSmiTagSize, 1); |
| 4442 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 4443 | kElementsStartOffset - kHeapObjectTag)); |
| 4444 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 4445 | __ j(equal, done); |
| 4446 | |
| 4447 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4448 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4449 | __ j(equal, miss); |
| 4450 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4451 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4452 | // Check for the hole and skip. |
| 4453 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4454 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4455 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4456 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4457 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4458 | __ JumpIfNotUniqueName(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 4459 | miss); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4460 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4461 | } |
| 4462 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4463 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4464 | __ push(Immediate(Handle<Object>(name))); |
| 4465 | __ push(Immediate(name->Hash())); |
| 4466 | __ CallStub(&stub); |
| 4467 | __ test(r0, r0); |
| 4468 | __ j(not_zero, miss); |
| 4469 | __ jmp(done); |
| 4470 | } |
| 4471 | |
| 4472 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4473 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4474 | // |done| label if a property with the given name is found leaving the |
| 4475 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 4476 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4477 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 4478 | Label* miss, |
| 4479 | Label* done, |
| 4480 | Register elements, |
| 4481 | Register name, |
| 4482 | Register r0, |
| 4483 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 4484 | ASSERT(!elements.is(r0)); |
| 4485 | ASSERT(!elements.is(r1)); |
| 4486 | ASSERT(!name.is(r0)); |
| 4487 | ASSERT(!name.is(r1)); |
| 4488 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4489 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4490 | |
| 4491 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 4492 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 4493 | __ dec(r1); |
| 4494 | |
| 4495 | // Generate an unrolled loop that performs a few probes before |
| 4496 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 4497 | // cover ~93% of loads from dictionaries. |
| 4498 | for (int i = 0; i < kInlinedProbes; i++) { |
| 4499 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4500 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 4501 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4502 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4503 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4504 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4505 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4506 | |
| 4507 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4508 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4509 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 4510 | |
| 4511 | // Check if the key is identical to the name. |
| 4512 | __ cmp(name, Operand(elements, |
| 4513 | r0, |
| 4514 | times_4, |
| 4515 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4516 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4517 | } |
| 4518 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4519 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4520 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4521 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 4522 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4523 | __ push(r0); |
| 4524 | __ CallStub(&stub); |
| 4525 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4526 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4527 | __ j(zero, miss); |
| 4528 | __ jmp(done); |
| 4529 | } |
| 4530 | |
| 4531 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4532 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4533 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 4534 | // 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] | 4535 | // Stack frame on entry: |
| 4536 | // esp[0 * kPointerSize]: return address. |
| 4537 | // esp[1 * kPointerSize]: key's hash. |
| 4538 | // esp[2 * kPointerSize]: key. |
| 4539 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4540 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4541 | // result_: used as scratch. |
| 4542 | // index_: will hold an index of entry if lookup is successful. |
| 4543 | // might alias with result_. |
| 4544 | // Returns: |
| 4545 | // result_ is zero if lookup failed, non zero otherwise. |
| 4546 | |
| 4547 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 4548 | |
| 4549 | Register scratch = result_; |
| 4550 | |
| 4551 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 4552 | __ dec(scratch); |
| 4553 | __ SmiUntag(scratch); |
| 4554 | __ push(scratch); |
| 4555 | |
| 4556 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 4557 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 4558 | // undefined value), it guarantees the hash table doesn't contain the |
| 4559 | // property. It's true even if some slots represent deleted properties |
| 4560 | // (their names are the null value). |
| 4561 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 4562 | // Compute the masked index: (hash + i + i * i) & mask. |
| 4563 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 4564 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4565 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4566 | } |
| 4567 | __ and_(scratch, Operand(esp, 0)); |
| 4568 | |
| 4569 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4570 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4571 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 4572 | |
| 4573 | // Having undefined at this place means the name is not contained. |
| 4574 | ASSERT_EQ(kSmiTagSize, 1); |
| 4575 | __ mov(scratch, Operand(dictionary_, |
| 4576 | index_, |
| 4577 | times_pointer_size, |
| 4578 | kElementsStartOffset - kHeapObjectTag)); |
| 4579 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 4580 | __ j(equal, ¬_in_dictionary); |
| 4581 | |
| 4582 | // Stop if found the property. |
| 4583 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 4584 | __ j(equal, &in_dictionary); |
| 4585 | |
| 4586 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4587 | // 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] | 4588 | // 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] | 4589 | // key we are looking for. |
| 4590 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4591 | // Check if the entry name is not a unique name. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4592 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4593 | __ JumpIfNotUniqueName(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 4594 | &maybe_in_dictionary); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4595 | } |
| 4596 | } |
| 4597 | |
| 4598 | __ bind(&maybe_in_dictionary); |
| 4599 | // If we are doing negative lookup then probing failure should be |
| 4600 | // treated as a lookup success. For positive lookup probing failure |
| 4601 | // should be treated as lookup failure. |
| 4602 | if (mode_ == POSITIVE_LOOKUP) { |
| 4603 | __ mov(result_, Immediate(0)); |
| 4604 | __ Drop(1); |
| 4605 | __ ret(2 * kPointerSize); |
| 4606 | } |
| 4607 | |
| 4608 | __ bind(&in_dictionary); |
| 4609 | __ mov(result_, Immediate(1)); |
| 4610 | __ Drop(1); |
| 4611 | __ ret(2 * kPointerSize); |
| 4612 | |
| 4613 | __ bind(¬_in_dictionary); |
| 4614 | __ mov(result_, Immediate(0)); |
| 4615 | __ Drop(1); |
| 4616 | __ ret(2 * kPointerSize); |
| 4617 | } |
| 4618 | |
| 4619 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4620 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 4621 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4622 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 4623 | stub.GetCode(isolate); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4624 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4625 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 4626 | stub2.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4627 | } |
| 4628 | } |
| 4629 | |
| 4630 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4631 | bool CodeStub::CanUseFPRegisters() { |
| 4632 | return CpuFeatures::IsSupported(SSE2); |
| 4633 | } |
| 4634 | |
| 4635 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4636 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 4637 | // the value has just been written into the object, now this stub makes sure |
| 4638 | // we keep the GC informed. The word in the object where the value has been |
| 4639 | // written is in the address register. |
| 4640 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 4641 | Label skip_to_incremental_noncompacting; |
| 4642 | Label skip_to_incremental_compacting; |
| 4643 | |
| 4644 | // The first two instructions are generated with labels so as to get the |
| 4645 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 4646 | // forth between a compare instructions (a nop in this position) and the |
| 4647 | // real branch when we start and stop incremental heap marking. |
| 4648 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 4649 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 4650 | |
| 4651 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 4652 | __ RememberedSetHelper(object_, |
| 4653 | address_, |
| 4654 | value_, |
| 4655 | save_fp_regs_mode_, |
| 4656 | MacroAssembler::kReturnAtEnd); |
| 4657 | } else { |
| 4658 | __ ret(0); |
| 4659 | } |
| 4660 | |
| 4661 | __ bind(&skip_to_incremental_noncompacting); |
| 4662 | GenerateIncremental(masm, INCREMENTAL); |
| 4663 | |
| 4664 | __ bind(&skip_to_incremental_compacting); |
| 4665 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 4666 | |
| 4667 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 4668 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 4669 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 4670 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 4671 | } |
| 4672 | |
| 4673 | |
| 4674 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 4675 | regs_.Save(masm); |
| 4676 | |
| 4677 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 4678 | Label dont_need_remembered_set; |
| 4679 | |
| 4680 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 4681 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 4682 | regs_.scratch0(), |
| 4683 | &dont_need_remembered_set); |
| 4684 | |
| 4685 | __ CheckPageFlag(regs_.object(), |
| 4686 | regs_.scratch0(), |
| 4687 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 4688 | not_zero, |
| 4689 | &dont_need_remembered_set); |
| 4690 | |
| 4691 | // First notify the incremental marker if necessary, then update the |
| 4692 | // remembered set. |
| 4693 | CheckNeedsToInformIncrementalMarker( |
| 4694 | masm, |
| 4695 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 4696 | mode); |
| 4697 | InformIncrementalMarker(masm, mode); |
| 4698 | regs_.Restore(masm); |
| 4699 | __ RememberedSetHelper(object_, |
| 4700 | address_, |
| 4701 | value_, |
| 4702 | save_fp_regs_mode_, |
| 4703 | MacroAssembler::kReturnAtEnd); |
| 4704 | |
| 4705 | __ bind(&dont_need_remembered_set); |
| 4706 | } |
| 4707 | |
| 4708 | CheckNeedsToInformIncrementalMarker( |
| 4709 | masm, |
| 4710 | kReturnOnNoNeedToInformIncrementalMarker, |
| 4711 | mode); |
| 4712 | InformIncrementalMarker(masm, mode); |
| 4713 | regs_.Restore(masm); |
| 4714 | __ ret(0); |
| 4715 | } |
| 4716 | |
| 4717 | |
| 4718 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 4719 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 4720 | int argument_count = 3; |
| 4721 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 4722 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 4723 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4724 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 4725 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4726 | |
| 4727 | AllowExternalCallThatCantCauseGC scope(masm); |
| 4728 | if (mode == INCREMENTAL_COMPACTION) { |
| 4729 | __ CallCFunction( |
| 4730 | ExternalReference::incremental_evacuation_record_write_function( |
| 4731 | masm->isolate()), |
| 4732 | argument_count); |
| 4733 | } else { |
| 4734 | ASSERT(mode == INCREMENTAL); |
| 4735 | __ CallCFunction( |
| 4736 | ExternalReference::incremental_marking_record_write_function( |
| 4737 | masm->isolate()), |
| 4738 | argument_count); |
| 4739 | } |
| 4740 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 4741 | } |
| 4742 | |
| 4743 | |
| 4744 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 4745 | MacroAssembler* masm, |
| 4746 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 4747 | Mode mode) { |
| 4748 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 4749 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 4750 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 4751 | __ and_(regs_.scratch0(), regs_.object()); |
| 4752 | __ mov(regs_.scratch1(), |
| 4753 | Operand(regs_.scratch0(), |
| 4754 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 4755 | __ sub(regs_.scratch1(), Immediate(1)); |
| 4756 | __ mov(Operand(regs_.scratch0(), |
| 4757 | MemoryChunk::kWriteBarrierCounterOffset), |
| 4758 | regs_.scratch1()); |
| 4759 | __ j(negative, &need_incremental); |
| 4760 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4761 | // Let's look at the color of the object: If it is not black we don't have |
| 4762 | // to inform the incremental marker. |
| 4763 | __ JumpIfBlack(regs_.object(), |
| 4764 | regs_.scratch0(), |
| 4765 | regs_.scratch1(), |
| 4766 | &object_is_black, |
| 4767 | Label::kNear); |
| 4768 | |
| 4769 | regs_.Restore(masm); |
| 4770 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 4771 | __ RememberedSetHelper(object_, |
| 4772 | address_, |
| 4773 | value_, |
| 4774 | save_fp_regs_mode_, |
| 4775 | MacroAssembler::kReturnAtEnd); |
| 4776 | } else { |
| 4777 | __ ret(0); |
| 4778 | } |
| 4779 | |
| 4780 | __ bind(&object_is_black); |
| 4781 | |
| 4782 | // Get the value from the slot. |
| 4783 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 4784 | |
| 4785 | if (mode == INCREMENTAL_COMPACTION) { |
| 4786 | Label ensure_not_white; |
| 4787 | |
| 4788 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 4789 | regs_.scratch1(), // Scratch. |
| 4790 | MemoryChunk::kEvacuationCandidateMask, |
| 4791 | zero, |
| 4792 | &ensure_not_white, |
| 4793 | Label::kNear); |
| 4794 | |
| 4795 | __ CheckPageFlag(regs_.object(), |
| 4796 | regs_.scratch1(), // Scratch. |
| 4797 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 4798 | not_zero, |
| 4799 | &ensure_not_white, |
| 4800 | Label::kNear); |
| 4801 | |
| 4802 | __ jmp(&need_incremental); |
| 4803 | |
| 4804 | __ bind(&ensure_not_white); |
| 4805 | } |
| 4806 | |
| 4807 | // We need an extra register for this, so we push the object register |
| 4808 | // temporarily. |
| 4809 | __ push(regs_.object()); |
| 4810 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 4811 | regs_.scratch1(), // Scratch. |
| 4812 | regs_.object(), // Scratch. |
| 4813 | &need_incremental_pop_object, |
| 4814 | Label::kNear); |
| 4815 | __ pop(regs_.object()); |
| 4816 | |
| 4817 | regs_.Restore(masm); |
| 4818 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 4819 | __ RememberedSetHelper(object_, |
| 4820 | address_, |
| 4821 | value_, |
| 4822 | save_fp_regs_mode_, |
| 4823 | MacroAssembler::kReturnAtEnd); |
| 4824 | } else { |
| 4825 | __ ret(0); |
| 4826 | } |
| 4827 | |
| 4828 | __ bind(&need_incremental_pop_object); |
| 4829 | __ pop(regs_.object()); |
| 4830 | |
| 4831 | __ bind(&need_incremental); |
| 4832 | |
| 4833 | // Fall through when we need to inform the incremental marker. |
| 4834 | } |
| 4835 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4836 | |
| 4837 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 4838 | // ----------- S t a t e ------------- |
| 4839 | // -- eax : element value to store |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4840 | // -- ecx : element index as smi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4841 | // -- esp[0] : return address |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 4842 | // -- esp[4] : array literal index in function |
| 4843 | // -- esp[8] : array literal |
| 4844 | // clobbers ebx, edx, edi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4845 | // ----------------------------------- |
| 4846 | |
| 4847 | Label element_done; |
| 4848 | Label double_elements; |
| 4849 | Label smi_element; |
| 4850 | Label slow_elements; |
| 4851 | Label slow_elements_from_double; |
| 4852 | Label fast_elements; |
| 4853 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 4854 | // Get array literal index, array literal and its map. |
| 4855 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 4856 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 4857 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 4858 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4859 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4860 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4861 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4862 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4863 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4864 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4865 | // Store into the array literal requires a elements transition. Call into |
| 4866 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4867 | |
| 4868 | __ bind(&slow_elements); |
| 4869 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 4870 | // call. |
| 4871 | __ push(ebx); |
| 4872 | __ push(ecx); |
| 4873 | __ push(eax); |
| 4874 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 4875 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 4876 | __ push(edx); |
| 4877 | __ push(edi); // Return return address so that tail call returns to right |
| 4878 | // place. |
| 4879 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 4880 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4881 | __ bind(&slow_elements_from_double); |
| 4882 | __ pop(edx); |
| 4883 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4884 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4885 | // 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] | 4886 | __ bind(&fast_elements); |
| 4887 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 4888 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 4889 | FixedArrayBase::kHeaderSize)); |
| 4890 | __ mov(Operand(ecx, 0), eax); |
| 4891 | // Update the write barrier for the array store. |
| 4892 | __ RecordWrite(ebx, ecx, eax, |
| 4893 | kDontSaveFPRegs, |
| 4894 | EMIT_REMEMBERED_SET, |
| 4895 | OMIT_SMI_CHECK); |
| 4896 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4897 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4898 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 4899 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4900 | __ bind(&smi_element); |
| 4901 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 4902 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 4903 | FixedArrayBase::kHeaderSize), eax); |
| 4904 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4905 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 4906 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4907 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4908 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 4909 | __ push(edx); |
| 4910 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 4911 | __ StoreNumberToDoubleElements(eax, |
| 4912 | edx, |
| 4913 | ecx, |
| 4914 | edi, |
| 4915 | xmm0, |
| 4916 | &slow_elements_from_double, |
| 4917 | false); |
| 4918 | __ pop(edx); |
| 4919 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 4920 | } |
| 4921 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4922 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 4923 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 4924 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4925 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 4926 | int parameter_count_offset = |
| 4927 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 4928 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 4929 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 4930 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 4931 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 4932 | ? kPointerSize |
| 4933 | : 0; |
| 4934 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 4935 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 4936 | } |
| 4937 | |
| 4938 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 4939 | void StubFailureTailCallTrampolineStub::Generate(MacroAssembler* masm) { |
| 4940 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
| 4941 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
| 4942 | __ mov(edi, eax); |
| 4943 | int parameter_count_offset = |
| 4944 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 4945 | __ mov(eax, MemOperand(ebp, parameter_count_offset)); |
| 4946 | // The parameter count above includes the receiver for the arguments passed to |
| 4947 | // the deoptimization handler. Subtract the receiver for the parameter count |
| 4948 | // for the call. |
| 4949 | __ sub(eax, Immediate(1)); |
| 4950 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 4951 | ParameterCount argument_count(eax); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 4952 | __ InvokeFunction(edi, argument_count, JUMP_FUNCTION, NullCallWrapper()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 4953 | } |
| 4954 | |
| 4955 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4956 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4957 | if (masm->isolate()->function_entry_hook() != NULL) { |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4958 | ProfileEntryHookStub stub; |
| 4959 | masm->CallStub(&stub); |
| 4960 | } |
| 4961 | } |
| 4962 | |
| 4963 | |
| 4964 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4965 | // Save volatile registers. |
| 4966 | const int kNumSavedRegisters = 3; |
| 4967 | __ push(eax); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4968 | __ push(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4969 | __ push(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4970 | |
| 4971 | // Calculate and push the original stack pointer. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4972 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4973 | __ push(eax); |
| 4974 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 4975 | // Retrieve our return address and use it to calculate the calling |
| 4976 | // function's address. |
| 4977 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4978 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 4979 | __ push(eax); |
| 4980 | |
| 4981 | // Call the entry hook. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4982 | ASSERT(masm->isolate()->function_entry_hook() != NULL); |
| 4983 | __ call(FUNCTION_ADDR(masm->isolate()->function_entry_hook()), |
| 4984 | RelocInfo::RUNTIME_ENTRY); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4985 | __ add(esp, Immediate(2 * kPointerSize)); |
| 4986 | |
| 4987 | // Restore ecx. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4988 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4989 | __ pop(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4990 | __ pop(eax); |
| 4991 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 4992 | __ ret(0); |
| 4993 | } |
| 4994 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 4995 | |
| 4996 | template<class T> |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 4997 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 4998 | AllocationSiteOverrideMode mode) { |
| 4999 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 5000 | T stub(GetInitialFastElementsKind(), |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5001 | mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5002 | __ TailCallStub(&stub); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5003 | } else if (mode == DONT_OVERRIDE) { |
| 5004 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 5005 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5006 | for (int i = 0; i <= last_index; ++i) { |
| 5007 | Label next; |
| 5008 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 5009 | __ cmp(edx, kind); |
| 5010 | __ j(not_equal, &next); |
| 5011 | T stub(kind); |
| 5012 | __ TailCallStub(&stub); |
| 5013 | __ bind(&next); |
| 5014 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5015 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5016 | // If we reached this point there is a problem. |
| 5017 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 5018 | } else { |
| 5019 | UNREACHABLE(); |
| 5020 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5021 | } |
| 5022 | |
| 5023 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5024 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 5025 | AllocationSiteOverrideMode mode) { |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5026 | // ebx - allocation site (if mode != DISABLE_ALLOCATION_SITES) |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5027 | // edx - kind (if mode != DISABLE_ALLOCATION_SITES) |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5028 | // eax - number of arguments |
| 5029 | // edi - constructor? |
| 5030 | // esp[0] - return address |
| 5031 | // esp[4] - last argument |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5032 | Label normal_sequence; |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5033 | if (mode == DONT_OVERRIDE) { |
| 5034 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 5035 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 5036 | ASSERT(FAST_ELEMENTS == 2); |
| 5037 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 5038 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 5039 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 5040 | |
| 5041 | // is the low bit set? If so, we are holey and that is good. |
| 5042 | __ test_b(edx, 1); |
| 5043 | __ j(not_zero, &normal_sequence); |
| 5044 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5045 | |
| 5046 | // look at the first argument |
| 5047 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 5048 | __ test(ecx, ecx); |
| 5049 | __ j(zero, &normal_sequence); |
| 5050 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5051 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 5052 | ElementsKind initial = GetInitialFastElementsKind(); |
| 5053 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5054 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5055 | ArraySingleArgumentConstructorStub stub_holey(holey_initial, |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5056 | DISABLE_ALLOCATION_SITES); |
| 5057 | __ TailCallStub(&stub_holey); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5058 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5059 | __ bind(&normal_sequence); |
| 5060 | ArraySingleArgumentConstructorStub stub(initial, |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5061 | DISABLE_ALLOCATION_SITES); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5062 | __ TailCallStub(&stub); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5063 | } else if (mode == DONT_OVERRIDE) { |
| 5064 | // We are going to create a holey array, but our kind is non-holey. |
| 5065 | // Fix kind and retry. |
| 5066 | __ inc(edx); |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5067 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5068 | if (FLAG_debug_code) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5069 | Handle<Map> allocation_site_map = |
| 5070 | masm->isolate()->factory()->allocation_site_map(); |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5071 | __ cmp(FieldOperand(ebx, 0), Immediate(allocation_site_map)); |
| 5072 | __ Assert(equal, kExpectedAllocationSite); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5073 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5074 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5075 | // Save the resulting elements kind in type info. We can't just store r3 |
| 5076 | // in the AllocationSite::transition_info field because elements kind is |
| 5077 | // restricted to a portion of the field...upper bits need to be left alone. |
| 5078 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5079 | __ add(FieldOperand(ebx, AllocationSite::kTransitionInfoOffset), |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5080 | Immediate(Smi::FromInt(kFastElementsKindPackedToHoley))); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5081 | |
| 5082 | __ bind(&normal_sequence); |
| 5083 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 5084 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5085 | for (int i = 0; i <= last_index; ++i) { |
| 5086 | Label next; |
| 5087 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 5088 | __ cmp(edx, kind); |
| 5089 | __ j(not_equal, &next); |
| 5090 | ArraySingleArgumentConstructorStub stub(kind); |
| 5091 | __ TailCallStub(&stub); |
| 5092 | __ bind(&next); |
| 5093 | } |
| 5094 | |
| 5095 | // If we reached this point there is a problem. |
| 5096 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 5097 | } else { |
| 5098 | UNREACHABLE(); |
| 5099 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5100 | } |
| 5101 | |
| 5102 | |
| 5103 | template<class T> |
| 5104 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 5105 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 5106 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5107 | for (int i = 0; i <= to_index; ++i) { |
| 5108 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5109 | T stub(kind); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5110 | stub.GetCode(isolate); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 5111 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 5112 | T stub1(kind, DISABLE_ALLOCATION_SITES); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5113 | stub1.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5114 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5115 | } |
| 5116 | } |
| 5117 | |
| 5118 | |
| 5119 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 5120 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 5121 | isolate); |
| 5122 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 5123 | isolate); |
| 5124 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 5125 | isolate); |
| 5126 | } |
| 5127 | |
| 5128 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5129 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 5130 | Isolate* isolate) { |
| 5131 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 5132 | for (int i = 0; i < 2; i++) { |
| 5133 | // For internal arrays we only need a few things |
| 5134 | InternalArrayNoArgumentConstructorStub stubh1(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5135 | stubh1.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5136 | InternalArraySingleArgumentConstructorStub stubh2(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5137 | stubh2.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5138 | InternalArrayNArgumentsConstructorStub stubh3(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5139 | stubh3.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5140 | } |
| 5141 | } |
| 5142 | |
| 5143 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5144 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 5145 | MacroAssembler* masm, |
| 5146 | AllocationSiteOverrideMode mode) { |
| 5147 | if (argument_count_ == ANY) { |
| 5148 | Label not_zero_case, not_one_case; |
| 5149 | __ test(eax, eax); |
| 5150 | __ j(not_zero, ¬_zero_case); |
| 5151 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 5152 | |
| 5153 | __ bind(¬_zero_case); |
| 5154 | __ cmp(eax, 1); |
| 5155 | __ j(greater, ¬_one_case); |
| 5156 | CreateArrayDispatchOneArgument(masm, mode); |
| 5157 | |
| 5158 | __ bind(¬_one_case); |
| 5159 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 5160 | } else if (argument_count_ == NONE) { |
| 5161 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 5162 | } else if (argument_count_ == ONE) { |
| 5163 | CreateArrayDispatchOneArgument(masm, mode); |
| 5164 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 5165 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 5166 | } else { |
| 5167 | UNREACHABLE(); |
| 5168 | } |
| 5169 | } |
| 5170 | |
| 5171 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5172 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 5173 | // ----------- S t a t e ------------- |
| 5174 | // -- eax : argc (only if argument_count_ == ANY) |
| 5175 | // -- ebx : type info cell |
| 5176 | // -- edi : constructor |
| 5177 | // -- esp[0] : return address |
| 5178 | // -- esp[4] : last argument |
| 5179 | // ----------------------------------- |
| 5180 | Handle<Object> undefined_sentinel( |
| 5181 | masm->isolate()->heap()->undefined_value(), |
| 5182 | masm->isolate()); |
| 5183 | |
| 5184 | if (FLAG_debug_code) { |
| 5185 | // The array construct code is only set for the global and natives |
| 5186 | // builtin Array functions which always have maps. |
| 5187 | |
| 5188 | // Initial map for the builtin Array function should be a map. |
| 5189 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5190 | // Will both indicate a NULL and a Smi. |
| 5191 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5192 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5193 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5194 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5195 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5196 | // We should either have undefined in ebx or a valid cell |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5197 | Label okay_here; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5198 | Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5199 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 5200 | __ j(equal, &okay_here); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5201 | __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5202 | __ Assert(equal, kExpectedPropertyCellInRegisterEbx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5203 | __ bind(&okay_here); |
| 5204 | } |
| 5205 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5206 | Label no_info; |
| 5207 | // If the type cell is undefined, or contains anything other than an |
| 5208 | // AllocationSite, call an array constructor that doesn't use AllocationSites. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5209 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 5210 | __ j(equal, &no_info); |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5211 | __ mov(ebx, FieldOperand(ebx, Cell::kValueOffset)); |
| 5212 | __ cmp(FieldOperand(ebx, 0), Immediate( |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5213 | masm->isolate()->factory()->allocation_site_map())); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 5214 | __ j(not_equal, &no_info); |
| 5215 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5216 | // Only look at the lower 16 bits of the transition info. |
machenbach@chromium.org | 6d26cbb | 2014-01-22 10:50:56 +0000 | [diff] [blame] | 5217 | __ mov(edx, FieldOperand(ebx, AllocationSite::kTransitionInfoOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5218 | __ SmiUntag(edx); |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5219 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 5220 | __ and_(edx, Immediate(AllocationSite::ElementsKindBits::kMask)); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5221 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 5222 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5223 | __ bind(&no_info); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5224 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5225 | } |
| 5226 | |
| 5227 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5228 | void InternalArrayConstructorStub::GenerateCase( |
| 5229 | MacroAssembler* masm, ElementsKind kind) { |
| 5230 | Label not_zero_case, not_one_case; |
| 5231 | Label normal_sequence; |
| 5232 | |
| 5233 | __ test(eax, eax); |
| 5234 | __ j(not_zero, ¬_zero_case); |
| 5235 | InternalArrayNoArgumentConstructorStub stub0(kind); |
| 5236 | __ TailCallStub(&stub0); |
| 5237 | |
| 5238 | __ bind(¬_zero_case); |
| 5239 | __ cmp(eax, 1); |
| 5240 | __ j(greater, ¬_one_case); |
| 5241 | |
| 5242 | if (IsFastPackedElementsKind(kind)) { |
| 5243 | // We might need to create a holey array |
| 5244 | // look at the first argument |
| 5245 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 5246 | __ test(ecx, ecx); |
| 5247 | __ j(zero, &normal_sequence); |
| 5248 | |
| 5249 | InternalArraySingleArgumentConstructorStub |
| 5250 | stub1_holey(GetHoleyElementsKind(kind)); |
| 5251 | __ TailCallStub(&stub1_holey); |
| 5252 | } |
| 5253 | |
| 5254 | __ bind(&normal_sequence); |
| 5255 | InternalArraySingleArgumentConstructorStub stub1(kind); |
| 5256 | __ TailCallStub(&stub1); |
| 5257 | |
| 5258 | __ bind(¬_one_case); |
| 5259 | InternalArrayNArgumentsConstructorStub stubN(kind); |
| 5260 | __ TailCallStub(&stubN); |
| 5261 | } |
| 5262 | |
| 5263 | |
| 5264 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 5265 | // ----------- S t a t e ------------- |
| 5266 | // -- eax : argc |
| 5267 | // -- ebx : type info cell |
| 5268 | // -- edi : constructor |
| 5269 | // -- esp[0] : return address |
| 5270 | // -- esp[4] : last argument |
| 5271 | // ----------------------------------- |
| 5272 | |
| 5273 | if (FLAG_debug_code) { |
| 5274 | // The array construct code is only set for the global and natives |
| 5275 | // builtin Array functions which always have maps. |
| 5276 | |
| 5277 | // Initial map for the builtin Array function should be a map. |
| 5278 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5279 | // Will both indicate a NULL and a Smi. |
| 5280 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5281 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5282 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5283 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5284 | } |
| 5285 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5286 | // Figure out the right elements kind |
| 5287 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5288 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5289 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 5290 | // but the following masking takes care of that anyway. |
| 5291 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 5292 | // Retrieve elements_kind from bit field 2. |
| 5293 | __ and_(ecx, Map::kElementsKindMask); |
| 5294 | __ shr(ecx, Map::kElementsKindShift); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5295 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5296 | if (FLAG_debug_code) { |
| 5297 | Label done; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5298 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5299 | __ j(equal, &done); |
| 5300 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 5301 | __ Assert(equal, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5302 | kInvalidElementsKindForInternalArrayOrInternalPackedArray); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5303 | __ bind(&done); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5304 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5305 | |
| 5306 | Label fast_elements_case; |
| 5307 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 5308 | __ j(equal, &fast_elements_case); |
| 5309 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 5310 | |
| 5311 | __ bind(&fast_elements_case); |
| 5312 | GenerateCase(masm, FAST_ELEMENTS); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5313 | } |
| 5314 | |
| 5315 | |
machenbach@chromium.org | e014e5b | 2014-01-28 07:51:38 +0000 | [diff] [blame] | 5316 | void CallApiFunctionStub::Generate(MacroAssembler* masm) { |
| 5317 | // ----------- S t a t e ------------- |
| 5318 | // -- eax : callee |
| 5319 | // -- ebx : call_data |
| 5320 | // -- ecx : holder |
| 5321 | // -- edx : api_function_address |
| 5322 | // -- esi : context |
| 5323 | // -- |
| 5324 | // -- esp[0] : return address |
| 5325 | // -- esp[4] : last argument |
| 5326 | // -- ... |
| 5327 | // -- esp[argc * 4] : first argument |
| 5328 | // -- esp[(argc + 1) * 4] : receiver |
| 5329 | // ----------------------------------- |
| 5330 | |
| 5331 | Register callee = eax; |
| 5332 | Register call_data = ebx; |
| 5333 | Register holder = ecx; |
| 5334 | Register api_function_address = edx; |
| 5335 | Register return_address = edi; |
| 5336 | Register context = esi; |
| 5337 | |
| 5338 | int argc = ArgumentBits::decode(bit_field_); |
| 5339 | bool restore_context = RestoreContextBits::decode(bit_field_); |
| 5340 | bool call_data_undefined = CallDataUndefinedBits::decode(bit_field_); |
| 5341 | |
| 5342 | typedef FunctionCallbackArguments FCA; |
| 5343 | |
| 5344 | STATIC_ASSERT(FCA::kContextSaveIndex == 6); |
| 5345 | STATIC_ASSERT(FCA::kCalleeIndex == 5); |
| 5346 | STATIC_ASSERT(FCA::kDataIndex == 4); |
| 5347 | STATIC_ASSERT(FCA::kReturnValueOffset == 3); |
| 5348 | STATIC_ASSERT(FCA::kReturnValueDefaultValueIndex == 2); |
| 5349 | STATIC_ASSERT(FCA::kIsolateIndex == 1); |
| 5350 | STATIC_ASSERT(FCA::kHolderIndex == 0); |
| 5351 | STATIC_ASSERT(FCA::kArgsLength == 7); |
| 5352 | |
| 5353 | Isolate* isolate = masm->isolate(); |
| 5354 | |
| 5355 | __ pop(return_address); |
| 5356 | |
| 5357 | // context save |
| 5358 | __ push(context); |
| 5359 | // load context from callee |
| 5360 | __ mov(context, FieldOperand(callee, JSFunction::kContextOffset)); |
| 5361 | |
| 5362 | // callee |
| 5363 | __ push(callee); |
| 5364 | |
| 5365 | // call data |
| 5366 | __ push(call_data); |
| 5367 | |
| 5368 | Register scratch = call_data; |
| 5369 | if (!call_data_undefined) { |
| 5370 | // return value |
| 5371 | __ push(Immediate(isolate->factory()->undefined_value())); |
| 5372 | // return value default |
| 5373 | __ push(Immediate(isolate->factory()->undefined_value())); |
| 5374 | } else { |
| 5375 | // return value |
| 5376 | __ push(scratch); |
| 5377 | // return value default |
| 5378 | __ push(scratch); |
| 5379 | } |
| 5380 | // isolate |
| 5381 | __ push(Immediate(reinterpret_cast<int>(isolate))); |
| 5382 | // holder |
| 5383 | __ push(holder); |
| 5384 | |
| 5385 | __ mov(scratch, esp); |
| 5386 | |
| 5387 | // return address |
| 5388 | __ push(return_address); |
| 5389 | |
| 5390 | // API function gets reference to the v8::Arguments. If CPU profiler |
| 5391 | // is enabled wrapper function will be called and we need to pass |
| 5392 | // address of the callback as additional parameter, always allocate |
| 5393 | // space for it. |
| 5394 | const int kApiArgc = 1 + 1; |
| 5395 | |
| 5396 | // Allocate the v8::Arguments structure in the arguments' space since |
| 5397 | // it's not controlled by GC. |
| 5398 | const int kApiStackSpace = 4; |
| 5399 | |
| 5400 | __ PrepareCallApiFunction(kApiArgc + kApiStackSpace); |
| 5401 | |
| 5402 | // FunctionCallbackInfo::implicit_args_. |
| 5403 | __ mov(ApiParameterOperand(2), scratch); |
| 5404 | __ add(scratch, Immediate((argc + FCA::kArgsLength - 1) * kPointerSize)); |
| 5405 | // FunctionCallbackInfo::values_. |
| 5406 | __ mov(ApiParameterOperand(3), scratch); |
| 5407 | // FunctionCallbackInfo::length_. |
| 5408 | __ Set(ApiParameterOperand(4), Immediate(argc)); |
| 5409 | // FunctionCallbackInfo::is_construct_call_. |
| 5410 | __ Set(ApiParameterOperand(5), Immediate(0)); |
| 5411 | |
| 5412 | // v8::InvocationCallback's argument. |
| 5413 | __ lea(scratch, ApiParameterOperand(2)); |
| 5414 | __ mov(ApiParameterOperand(0), scratch); |
| 5415 | |
| 5416 | Address thunk_address = FUNCTION_ADDR(&InvokeFunctionCallback); |
| 5417 | |
| 5418 | Operand context_restore_operand(ebp, |
| 5419 | (2 + FCA::kContextSaveIndex) * kPointerSize); |
| 5420 | Operand return_value_operand(ebp, |
| 5421 | (2 + FCA::kReturnValueOffset) * kPointerSize); |
| 5422 | __ CallApiFunctionAndReturn(api_function_address, |
| 5423 | thunk_address, |
| 5424 | ApiParameterOperand(1), |
| 5425 | argc + FCA::kArgsLength + 1, |
| 5426 | return_value_operand, |
| 5427 | restore_context ? |
| 5428 | &context_restore_operand : NULL); |
| 5429 | } |
| 5430 | |
| 5431 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5432 | #undef __ |
| 5433 | |
| 5434 | } } // namespace v8::internal |
| 5435 | |
| 5436 | #endif // V8_TARGET_ARCH_IA32 |