yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #include "v8.h" |
| 29 | |
jkummerow@chromium.org | 93a47f4 | 2013-07-02 14:43:41 +0000 | [diff] [blame] | 30 | #if V8_TARGET_ARCH_IA32 |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 31 | |
| 32 | #include "bootstrapper.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 33 | #include "code-stubs.h" |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 34 | #include "isolate.h" |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 35 | #include "jsregexp.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 36 | #include "regexp-macro-assembler.h" |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 37 | #include "runtime.h" |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 38 | #include "stub-cache.h" |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 39 | #include "codegen.h" |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 40 | #include "runtime.h" |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 41 | |
| 42 | namespace v8 { |
| 43 | namespace internal { |
| 44 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 45 | |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 46 | void FastNewClosureStub::InitializeInterfaceDescriptor( |
| 47 | Isolate* isolate, |
| 48 | CodeStubInterfaceDescriptor* descriptor) { |
| 49 | static Register registers[] = { ebx }; |
| 50 | descriptor->register_param_count_ = 1; |
| 51 | descriptor->register_params_ = registers; |
| 52 | descriptor->deoptimization_handler_ = |
| 53 | Runtime::FunctionForId(Runtime::kNewClosureFromStubFailure)->entry; |
| 54 | } |
| 55 | |
| 56 | |
yangguo@chromium.org | c73d55b | 2013-07-24 08:18:28 +0000 | [diff] [blame] | 57 | void ToNumberStub::InitializeInterfaceDescriptor( |
| 58 | Isolate* isolate, |
| 59 | CodeStubInterfaceDescriptor* descriptor) { |
| 60 | static Register registers[] = { eax }; |
| 61 | descriptor->register_param_count_ = 1; |
| 62 | descriptor->register_params_ = registers; |
| 63 | descriptor->deoptimization_handler_ = NULL; |
| 64 | } |
| 65 | |
| 66 | |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 67 | void NumberToStringStub::InitializeInterfaceDescriptor( |
| 68 | Isolate* isolate, |
| 69 | CodeStubInterfaceDescriptor* descriptor) { |
| 70 | static Register registers[] = { eax }; |
| 71 | descriptor->register_param_count_ = 1; |
| 72 | descriptor->register_params_ = registers; |
bmeurer@chromium.org | e7a0745 | 2013-10-21 13:27:29 +0000 | [diff] [blame] | 73 | descriptor->deoptimization_handler_ = |
| 74 | Runtime::FunctionForId(Runtime::kNumberToString)->entry; |
machenbach@chromium.org | 3d079fe | 2013-09-25 08:19:55 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 78 | void FastCloneShallowArrayStub::InitializeInterfaceDescriptor( |
| 79 | Isolate* isolate, |
| 80 | CodeStubInterfaceDescriptor* descriptor) { |
| 81 | static Register registers[] = { eax, ebx, ecx }; |
| 82 | descriptor->register_param_count_ = 3; |
| 83 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 84 | descriptor->deoptimization_handler_ = |
machenbach@chromium.org | 37be408 | 2013-11-26 13:50:38 +0000 | [diff] [blame] | 85 | Runtime::FunctionForId(Runtime::kCreateArrayLiteralStubBailout)->entry; |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 89 | void FastCloneShallowObjectStub::InitializeInterfaceDescriptor( |
| 90 | Isolate* isolate, |
| 91 | CodeStubInterfaceDescriptor* descriptor) { |
| 92 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 93 | descriptor->register_param_count_ = 4; |
| 94 | descriptor->register_params_ = registers; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 95 | descriptor->deoptimization_handler_ = |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 96 | Runtime::FunctionForId(Runtime::kCreateObjectLiteral)->entry; |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 100 | void CreateAllocationSiteStub::InitializeInterfaceDescriptor( |
| 101 | Isolate* isolate, |
| 102 | CodeStubInterfaceDescriptor* descriptor) { |
| 103 | static Register registers[] = { ebx }; |
| 104 | descriptor->register_param_count_ = 1; |
| 105 | descriptor->register_params_ = registers; |
| 106 | descriptor->deoptimization_handler_ = NULL; |
| 107 | } |
| 108 | |
| 109 | |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 110 | void KeyedLoadFastElementStub::InitializeInterfaceDescriptor( |
| 111 | Isolate* isolate, |
| 112 | CodeStubInterfaceDescriptor* descriptor) { |
| 113 | static Register registers[] = { edx, ecx }; |
| 114 | descriptor->register_param_count_ = 2; |
| 115 | descriptor->register_params_ = registers; |
| 116 | descriptor->deoptimization_handler_ = |
mstarzinger@chromium.org | e3b8d0f | 2013-02-01 09:06:41 +0000 | [diff] [blame] | 117 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 121 | void KeyedLoadDictionaryElementStub::InitializeInterfaceDescriptor( |
| 122 | Isolate* isolate, |
| 123 | CodeStubInterfaceDescriptor* descriptor) { |
| 124 | static Register registers[] = { edx, ecx }; |
| 125 | descriptor->register_param_count_ = 2; |
| 126 | descriptor->register_params_ = registers; |
| 127 | descriptor->deoptimization_handler_ = |
| 128 | FUNCTION_ADDR(KeyedLoadIC_MissFromStubFailure); |
| 129 | } |
| 130 | |
| 131 | |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 132 | void LoadFieldStub::InitializeInterfaceDescriptor( |
| 133 | Isolate* isolate, |
| 134 | CodeStubInterfaceDescriptor* descriptor) { |
| 135 | static Register registers[] = { edx }; |
| 136 | descriptor->register_param_count_ = 1; |
| 137 | descriptor->register_params_ = registers; |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 138 | descriptor->deoptimization_handler_ = NULL; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | void KeyedLoadFieldStub::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 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 152 | void KeyedArrayCallStub::InitializeInterfaceDescriptor( |
| 153 | Isolate* isolate, |
| 154 | CodeStubInterfaceDescriptor* descriptor) { |
| 155 | static Register registers[] = { ecx }; |
| 156 | descriptor->register_param_count_ = 1; |
| 157 | descriptor->register_params_ = registers; |
| 158 | descriptor->continuation_type_ = TAIL_CALL_CONTINUATION; |
| 159 | descriptor->handler_arguments_mode_ = PASS_ARGUMENTS; |
| 160 | descriptor->deoptimization_handler_ = |
| 161 | FUNCTION_ADDR(KeyedCallIC_MissFromStubFailure); |
| 162 | } |
| 163 | |
| 164 | |
jkummerow@chromium.org | 7bd87f0 | 2013-03-20 18:06:29 +0000 | [diff] [blame] | 165 | void KeyedStoreFastElementStub::InitializeInterfaceDescriptor( |
| 166 | Isolate* isolate, |
| 167 | CodeStubInterfaceDescriptor* descriptor) { |
| 168 | static Register registers[] = { edx, ecx, eax }; |
| 169 | descriptor->register_param_count_ = 3; |
| 170 | descriptor->register_params_ = registers; |
| 171 | descriptor->deoptimization_handler_ = |
| 172 | FUNCTION_ADDR(KeyedStoreIC_MissFromStubFailure); |
| 173 | } |
| 174 | |
| 175 | |
danno@chromium.org | 94b0d6f | 2013-02-04 13:33:20 +0000 | [diff] [blame] | 176 | void TransitionElementsKindStub::InitializeInterfaceDescriptor( |
| 177 | Isolate* isolate, |
| 178 | CodeStubInterfaceDescriptor* descriptor) { |
| 179 | static Register registers[] = { eax, ebx }; |
| 180 | descriptor->register_param_count_ = 2; |
| 181 | descriptor->register_params_ = registers; |
| 182 | descriptor->deoptimization_handler_ = |
| 183 | Runtime::FunctionForId(Runtime::kTransitionElementsKind)->entry; |
| 184 | } |
| 185 | |
| 186 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 187 | static void InitializeArrayConstructorDescriptor( |
| 188 | Isolate* isolate, |
| 189 | CodeStubInterfaceDescriptor* descriptor, |
| 190 | int constant_stack_parameter_count) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 191 | // register state |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 192 | // eax -- number of arguments |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 193 | // edi -- function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 194 | // ebx -- type info cell with elements kind |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 195 | static Register registers_variable_args[] = { edi, ebx, eax }; |
| 196 | static Register registers_no_args[] = { edi, ebx }; |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 197 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 198 | if (constant_stack_parameter_count == 0) { |
| 199 | descriptor->register_param_count_ = 2; |
| 200 | descriptor->register_params_ = registers_no_args; |
| 201 | } else { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 202 | // stack param count needs (constructor pointer, and single argument) |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 203 | descriptor->handler_arguments_mode_ = PASS_ARGUMENTS; |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 204 | descriptor->stack_parameter_count_ = eax; |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 205 | descriptor->register_param_count_ = 3; |
| 206 | descriptor->register_params_ = registers_variable_args; |
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 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 209 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 210 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 211 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 212 | Runtime::FunctionForId(Runtime::kArrayConstructor)->entry; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 216 | static void InitializeInternalArrayConstructorDescriptor( |
| 217 | Isolate* isolate, |
| 218 | CodeStubInterfaceDescriptor* descriptor, |
| 219 | int constant_stack_parameter_count) { |
| 220 | // register state |
| 221 | // eax -- number of arguments |
| 222 | // edi -- constructor function |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 223 | static Register registers_variable_args[] = { edi, eax }; |
| 224 | static Register registers_no_args[] = { edi }; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 225 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 226 | if (constant_stack_parameter_count == 0) { |
| 227 | descriptor->register_param_count_ = 1; |
| 228 | descriptor->register_params_ = registers_no_args; |
| 229 | } else { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 230 | // stack param count needs (constructor pointer, and single argument) |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 231 | descriptor->handler_arguments_mode_ = PASS_ARGUMENTS; |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 232 | descriptor->stack_parameter_count_ = eax; |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 233 | descriptor->register_param_count_ = 2; |
| 234 | descriptor->register_params_ = registers_variable_args; |
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 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 237 | descriptor->hint_stack_parameter_count_ = constant_stack_parameter_count; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 238 | descriptor->function_mode_ = JS_FUNCTION_STUB_MODE; |
| 239 | descriptor->deoptimization_handler_ = |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 240 | Runtime::FunctionForId(Runtime::kInternalArrayConstructor)->entry; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 244 | void ArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 245 | Isolate* isolate, |
| 246 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 247 | InitializeArrayConstructorDescriptor(isolate, descriptor, 0); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | |
| 251 | void ArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 252 | Isolate* isolate, |
| 253 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 254 | InitializeArrayConstructorDescriptor(isolate, descriptor, 1); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | |
| 258 | void ArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 259 | Isolate* isolate, |
| 260 | CodeStubInterfaceDescriptor* descriptor) { |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 261 | InitializeArrayConstructorDescriptor(isolate, descriptor, -1); |
| 262 | } |
| 263 | |
| 264 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 265 | void InternalArrayNoArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 266 | Isolate* isolate, |
| 267 | CodeStubInterfaceDescriptor* descriptor) { |
| 268 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 0); |
| 269 | } |
| 270 | |
| 271 | |
| 272 | void InternalArraySingleArgumentConstructorStub::InitializeInterfaceDescriptor( |
| 273 | Isolate* isolate, |
| 274 | CodeStubInterfaceDescriptor* descriptor) { |
| 275 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, 1); |
| 276 | } |
| 277 | |
| 278 | |
| 279 | void InternalArrayNArgumentsConstructorStub::InitializeInterfaceDescriptor( |
| 280 | Isolate* isolate, |
| 281 | CodeStubInterfaceDescriptor* descriptor) { |
| 282 | InitializeInternalArrayConstructorDescriptor(isolate, descriptor, -1); |
| 283 | } |
| 284 | |
| 285 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 286 | void CompareNilICStub::InitializeInterfaceDescriptor( |
| 287 | Isolate* isolate, |
| 288 | CodeStubInterfaceDescriptor* descriptor) { |
| 289 | static Register registers[] = { eax }; |
| 290 | descriptor->register_param_count_ = 1; |
| 291 | descriptor->register_params_ = registers; |
| 292 | descriptor->deoptimization_handler_ = |
| 293 | FUNCTION_ADDR(CompareNilIC_Miss); |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 294 | descriptor->SetMissHandler( |
| 295 | ExternalReference(IC_Utility(IC::kCompareNilIC_Miss), isolate)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 296 | } |
| 297 | |
rossberg@chromium.org | b99c754 | 2013-05-31 11:40:45 +0000 | [diff] [blame] | 298 | void ToBooleanStub::InitializeInterfaceDescriptor( |
| 299 | Isolate* isolate, |
| 300 | CodeStubInterfaceDescriptor* descriptor) { |
| 301 | static Register registers[] = { eax }; |
| 302 | descriptor->register_param_count_ = 1; |
| 303 | descriptor->register_params_ = registers; |
| 304 | descriptor->deoptimization_handler_ = |
| 305 | FUNCTION_ADDR(ToBooleanIC_Miss); |
| 306 | descriptor->SetMissHandler( |
| 307 | ExternalReference(IC_Utility(IC::kToBooleanIC_Miss), isolate)); |
| 308 | } |
| 309 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 310 | |
mstarzinger@chromium.org | e0e1b0d | 2013-07-08 08:38:06 +0000 | [diff] [blame] | 311 | void StoreGlobalStub::InitializeInterfaceDescriptor( |
| 312 | Isolate* isolate, |
| 313 | CodeStubInterfaceDescriptor* descriptor) { |
| 314 | static Register registers[] = { edx, ecx, eax }; |
| 315 | descriptor->register_param_count_ = 3; |
| 316 | descriptor->register_params_ = registers; |
| 317 | descriptor->deoptimization_handler_ = |
| 318 | FUNCTION_ADDR(StoreIC_MissFromStubFailure); |
| 319 | } |
| 320 | |
| 321 | |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 322 | void ElementsTransitionAndStoreStub::InitializeInterfaceDescriptor( |
| 323 | Isolate* isolate, |
| 324 | CodeStubInterfaceDescriptor* descriptor) { |
| 325 | static Register registers[] = { eax, ebx, ecx, edx }; |
| 326 | descriptor->register_param_count_ = 4; |
| 327 | descriptor->register_params_ = registers; |
| 328 | descriptor->deoptimization_handler_ = |
| 329 | FUNCTION_ADDR(ElementsTransitionAndStoreIC_Miss); |
| 330 | } |
| 331 | |
| 332 | |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 333 | void BinaryOpICStub::InitializeInterfaceDescriptor( |
jkummerow@chromium.org | 25b0e21 | 2013-10-04 15:38:52 +0000 | [diff] [blame] | 334 | Isolate* isolate, |
| 335 | CodeStubInterfaceDescriptor* descriptor) { |
| 336 | static Register registers[] = { edx, eax }; |
| 337 | descriptor->register_param_count_ = 2; |
| 338 | descriptor->register_params_ = registers; |
| 339 | descriptor->deoptimization_handler_ = FUNCTION_ADDR(BinaryOpIC_Miss); |
| 340 | descriptor->SetMissHandler( |
| 341 | ExternalReference(IC_Utility(IC::kBinaryOpIC_Miss), isolate)); |
| 342 | } |
| 343 | |
| 344 | |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 345 | void BinaryOpWithAllocationSiteStub::InitializeInterfaceDescriptor( |
| 346 | Isolate* isolate, |
| 347 | CodeStubInterfaceDescriptor* descriptor) { |
| 348 | static Register registers[] = { ecx, edx, eax }; |
| 349 | descriptor->register_param_count_ = 3; |
| 350 | descriptor->register_params_ = registers; |
| 351 | descriptor->deoptimization_handler_ = |
| 352 | FUNCTION_ADDR(BinaryOpIC_MissWithAllocationSite); |
| 353 | } |
| 354 | |
| 355 | |
machenbach@chromium.org | 0cc0950 | 2013-11-13 12:20:55 +0000 | [diff] [blame] | 356 | void NewStringAddStub::InitializeInterfaceDescriptor( |
| 357 | Isolate* isolate, |
| 358 | CodeStubInterfaceDescriptor* descriptor) { |
| 359 | static Register registers[] = { edx, eax }; |
| 360 | descriptor->register_param_count_ = 2; |
| 361 | descriptor->register_params_ = registers; |
| 362 | descriptor->deoptimization_handler_ = |
| 363 | Runtime::FunctionForId(Runtime::kStringAdd)->entry; |
| 364 | } |
| 365 | |
| 366 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 367 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 368 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 369 | |
| 370 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
| 371 | // Update the static counter each time a new code stub is generated. |
| 372 | Isolate* isolate = masm->isolate(); |
| 373 | isolate->counters()->code_stubs()->Increment(); |
| 374 | |
| 375 | CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
| 376 | int param_count = descriptor->register_param_count_; |
| 377 | { |
| 378 | // Call the runtime system in a fresh internal frame. |
| 379 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 380 | ASSERT(descriptor->register_param_count_ == 0 || |
| 381 | eax.is(descriptor->register_params_[param_count - 1])); |
| 382 | // Push arguments |
| 383 | for (int i = 0; i < param_count; ++i) { |
| 384 | __ push(descriptor->register_params_[i]); |
| 385 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 386 | ExternalReference miss = descriptor->miss_handler(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 387 | __ CallExternalReference(miss, descriptor->register_param_count_); |
| 388 | } |
| 389 | |
| 390 | __ ret(0); |
| 391 | } |
| 392 | |
| 393 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 394 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 395 | // Try to allocate the context in new space. |
| 396 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 397 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 398 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 399 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 400 | |
| 401 | // Get the function from the stack. |
| 402 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 403 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 404 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 405 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 406 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 407 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 408 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 409 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 410 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 411 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 412 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 413 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 414 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 415 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 416 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 417 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 418 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 419 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 420 | |
| 421 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 422 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 423 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 424 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 425 | } |
| 426 | |
| 427 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 428 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 429 | __ ret(1 * kPointerSize); |
| 430 | |
| 431 | // Need to collect. Call into runtime system. |
| 432 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 433 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 437 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 438 | // Stack layout on entry: |
| 439 | // |
| 440 | // [esp + (1 * kPointerSize)]: function |
| 441 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 442 | |
| 443 | // Try to allocate the context in new space. |
| 444 | Label gc; |
| 445 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 446 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 447 | |
| 448 | // Get the function or sentinel from the stack. |
| 449 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 450 | |
| 451 | // Get the serialized scope info from the stack. |
| 452 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 453 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 454 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 455 | Factory* factory = masm->isolate()->factory(); |
| 456 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 457 | factory->block_context_map()); |
| 458 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 459 | Immediate(Smi::FromInt(length))); |
| 460 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 461 | // If this block context is nested in the native context we get a smi |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 462 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 463 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 464 | // we still have to look up. |
| 465 | Label after_sentinel; |
| 466 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 467 | if (FLAG_debug_code) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 468 | __ cmp(ecx, 0); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 469 | __ Assert(equal, kExpected0AsASmiSentinel); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 470 | } |
| 471 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 472 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 473 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 474 | __ bind(&after_sentinel); |
| 475 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 476 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 477 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 478 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 479 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 480 | |
| 481 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 482 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 483 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 484 | |
| 485 | // Initialize the rest of the slots to the hole value. |
| 486 | if (slots_ == 1) { |
| 487 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 488 | factory->the_hole_value()); |
| 489 | } else { |
| 490 | __ mov(ebx, factory->the_hole_value()); |
| 491 | for (int i = 0; i < slots_; i++) { |
| 492 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | // Return and remove the on-stack parameters. |
| 497 | __ mov(esi, eax); |
| 498 | __ ret(2 * kPointerSize); |
| 499 | |
| 500 | // Need to collect. Call into runtime system. |
| 501 | __ bind(&gc); |
| 502 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 503 | } |
| 504 | |
| 505 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 506 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 507 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 508 | // store the registers in any particular way, but we do have to store and |
| 509 | // restore them. |
| 510 | __ pushad(); |
| 511 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 512 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 513 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 514 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 515 | XMMRegister reg = XMMRegister::from_code(i); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 516 | __ movsd(Operand(esp, i * kDoubleSize), reg); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | const int argument_count = 1; |
| 520 | |
| 521 | AllowExternalCallThatCantCauseGC scope(masm); |
| 522 | __ PrepareCallCFunction(argument_count, ecx); |
| 523 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 524 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 525 | __ CallCFunction( |
| 526 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 527 | argument_count); |
| 528 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 529 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 530 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 531 | XMMRegister reg = XMMRegister::from_code(i); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 532 | __ movsd(reg, Operand(esp, i * kDoubleSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 533 | } |
| 534 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 535 | } |
| 536 | __ popad(); |
| 537 | __ ret(0); |
| 538 | } |
| 539 | |
| 540 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 541 | class FloatingPointHelper : public AllStatic { |
| 542 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 543 | enum ArgLocation { |
| 544 | ARGS_ON_STACK, |
| 545 | ARGS_IN_REGISTERS |
| 546 | }; |
| 547 | |
| 548 | // Code pattern for loading a floating point value. Input value must |
| 549 | // be either a smi or a heap number object (fp value). Requirements: |
| 550 | // operand in register number. Returns operand as floating point number |
| 551 | // on FPU stack. |
| 552 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 553 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 554 | // Test if operands are smi or number objects (fp). Requirements: |
| 555 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 556 | // operands, jumps to the non_float label otherwise. |
| 557 | static void CheckFloatOperands(MacroAssembler* masm, |
| 558 | Label* non_float, |
| 559 | Register scratch); |
| 560 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 561 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 562 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 563 | // either operand is not a number. Operands are in edx and eax. |
| 564 | // Leaves operands unchanged. |
| 565 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 566 | }; |
| 567 | |
| 568 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 569 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 570 | Register input_reg = this->source(); |
| 571 | Register final_result_reg = this->destination(); |
| 572 | ASSERT(is_truncating()); |
| 573 | |
| 574 | Label check_negative, process_64_bits, done, done_no_stash; |
| 575 | |
| 576 | int double_offset = offset(); |
| 577 | |
| 578 | // Account for return address and saved regs if input is esp. |
| 579 | if (input_reg.is(esp)) double_offset += 3 * kPointerSize; |
| 580 | |
| 581 | MemOperand mantissa_operand(MemOperand(input_reg, double_offset)); |
| 582 | MemOperand exponent_operand(MemOperand(input_reg, |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 583 | double_offset + kDoubleSize / 2)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 584 | |
| 585 | Register scratch1; |
| 586 | { |
| 587 | Register scratch_candidates[3] = { ebx, edx, edi }; |
| 588 | for (int i = 0; i < 3; i++) { |
| 589 | scratch1 = scratch_candidates[i]; |
| 590 | if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break; |
| 591 | } |
| 592 | } |
| 593 | // Since we must use ecx for shifts below, use some other register (eax) |
| 594 | // to calculate the result if ecx is the requested return register. |
| 595 | Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg; |
| 596 | // Save ecx if it isn't the return register and therefore volatile, or if it |
| 597 | // is the return register, then save the temp register we use in its stead for |
| 598 | // the result. |
| 599 | Register save_reg = final_result_reg.is(ecx) ? eax : ecx; |
| 600 | __ push(scratch1); |
| 601 | __ push(save_reg); |
| 602 | |
| 603 | bool stash_exponent_copy = !input_reg.is(esp); |
| 604 | __ mov(scratch1, mantissa_operand); |
| 605 | if (CpuFeatures::IsSupported(SSE3)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 606 | CpuFeatureScope scope(masm, SSE3); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 607 | // Load x87 register with heap number. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 608 | __ fld_d(mantissa_operand); |
| 609 | } |
| 610 | __ mov(ecx, exponent_operand); |
| 611 | if (stash_exponent_copy) __ push(ecx); |
| 612 | |
| 613 | __ and_(ecx, HeapNumber::kExponentMask); |
| 614 | __ shr(ecx, HeapNumber::kExponentShift); |
| 615 | __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias)); |
| 616 | __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits)); |
| 617 | __ j(below, &process_64_bits); |
| 618 | |
| 619 | // Result is entirely in lower 32-bits of mantissa |
| 620 | int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize; |
| 621 | if (CpuFeatures::IsSupported(SSE3)) { |
| 622 | __ fstp(0); |
| 623 | } |
| 624 | __ sub(ecx, Immediate(delta)); |
| 625 | __ xor_(result_reg, result_reg); |
| 626 | __ cmp(ecx, Immediate(31)); |
| 627 | __ j(above, &done); |
| 628 | __ shl_cl(scratch1); |
| 629 | __ jmp(&check_negative); |
| 630 | |
| 631 | __ bind(&process_64_bits); |
| 632 | if (CpuFeatures::IsSupported(SSE3)) { |
| 633 | CpuFeatureScope scope(masm, SSE3); |
| 634 | if (stash_exponent_copy) { |
| 635 | // Already a copy of the exponent on the stack, overwrite it. |
| 636 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 637 | __ sub(esp, Immediate(kDoubleSize / 2)); |
| 638 | } else { |
| 639 | // Reserve space for 64 bit answer. |
| 640 | __ sub(esp, Immediate(kDoubleSize)); // Nolint. |
| 641 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 642 | // Do conversion, which cannot fail because we checked the exponent. |
| 643 | __ fisttp_d(Operand(esp, 0)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 644 | __ mov(result_reg, Operand(esp, 0)); // Load low word of answer as result |
| 645 | __ add(esp, Immediate(kDoubleSize)); |
| 646 | __ jmp(&done_no_stash); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 647 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 648 | // Result must be extracted from shifted 32-bit mantissa |
| 649 | __ sub(ecx, Immediate(delta)); |
| 650 | __ neg(ecx); |
| 651 | if (stash_exponent_copy) { |
| 652 | __ mov(result_reg, MemOperand(esp, 0)); |
| 653 | } else { |
| 654 | __ mov(result_reg, exponent_operand); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 655 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 656 | __ and_(result_reg, |
| 657 | Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32))); |
| 658 | __ add(result_reg, |
| 659 | Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32))); |
| 660 | __ shrd(result_reg, scratch1); |
| 661 | __ shr_cl(result_reg); |
| 662 | __ test(ecx, Immediate(32)); |
| 663 | if (CpuFeatures::IsSupported(CMOV)) { |
| 664 | CpuFeatureScope use_cmov(masm, CMOV); |
| 665 | __ cmov(not_equal, scratch1, result_reg); |
| 666 | } else { |
| 667 | Label skip_mov; |
| 668 | __ j(equal, &skip_mov, Label::kNear); |
| 669 | __ mov(scratch1, result_reg); |
| 670 | __ bind(&skip_mov); |
| 671 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 672 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 673 | |
| 674 | // If the double was negative, negate the integer result. |
| 675 | __ bind(&check_negative); |
| 676 | __ mov(result_reg, scratch1); |
| 677 | __ neg(result_reg); |
| 678 | if (stash_exponent_copy) { |
| 679 | __ cmp(MemOperand(esp, 0), Immediate(0)); |
| 680 | } else { |
| 681 | __ cmp(exponent_operand, Immediate(0)); |
| 682 | } |
| 683 | if (CpuFeatures::IsSupported(CMOV)) { |
| 684 | CpuFeatureScope use_cmov(masm, CMOV); |
| 685 | __ cmov(greater, result_reg, scratch1); |
| 686 | } else { |
| 687 | Label skip_mov; |
| 688 | __ j(less_equal, &skip_mov, Label::kNear); |
| 689 | __ mov(result_reg, scratch1); |
| 690 | __ bind(&skip_mov); |
| 691 | } |
| 692 | |
| 693 | // Restore registers |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 694 | __ bind(&done); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 695 | if (stash_exponent_copy) { |
| 696 | __ add(esp, Immediate(kDoubleSize / 2)); |
| 697 | } |
| 698 | __ bind(&done_no_stash); |
| 699 | if (!final_result_reg.is(result_reg)) { |
| 700 | ASSERT(final_result_reg.is(ecx)); |
| 701 | __ mov(final_result_reg, result_reg); |
| 702 | } |
| 703 | __ pop(save_reg); |
| 704 | __ pop(scratch1); |
| 705 | __ ret(0); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 709 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 710 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 711 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 712 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 713 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 714 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 715 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 716 | |
| 717 | __ bind(&load_smi); |
| 718 | __ SmiUntag(number); |
| 719 | __ push(number); |
| 720 | __ fild_s(Operand(esp, 0)); |
| 721 | __ pop(number); |
| 722 | |
| 723 | __ bind(&done); |
| 724 | } |
| 725 | |
| 726 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 727 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 728 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 729 | 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] | 730 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 731 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 732 | Factory* factory = masm->isolate()->factory(); |
| 733 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 734 | __ 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] | 735 | __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 736 | __ bind(&load_eax); |
| 737 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 738 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 739 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 740 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 741 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 742 | __ bind(&load_smi_edx); |
| 743 | __ SmiUntag(edx); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 744 | __ Cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 745 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 746 | __ jmp(&load_eax); |
| 747 | __ bind(&load_smi_eax); |
| 748 | __ SmiUntag(eax); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 749 | __ Cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 750 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 751 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 752 | __ bind(&load_float_eax); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 753 | __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 754 | __ bind(&done); |
| 755 | } |
| 756 | |
| 757 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 758 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 759 | Label* non_float, |
| 760 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 761 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 762 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 763 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 764 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 765 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 766 | Factory* factory = masm->isolate()->factory(); |
| 767 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 768 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 769 | |
| 770 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 771 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 772 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 773 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 774 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 775 | |
| 776 | // Fall-through: Both operands are numbers. |
| 777 | __ bind(&done); |
| 778 | } |
| 779 | |
| 780 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 781 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 782 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 783 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 784 | const Register exponent = eax; |
| 785 | const Register base = edx; |
| 786 | const Register scratch = ecx; |
| 787 | const XMMRegister double_result = xmm3; |
| 788 | const XMMRegister double_base = xmm2; |
| 789 | const XMMRegister double_exponent = xmm1; |
| 790 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 791 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 792 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 793 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 794 | // Save 1 in double_result - we need this several times later on. |
| 795 | __ mov(scratch, Immediate(1)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 796 | __ Cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 797 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 798 | if (exponent_type_ == ON_STACK) { |
| 799 | Label base_is_smi, unpack_exponent; |
| 800 | // The exponent and base are supplied as arguments on the stack. |
| 801 | // This can only happen if the stub is called from non-optimized code. |
| 802 | // Load input parameters from stack. |
| 803 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 804 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 805 | |
| 806 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 807 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 808 | factory->heap_number_map()); |
| 809 | __ j(not_equal, &call_runtime); |
| 810 | |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 811 | __ movsd(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 812 | __ jmp(&unpack_exponent, Label::kNear); |
| 813 | |
| 814 | __ bind(&base_is_smi); |
| 815 | __ SmiUntag(base); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 816 | __ Cvtsi2sd(double_base, base); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 817 | |
| 818 | __ bind(&unpack_exponent); |
| 819 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 820 | __ SmiUntag(exponent); |
| 821 | __ jmp(&int_exponent); |
| 822 | |
| 823 | __ bind(&exponent_not_smi); |
| 824 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 825 | factory->heap_number_map()); |
| 826 | __ j(not_equal, &call_runtime); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 827 | __ movsd(double_exponent, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 828 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 829 | } else if (exponent_type_ == TAGGED) { |
| 830 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 831 | __ SmiUntag(exponent); |
| 832 | __ jmp(&int_exponent); |
| 833 | |
| 834 | __ bind(&exponent_not_smi); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 835 | __ movsd(double_exponent, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 836 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 837 | } |
| 838 | |
| 839 | if (exponent_type_ != INTEGER) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 840 | Label fast_power, try_arithmetic_simplification; |
| 841 | __ DoubleToI(exponent, double_exponent, double_scratch, |
| 842 | TREAT_MINUS_ZERO_AS_ZERO, &try_arithmetic_simplification); |
| 843 | __ jmp(&int_exponent); |
| 844 | |
| 845 | __ bind(&try_arithmetic_simplification); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 846 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 847 | __ cvttsd2si(exponent, Operand(double_exponent)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 848 | __ cmp(exponent, Immediate(0x80000000u)); |
| 849 | __ j(equal, &call_runtime); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 850 | |
| 851 | if (exponent_type_ == ON_STACK) { |
| 852 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 853 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 854 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 855 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 856 | // Test for 0.5. |
| 857 | // Load double_scratch with 0.5. |
| 858 | __ mov(scratch, Immediate(0x3F000000u)); |
| 859 | __ movd(double_scratch, scratch); |
| 860 | __ cvtss2sd(double_scratch, double_scratch); |
| 861 | // Already ruled out NaNs for exponent. |
| 862 | __ ucomisd(double_scratch, double_exponent); |
| 863 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 864 | |
| 865 | // Calculates square root of base. Check for the special case of |
| 866 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 867 | // According to IEEE-754, single-precision -Infinity has the highest |
| 868 | // 9 bits set and the lowest 23 bits cleared. |
| 869 | __ mov(scratch, 0xFF800000u); |
| 870 | __ movd(double_scratch, scratch); |
| 871 | __ cvtss2sd(double_scratch, double_scratch); |
| 872 | __ ucomisd(double_base, double_scratch); |
| 873 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 874 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 875 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 876 | __ j(carry, &continue_sqrt, Label::kNear); |
| 877 | |
| 878 | // Set result to Infinity in the special case. |
| 879 | __ xorps(double_result, double_result); |
| 880 | __ subsd(double_result, double_scratch); |
| 881 | __ jmp(&done); |
| 882 | |
| 883 | __ bind(&continue_sqrt); |
| 884 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 885 | __ xorps(double_scratch, double_scratch); |
| 886 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 887 | __ sqrtsd(double_result, double_scratch); |
| 888 | __ jmp(&done); |
| 889 | |
| 890 | // Test for -0.5. |
| 891 | __ bind(¬_plus_half); |
| 892 | // Load double_exponent with -0.5 by substracting 1. |
| 893 | __ subsd(double_scratch, double_result); |
| 894 | // Already ruled out NaNs for exponent. |
| 895 | __ ucomisd(double_scratch, double_exponent); |
| 896 | __ j(not_equal, &fast_power, Label::kNear); |
| 897 | |
| 898 | // Calculates reciprocal of square root of base. Check for the special |
| 899 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 900 | // According to IEEE-754, single-precision -Infinity has the highest |
| 901 | // 9 bits set and the lowest 23 bits cleared. |
| 902 | __ mov(scratch, 0xFF800000u); |
| 903 | __ movd(double_scratch, scratch); |
| 904 | __ cvtss2sd(double_scratch, double_scratch); |
| 905 | __ ucomisd(double_base, double_scratch); |
| 906 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 907 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 908 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 909 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 910 | |
| 911 | // Set result to 0 in the special case. |
| 912 | __ xorps(double_result, double_result); |
| 913 | __ jmp(&done); |
| 914 | |
| 915 | __ bind(&continue_rsqrt); |
| 916 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 917 | __ xorps(double_exponent, double_exponent); |
| 918 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 919 | __ sqrtsd(double_exponent, double_exponent); |
| 920 | __ divsd(double_result, double_exponent); |
| 921 | __ jmp(&done); |
| 922 | } |
| 923 | |
| 924 | // Using FPU instructions to calculate power. |
| 925 | Label fast_power_failed; |
| 926 | __ bind(&fast_power); |
| 927 | __ fnclex(); // Clear flags to catch exceptions later. |
| 928 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 929 | __ sub(esp, Immediate(kDoubleSize)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 930 | __ movsd(Operand(esp, 0), double_exponent); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 931 | __ fld_d(Operand(esp, 0)); // E |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 932 | __ movsd(Operand(esp, 0), double_base); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 933 | __ fld_d(Operand(esp, 0)); // B, E |
| 934 | |
| 935 | // Exponent is in st(1) and base is in st(0) |
| 936 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 937 | // FYL2X calculates st(1) * log2(st(0)) |
| 938 | __ fyl2x(); // X |
| 939 | __ fld(0); // X, X |
| 940 | __ frndint(); // rnd(X), X |
| 941 | __ fsub(1); // rnd(X), X-rnd(X) |
| 942 | __ fxch(1); // X - rnd(X), rnd(X) |
| 943 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 944 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 945 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 946 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 947 | // FSCALE calculates st(0) * 2^st(1) |
| 948 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 949 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 950 | // Bail out to runtime in case of exceptions in the status word. |
| 951 | __ fnstsw_ax(); |
| 952 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 953 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 954 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 955 | __ movsd(double_result, Operand(esp, 0)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 956 | __ add(esp, Immediate(kDoubleSize)); |
| 957 | __ jmp(&done); |
| 958 | |
| 959 | __ bind(&fast_power_failed); |
| 960 | __ fninit(); |
| 961 | __ add(esp, Immediate(kDoubleSize)); |
| 962 | __ jmp(&call_runtime); |
| 963 | } |
| 964 | |
| 965 | // Calculate power with integer exponent. |
| 966 | __ bind(&int_exponent); |
| 967 | const XMMRegister double_scratch2 = double_exponent; |
| 968 | __ mov(scratch, exponent); // Back up exponent. |
| 969 | __ movsd(double_scratch, double_base); // Back up base. |
| 970 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 971 | |
| 972 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 973 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 974 | __ test(scratch, scratch); |
| 975 | __ j(positive, &no_neg, Label::kNear); |
| 976 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 977 | __ bind(&no_neg); |
| 978 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 979 | __ j(zero, &while_false, Label::kNear); |
| 980 | __ shr(scratch, 1); |
| 981 | // Above condition means CF==0 && ZF==0. This means that the |
| 982 | // bit that has been shifted out is 0 and the result is not 0. |
| 983 | __ j(above, &while_true, Label::kNear); |
| 984 | __ movsd(double_result, double_scratch); |
| 985 | __ j(zero, &while_false, Label::kNear); |
| 986 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 987 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 988 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 989 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 990 | __ j(above, &while_true, Label::kNear); |
| 991 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 992 | __ j(not_zero, &while_true); |
| 993 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 994 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 995 | // scratch has the original value of the exponent - if the exponent is |
| 996 | // negative, return 1/result. |
| 997 | __ test(exponent, exponent); |
| 998 | __ j(positive, &done); |
| 999 | __ divsd(double_scratch2, double_result); |
| 1000 | __ movsd(double_result, double_scratch2); |
| 1001 | // Test whether result is zero. Bail out to check for subnormal result. |
| 1002 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 1003 | __ xorps(double_scratch2, double_scratch2); |
| 1004 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 1005 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 1006 | // and may not have contained the exponent value in the first place when the |
| 1007 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 1008 | __ j(not_equal, &done); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1009 | __ Cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1010 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1011 | // Returning or bailing out. |
| 1012 | Counters* counters = masm->isolate()->counters(); |
| 1013 | if (exponent_type_ == ON_STACK) { |
| 1014 | // The arguments are still on the stack. |
| 1015 | __ bind(&call_runtime); |
| 1016 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1017 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1018 | // The stub is called from non-optimized code, which expects the result |
| 1019 | // as heap number in exponent. |
| 1020 | __ bind(&done); |
| 1021 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1022 | __ movsd(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1023 | __ IncrementCounter(counters->math_pow(), 1); |
| 1024 | __ ret(2 * kPointerSize); |
| 1025 | } else { |
| 1026 | __ bind(&call_runtime); |
| 1027 | { |
| 1028 | AllowExternalCallThatCantCauseGC scope(masm); |
| 1029 | __ PrepareCallCFunction(4, scratch); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1030 | __ movsd(Operand(esp, 0 * kDoubleSize), double_base); |
| 1031 | __ movsd(Operand(esp, 1 * kDoubleSize), double_exponent); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1032 | __ CallCFunction( |
| 1033 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 1034 | } |
| 1035 | // Return value is in st(0) on ia32. |
| 1036 | // Store it into the (fixed) result register. |
| 1037 | __ sub(esp, Immediate(kDoubleSize)); |
| 1038 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1039 | __ movsd(double_result, Operand(esp, 0)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1040 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1041 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1042 | __ bind(&done); |
| 1043 | __ IncrementCounter(counters->math_pow(), 1); |
| 1044 | __ ret(0); |
| 1045 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1049 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 1050 | // ----------- S t a t e ------------- |
| 1051 | // -- ecx : name |
| 1052 | // -- edx : receiver |
| 1053 | // -- esp[0] : return address |
| 1054 | // ----------------------------------- |
| 1055 | Label miss; |
| 1056 | |
| 1057 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1058 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1059 | __ j(not_equal, &miss); |
| 1060 | } |
| 1061 | |
| 1062 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 1063 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1064 | StubCompiler::TailCallBuiltin( |
| 1065 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1066 | } |
| 1067 | |
| 1068 | |
| 1069 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 1070 | // ----------- S t a t e ------------- |
| 1071 | // -- ecx : name |
| 1072 | // -- edx : receiver |
| 1073 | // -- esp[0] : return address |
| 1074 | // ----------------------------------- |
| 1075 | Label miss; |
| 1076 | |
| 1077 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1078 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1079 | __ j(not_equal, &miss); |
| 1080 | } |
| 1081 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1082 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1083 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1084 | StubCompiler::TailCallBuiltin( |
| 1085 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1089 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 1090 | // ----------- S t a t e ------------- |
| 1091 | // -- eax : value |
| 1092 | // -- ecx : name |
| 1093 | // -- edx : receiver |
| 1094 | // -- esp[0] : return address |
| 1095 | // ----------------------------------- |
| 1096 | // |
| 1097 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 1098 | // (currently anything except for external arrays which means anything with |
| 1099 | // elements of FixedArray type). Value must be a number, but only smis are |
| 1100 | // accepted as the most common case. |
| 1101 | |
| 1102 | Label miss; |
| 1103 | |
| 1104 | Register receiver = edx; |
| 1105 | Register value = eax; |
| 1106 | Register scratch = ebx; |
| 1107 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1108 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1109 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1110 | __ j(not_equal, &miss); |
| 1111 | } |
| 1112 | |
| 1113 | // Check that the receiver isn't a smi. |
| 1114 | __ JumpIfSmi(receiver, &miss); |
| 1115 | |
| 1116 | // Check that the object is a JS array. |
| 1117 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 1118 | __ j(not_equal, &miss); |
| 1119 | |
| 1120 | // Check that elements are FixedArray. |
| 1121 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 1122 | // fast elements (including COW). |
| 1123 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 1124 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 1125 | __ j(not_equal, &miss); |
| 1126 | |
| 1127 | // Check that the array has fast properties, otherwise the length |
| 1128 | // property might have been redefined. |
| 1129 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 1130 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 1131 | Heap::kHashTableMapRootIndex); |
| 1132 | __ j(equal, &miss); |
| 1133 | |
| 1134 | // Check that value is a smi. |
| 1135 | __ JumpIfNotSmi(value, &miss); |
| 1136 | |
| 1137 | // Prepare tail call to StoreIC_ArrayLength. |
| 1138 | __ pop(scratch); |
| 1139 | __ push(receiver); |
| 1140 | __ push(value); |
| 1141 | __ push(scratch); // return address |
| 1142 | |
| 1143 | ExternalReference ref = |
| 1144 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 1145 | __ TailCallExternalReference(ref, 2, 1); |
| 1146 | |
| 1147 | __ bind(&miss); |
| 1148 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1149 | StubCompiler::TailCallBuiltin( |
| 1150 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1154 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 1155 | // The key is in edx and the parameter count is in eax. |
| 1156 | |
| 1157 | // The displacement is used for skipping the frame pointer on the |
| 1158 | // stack. It is the offset of the last parameter (if any) relative |
| 1159 | // to the frame pointer. |
| 1160 | static const int kDisplacement = 1 * kPointerSize; |
| 1161 | |
| 1162 | // Check that the key is a smi. |
| 1163 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1164 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1165 | |
| 1166 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1167 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1168 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1169 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1170 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1171 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1172 | |
| 1173 | // Check index against formal parameters count limit passed in |
| 1174 | // through register eax. Use unsigned comparison to get negative |
| 1175 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1176 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1177 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1178 | |
| 1179 | // Read the argument from the stack and return it. |
| 1180 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1181 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 1182 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 1183 | __ neg(edx); |
| 1184 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 1185 | __ ret(0); |
| 1186 | |
| 1187 | // Arguments adaptor case: Check index against actual arguments |
| 1188 | // limit found in the arguments adaptor frame. Use unsigned |
| 1189 | // comparison to get negative check for free. |
| 1190 | __ bind(&adaptor); |
| 1191 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1192 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1193 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1194 | |
| 1195 | // Read the argument from the stack and return it. |
| 1196 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1197 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 1198 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 1199 | __ neg(edx); |
| 1200 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 1201 | __ ret(0); |
| 1202 | |
| 1203 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 1204 | // by calling the runtime system. |
| 1205 | __ bind(&slow); |
| 1206 | __ pop(ebx); // Return address. |
| 1207 | __ push(edx); |
| 1208 | __ push(ebx); |
| 1209 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 1210 | } |
| 1211 | |
| 1212 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1213 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1214 | // esp[0] : return address |
| 1215 | // esp[4] : number of parameters |
| 1216 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1217 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1218 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1219 | // Check if the calling frame is an arguments adaptor frame. |
| 1220 | Label runtime; |
| 1221 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1222 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1223 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1224 | __ j(not_equal, &runtime, Label::kNear); |
| 1225 | |
| 1226 | // Patch the arguments.length and the parameters pointer. |
| 1227 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1228 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 1229 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1230 | StandardFrameConstants::kCallerSPOffset)); |
| 1231 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1232 | |
| 1233 | __ bind(&runtime); |
| 1234 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 1235 | } |
| 1236 | |
| 1237 | |
| 1238 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1239 | Isolate* isolate = masm->isolate(); |
| 1240 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1241 | // esp[0] : return address |
| 1242 | // esp[4] : number of parameters (tagged) |
| 1243 | // esp[8] : receiver displacement |
| 1244 | // esp[12] : function |
| 1245 | |
| 1246 | // ebx = parameter count (tagged) |
| 1247 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1248 | |
| 1249 | // Check if the calling frame is an arguments adaptor frame. |
| 1250 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 1251 | // Generate* functions. |
| 1252 | Label runtime; |
| 1253 | Label adaptor_frame, try_allocate; |
| 1254 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1255 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1256 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1257 | __ j(equal, &adaptor_frame, Label::kNear); |
| 1258 | |
| 1259 | // No adaptor, parameter count = argument count. |
| 1260 | __ mov(ecx, ebx); |
| 1261 | __ jmp(&try_allocate, Label::kNear); |
| 1262 | |
| 1263 | // We have an adaptor frame. Patch the parameters pointer. |
| 1264 | __ bind(&adaptor_frame); |
| 1265 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1266 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1267 | StandardFrameConstants::kCallerSPOffset)); |
| 1268 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1269 | |
| 1270 | // ebx = parameter count (tagged) |
| 1271 | // ecx = argument count (tagged) |
| 1272 | // esp[4] = parameter count (tagged) |
| 1273 | // esp[8] = address of receiver argument |
| 1274 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1275 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1276 | __ j(less_equal, &try_allocate, Label::kNear); |
| 1277 | __ mov(ebx, ecx); |
| 1278 | |
| 1279 | __ bind(&try_allocate); |
| 1280 | |
| 1281 | // Save mapped parameter count. |
| 1282 | __ push(ebx); |
| 1283 | |
| 1284 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 1285 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 1286 | const int kParameterMapHeaderSize = |
| 1287 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 1288 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1289 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1290 | __ j(zero, &no_parameter_map, Label::kNear); |
| 1291 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 1292 | __ bind(&no_parameter_map); |
| 1293 | |
| 1294 | // 2. Backing store. |
| 1295 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 1296 | |
| 1297 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1298 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1299 | |
| 1300 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1301 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1302 | |
| 1303 | // eax = address of new object(s) (tagged) |
| 1304 | // ecx = argument count (tagged) |
| 1305 | // esp[0] = mapped parameter count (tagged) |
| 1306 | // esp[8] = parameter count (tagged) |
| 1307 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1308 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1309 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1310 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 1311 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1312 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1313 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1314 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 1315 | __ mov(edi, Operand(edi, |
| 1316 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 1317 | __ jmp(©, Label::kNear); |
| 1318 | |
| 1319 | __ bind(&has_mapped_parameters); |
| 1320 | __ mov(edi, Operand(edi, |
| 1321 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 1322 | __ bind(©); |
| 1323 | |
| 1324 | // eax = address of new object (tagged) |
| 1325 | // ebx = mapped parameter count (tagged) |
| 1326 | // ecx = argument count (tagged) |
| 1327 | // edi = address of boilerplate object (tagged) |
| 1328 | // esp[0] = mapped parameter count (tagged) |
| 1329 | // esp[8] = parameter count (tagged) |
| 1330 | // esp[12] = address of receiver argument |
| 1331 | // Copy the JS object part. |
| 1332 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 1333 | __ mov(edx, FieldOperand(edi, i)); |
| 1334 | __ mov(FieldOperand(eax, i), edx); |
| 1335 | } |
| 1336 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1337 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1338 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 1339 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 1340 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 1341 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 1342 | edx); |
| 1343 | |
| 1344 | // Use the length (smi tagged) and set that as an in-object property too. |
| 1345 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 1346 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 1347 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 1348 | ecx); |
| 1349 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1350 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1351 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 1352 | // backing store. |
| 1353 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 1354 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 1355 | |
| 1356 | // eax = address of new object (tagged) |
| 1357 | // ebx = mapped parameter count (tagged) |
| 1358 | // ecx = argument count (tagged) |
| 1359 | // edi = address of parameter map or backing store (tagged) |
| 1360 | // esp[0] = mapped parameter count (tagged) |
| 1361 | // esp[8] = parameter count (tagged) |
| 1362 | // esp[12] = address of receiver argument |
| 1363 | // Free a register. |
| 1364 | __ push(eax); |
| 1365 | |
| 1366 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 1367 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1368 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1369 | __ j(zero, &skip_parameter_map); |
| 1370 | |
| 1371 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1372 | Immediate(isolate->factory()->non_strict_arguments_elements_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1373 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 1374 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 1375 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 1376 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 1377 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 1378 | |
| 1379 | // Copy the parameter slots and the holes in the arguments. |
| 1380 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 1381 | // where parameters are stored in reverse order, at |
| 1382 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 1383 | // The mapped parameter thus need to get indices |
| 1384 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 1385 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 1386 | // We loop from right to left. |
| 1387 | Label parameters_loop, parameters_test; |
| 1388 | __ push(ecx); |
| 1389 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 1390 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 1391 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1392 | __ sub(ebx, eax); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1393 | __ mov(ecx, isolate->factory()->the_hole_value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1394 | __ mov(edx, edi); |
| 1395 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 1396 | // eax = loop variable (tagged) |
| 1397 | // ebx = mapping index (tagged) |
| 1398 | // ecx = the hole value |
| 1399 | // edx = address of parameter map (tagged) |
| 1400 | // edi = address of backing store (tagged) |
| 1401 | // esp[0] = argument count (tagged) |
| 1402 | // esp[4] = address of new object (tagged) |
| 1403 | // esp[8] = mapped parameter count (tagged) |
| 1404 | // esp[16] = parameter count (tagged) |
| 1405 | // esp[20] = address of receiver argument |
| 1406 | __ jmp(¶meters_test, Label::kNear); |
| 1407 | |
| 1408 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1409 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1410 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 1411 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1412 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1413 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1414 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1415 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 1416 | __ pop(ecx); |
| 1417 | |
| 1418 | __ bind(&skip_parameter_map); |
| 1419 | |
| 1420 | // ecx = argument count (tagged) |
| 1421 | // edi = address of backing store (tagged) |
| 1422 | // esp[0] = address of new object (tagged) |
| 1423 | // esp[4] = mapped parameter count (tagged) |
| 1424 | // esp[12] = parameter count (tagged) |
| 1425 | // esp[16] = address of receiver argument |
| 1426 | // Copy arguments header and remaining slots (if there are any). |
| 1427 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1428 | Immediate(isolate->factory()->fixed_array_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1429 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 1430 | |
| 1431 | Label arguments_loop, arguments_test; |
| 1432 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1433 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1434 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 1435 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1436 | __ jmp(&arguments_test, Label::kNear); |
| 1437 | |
| 1438 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1439 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1440 | __ mov(eax, Operand(edx, 0)); |
| 1441 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1442 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1443 | |
| 1444 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1445 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1446 | __ j(less, &arguments_loop, Label::kNear); |
| 1447 | |
| 1448 | // Restore. |
| 1449 | __ pop(eax); // Address of arguments object. |
| 1450 | __ pop(ebx); // Parameter count. |
| 1451 | |
| 1452 | // Return and remove the on-stack parameters. |
| 1453 | __ ret(3 * kPointerSize); |
| 1454 | |
| 1455 | // Do the runtime call to allocate the arguments object. |
| 1456 | __ bind(&runtime); |
| 1457 | __ pop(eax); // Remove saved parameter count. |
| 1458 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 1459 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | |
| 1463 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1464 | Isolate* isolate = masm->isolate(); |
| 1465 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1466 | // esp[0] : return address |
| 1467 | // esp[4] : number of parameters |
| 1468 | // esp[8] : receiver displacement |
| 1469 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1470 | |
| 1471 | // Check if the calling frame is an arguments adaptor frame. |
| 1472 | Label adaptor_frame, try_allocate, runtime; |
| 1473 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1474 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1475 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1476 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1477 | |
| 1478 | // Get the length from the frame. |
| 1479 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1480 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1481 | |
| 1482 | // Patch the arguments.length and the parameters pointer. |
| 1483 | __ bind(&adaptor_frame); |
| 1484 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1485 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1486 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1487 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1488 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1489 | |
| 1490 | // Try the new space allocation. Start out with computing the size of |
| 1491 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1492 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1493 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1494 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1495 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1496 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 1497 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1498 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1499 | |
| 1500 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1501 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1502 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1503 | // Get the arguments boilerplate from the current native context. |
| 1504 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 1505 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1506 | const int offset = |
| 1507 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 1508 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1509 | |
| 1510 | // Copy the JS object part. |
| 1511 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 1512 | __ mov(ebx, FieldOperand(edi, i)); |
| 1513 | __ mov(FieldOperand(eax, i), ebx); |
| 1514 | } |
| 1515 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1516 | // 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] | 1517 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1518 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1519 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1520 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1521 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1522 | |
| 1523 | // If there are no actual arguments, we're done. |
| 1524 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1525 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1526 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1527 | |
| 1528 | // Get the parameters pointer from the stack. |
| 1529 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 1530 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1531 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1532 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1533 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1534 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 1535 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1536 | Immediate(isolate->factory()->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1537 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1538 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 1539 | // Untag the length for the loop below. |
| 1540 | __ SmiUntag(ecx); |
| 1541 | |
| 1542 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1543 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1544 | __ bind(&loop); |
| 1545 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 1546 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1547 | __ add(edi, Immediate(kPointerSize)); |
| 1548 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1549 | __ dec(ecx); |
| 1550 | __ j(not_zero, &loop); |
| 1551 | |
| 1552 | // Return and remove the on-stack parameters. |
| 1553 | __ bind(&done); |
| 1554 | __ ret(3 * kPointerSize); |
| 1555 | |
| 1556 | // Do the runtime call to allocate the arguments object. |
| 1557 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1558 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | |
| 1562 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 1563 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 1564 | // time or if regexp entry in generated code is turned off runtime switch or |
| 1565 | // at compilation. |
| 1566 | #ifdef V8_INTERPRETED_REGEXP |
| 1567 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 1568 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1569 | |
| 1570 | // Stack frame on entry. |
| 1571 | // esp[0]: return address |
| 1572 | // esp[4]: last_match_info (expected JSArray) |
| 1573 | // esp[8]: previous index |
| 1574 | // esp[12]: subject string |
| 1575 | // esp[16]: JSRegExp object |
| 1576 | |
| 1577 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 1578 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 1579 | static const int kSubjectOffset = 3 * kPointerSize; |
| 1580 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 1581 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1582 | Label runtime; |
| 1583 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1584 | |
| 1585 | // Ensure that a RegExp stack is allocated. |
| 1586 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1587 | ExternalReference::address_of_regexp_stack_memory_address( |
| 1588 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1589 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1590 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1591 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1592 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1593 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1594 | |
| 1595 | // Check that the first argument is a JSRegExp object. |
| 1596 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 1597 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1598 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1599 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 1600 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1601 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1602 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 1603 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 1604 | if (FLAG_debug_code) { |
| 1605 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1606 | __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1607 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1608 | __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | // ecx: RegExp data (FixedArray) |
| 1612 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 1613 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1614 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1615 | __ j(not_equal, &runtime); |
| 1616 | |
| 1617 | // ecx: RegExp data (FixedArray) |
| 1618 | // Check that the number of captures fit in the static offsets vector buffer. |
| 1619 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1620 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 1621 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 1622 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1623 | STATIC_ASSERT(kSmiTag == 0); |
| 1624 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1625 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 1626 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1627 | __ j(above, &runtime); |
| 1628 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1629 | // Reset offset for possibly sliced string. |
| 1630 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1631 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1632 | __ JumpIfSmi(eax, &runtime); |
| 1633 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1634 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1635 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1636 | |
| 1637 | // eax: subject string |
| 1638 | // edx: subject string |
| 1639 | // ebx: subject string instance type |
| 1640 | // ecx: RegExp data (FixedArray) |
| 1641 | // Handle subject string according to its encoding and representation: |
| 1642 | // (1) Sequential two byte? If yes, go to (9). |
| 1643 | // (2) Sequential one byte? If yes, go to (6). |
| 1644 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 1645 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 1646 | // Otherwise bailout. |
| 1647 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 1648 | // (5b) Is subject external? If yes, go to (8). |
| 1649 | // (6) One byte sequential. Load regexp code for one byte. |
| 1650 | // (E) Carry on. |
| 1651 | /// [...] |
| 1652 | |
| 1653 | // Deferred code at the end of the stub: |
| 1654 | // (7) Not a long external string? If yes, go to (10). |
| 1655 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 1656 | // (8a) Is the external string one byte? If yes, go to (6). |
| 1657 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 1658 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 1659 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 1660 | |
| 1661 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 1662 | external_string /* 8 */, check_underlying /* 5a */, |
| 1663 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 1664 | not_long_external /* 10 */; |
| 1665 | |
| 1666 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1667 | __ and_(ebx, kIsNotStringMask | |
| 1668 | kStringRepresentationMask | |
| 1669 | kStringEncodingMask | |
| 1670 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1671 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1672 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 1673 | |
| 1674 | // (2) Sequential one byte? If yes, go to (6). |
| 1675 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1676 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 1677 | kStringRepresentationMask | |
| 1678 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1679 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1680 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1681 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 1682 | // We check whether the subject string is a cons, since sequential strings |
| 1683 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1684 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 1685 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1686 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 1687 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1688 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1689 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1690 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1691 | // (4) Cons string. Check that it's flat. |
| 1692 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1693 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1694 | __ j(not_equal, &runtime); |
| 1695 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1696 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1697 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1698 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 1699 | |
| 1700 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 1701 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1702 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1703 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 1704 | // (5b) Is subject external? If yes, go to (8). |
| 1705 | __ test_b(ebx, kStringRepresentationMask); |
| 1706 | // The underlying external string is never a short external string. |
| 1707 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 1708 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 1709 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1710 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1711 | // eax: sequential subject string (or look-alike, external string) |
| 1712 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1713 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1714 | // (6) One byte sequential. Load regexp code for one byte. |
| 1715 | __ bind(&seq_one_byte_string); |
| 1716 | // Load previous index and check range before edx is overwritten. We have |
| 1717 | // to use edx instead of eax here because it might have been only made to |
| 1718 | // look like a sequential string when it actually is an external string. |
| 1719 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 1720 | __ JumpIfNotSmi(ebx, &runtime); |
| 1721 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 1722 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1723 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1724 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1725 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1726 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1727 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1728 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1729 | // Check that the irregexp code has been generated for the actual string |
| 1730 | // 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] | 1731 | // a smi (code flushing support). |
| 1732 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1733 | |
| 1734 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1735 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1736 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1737 | // 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] | 1738 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1739 | Counters* counters = masm->isolate()->counters(); |
| 1740 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1741 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1742 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1743 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1744 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1745 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1746 | // Argument 9: Pass current isolate address. |
| 1747 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1748 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1749 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1750 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 1751 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1752 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1753 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1754 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 1755 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1756 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 1757 | |
| 1758 | // Argument 6: Set the number of capture registers to zero to force global |
| 1759 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 1760 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1761 | |
| 1762 | // Argument 5: static offsets vector buffer. |
| 1763 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1764 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 1765 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1766 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1767 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1768 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1769 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1770 | |
| 1771 | // Argument 1: Original subject string. |
| 1772 | // The original subject is in the previous stack frame. Therefore we have to |
| 1773 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 1774 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 1775 | // and thereby moves up esp by one kPointerSize.) |
| 1776 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 1777 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 1778 | |
| 1779 | // esi: original subject string |
| 1780 | // eax: underlying subject string |
| 1781 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1782 | // 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] | 1783 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1784 | // Argument 4: End of string data |
| 1785 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1786 | // Prepare start and end index of the input. |
| 1787 | // Load the length from the original sliced string if that is the case. |
| 1788 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1789 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1790 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1791 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1792 | |
| 1793 | // ebx: start index of the input string |
| 1794 | // esi: end index of the input string |
| 1795 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1796 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1797 | __ j(zero, &setup_two_byte, Label::kNear); |
| 1798 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1799 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1800 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1801 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1802 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1803 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1804 | |
| 1805 | __ bind(&setup_two_byte); |
| 1806 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1807 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 1808 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1809 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 1810 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 1811 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 1812 | |
| 1813 | __ bind(&setup_rest); |
| 1814 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1815 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1816 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1817 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1818 | |
| 1819 | // Drop arguments and come back to JS mode. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1820 | __ LeaveApiExitFrame(true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1821 | |
| 1822 | // Check the result. |
| 1823 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1824 | __ cmp(eax, 1); |
| 1825 | // We expect exactly one result since we force the called regexp to behave |
| 1826 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1827 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1828 | Label failure; |
| 1829 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1830 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1831 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 1832 | // If not exception it can only be retry. Handle that in the runtime system. |
| 1833 | __ j(not_equal, &runtime); |
| 1834 | // Result must now be exception. If there is no pending exception already a |
| 1835 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 1836 | // haven't created the exception yet. Handle that in the runtime system. |
| 1837 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1838 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1839 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1840 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1841 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1842 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1843 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1844 | // For exception, throw the exception again. |
| 1845 | |
| 1846 | // Clear the pending exception variable. |
| 1847 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 1848 | |
| 1849 | // Special handling of termination exceptions which are uncatchable |
| 1850 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1851 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1852 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1853 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1854 | |
| 1855 | // Handle normal exception by following handler chain. |
| 1856 | __ Throw(eax); |
| 1857 | |
| 1858 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1859 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1860 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1861 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1862 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1863 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1864 | __ ret(4 * kPointerSize); |
| 1865 | |
| 1866 | // Load RegExp data. |
| 1867 | __ bind(&success); |
| 1868 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 1869 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 1870 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 1871 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 1872 | STATIC_ASSERT(kSmiTag == 0); |
| 1873 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1874 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1875 | |
| 1876 | // edx: Number of capture registers |
| 1877 | // 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] | 1878 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1879 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1880 | __ JumpIfSmi(eax, &runtime); |
| 1881 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 1882 | __ j(not_equal, &runtime); |
| 1883 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1884 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1885 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 1886 | __ cmp(eax, factory->fixed_array_map()); |
| 1887 | __ j(not_equal, &runtime); |
| 1888 | // Check that the last match info has space for the capture registers and the |
| 1889 | // additional information. |
| 1890 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 1891 | __ SmiUntag(eax); |
| 1892 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 1893 | __ cmp(edx, eax); |
| 1894 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1895 | |
| 1896 | // ebx: last_match_info backing store (FixedArray) |
| 1897 | // edx: number of capture registers |
| 1898 | // Store the capture count. |
| 1899 | __ SmiTag(edx); // Number of capture registers to smi. |
| 1900 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 1901 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 1902 | // Store last subject and last input. |
| 1903 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1904 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1905 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1906 | __ RecordWriteField(ebx, |
| 1907 | RegExpImpl::kLastSubjectOffset, |
| 1908 | eax, |
| 1909 | edi, |
| 1910 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1911 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1912 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1913 | __ RecordWriteField(ebx, |
| 1914 | RegExpImpl::kLastInputOffset, |
| 1915 | eax, |
| 1916 | edi, |
| 1917 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1918 | |
| 1919 | // Get the static offsets vector filled by the native regexp code. |
| 1920 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1921 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1922 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 1923 | |
| 1924 | // ebx: last_match_info backing store (FixedArray) |
| 1925 | // ecx: offsets vector |
| 1926 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1927 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1928 | // Capture register counter starts from number of capture registers and |
| 1929 | // counts down until wraping after zero. |
| 1930 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1931 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1932 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1933 | // Read the value from the static offsets vector buffer. |
| 1934 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 1935 | __ SmiTag(edi); |
| 1936 | // Store the smi value in the last match info. |
| 1937 | __ mov(FieldOperand(ebx, |
| 1938 | edx, |
| 1939 | times_pointer_size, |
| 1940 | RegExpImpl::kFirstCaptureOffset), |
| 1941 | edi); |
| 1942 | __ jmp(&next_capture); |
| 1943 | __ bind(&done); |
| 1944 | |
| 1945 | // Return last match info. |
| 1946 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 1947 | __ ret(4 * kPointerSize); |
| 1948 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1949 | // Do the runtime call to execute the regexp. |
| 1950 | __ bind(&runtime); |
| 1951 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 1952 | |
| 1953 | // Deferred code for string handling. |
| 1954 | // (7) Not a long external string? If yes, go to (10). |
| 1955 | __ bind(¬_seq_nor_cons); |
| 1956 | // Compare flags are still set from (3). |
| 1957 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 1958 | |
| 1959 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1960 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1961 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1962 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1963 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 1964 | if (FLAG_debug_code) { |
| 1965 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 1966 | // Sequential strings have already been ruled out. |
| 1967 | __ test_b(ebx, kIsIndirectStringMask); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1968 | __ Assert(zero, kExternalStringExpectedButNotFound); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1969 | } |
| 1970 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 1971 | // 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] | 1972 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1973 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 1974 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1975 | // (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] | 1976 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1977 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1978 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1979 | // eax: sequential subject string (or look-alike, external string) |
| 1980 | // edx: original subject string |
| 1981 | // ecx: RegExp data (FixedArray) |
| 1982 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 1983 | __ bind(&seq_two_byte_string); |
| 1984 | // Load previous index and check range before edx is overwritten. We have |
| 1985 | // to use edx instead of eax here because it might have been only made to |
| 1986 | // look like a sequential string when it actually is an external string. |
| 1987 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 1988 | __ JumpIfNotSmi(ebx, &runtime); |
| 1989 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 1990 | __ j(above_equal, &runtime); |
| 1991 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 1992 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 1993 | __ jmp(&check_code); // Go to (E). |
| 1994 | |
| 1995 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 1996 | __ bind(¬_long_external); |
| 1997 | // Catch non-string subject or short external string. |
| 1998 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 1999 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 2000 | __ j(not_zero, &runtime); |
| 2001 | |
| 2002 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 2003 | // Load offset into edi and replace subject string with parent. |
| 2004 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 2005 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 2006 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2007 | #endif // V8_INTERPRETED_REGEXP |
| 2008 | } |
| 2009 | |
| 2010 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2011 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 2012 | const int kMaxInlineLength = 100; |
| 2013 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2014 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2015 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2016 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2017 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2018 | __ j(above, &slowcase); |
| 2019 | // Smi-tagging is equivalent to multiplying by 2. |
| 2020 | STATIC_ASSERT(kSmiTag == 0); |
| 2021 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2022 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 2023 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 2024 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2025 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 2026 | times_pointer_size, |
| 2027 | ebx, // In: Number of elements as a smi |
| 2028 | REGISTER_VALUE_IS_SMI, |
| 2029 | eax, // Out: Start of allocation (tagged). |
| 2030 | ecx, // Out: End of allocation. |
| 2031 | edx, // Scratch register |
| 2032 | &slowcase, |
| 2033 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2034 | // eax: Start of allocated area, object-tagged. |
| 2035 | |
| 2036 | // Set JSArray map to global.regexp_result_map(). |
| 2037 | // Set empty properties FixedArray. |
| 2038 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 2039 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2040 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2041 | Factory* factory = masm->isolate()->factory(); |
| 2042 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2043 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2044 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2045 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 2046 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 2047 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 2048 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 2049 | |
| 2050 | // Set input, index and length fields from arguments. |
| 2051 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 2052 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 2053 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 2054 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 2055 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 2056 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 2057 | |
| 2058 | // Fill out the elements FixedArray. |
| 2059 | // eax: JSArray. |
| 2060 | // ebx: FixedArray. |
| 2061 | // ecx: Number of elements in array, as smi. |
| 2062 | |
| 2063 | // Set map. |
| 2064 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2065 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2066 | // Set length. |
| 2067 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2068 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2069 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2070 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2071 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2072 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2073 | // eax: JSArray. |
| 2074 | // ecx: Number of elements to fill. |
| 2075 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2076 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2077 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2078 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2079 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2080 | __ 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] | 2081 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2082 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 2083 | __ jmp(&loop); |
| 2084 | |
| 2085 | __ bind(&done); |
| 2086 | __ ret(3 * kPointerSize); |
| 2087 | |
| 2088 | __ bind(&slowcase); |
| 2089 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 2090 | } |
| 2091 | |
| 2092 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2093 | static int NegativeComparisonResult(Condition cc) { |
| 2094 | ASSERT(cc != equal); |
| 2095 | ASSERT((cc == less) || (cc == less_equal) |
| 2096 | || (cc == greater) || (cc == greater_equal)); |
| 2097 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 2098 | } |
| 2099 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2100 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2101 | static void CheckInputType(MacroAssembler* masm, |
| 2102 | Register input, |
| 2103 | CompareIC::State expected, |
| 2104 | Label* fail) { |
| 2105 | Label ok; |
| 2106 | if (expected == CompareIC::SMI) { |
| 2107 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2108 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2109 | __ JumpIfSmi(input, &ok); |
| 2110 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 2111 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 2112 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2113 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2114 | // 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] | 2115 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 2116 | __ bind(&ok); |
| 2117 | } |
| 2118 | |
| 2119 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2120 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 2121 | Label* label, |
| 2122 | Register object, |
| 2123 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2124 | __ JumpIfSmi(object, label); |
| 2125 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 2126 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 2127 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 2128 | __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 2129 | __ j(not_zero, label); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | |
| 2133 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 2134 | Label check_unequal_objects; |
| 2135 | Condition cc = GetCondition(); |
| 2136 | |
| 2137 | Label miss; |
| 2138 | CheckInputType(masm, edx, left_, &miss); |
| 2139 | CheckInputType(masm, eax, right_, &miss); |
| 2140 | |
| 2141 | // Compare two smis. |
| 2142 | Label non_smi, smi_done; |
| 2143 | __ mov(ecx, edx); |
| 2144 | __ or_(ecx, eax); |
| 2145 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 2146 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 2147 | __ j(no_overflow, &smi_done, Label::kNear); |
| 2148 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 2149 | __ bind(&smi_done); |
| 2150 | __ mov(eax, edx); |
| 2151 | __ ret(0); |
| 2152 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2153 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2154 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 2155 | // it is certain that at least one operand isn't a smi. |
| 2156 | |
| 2157 | // Identical objects can be compared fast, but there are some tricky cases |
| 2158 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2159 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2160 | { |
| 2161 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2162 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2163 | __ j(not_equal, ¬_identical); |
| 2164 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2165 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2166 | // Check for undefined. undefined OP undefined is false even though |
| 2167 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2168 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2169 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2170 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2171 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2172 | __ ret(0); |
| 2173 | __ bind(&check_for_nan); |
| 2174 | } |
| 2175 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2176 | // Test for NaN. Compare heap numbers in a general way, |
| 2177 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2178 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 2179 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2180 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2181 | if (cc != equal) { |
| 2182 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 2183 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 2184 | __ j(above_equal, ¬_identical); |
| 2185 | } |
| 2186 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 2187 | __ ret(0); |
| 2188 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2189 | |
| 2190 | __ bind(¬_identical); |
| 2191 | } |
| 2192 | |
| 2193 | // Strict equality can quickly decide whether objects are equal. |
| 2194 | // 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] | 2195 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2196 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2197 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2198 | // If we're doing a strict equality comparison, we don't have to do |
| 2199 | // type conversion, so we generate code to do fast comparison for objects |
| 2200 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 2201 | // slow-case code. |
| 2202 | // If either is a Smi (we know that not both are), then they can only |
| 2203 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 2204 | STATIC_ASSERT(kSmiTag == 0); |
| 2205 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 2206 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2207 | __ and_(ecx, eax); |
| 2208 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2209 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2210 | // One operand is a smi. |
| 2211 | |
| 2212 | // Check whether the non-smi is a heap number. |
| 2213 | STATIC_ASSERT(kSmiTagMask == 1); |
| 2214 | // 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] | 2215 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2216 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2217 | __ xor_(ebx, eax); |
| 2218 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 2219 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2220 | // if eax was smi, ebx is now edx, else eax. |
| 2221 | |
| 2222 | // Check if the non-smi operand is a heap number. |
| 2223 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2224 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2225 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2226 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2227 | // Return non-equal (ebx is not zero) |
| 2228 | __ mov(eax, ebx); |
| 2229 | __ ret(0); |
| 2230 | |
| 2231 | __ bind(¬_smis); |
| 2232 | // If either operand is a JSObject or an oddball value, then they are not |
| 2233 | // equal since their pointers are different |
| 2234 | // There is no test for undetectability in strict equality. |
| 2235 | |
| 2236 | // Get the type of the first operand. |
| 2237 | // 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] | 2238 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2239 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 2240 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2241 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2242 | |
| 2243 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2244 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2245 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 2246 | __ bind(&return_not_equal); |
| 2247 | __ ret(0); |
| 2248 | |
| 2249 | __ bind(&first_non_object); |
| 2250 | // Check for oddballs: true, false, null, undefined. |
| 2251 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 2252 | __ j(equal, &return_not_equal); |
| 2253 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2254 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2255 | __ j(above_equal, &return_not_equal); |
| 2256 | |
| 2257 | // Check for oddballs: true, false, null, undefined. |
| 2258 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 2259 | __ j(equal, &return_not_equal); |
| 2260 | |
| 2261 | // Fall through to the general case. |
| 2262 | __ bind(&slow); |
| 2263 | } |
| 2264 | |
| 2265 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2266 | Label non_number_comparison; |
| 2267 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2268 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2269 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2270 | CpuFeatureScope use_sse2(masm, SSE2); |
| 2271 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2272 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2273 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 2274 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2275 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2276 | // Don't base result on EFLAGS when a NaN is involved. |
| 2277 | __ j(parity_even, &unordered, Label::kNear); |
| 2278 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 2279 | __ mov(eax, 0); // equal |
| 2280 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 2281 | __ cmov(above, eax, ecx); |
| 2282 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 2283 | __ cmov(below, eax, ecx); |
| 2284 | __ ret(0); |
| 2285 | } else { |
| 2286 | FloatingPointHelper::CheckFloatOperands( |
| 2287 | masm, &non_number_comparison, ebx); |
| 2288 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 2289 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 2290 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2291 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2292 | // Don't base result on EFLAGS when a NaN is involved. |
| 2293 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2294 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2295 | Label below_label, above_label; |
| 2296 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 2297 | __ j(below, &below_label, Label::kNear); |
| 2298 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2299 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2300 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2301 | __ ret(0); |
| 2302 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2303 | __ bind(&below_label); |
| 2304 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 2305 | __ ret(0); |
| 2306 | |
| 2307 | __ bind(&above_label); |
| 2308 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 2309 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2310 | } |
| 2311 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2312 | // If one of the numbers was NaN, then the result is always false. |
| 2313 | // The cc is never not-equal. |
| 2314 | __ bind(&unordered); |
| 2315 | ASSERT(cc != not_equal); |
| 2316 | if (cc == less || cc == less_equal) { |
| 2317 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 2318 | } else { |
| 2319 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 2320 | } |
| 2321 | __ ret(0); |
| 2322 | |
| 2323 | // The number comparison code did not provide a valid result. |
| 2324 | __ bind(&non_number_comparison); |
| 2325 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2326 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2327 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2328 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2329 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 2330 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2331 | |
| 2332 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2333 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2334 | // non-zero value, which indicates not equal, so just return. |
| 2335 | __ ret(0); |
| 2336 | } |
| 2337 | |
| 2338 | __ bind(&check_for_strings); |
| 2339 | |
| 2340 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 2341 | &check_unequal_objects); |
| 2342 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2343 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2344 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2345 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2346 | edx, |
| 2347 | eax, |
| 2348 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2349 | ebx); |
| 2350 | } else { |
| 2351 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 2352 | edx, |
| 2353 | eax, |
| 2354 | ecx, |
| 2355 | ebx, |
| 2356 | edi); |
| 2357 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2358 | #ifdef DEBUG |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2359 | __ Abort(kUnexpectedFallThroughFromStringComparison); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2360 | #endif |
| 2361 | |
| 2362 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2363 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2364 | // Non-strict equality. Objects are unequal if |
| 2365 | // they are both JSObjects and not undetectable, |
| 2366 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2367 | Label not_both_objects; |
| 2368 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2369 | // At most one is a smi, so we can test for smi by adding the two. |
| 2370 | // A smi plus a heap object has the low bit set, a heap object plus |
| 2371 | // a heap object has the low bit clear. |
| 2372 | STATIC_ASSERT(kSmiTag == 0); |
| 2373 | STATIC_ASSERT(kSmiTagMask == 1); |
| 2374 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 2375 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2376 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2377 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2378 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2379 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2380 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2381 | // We do not bail out after this point. Both are JSObjects, and |
| 2382 | // they are equal if and only if both are undetectable. |
| 2383 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 2384 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 2385 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2386 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2387 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 2388 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2389 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2390 | // The objects are both undetectable, so they both compare as the value |
| 2391 | // undefined, and are equal. |
| 2392 | __ Set(eax, Immediate(EQUAL)); |
| 2393 | __ bind(&return_unequal); |
| 2394 | // Return non-equal by returning the non-zero object pointer in eax, |
| 2395 | // or return equal if we fell through to here. |
| 2396 | __ ret(0); // rax, rdx were pushed |
| 2397 | __ bind(¬_both_objects); |
| 2398 | } |
| 2399 | |
| 2400 | // Push arguments below the return address. |
| 2401 | __ pop(ecx); |
| 2402 | __ push(edx); |
| 2403 | __ push(eax); |
| 2404 | |
| 2405 | // Figure out which native to call and setup the arguments. |
| 2406 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2407 | if (cc == equal) { |
| 2408 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2409 | } else { |
| 2410 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2411 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | // Restore return address on the stack. |
| 2415 | __ push(ecx); |
| 2416 | |
| 2417 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 2418 | // tagged as a small integer. |
| 2419 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2420 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2421 | __ bind(&miss); |
| 2422 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2426 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 2427 | // Cache the called function in a global property cell. Cache states |
| 2428 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 2429 | // megamorphic. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2430 | // eax : number of arguments to the construct function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2431 | // ebx : cache cell for call target |
| 2432 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2433 | Isolate* isolate = masm->isolate(); |
| 2434 | Label initialize, done, miss, megamorphic, not_array_function; |
| 2435 | |
| 2436 | // Load the cache state into ecx. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2437 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2438 | |
| 2439 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 2440 | // function without changing the state. |
| 2441 | __ cmp(ecx, edi); |
| 2442 | __ j(equal, &done); |
| 2443 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 2444 | __ j(equal, &done); |
| 2445 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2446 | // If we came here, we need to see if we are the array function. |
| 2447 | // If we didn't have a matching function, and we didn't find the megamorph |
| 2448 | // sentinel, then we have in the cell either some other function or an |
| 2449 | // AllocationSite. Do a map check on the object in ecx. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2450 | Handle<Map> allocation_site_map = |
| 2451 | masm->isolate()->factory()->allocation_site_map(); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2452 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 2453 | __ j(not_equal, &miss); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2454 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2455 | // Load the global or builtins object from the current context |
| 2456 | __ LoadGlobalContext(ecx); |
| 2457 | // Make sure the function is the Array() function |
| 2458 | __ cmp(edi, Operand(ecx, |
| 2459 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 2460 | __ j(not_equal, &megamorphic); |
| 2461 | __ jmp(&done); |
| 2462 | |
| 2463 | __ bind(&miss); |
| 2464 | |
| 2465 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 2466 | // megamorphic. |
| 2467 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 2468 | __ j(equal, &initialize); |
| 2469 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 2470 | // write-barrier is needed. |
| 2471 | __ bind(&megamorphic); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2472 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2473 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 2474 | __ jmp(&done, Label::kNear); |
| 2475 | |
| 2476 | // An uninitialized cache is patched with the function or sentinel to |
| 2477 | // indicate the ElementsKind if function is the Array constructor. |
| 2478 | __ bind(&initialize); |
| 2479 | __ LoadGlobalContext(ecx); |
| 2480 | // Make sure the function is the Array() function |
| 2481 | __ cmp(edi, Operand(ecx, |
| 2482 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 2483 | __ j(not_equal, ¬_array_function); |
| 2484 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2485 | // The target function is the Array constructor, |
| 2486 | // Create an AllocationSite if we don't already have it, store it in the cell |
| 2487 | { |
| 2488 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2489 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2490 | // Arguments register must be smi-tagged to call out. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2491 | __ SmiTag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2492 | __ push(eax); |
| 2493 | __ push(edi); |
| 2494 | __ push(ebx); |
| 2495 | |
| 2496 | CreateAllocationSiteStub create_stub; |
| 2497 | __ CallStub(&create_stub); |
| 2498 | |
| 2499 | __ pop(ebx); |
| 2500 | __ pop(edi); |
| 2501 | __ pop(eax); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2502 | __ SmiUntag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2503 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2504 | __ jmp(&done); |
| 2505 | |
| 2506 | __ bind(¬_array_function); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2507 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2508 | // No need for a write barrier here - cells are rescanned. |
| 2509 | |
| 2510 | __ bind(&done); |
| 2511 | } |
| 2512 | |
| 2513 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2514 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2515 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2516 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2517 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2518 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2519 | |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame] | 2520 | // Check that the function really is a JavaScript function. |
| 2521 | __ JumpIfSmi(edi, &non_function); |
| 2522 | |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2523 | // The receiver might implicitly be the global object. This is |
| 2524 | // indicated by passing the hole as the receiver to the call |
| 2525 | // function stub. |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame] | 2526 | if (ReceiverMightBeImplicit() || ReceiverIsImplicit()) { |
| 2527 | Label try_call, call, patch_current_context; |
| 2528 | if (ReceiverMightBeImplicit()) { |
| 2529 | // Get the receiver from the stack. |
| 2530 | // +1 ~ return address |
| 2531 | __ mov(eax, Operand(esp, (argc_ + 1) * kPointerSize)); |
| 2532 | // Call as function is indicated with the hole. |
| 2533 | __ cmp(eax, isolate->factory()->the_hole_value()); |
| 2534 | __ j(not_equal, &try_call, Label::kNear); |
| 2535 | } |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2536 | // Patch the receiver on the stack with the global receiver object. |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame] | 2537 | // Goto slow case if we do not have a function. |
| 2538 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2539 | __ j(not_equal, &patch_current_context); |
| 2540 | CallStubCompiler::FetchGlobalProxy(masm, ecx, edi); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2541 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), ecx); |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame] | 2542 | __ jmp(&call, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2543 | |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame] | 2544 | __ bind(&patch_current_context); |
| 2545 | __ mov(edx, isolate->factory()->undefined_value()); |
| 2546 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edx); |
| 2547 | __ jmp(&slow); |
| 2548 | |
| 2549 | __ bind(&try_call); |
| 2550 | // Goto slow case if we do not have a function. |
| 2551 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2552 | __ j(not_equal, &slow); |
| 2553 | |
| 2554 | __ bind(&call); |
| 2555 | } else { |
| 2556 | // Goto slow case if we do not have a function. |
| 2557 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2558 | __ j(not_equal, &slow); |
| 2559 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2560 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2561 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2562 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2563 | } |
| 2564 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2565 | // Fast-case: Just invoke the function. |
| 2566 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2567 | |
| 2568 | if (ReceiverMightBeImplicit()) { |
| 2569 | Label call_as_function; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2570 | __ cmp(eax, isolate->factory()->the_hole_value()); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2571 | __ j(equal, &call_as_function); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2572 | __ InvokeFunction(edi, |
| 2573 | actual, |
| 2574 | JUMP_FUNCTION, |
| 2575 | NullCallWrapper(), |
| 2576 | CALL_AS_METHOD); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2577 | __ bind(&call_as_function); |
| 2578 | } |
| 2579 | __ InvokeFunction(edi, |
| 2580 | actual, |
| 2581 | JUMP_FUNCTION, |
| 2582 | NullCallWrapper(), |
| 2583 | CALL_AS_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2584 | |
| 2585 | // Slow-case: Non-function called. |
| 2586 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2587 | if (RecordCallTarget()) { |
| 2588 | // 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] | 2589 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 2590 | // object (undefined) so no write barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2591 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2592 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2593 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2594 | // Check for function proxy. |
| 2595 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 2596 | __ j(not_equal, &non_function); |
| 2597 | __ pop(ecx); |
| 2598 | __ push(edi); // put proxy as additional argument under return address |
| 2599 | __ push(ecx); |
| 2600 | __ Set(eax, Immediate(argc_ + 1)); |
| 2601 | __ Set(ebx, Immediate(0)); |
| 2602 | __ SetCallKind(ecx, CALL_AS_FUNCTION); |
| 2603 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY); |
| 2604 | { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2605 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2606 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 2607 | } |
| 2608 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2609 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 2610 | // of the original receiver from the call site). |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2611 | __ bind(&non_function); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2612 | __ mov(Operand(esp, (argc_ + 1) * kPointerSize), edi); |
| 2613 | __ Set(eax, Immediate(argc_)); |
| 2614 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2615 | __ SetCallKind(ecx, CALL_AS_METHOD); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2616 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2617 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2618 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 2619 | } |
| 2620 | |
| 2621 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2622 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 2623 | // eax : number of arguments |
| 2624 | // ebx : cache cell for call target |
| 2625 | // edi : constructor function |
| 2626 | Label slow, non_function_call; |
| 2627 | |
| 2628 | // Check that function is not a smi. |
| 2629 | __ JumpIfSmi(edi, &non_function_call); |
| 2630 | // Check that function is a JSFunction. |
| 2631 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2632 | __ j(not_equal, &slow); |
| 2633 | |
| 2634 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2635 | GenerateRecordCallTarget(masm); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2636 | } |
| 2637 | |
| 2638 | // Jump to the function-specific construct stub. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2639 | Register jmp_reg = ecx; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2640 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2641 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 2642 | SharedFunctionInfo::kConstructStubOffset)); |
| 2643 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 2644 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2645 | |
| 2646 | // edi: called object |
| 2647 | // eax: number of arguments |
| 2648 | // ecx: object map |
| 2649 | Label do_call; |
| 2650 | __ bind(&slow); |
| 2651 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 2652 | __ j(not_equal, &non_function_call); |
| 2653 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 2654 | __ jmp(&do_call); |
| 2655 | |
| 2656 | __ bind(&non_function_call); |
| 2657 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 2658 | __ bind(&do_call); |
| 2659 | // Set expected number of arguments to zero (not changing eax). |
| 2660 | __ Set(ebx, Immediate(0)); |
| 2661 | Handle<Code> arguments_adaptor = |
| 2662 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
| 2663 | __ SetCallKind(ecx, CALL_AS_METHOD); |
| 2664 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 2665 | } |
| 2666 | |
| 2667 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2668 | bool CEntryStub::NeedsImmovableCode() { |
| 2669 | return false; |
| 2670 | } |
| 2671 | |
| 2672 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2673 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 2674 | CEntryStub::GenerateAheadOfTime(isolate); |
| 2675 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2676 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2677 | // 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] | 2678 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2679 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2680 | if (Serializer::enabled()) { |
| 2681 | PlatformFeatureScope sse2(SSE2); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2682 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 2683 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2684 | } else { |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2685 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 2686 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2687 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2688 | } |
| 2689 | |
| 2690 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2691 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2692 | if (CpuFeatures::IsSupported(SSE2)) { |
| 2693 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 2694 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 2695 | // which would lead to code stub initialization state being messed up. |
| 2696 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2697 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 2698 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2699 | } |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2700 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2701 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2705 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2706 | CEntryStub stub(1, kDontSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2707 | stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2711 | static void JumpIfOOM(MacroAssembler* masm, |
| 2712 | Register value, |
| 2713 | Register scratch, |
| 2714 | Label* oom_label) { |
| 2715 | __ mov(scratch, value); |
| 2716 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 2717 | STATIC_ASSERT(kFailureTag == 3); |
| 2718 | __ and_(scratch, 0xf); |
| 2719 | __ cmp(scratch, 0xf); |
| 2720 | __ j(equal, oom_label); |
| 2721 | } |
| 2722 | |
| 2723 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2724 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 2725 | Label* throw_normal_exception, |
| 2726 | Label* throw_termination_exception, |
| 2727 | Label* throw_out_of_memory_exception, |
| 2728 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2729 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2730 | // eax: result parameter for PerformGC, if any |
| 2731 | // ebx: pointer to C function (C callee-saved) |
| 2732 | // ebp: frame pointer (restored after C call) |
| 2733 | // esp: stack pointer (restored after C call) |
| 2734 | // edi: number of arguments including receiver (C callee-saved) |
| 2735 | // esi: pointer to the first argument (C callee-saved) |
| 2736 | |
| 2737 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 2738 | |
| 2739 | // Check stack alignment. |
| 2740 | if (FLAG_debug_code) { |
| 2741 | __ CheckStackAlignment(); |
| 2742 | } |
| 2743 | |
| 2744 | if (do_gc) { |
| 2745 | // Pass failure code returned from last attempt as first argument to |
| 2746 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 2747 | // stack alignment is known to be correct. This function takes one argument |
| 2748 | // which is passed on the stack, and we know that the stack has been |
| 2749 | // prepared to pass at least one argument. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2750 | __ mov(Operand(esp, 1 * kPointerSize), |
| 2751 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2752 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 2753 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 2754 | } |
| 2755 | |
| 2756 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2757 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2758 | if (always_allocate_scope) { |
| 2759 | __ inc(Operand::StaticVariable(scope_depth)); |
| 2760 | } |
| 2761 | |
| 2762 | // Call C function. |
| 2763 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 2764 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2765 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2766 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2767 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2768 | // Result is in eax or edx:eax - do not destroy these registers! |
| 2769 | |
| 2770 | if (always_allocate_scope) { |
| 2771 | __ dec(Operand::StaticVariable(scope_depth)); |
| 2772 | } |
| 2773 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2774 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 2775 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2776 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2777 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2778 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2779 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2780 | __ int3(); |
| 2781 | __ bind(&okay); |
| 2782 | } |
| 2783 | |
| 2784 | // Check for failure result. |
| 2785 | Label failure_returned; |
| 2786 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 2787 | __ lea(ecx, Operand(eax, 1)); |
| 2788 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 2789 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2790 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2791 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2792 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2793 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2794 | |
| 2795 | // Check that there is no pending exception, otherwise we |
| 2796 | // should have returned some failure value. |
| 2797 | if (FLAG_debug_code) { |
| 2798 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2799 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2800 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2801 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 2802 | // 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] | 2803 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2804 | __ int3(); |
| 2805 | __ bind(&okay); |
| 2806 | __ pop(edx); |
| 2807 | } |
| 2808 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2809 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2810 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2811 | __ ret(0); |
| 2812 | |
| 2813 | // Handling of failure. |
| 2814 | __ bind(&failure_returned); |
| 2815 | |
| 2816 | Label retry; |
| 2817 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 2818 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 2819 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2820 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2821 | |
| 2822 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2823 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2824 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2825 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2826 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2827 | |
| 2828 | // See if we just retrieved an OOM exception. |
| 2829 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 2830 | |
| 2831 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2832 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2833 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 2834 | |
| 2835 | // Special handling of termination exceptions which are uncatchable |
| 2836 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2837 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2838 | __ j(equal, throw_termination_exception); |
| 2839 | |
| 2840 | // Handle normal exception. |
| 2841 | __ jmp(throw_normal_exception); |
| 2842 | |
| 2843 | // Retry. |
| 2844 | __ bind(&retry); |
| 2845 | } |
| 2846 | |
| 2847 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2848 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 2849 | // eax: number of arguments including receiver |
| 2850 | // ebx: pointer to C function (C callee-saved) |
| 2851 | // ebp: frame pointer (restored after C call) |
| 2852 | // esp: stack pointer (restored after C call) |
| 2853 | // esi: current context (C callee-saved) |
| 2854 | // edi: JS function of the caller (C callee-saved) |
| 2855 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2856 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 2857 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2858 | // NOTE: Invocations of builtins may return failure objects instead |
| 2859 | // of a proper result. The builtin entry handles this by performing |
| 2860 | // a garbage collection and retrying the builtin (twice). |
| 2861 | |
| 2862 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2863 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2864 | |
| 2865 | // eax: result parameter for PerformGC, if any (setup below) |
| 2866 | // ebx: pointer to builtin function (C callee-saved) |
| 2867 | // ebp: frame pointer (restored after C call) |
| 2868 | // esp: stack pointer (restored after C call) |
| 2869 | // edi: number of arguments including receiver (C callee-saved) |
| 2870 | // esi: argv pointer (C callee-saved) |
| 2871 | |
| 2872 | Label throw_normal_exception; |
| 2873 | Label throw_termination_exception; |
| 2874 | Label throw_out_of_memory_exception; |
| 2875 | |
| 2876 | // Call into the runtime system. |
| 2877 | GenerateCore(masm, |
| 2878 | &throw_normal_exception, |
| 2879 | &throw_termination_exception, |
| 2880 | &throw_out_of_memory_exception, |
| 2881 | false, |
| 2882 | false); |
| 2883 | |
| 2884 | // Do space-specific GC and retry runtime call. |
| 2885 | GenerateCore(masm, |
| 2886 | &throw_normal_exception, |
| 2887 | &throw_termination_exception, |
| 2888 | &throw_out_of_memory_exception, |
| 2889 | true, |
| 2890 | false); |
| 2891 | |
| 2892 | // Do full GC and retry runtime call one final time. |
| 2893 | Failure* failure = Failure::InternalError(); |
| 2894 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 2895 | GenerateCore(masm, |
| 2896 | &throw_normal_exception, |
| 2897 | &throw_termination_exception, |
| 2898 | &throw_out_of_memory_exception, |
| 2899 | true, |
| 2900 | true); |
| 2901 | |
| 2902 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2903 | // Set external caught exception to false. |
| 2904 | Isolate* isolate = masm->isolate(); |
| 2905 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 2906 | isolate); |
| 2907 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 2908 | |
| 2909 | // Set pending exception and eax to out of memory exception. |
| 2910 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 2911 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2912 | Label already_have_failure; |
| 2913 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 2914 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 2915 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2916 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 2917 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2918 | |
| 2919 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2920 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2921 | |
| 2922 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2923 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | |
| 2927 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2928 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2929 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2930 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2931 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 2932 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2933 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2934 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2935 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2936 | |
| 2937 | // Push marker in two places. |
| 2938 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 2939 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 2940 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 2941 | // Save callee-saved registers (C calling conventions). |
| 2942 | __ push(edi); |
| 2943 | __ push(esi); |
| 2944 | __ push(ebx); |
| 2945 | |
| 2946 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2947 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2948 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 2949 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2950 | // 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] | 2951 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2952 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2953 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2954 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2955 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2956 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 2957 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2958 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2959 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2960 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2961 | // Jump to a faked try block that does the invoke, with a faked catch |
| 2962 | // block that sets the pending exception. |
| 2963 | __ jmp(&invoke); |
| 2964 | __ bind(&handler_entry); |
| 2965 | handler_offset_ = handler_entry.pos(); |
| 2966 | // Caught exception: Store result (exception) in the pending exception |
| 2967 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2968 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2969 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2970 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 2971 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 2972 | __ jmp(&exit); |
| 2973 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2974 | // Invoke: Link this frame into the handler chain. There's only one |
| 2975 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2976 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 2977 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2978 | |
| 2979 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2980 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2981 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 2982 | |
| 2983 | // Fake a receiver (NULL). |
| 2984 | __ push(Immediate(0)); // receiver |
| 2985 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2986 | // Invoke the function by calling through JS entry trampoline builtin and |
| 2987 | // pop the faked function when we return. Notice that we cannot store a |
| 2988 | // reference to the trampoline code directly in this stub, because the |
| 2989 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2990 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2991 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 2992 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2993 | __ mov(edx, Immediate(construct_entry)); |
| 2994 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2995 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2996 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2997 | __ mov(edx, Immediate(entry)); |
| 2998 | } |
| 2999 | __ mov(edx, Operand(edx, 0)); // deref address |
| 3000 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3001 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3002 | |
| 3003 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3004 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3005 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3006 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3007 | // Check if the current stack frame is marked as the outermost JS frame. |
| 3008 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3009 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3010 | __ j(not_equal, ¬_outermost_js_2); |
| 3011 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 3012 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3013 | |
| 3014 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3015 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3016 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3017 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3018 | |
| 3019 | // Restore callee-saved registers (C calling conventions). |
| 3020 | __ pop(ebx); |
| 3021 | __ pop(esi); |
| 3022 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3023 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3024 | |
| 3025 | // Restore frame pointer and return. |
| 3026 | __ pop(ebp); |
| 3027 | __ ret(0); |
| 3028 | } |
| 3029 | |
| 3030 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3031 | // Generate stub code for instanceof. |
| 3032 | // This code can patch a call site inlined cache of the instance of check, |
| 3033 | // which looks like this. |
| 3034 | // |
| 3035 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 3036 | // 75 0a jne <some near label> |
| 3037 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 3038 | // |
| 3039 | // If call site patching is requested the stack will have the delta from the |
| 3040 | // return address to the cmp instruction just below the return address. This |
| 3041 | // also means that call site patching can only take place with arguments in |
| 3042 | // registers. TOS looks like this when call site patching is requested |
| 3043 | // |
| 3044 | // esp[0] : return address |
| 3045 | // esp[4] : delta from return address to cmp instruction |
| 3046 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3047 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3048 | // Call site inlining and patching implies arguments in registers. |
| 3049 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 3050 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3051 | // Fixed register usage throughout the stub. |
| 3052 | Register object = eax; // Object (lhs). |
| 3053 | Register map = ebx; // Map of the object. |
| 3054 | Register function = edx; // Function (rhs). |
| 3055 | Register prototype = edi; // Prototype of the function. |
| 3056 | Register scratch = ecx; |
| 3057 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3058 | // Constants describing the call site code to patch. |
| 3059 | static const int kDeltaToCmpImmediate = 2; |
| 3060 | static const int kDeltaToMov = 8; |
| 3061 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3062 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 3063 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3064 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 3065 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3066 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 3067 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 3068 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3069 | // Get the object and function - they are always both needed. |
| 3070 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3071 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3072 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 3073 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 3074 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3075 | |
| 3076 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3077 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3078 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3079 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3080 | // If there is a call site cache don't look in the global cache, but do the |
| 3081 | // real lookup and update the call site cache. |
| 3082 | if (!HasCallSiteInlineCheck()) { |
| 3083 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3084 | Label miss; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3085 | __ CompareRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3086 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3087 | __ CompareRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3088 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3089 | __ LoadRoot(eax, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3090 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 3091 | __ bind(&miss); |
| 3092 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3093 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3094 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3095 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3096 | |
| 3097 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3098 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3099 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3100 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3101 | // Update the global instanceof or call site inlined cache with the current |
| 3102 | // map and function. The cached answer will be set when it is known below. |
| 3103 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3104 | __ StoreRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
| 3105 | __ StoreRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3106 | } else { |
| 3107 | // The constants for the code patching are based on no push instructions |
| 3108 | // at the call site. |
| 3109 | ASSERT(HasArgsInRegisters()); |
| 3110 | // Get return address and delta to inlined map check. |
| 3111 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3112 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3113 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3114 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3115 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp1); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3116 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3117 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3118 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3119 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 3120 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3121 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3122 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3123 | // Loop through the prototype chain of the object looking for the function |
| 3124 | // prototype. |
| 3125 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3126 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3127 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3128 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3129 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3130 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3131 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3132 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3133 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 3134 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3135 | __ jmp(&loop); |
| 3136 | |
| 3137 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3138 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3139 | __ mov(eax, Immediate(0)); |
| 3140 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3141 | } else { |
| 3142 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3143 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3144 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3145 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3146 | if (FLAG_debug_code) { |
| 3147 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3148 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3149 | } |
| 3150 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 3151 | if (!ReturnTrueFalseObject()) { |
| 3152 | __ Set(eax, Immediate(0)); |
| 3153 | } |
| 3154 | } |
| 3155 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3156 | |
| 3157 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3158 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3159 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 3160 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3161 | } else { |
| 3162 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3163 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3164 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3165 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3166 | if (FLAG_debug_code) { |
| 3167 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3168 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3169 | } |
| 3170 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 3171 | if (!ReturnTrueFalseObject()) { |
| 3172 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 3173 | } |
| 3174 | } |
| 3175 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3176 | |
| 3177 | Label object_not_null, object_not_null_or_smi; |
| 3178 | __ bind(¬_js_object); |
| 3179 | // Before null, smi and string value checks, check that the rhs is a function |
| 3180 | // 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] | 3181 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3182 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3183 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3184 | |
| 3185 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3186 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3187 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3188 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3189 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3190 | |
| 3191 | __ bind(&object_not_null); |
| 3192 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3193 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3194 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3195 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3196 | |
| 3197 | __ bind(&object_not_null_or_smi); |
| 3198 | // String values is not instance of anything. |
| 3199 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3200 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3201 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3202 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3203 | |
| 3204 | // Slow-case: Go through the JavaScript implementation. |
| 3205 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3206 | if (!ReturnTrueFalseObject()) { |
| 3207 | // Tail call the builtin which returns 0 or 1. |
| 3208 | if (HasArgsInRegisters()) { |
| 3209 | // Push arguments below return address. |
| 3210 | __ pop(scratch); |
| 3211 | __ push(object); |
| 3212 | __ push(function); |
| 3213 | __ push(scratch); |
| 3214 | } |
| 3215 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 3216 | } else { |
| 3217 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3218 | { |
| 3219 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3220 | __ push(object); |
| 3221 | __ push(function); |
| 3222 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 3223 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3224 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3225 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3226 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3227 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3228 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3229 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3230 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3231 | __ bind(&done); |
| 3232 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3233 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3237 | Register InstanceofStub::left() { return eax; } |
| 3238 | |
| 3239 | |
| 3240 | Register InstanceofStub::right() { return edx; } |
| 3241 | |
| 3242 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3243 | // ------------------------------------------------------------------------- |
| 3244 | // StringCharCodeAtGenerator |
| 3245 | |
| 3246 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3247 | // If the receiver is a smi trigger the non-string case. |
| 3248 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3249 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3250 | |
| 3251 | // Fetch the instance type of the receiver into result register. |
| 3252 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 3253 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 3254 | // If the receiver is not a string trigger the non-string case. |
| 3255 | __ test(result_, Immediate(kIsNotStringMask)); |
| 3256 | __ j(not_zero, receiver_not_string_); |
| 3257 | |
| 3258 | // If the index is non-smi trigger the non-smi case. |
| 3259 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3260 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3261 | __ bind(&got_smi_index_); |
| 3262 | |
| 3263 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3264 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3265 | __ j(above_equal, index_out_of_range_); |
| 3266 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3267 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3268 | |
| 3269 | Factory* factory = masm->isolate()->factory(); |
| 3270 | StringCharLoadGenerator::Generate( |
| 3271 | masm, factory, object_, index_, result_, &call_runtime_); |
| 3272 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3273 | __ SmiTag(result_); |
| 3274 | __ bind(&exit_); |
| 3275 | } |
| 3276 | |
| 3277 | |
| 3278 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3279 | MacroAssembler* masm, |
| 3280 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3281 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3282 | |
| 3283 | // Index is not a smi. |
| 3284 | __ bind(&index_not_smi_); |
| 3285 | // 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] | 3286 | __ CheckMap(index_, |
| 3287 | masm->isolate()->factory()->heap_number_map(), |
| 3288 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3289 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3290 | call_helper.BeforeCall(masm); |
| 3291 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3292 | __ push(index_); // Consumed by runtime conversion function. |
| 3293 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 3294 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 3295 | } else { |
| 3296 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 3297 | // NumberToSmi discards numbers that are not exact integers. |
| 3298 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 3299 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3300 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3301 | // Save the conversion result before the pop instructions below |
| 3302 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3303 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3304 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3305 | __ pop(object_); |
| 3306 | // Reload the instance type. |
| 3307 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 3308 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 3309 | call_helper.AfterCall(masm); |
| 3310 | // If index is still not a smi, it must be out of range. |
| 3311 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3312 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3313 | // Otherwise, return to the fast path. |
| 3314 | __ jmp(&got_smi_index_); |
| 3315 | |
| 3316 | // Call runtime. We get here when the receiver is a string and the |
| 3317 | // index is a number, but the code of getting the actual character |
| 3318 | // is too complex (e.g., when the string needs to be flattened). |
| 3319 | __ bind(&call_runtime_); |
| 3320 | call_helper.BeforeCall(masm); |
| 3321 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3322 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3323 | __ push(index_); |
| 3324 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 3325 | if (!result_.is(eax)) { |
| 3326 | __ mov(result_, eax); |
| 3327 | } |
| 3328 | call_helper.AfterCall(masm); |
| 3329 | __ jmp(&exit_); |
| 3330 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3331 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | |
| 3335 | // ------------------------------------------------------------------------- |
| 3336 | // StringCharFromCodeGenerator |
| 3337 | |
| 3338 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 3339 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 3340 | STATIC_ASSERT(kSmiTag == 0); |
| 3341 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3342 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3343 | __ test(code_, |
| 3344 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3345 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3346 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3347 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3348 | Factory* factory = masm->isolate()->factory(); |
| 3349 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3350 | STATIC_ASSERT(kSmiTag == 0); |
| 3351 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3352 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3353 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3354 | __ mov(result_, FieldOperand(result_, |
| 3355 | code_, times_half_pointer_size, |
| 3356 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3357 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3358 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3359 | __ bind(&exit_); |
| 3360 | } |
| 3361 | |
| 3362 | |
| 3363 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3364 | MacroAssembler* masm, |
| 3365 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3366 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3367 | |
| 3368 | __ bind(&slow_case_); |
| 3369 | call_helper.BeforeCall(masm); |
| 3370 | __ push(code_); |
| 3371 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 3372 | if (!result_.is(eax)) { |
| 3373 | __ mov(result_, eax); |
| 3374 | } |
| 3375 | call_helper.AfterCall(masm); |
| 3376 | __ jmp(&exit_); |
| 3377 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3378 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3382 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3383 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3384 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3385 | |
| 3386 | // Load the two arguments. |
| 3387 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 3388 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 3389 | |
| 3390 | // Make sure that both arguments are strings if not known in advance. |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3391 | // Otherwise, at least one of the arguments is definitely a string, |
| 3392 | // and we convert the one that is not known to be a string. |
| 3393 | if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) { |
| 3394 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT); |
| 3395 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3396 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3397 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3398 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3399 | |
| 3400 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3401 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3402 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3403 | __ j(above_equal, &call_runtime); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3404 | } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) { |
| 3405 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0); |
| 3406 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 3407 | &call_builtin); |
| 3408 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 3409 | } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) { |
| 3410 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0); |
| 3411 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 3412 | &call_builtin); |
| 3413 | builtin_id = Builtins::STRING_ADD_LEFT; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | // Both arguments are strings. |
| 3417 | // eax: first string |
| 3418 | // edx: second string |
| 3419 | // Check if either of the strings are empty. In that case return the other. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3420 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3421 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 3422 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3423 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3424 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3425 | // Second string is empty, result is first string which is already in eax. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3426 | Counters* counters = masm->isolate()->counters(); |
| 3427 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3428 | __ ret(2 * kPointerSize); |
| 3429 | __ bind(&second_not_zero_length); |
| 3430 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 3431 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3432 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3433 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3434 | // First string is empty, result is second string which is in edx. |
| 3435 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3436 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3437 | __ ret(2 * kPointerSize); |
| 3438 | |
| 3439 | // Both strings are non-empty. |
| 3440 | // eax: first string |
| 3441 | // ebx: length of first string as a smi |
| 3442 | // ecx: length of second string as a smi |
| 3443 | // edx: second string |
| 3444 | // Look at the length of the result of adding the two strings. |
| 3445 | Label string_add_flat_result, longer_than_two; |
| 3446 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3447 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3448 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 3449 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3450 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3451 | // Use the string table when adding two one character strings, as it |
| 3452 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3453 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3454 | __ j(not_equal, &longer_than_two); |
| 3455 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3456 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3457 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3458 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3459 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3460 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 3461 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3462 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3463 | // Try to lookup two character string in string table. If it is not found |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3464 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3465 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3466 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3467 | masm, ebx, ecx, eax, edx, edi, |
| 3468 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3469 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3470 | __ ret(2 * kPointerSize); |
| 3471 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3472 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3473 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3474 | // Reload the arguments. |
| 3475 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 3476 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 3477 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3478 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 3479 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3480 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3481 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3482 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3483 | // Pack both characters in ebx. |
| 3484 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3485 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3486 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3487 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3488 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3489 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3490 | |
| 3491 | __ bind(&longer_than_two); |
| 3492 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3493 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3494 | __ j(below, &string_add_flat_result); |
| 3495 | |
| 3496 | // If result is not supposed to be flat allocate a cons string object. If both |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3497 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3498 | Label non_ascii, allocated, ascii_data; |
| 3499 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3500 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 3501 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 3502 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3503 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3504 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3505 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 3506 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3507 | __ j(zero, &non_ascii); |
| 3508 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3509 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3510 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3511 | __ bind(&allocated); |
| 3512 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3513 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3514 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 3515 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 3516 | Immediate(String::kEmptyHashField)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3517 | |
| 3518 | Label skip_write_barrier, after_writing; |
| 3519 | ExternalReference high_promotion_mode = ExternalReference:: |
| 3520 | new_space_high_promotion_mode_active_address(masm->isolate()); |
| 3521 | __ test(Operand::StaticVariable(high_promotion_mode), Immediate(1)); |
| 3522 | __ j(zero, &skip_write_barrier); |
| 3523 | |
| 3524 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 3525 | __ RecordWriteField(ecx, |
| 3526 | ConsString::kFirstOffset, |
| 3527 | eax, |
| 3528 | ebx, |
| 3529 | kDontSaveFPRegs); |
| 3530 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 3531 | __ RecordWriteField(ecx, |
| 3532 | ConsString::kSecondOffset, |
| 3533 | edx, |
| 3534 | ebx, |
| 3535 | kDontSaveFPRegs); |
| 3536 | __ jmp(&after_writing); |
| 3537 | |
| 3538 | __ bind(&skip_write_barrier); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3539 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 3540 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3541 | |
| 3542 | __ bind(&after_writing); |
| 3543 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3544 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3545 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3546 | __ ret(2 * kPointerSize); |
| 3547 | __ bind(&non_ascii); |
| 3548 | // At least one of the strings is two-byte. Check whether it happens |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3549 | // to contain only one byte characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3550 | // ecx: first instance type AND second instance type. |
| 3551 | // edi: second instance type. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3552 | __ test(ecx, Immediate(kOneByteDataHintMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3553 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3554 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3555 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 3556 | __ xor_(edi, ecx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3557 | STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0); |
| 3558 | __ and_(edi, kOneByteStringTag | kOneByteDataHintTag); |
| 3559 | __ cmp(edi, kOneByteStringTag | kOneByteDataHintTag); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3560 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3561 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3562 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3563 | __ jmp(&allocated); |
| 3564 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3565 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3566 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3567 | // Handle creating a flat result from either external or sequential strings. |
| 3568 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3569 | // eax: first string |
| 3570 | // ebx: length of resulting flat string as a smi |
| 3571 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3572 | Label first_prepared, second_prepared; |
| 3573 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3574 | __ bind(&string_add_flat_result); |
| 3575 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3576 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3577 | // ecx: instance type of first string |
| 3578 | STATIC_ASSERT(kSeqStringTag == 0); |
| 3579 | __ test_b(ecx, kStringRepresentationMask); |
| 3580 | __ j(zero, &first_is_sequential, Label::kNear); |
| 3581 | // Rule out short external string and load string resource. |
| 3582 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 3583 | __ test_b(ecx, kShortExternalStringMask); |
| 3584 | __ j(not_zero, &call_runtime); |
| 3585 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3586 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3587 | __ jmp(&first_prepared, Label::kNear); |
| 3588 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3589 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3590 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3591 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3592 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 3593 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 3594 | // Check whether both strings have same encoding. |
| 3595 | // edi: instance type of second string |
| 3596 | __ xor_(ecx, edi); |
| 3597 | __ test_b(ecx, kStringEncodingMask); |
| 3598 | __ j(not_zero, &call_runtime); |
| 3599 | STATIC_ASSERT(kSeqStringTag == 0); |
| 3600 | __ test_b(edi, kStringRepresentationMask); |
| 3601 | __ j(zero, &second_is_sequential, Label::kNear); |
| 3602 | // Rule out short external string and load string resource. |
| 3603 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 3604 | __ test_b(edi, kShortExternalStringMask); |
| 3605 | __ j(not_zero, &call_runtime); |
| 3606 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3607 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3608 | __ jmp(&second_prepared, Label::kNear); |
| 3609 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3610 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3611 | __ bind(&second_prepared); |
| 3612 | |
| 3613 | // Push the addresses of both strings' first characters onto the stack. |
| 3614 | __ push(edx); |
| 3615 | __ push(eax); |
| 3616 | |
| 3617 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 3618 | // edi: instance type of second string |
| 3619 | // First string and second string have the same encoding. |
| 3620 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 3621 | __ test_b(edi, kStringEncodingMask); |
| 3622 | __ j(zero, &non_ascii_string_add_flat_result); |
| 3623 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3624 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3625 | // ebx: length of resulting flat string as a smi |
| 3626 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3627 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3628 | // eax: result string |
| 3629 | __ mov(ecx, eax); |
| 3630 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3631 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3632 | // Load first argument's length and first character location. Account for |
| 3633 | // values currently on the stack when fetching arguments from it. |
| 3634 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3635 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 3636 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3637 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3638 | // eax: result string |
| 3639 | // ecx: first character of result |
| 3640 | // edx: first char of first argument |
| 3641 | // edi: length of first argument |
| 3642 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3643 | // Load second argument's length and first character location. Account for |
| 3644 | // values currently on the stack when fetching arguments from it. |
| 3645 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3646 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 3647 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3648 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3649 | // eax: result string |
| 3650 | // ecx: next character of result |
| 3651 | // edx: first char of second argument |
| 3652 | // edi: length of second argument |
| 3653 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3654 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3655 | __ ret(2 * kPointerSize); |
| 3656 | |
| 3657 | // Handle creating a flat two byte result. |
| 3658 | // eax: first string - known to be two byte |
| 3659 | // ebx: length of resulting flat string as a smi |
| 3660 | // edx: second string |
| 3661 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3662 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3663 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3664 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3665 | // eax: result string |
| 3666 | __ mov(ecx, eax); |
| 3667 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3668 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3669 | // Load second argument's length and first character location. Account for |
| 3670 | // values currently on the stack when fetching arguments from it. |
| 3671 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3672 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 3673 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3674 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3675 | // eax: result string |
| 3676 | // ecx: first character of result |
| 3677 | // edx: first char of first argument |
| 3678 | // edi: length of first argument |
| 3679 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3680 | // Load second argument's length and first character location. Account for |
| 3681 | // values currently on the stack when fetching arguments from it. |
| 3682 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3683 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 3684 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3685 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3686 | // eax: result string |
| 3687 | // ecx: next character of result |
| 3688 | // edx: first char of second argument |
| 3689 | // edi: length of second argument |
| 3690 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3691 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3692 | __ ret(2 * kPointerSize); |
| 3693 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3694 | // Recover stack pointer before jumping to runtime. |
| 3695 | __ bind(&call_runtime_drop_two); |
| 3696 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3697 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3698 | __ bind(&call_runtime); |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 3699 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3700 | |
| 3701 | if (call_builtin.is_linked()) { |
| 3702 | __ bind(&call_builtin); |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 3703 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3704 | } |
| 3705 | } |
| 3706 | |
| 3707 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3708 | void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
| 3709 | __ push(eax); |
| 3710 | __ push(edx); |
| 3711 | } |
| 3712 | |
| 3713 | |
| 3714 | void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm, |
| 3715 | Register temp) { |
| 3716 | __ pop(temp); |
| 3717 | __ pop(edx); |
| 3718 | __ pop(eax); |
| 3719 | __ push(temp); |
| 3720 | } |
| 3721 | |
| 3722 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3723 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 3724 | int stack_offset, |
| 3725 | Register arg, |
| 3726 | Register scratch1, |
| 3727 | Register scratch2, |
| 3728 | Register scratch3, |
| 3729 | Label* slow) { |
| 3730 | // First check if the argument is already a string. |
| 3731 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3732 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3733 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 3734 | __ j(below, &done); |
| 3735 | |
| 3736 | // Check the number to string cache. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3737 | __ bind(¬_string); |
| 3738 | // Puts the cached result into scratch1. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3739 | __ LookupNumberStringCache(arg, scratch1, scratch2, scratch3, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3740 | __ mov(arg, scratch1); |
| 3741 | __ mov(Operand(esp, stack_offset), arg); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3742 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | |
| 3746 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 3747 | Register dest, |
| 3748 | Register src, |
| 3749 | Register count, |
| 3750 | Register scratch, |
| 3751 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3752 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3753 | __ bind(&loop); |
| 3754 | // This loop just copies one character at a time, as it is only used for very |
| 3755 | // short strings. |
| 3756 | if (ascii) { |
| 3757 | __ mov_b(scratch, Operand(src, 0)); |
| 3758 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3759 | __ add(src, Immediate(1)); |
| 3760 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3761 | } else { |
| 3762 | __ mov_w(scratch, Operand(src, 0)); |
| 3763 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3764 | __ add(src, Immediate(2)); |
| 3765 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3766 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3767 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3768 | __ j(not_zero, &loop); |
| 3769 | } |
| 3770 | |
| 3771 | |
| 3772 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 3773 | Register dest, |
| 3774 | Register src, |
| 3775 | Register count, |
| 3776 | Register scratch, |
| 3777 | bool ascii) { |
| 3778 | // Copy characters using rep movs of doublewords. |
| 3779 | // The destination is aligned on a 4 byte boundary because we are |
| 3780 | // copying to the beginning of a newly allocated string. |
| 3781 | ASSERT(dest.is(edi)); // rep movs destination |
| 3782 | ASSERT(src.is(esi)); // rep movs source |
| 3783 | ASSERT(count.is(ecx)); // rep movs count |
| 3784 | ASSERT(!scratch.is(dest)); |
| 3785 | ASSERT(!scratch.is(src)); |
| 3786 | ASSERT(!scratch.is(count)); |
| 3787 | |
| 3788 | // Nothing to do for zero characters. |
| 3789 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3790 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3791 | __ j(zero, &done); |
| 3792 | |
| 3793 | // Make count the number of bytes to copy. |
| 3794 | if (!ascii) { |
| 3795 | __ shl(count, 1); |
| 3796 | } |
| 3797 | |
| 3798 | // 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] | 3799 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3800 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3801 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3802 | |
| 3803 | // Copy from edi to esi using rep movs instruction. |
| 3804 | __ mov(scratch, count); |
| 3805 | __ sar(count, 2); // Number of doublewords to copy. |
| 3806 | __ cld(); |
| 3807 | __ rep_movs(); |
| 3808 | |
| 3809 | // Find number of bytes left. |
| 3810 | __ mov(count, scratch); |
| 3811 | __ and_(count, 3); |
| 3812 | |
| 3813 | // Check if there are more bytes to copy. |
| 3814 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3815 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3816 | __ j(zero, &done); |
| 3817 | |
| 3818 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3819 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3820 | __ bind(&loop); |
| 3821 | __ mov_b(scratch, Operand(src, 0)); |
| 3822 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3823 | __ add(src, Immediate(1)); |
| 3824 | __ add(dest, Immediate(1)); |
| 3825 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3826 | __ j(not_zero, &loop); |
| 3827 | |
| 3828 | __ bind(&done); |
| 3829 | } |
| 3830 | |
| 3831 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3832 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3833 | Register c1, |
| 3834 | Register c2, |
| 3835 | Register scratch1, |
| 3836 | Register scratch2, |
| 3837 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3838 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3839 | Label* not_found) { |
| 3840 | // Register scratch3 is the general scratch register in this function. |
| 3841 | Register scratch = scratch3; |
| 3842 | |
| 3843 | // Make sure that both characters are not digits as such strings has a |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3844 | // different hash algorithm. Don't try to look for these in the string table. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3845 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3846 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3847 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 3848 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3849 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3850 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3851 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 3852 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3853 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3854 | |
| 3855 | __ bind(¬_array_index); |
| 3856 | // Calculate the two character string hash. |
| 3857 | Register hash = scratch1; |
| 3858 | GenerateHashInit(masm, hash, c1, scratch); |
| 3859 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 3860 | GenerateHashGetHash(masm, hash, scratch); |
| 3861 | |
| 3862 | // Collect the two characters in a register. |
| 3863 | Register chars = c1; |
| 3864 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3865 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3866 | |
| 3867 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 3868 | // hash: hash of two character string. |
| 3869 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3870 | // Load the string table. |
| 3871 | Register string_table = c2; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3872 | __ LoadRoot(string_table, Heap::kStringTableRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3873 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3874 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3875 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3876 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3877 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3878 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3879 | |
| 3880 | // Registers |
| 3881 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 3882 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3883 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3884 | // mask: capacity mask |
| 3885 | // scratch: - |
| 3886 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3887 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3888 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3889 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3890 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3891 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3892 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3893 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3894 | __ mov(scratch, hash); |
| 3895 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3896 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3897 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3898 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3899 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3900 | // Load the entry from the string table. |
| 3901 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3902 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3903 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3904 | scratch, |
| 3905 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3906 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3907 | |
| 3908 | // If entry is undefined no string with this hash can be found. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3909 | Factory* factory = masm->isolate()->factory(); |
| 3910 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3911 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3912 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3913 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3914 | |
| 3915 | // If length is not 2 the string is not a candidate. |
| 3916 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 3917 | Immediate(Smi::FromInt(2))); |
| 3918 | __ j(not_equal, &next_probe[i]); |
| 3919 | |
| 3920 | // As we are out of registers save the mask on the stack and use that |
| 3921 | // register as a temporary. |
| 3922 | __ push(mask); |
| 3923 | Register temp = mask; |
| 3924 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3925 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3926 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 3927 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 3928 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 3929 | temp, temp, &next_probe_pop_mask[i]); |
| 3930 | |
| 3931 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3932 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3933 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3934 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3935 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3936 | __ bind(&next_probe_pop_mask[i]); |
| 3937 | __ pop(mask); |
| 3938 | __ bind(&next_probe[i]); |
| 3939 | } |
| 3940 | |
| 3941 | // No matching 2 character string found by probing. |
| 3942 | __ jmp(not_found); |
| 3943 | |
| 3944 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3945 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3946 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3947 | __ pop(mask); // Pop saved mask from the stack. |
| 3948 | if (!result.is(eax)) { |
| 3949 | __ mov(eax, result); |
| 3950 | } |
| 3951 | } |
| 3952 | |
| 3953 | |
| 3954 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 3955 | Register hash, |
| 3956 | Register character, |
| 3957 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3958 | // hash = (seed + character) + ((seed + character) << 10); |
| 3959 | if (Serializer::enabled()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3960 | __ LoadRoot(scratch, Heap::kHashSeedRootIndex); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3961 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3962 | __ add(scratch, character); |
| 3963 | __ mov(hash, scratch); |
| 3964 | __ shl(scratch, 10); |
| 3965 | __ add(hash, scratch); |
| 3966 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3967 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3968 | __ lea(scratch, Operand(character, seed)); |
| 3969 | __ shl(scratch, 10); |
| 3970 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 3971 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3972 | // hash ^= hash >> 6; |
| 3973 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3974 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3975 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3976 | } |
| 3977 | |
| 3978 | |
| 3979 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 3980 | Register hash, |
| 3981 | Register character, |
| 3982 | Register scratch) { |
| 3983 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3984 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3985 | // hash += hash << 10; |
| 3986 | __ mov(scratch, hash); |
| 3987 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3988 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3989 | // hash ^= hash >> 6; |
| 3990 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3991 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3992 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3993 | } |
| 3994 | |
| 3995 | |
| 3996 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 3997 | Register hash, |
| 3998 | Register scratch) { |
| 3999 | // hash += hash << 3; |
| 4000 | __ mov(scratch, hash); |
| 4001 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4002 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4003 | // hash ^= hash >> 11; |
| 4004 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 4005 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4006 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4007 | // hash += hash << 15; |
| 4008 | __ mov(scratch, hash); |
| 4009 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4010 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4011 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4012 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 4013 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4014 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4015 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4016 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4017 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4018 | __ bind(&hash_not_zero); |
| 4019 | } |
| 4020 | |
| 4021 | |
| 4022 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 4023 | Label runtime; |
| 4024 | |
| 4025 | // Stack frame on entry. |
| 4026 | // esp[0]: return address |
| 4027 | // esp[4]: to |
| 4028 | // esp[8]: from |
| 4029 | // esp[12]: string |
| 4030 | |
| 4031 | // Make sure first argument is a string. |
| 4032 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 4033 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4034 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4035 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 4036 | __ j(NegateCondition(is_string), &runtime); |
| 4037 | |
| 4038 | // eax: string |
| 4039 | // ebx: instance type |
| 4040 | |
| 4041 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4042 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4043 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4044 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4045 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4046 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4047 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4048 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4049 | // Shorter than original string's length: an actual substring. |
| 4050 | __ j(below, ¬_original_string, Label::kNear); |
| 4051 | // Longer than original string's length or negative: unsafe arguments. |
| 4052 | __ j(above, &runtime); |
| 4053 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4054 | Counters* counters = masm->isolate()->counters(); |
| 4055 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 4056 | __ ret(3 * kPointerSize); |
| 4057 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4058 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 4059 | Label single_char; |
| 4060 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 4061 | __ j(equal, &single_char); |
| 4062 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4063 | // eax: string |
| 4064 | // ebx: instance type |
| 4065 | // ecx: sub string length (smi) |
| 4066 | // edx: from index (smi) |
| 4067 | // Deal with different string types: update the index if necessary |
| 4068 | // and put the underlying string into edi. |
| 4069 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 4070 | // If the string is not indirect, it can only be sequential or external. |
| 4071 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 4072 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 4073 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 4074 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 4075 | |
| 4076 | Factory* factory = masm->isolate()->factory(); |
| 4077 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 4078 | __ j(not_zero, &sliced_string, Label::kNear); |
| 4079 | // Cons string. Check whether it is flat, then fetch first part. |
| 4080 | // Flat cons strings have an empty second part. |
| 4081 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 4082 | factory->empty_string()); |
| 4083 | __ j(not_equal, &runtime); |
| 4084 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 4085 | // Update instance type. |
| 4086 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 4087 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4088 | __ jmp(&underlying_unpacked, Label::kNear); |
| 4089 | |
| 4090 | __ bind(&sliced_string); |
| 4091 | // Sliced string. Fetch parent and adjust start index by offset. |
| 4092 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 4093 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 4094 | // Update instance type. |
| 4095 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 4096 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4097 | __ jmp(&underlying_unpacked, Label::kNear); |
| 4098 | |
| 4099 | __ bind(&seq_or_external_string); |
| 4100 | // Sequential or external string. Just move string to the expected register. |
| 4101 | __ mov(edi, eax); |
| 4102 | |
| 4103 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4104 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4105 | if (FLAG_string_slices) { |
| 4106 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4107 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4108 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4109 | // edx: adjusted start index (smi) |
| 4110 | // ecx: length (smi) |
| 4111 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 4112 | // Short slice. Copy instead of slicing. |
| 4113 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4114 | // Allocate new sliced string. At this point we do not reload the instance |
| 4115 | // type including the string encoding because we simply rely on the info |
| 4116 | // provided by the original string. It does not matter if the original |
| 4117 | // string's encoding is wrong because we always have to recheck encoding of |
| 4118 | // the newly created string's parent anyways due to externalized strings. |
| 4119 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4120 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4121 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 4122 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4123 | __ j(zero, &two_byte_slice, Label::kNear); |
| 4124 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 4125 | __ jmp(&set_slice_header, Label::kNear); |
| 4126 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4127 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4128 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4129 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4130 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 4131 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4132 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 4133 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4134 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 4135 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4136 | |
| 4137 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4138 | } |
| 4139 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4140 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4141 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4142 | // edx: adjusted start index (smi) |
| 4143 | // ecx: length (smi) |
| 4144 | // The subject string can only be external or sequential string of either |
| 4145 | // encoding at this point. |
| 4146 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 4147 | STATIC_ASSERT(kExternalStringTag != 0); |
| 4148 | STATIC_ASSERT(kSeqStringTag == 0); |
| 4149 | __ test_b(ebx, kExternalStringTag); |
| 4150 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4151 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4152 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4153 | // Rule out short external strings. |
| 4154 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 4155 | __ test_b(ebx, kShortExternalStringMask); |
| 4156 | __ j(not_zero, &runtime); |
| 4157 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 4158 | // 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] | 4159 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4160 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4161 | |
| 4162 | __ bind(&sequential_string); |
| 4163 | // Stash away (adjusted) index and (underlying) string. |
| 4164 | __ push(edx); |
| 4165 | __ push(edi); |
| 4166 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4167 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4168 | __ test_b(ebx, kStringEncodingMask); |
| 4169 | __ j(zero, &two_byte_sequential); |
| 4170 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4171 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4172 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4173 | |
| 4174 | // eax: result string |
| 4175 | // ecx: result string length |
| 4176 | __ mov(edx, esi); // esi used by following code. |
| 4177 | // Locate first character of result. |
| 4178 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4179 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4180 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4181 | __ pop(esi); |
| 4182 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4183 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4184 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4185 | |
| 4186 | // eax: result string |
| 4187 | // ecx: result length |
| 4188 | // edx: original value of esi |
| 4189 | // edi: first character of result |
| 4190 | // esi: character of sub string start |
| 4191 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 4192 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4193 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4194 | __ ret(3 * kPointerSize); |
| 4195 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4196 | __ bind(&two_byte_sequential); |
| 4197 | // Sequential two-byte string. Allocate the result. |
| 4198 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4199 | |
| 4200 | // eax: result string |
| 4201 | // ecx: result string length |
| 4202 | __ mov(edx, esi); // esi used by following code. |
| 4203 | // Locate first character of result. |
| 4204 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4205 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4206 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4207 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4208 | __ pop(esi); |
| 4209 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4210 | // As from is a smi it is 2 times the value which matches the size of a two |
| 4211 | // byte character. |
| 4212 | STATIC_ASSERT(kSmiTag == 0); |
| 4213 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4214 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4215 | |
| 4216 | // eax: result string |
| 4217 | // ecx: result length |
| 4218 | // edx: original value of esi |
| 4219 | // edi: first character of result |
| 4220 | // esi: character of sub string start |
| 4221 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 4222 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4223 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4224 | __ ret(3 * kPointerSize); |
| 4225 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4226 | // Drop pushed values on the stack before tail call. |
| 4227 | __ bind(&runtime_drop_two); |
| 4228 | __ Drop(2); |
| 4229 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4230 | // Just jump to runtime to create the sub string. |
| 4231 | __ bind(&runtime); |
| 4232 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 4233 | |
| 4234 | __ bind(&single_char); |
| 4235 | // eax: string |
| 4236 | // ebx: instance type |
| 4237 | // ecx: sub string length (smi) |
| 4238 | // edx: from index (smi) |
| 4239 | StringCharAtGenerator generator( |
| 4240 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 4241 | generator.GenerateFast(masm); |
| 4242 | __ ret(3 * kPointerSize); |
| 4243 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4247 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 4248 | Register left, |
| 4249 | Register right, |
| 4250 | Register scratch1, |
| 4251 | Register scratch2) { |
| 4252 | Register length = scratch1; |
| 4253 | |
| 4254 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4255 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4256 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 4257 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4258 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4259 | __ bind(&strings_not_equal); |
| 4260 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 4261 | __ ret(0); |
| 4262 | |
| 4263 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4264 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4265 | __ bind(&check_zero_length); |
| 4266 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4267 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4268 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4269 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4270 | __ ret(0); |
| 4271 | |
| 4272 | // Compare characters. |
| 4273 | __ bind(&compare_chars); |
| 4274 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4275 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4276 | |
| 4277 | // Characters are equal. |
| 4278 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4279 | __ ret(0); |
| 4280 | } |
| 4281 | |
| 4282 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4283 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 4284 | Register left, |
| 4285 | Register right, |
| 4286 | Register scratch1, |
| 4287 | Register scratch2, |
| 4288 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4289 | Counters* counters = masm->isolate()->counters(); |
| 4290 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4291 | |
| 4292 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4293 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4294 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 4295 | __ mov(scratch3, scratch1); |
| 4296 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 4297 | |
| 4298 | Register length_delta = scratch3; |
| 4299 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4300 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4301 | // 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] | 4302 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4303 | __ bind(&left_shorter); |
| 4304 | |
| 4305 | Register min_length = scratch1; |
| 4306 | |
| 4307 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4308 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4309 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4310 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4311 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4312 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4313 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4314 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4315 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4316 | |
| 4317 | // Compare lengths - strings up to min-length are equal. |
| 4318 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4319 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4320 | Label length_not_equal; |
| 4321 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4322 | |
| 4323 | // Result is EQUAL. |
| 4324 | STATIC_ASSERT(EQUAL == 0); |
| 4325 | STATIC_ASSERT(kSmiTag == 0); |
| 4326 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4327 | __ ret(0); |
| 4328 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4329 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4330 | Label result_less; |
| 4331 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4332 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4333 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4334 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4335 | __ j(above, &result_greater, Label::kNear); |
| 4336 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4337 | |
| 4338 | // Result is LESS. |
| 4339 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 4340 | __ ret(0); |
| 4341 | |
| 4342 | // Result is GREATER. |
| 4343 | __ bind(&result_greater); |
| 4344 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 4345 | __ ret(0); |
| 4346 | } |
| 4347 | |
| 4348 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4349 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 4350 | MacroAssembler* masm, |
| 4351 | Register left, |
| 4352 | Register right, |
| 4353 | Register length, |
| 4354 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4355 | Label* chars_not_equal, |
| 4356 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4357 | // Change index to run from -length to -1 by adding length to string |
| 4358 | // start. This means that loop ends when index reaches zero, which |
| 4359 | // doesn't need an additional compare. |
| 4360 | __ SmiUntag(length); |
| 4361 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4362 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4363 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4364 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4365 | __ neg(length); |
| 4366 | Register index = length; // index = -length; |
| 4367 | |
| 4368 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4369 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4370 | __ bind(&loop); |
| 4371 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 4372 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4373 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4374 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4375 | __ j(not_zero, &loop); |
| 4376 | } |
| 4377 | |
| 4378 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4379 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 4380 | Label runtime; |
| 4381 | |
| 4382 | // Stack frame on entry. |
| 4383 | // esp[0]: return address |
| 4384 | // esp[4]: right string |
| 4385 | // esp[8]: left string |
| 4386 | |
| 4387 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 4388 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 4389 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4390 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4391 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4392 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4393 | STATIC_ASSERT(EQUAL == 0); |
| 4394 | STATIC_ASSERT(kSmiTag == 0); |
| 4395 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4396 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4397 | __ ret(2 * kPointerSize); |
| 4398 | |
| 4399 | __ bind(¬_same); |
| 4400 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4401 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4402 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 4403 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4404 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4405 | // Drop arguments from the stack. |
| 4406 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4407 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4408 | __ push(ecx); |
| 4409 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 4410 | |
| 4411 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4412 | // tagged as a small integer. |
| 4413 | __ bind(&runtime); |
| 4414 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 4415 | } |
| 4416 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4417 | |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 4418 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 4419 | // ----------- S t a t e ------------- |
| 4420 | // -- edx : left |
| 4421 | // -- eax : right |
| 4422 | // -- esp[0] : return address |
| 4423 | // ----------------------------------- |
| 4424 | Isolate* isolate = masm->isolate(); |
| 4425 | |
| 4426 | // Load ecx with the allocation site. We stick an undefined dummy value here |
| 4427 | // and replace it with the real allocation site later when we instantiate this |
| 4428 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
| 4429 | __ mov(ecx, handle(isolate->heap()->undefined_value())); |
| 4430 | |
| 4431 | // Make sure that we actually patched the allocation site. |
| 4432 | if (FLAG_debug_code) { |
| 4433 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4434 | __ Assert(not_equal, kExpectedAllocationSite); |
| 4435 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 4436 | isolate->factory()->allocation_site_map()); |
| 4437 | __ Assert(equal, kExpectedAllocationSite); |
| 4438 | } |
| 4439 | |
| 4440 | // Tail call into the stub that handles binary operations with allocation |
| 4441 | // sites. |
| 4442 | BinaryOpWithAllocationSiteStub stub(state_); |
| 4443 | __ TailCallStub(&stub); |
| 4444 | } |
| 4445 | |
| 4446 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4447 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4448 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4449 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4450 | __ mov(ecx, edx); |
| 4451 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4452 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4453 | |
| 4454 | if (GetCondition() == equal) { |
| 4455 | // 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] | 4456 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4457 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4458 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4459 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4460 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4461 | // Correct sign of result in case of overflow. |
| 4462 | __ not_(edx); |
| 4463 | __ bind(&done); |
| 4464 | __ mov(eax, edx); |
| 4465 | } |
| 4466 | __ ret(0); |
| 4467 | |
| 4468 | __ bind(&miss); |
| 4469 | GenerateMiss(masm); |
| 4470 | } |
| 4471 | |
| 4472 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4473 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 4474 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4475 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4476 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4477 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4478 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4479 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4480 | if (left_ == CompareIC::SMI) { |
| 4481 | __ JumpIfNotSmi(edx, &miss); |
| 4482 | } |
| 4483 | if (right_ == CompareIC::SMI) { |
| 4484 | __ JumpIfNotSmi(eax, &miss); |
| 4485 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4486 | |
| 4487 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4488 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4489 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4490 | CpuFeatureScope scope1(masm, SSE2); |
| 4491 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4492 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4493 | // Load left and right operand. |
| 4494 | Label done, left, left_smi, right_smi; |
| 4495 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 4496 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 4497 | masm->isolate()->factory()->heap_number_map()); |
| 4498 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4499 | __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4500 | __ jmp(&left, Label::kNear); |
| 4501 | __ bind(&right_smi); |
| 4502 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 4503 | __ SmiUntag(ecx); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4504 | __ Cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4505 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4506 | __ bind(&left); |
| 4507 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 4508 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4509 | masm->isolate()->factory()->heap_number_map()); |
| 4510 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4511 | __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4512 | __ jmp(&done); |
| 4513 | __ bind(&left_smi); |
| 4514 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 4515 | __ SmiUntag(ecx); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4516 | __ Cvtsi2sd(xmm0, ecx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4517 | |
| 4518 | __ bind(&done); |
| 4519 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4520 | __ ucomisd(xmm0, xmm1); |
| 4521 | |
| 4522 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4523 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4524 | |
| 4525 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4526 | // Performing mov, because xor would destroy the flag register. |
| 4527 | __ mov(eax, 0); // equal |
| 4528 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4529 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4530 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4531 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4532 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4533 | } else { |
| 4534 | __ mov(ecx, edx); |
| 4535 | __ and_(ecx, eax); |
| 4536 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 4537 | |
| 4538 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 4539 | masm->isolate()->factory()->heap_number_map()); |
| 4540 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 4541 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4542 | masm->isolate()->factory()->heap_number_map()); |
| 4543 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4544 | } |
| 4545 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4546 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4547 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4548 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 4549 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4550 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4551 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4552 | __ bind(&maybe_undefined1); |
| 4553 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 4554 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 4555 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4556 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4557 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 4558 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 4559 | __ jmp(&unordered); |
| 4560 | } |
| 4561 | |
| 4562 | __ bind(&maybe_undefined2); |
| 4563 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 4564 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 4565 | __ j(equal, &unordered); |
| 4566 | } |
| 4567 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4568 | __ bind(&miss); |
| 4569 | GenerateMiss(masm); |
| 4570 | } |
| 4571 | |
| 4572 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4573 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 4574 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4575 | ASSERT(GetCondition() == equal); |
| 4576 | |
| 4577 | // Registers containing left and right operands respectively. |
| 4578 | Register left = edx; |
| 4579 | Register right = eax; |
| 4580 | Register tmp1 = ecx; |
| 4581 | Register tmp2 = ebx; |
| 4582 | |
| 4583 | // Check that both operands are heap objects. |
| 4584 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4585 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4586 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4587 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4588 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4589 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4590 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4591 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4592 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4593 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4594 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4595 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 4596 | __ or_(tmp1, tmp2); |
| 4597 | __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 4598 | __ j(not_zero, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4599 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4600 | // Internalized strings are compared by identity. |
| 4601 | Label done; |
| 4602 | __ cmp(left, right); |
| 4603 | // Make sure eax is non-zero. At this point input operands are |
| 4604 | // guaranteed to be non-zero. |
| 4605 | ASSERT(right.is(eax)); |
| 4606 | __ j(not_equal, &done, Label::kNear); |
| 4607 | STATIC_ASSERT(EQUAL == 0); |
| 4608 | STATIC_ASSERT(kSmiTag == 0); |
| 4609 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4610 | __ bind(&done); |
| 4611 | __ ret(0); |
| 4612 | |
| 4613 | __ bind(&miss); |
| 4614 | GenerateMiss(masm); |
| 4615 | } |
| 4616 | |
| 4617 | |
| 4618 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 4619 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 4620 | ASSERT(GetCondition() == equal); |
| 4621 | |
| 4622 | // Registers containing left and right operands respectively. |
| 4623 | Register left = edx; |
| 4624 | Register right = eax; |
| 4625 | Register tmp1 = ecx; |
| 4626 | Register tmp2 = ebx; |
| 4627 | |
| 4628 | // Check that both operands are heap objects. |
| 4629 | Label miss; |
| 4630 | __ mov(tmp1, left); |
| 4631 | STATIC_ASSERT(kSmiTag == 0); |
| 4632 | __ and_(tmp1, right); |
| 4633 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 4634 | |
| 4635 | // Check that both operands are unique names. This leaves the instance |
| 4636 | // types loaded in tmp1 and tmp2. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4637 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4638 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4639 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4640 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 4641 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4642 | __ JumpIfNotUniqueName(tmp1, &miss, Label::kNear); |
| 4643 | __ JumpIfNotUniqueName(tmp2, &miss, Label::kNear); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4644 | |
| 4645 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4646 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4647 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4648 | // Make sure eax is non-zero. At this point input operands are |
| 4649 | // guaranteed to be non-zero. |
| 4650 | ASSERT(right.is(eax)); |
| 4651 | __ j(not_equal, &done, Label::kNear); |
| 4652 | STATIC_ASSERT(EQUAL == 0); |
| 4653 | STATIC_ASSERT(kSmiTag == 0); |
| 4654 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4655 | __ bind(&done); |
| 4656 | __ ret(0); |
| 4657 | |
| 4658 | __ bind(&miss); |
| 4659 | GenerateMiss(masm); |
| 4660 | } |
| 4661 | |
| 4662 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4663 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4664 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4665 | Label miss; |
| 4666 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4667 | bool equality = Token::IsEqualityOp(op_); |
| 4668 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4669 | // Registers containing left and right operands respectively. |
| 4670 | Register left = edx; |
| 4671 | Register right = eax; |
| 4672 | Register tmp1 = ecx; |
| 4673 | Register tmp2 = ebx; |
| 4674 | Register tmp3 = edi; |
| 4675 | |
| 4676 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4677 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4678 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4679 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4680 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4681 | |
| 4682 | // Check that both operands are strings. This leaves the instance |
| 4683 | // types loaded in tmp1 and tmp2. |
| 4684 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4685 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4686 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4687 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 4688 | __ mov(tmp3, tmp1); |
| 4689 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4690 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4691 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 4692 | __ j(not_zero, &miss); |
| 4693 | |
| 4694 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4695 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4696 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4697 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4698 | STATIC_ASSERT(EQUAL == 0); |
| 4699 | STATIC_ASSERT(kSmiTag == 0); |
| 4700 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4701 | __ ret(0); |
| 4702 | |
| 4703 | // Handle not identical strings. |
| 4704 | __ bind(¬_same); |
| 4705 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4706 | // 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] | 4707 | // 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] | 4708 | // non-equality compare, we still need to determine the order. We |
| 4709 | // also know they are both strings. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4710 | if (equality) { |
| 4711 | Label do_compare; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4712 | STATIC_ASSERT(kInternalizedTag == 0); |
| 4713 | __ or_(tmp1, tmp2); |
| 4714 | __ test(tmp1, Immediate(kIsNotInternalizedMask)); |
| 4715 | __ j(not_zero, &do_compare, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4716 | // Make sure eax is non-zero. At this point input operands are |
| 4717 | // guaranteed to be non-zero. |
| 4718 | ASSERT(right.is(eax)); |
| 4719 | __ ret(0); |
| 4720 | __ bind(&do_compare); |
| 4721 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4722 | |
| 4723 | // Check that both strings are sequential ASCII. |
| 4724 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4725 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 4726 | |
| 4727 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4728 | if (equality) { |
| 4729 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 4730 | masm, left, right, tmp1, tmp2); |
| 4731 | } else { |
| 4732 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 4733 | masm, left, right, tmp1, tmp2, tmp3); |
| 4734 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4735 | |
| 4736 | // Handle more complex cases in runtime. |
| 4737 | __ bind(&runtime); |
| 4738 | __ pop(tmp1); // Return address. |
| 4739 | __ push(left); |
| 4740 | __ push(right); |
| 4741 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4742 | if (equality) { |
| 4743 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 4744 | } else { |
| 4745 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 4746 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4747 | |
| 4748 | __ bind(&miss); |
| 4749 | GenerateMiss(masm); |
| 4750 | } |
| 4751 | |
| 4752 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4753 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4754 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4755 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4756 | __ mov(ecx, edx); |
| 4757 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4758 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4759 | |
| 4760 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4761 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4762 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4763 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4764 | |
| 4765 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4766 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4767 | __ ret(0); |
| 4768 | |
| 4769 | __ bind(&miss); |
| 4770 | GenerateMiss(masm); |
| 4771 | } |
| 4772 | |
| 4773 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4774 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 4775 | Label miss; |
| 4776 | __ mov(ecx, edx); |
| 4777 | __ and_(ecx, eax); |
| 4778 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4779 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4780 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4781 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 4782 | __ cmp(ecx, known_map_); |
| 4783 | __ j(not_equal, &miss, Label::kNear); |
| 4784 | __ cmp(ebx, known_map_); |
| 4785 | __ j(not_equal, &miss, Label::kNear); |
| 4786 | |
| 4787 | __ sub(eax, edx); |
| 4788 | __ ret(0); |
| 4789 | |
| 4790 | __ bind(&miss); |
| 4791 | GenerateMiss(masm); |
| 4792 | } |
| 4793 | |
| 4794 | |
| 4795 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4796 | { |
| 4797 | // Call the runtime system in a fresh internal frame. |
| 4798 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 4799 | masm->isolate()); |
| 4800 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4801 | __ push(edx); // Preserve edx and eax. |
| 4802 | __ push(eax); |
| 4803 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4804 | __ push(eax); |
| 4805 | __ push(Immediate(Smi::FromInt(op_))); |
| 4806 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4807 | // Compute the entry point of the rewritten stub. |
| 4808 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 4809 | __ pop(eax); |
| 4810 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4811 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4812 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4813 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4814 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4815 | } |
| 4816 | |
| 4817 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4818 | // Helper function used to check that the dictionary doesn't contain |
| 4819 | // the property. This function may return false negatives, so miss_label |
| 4820 | // must always call a backup property check that is complete. |
| 4821 | // 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] | 4822 | // Name must be a unique name and receiver must be a heap object. |
| 4823 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 4824 | Label* miss, |
| 4825 | Label* done, |
| 4826 | Register properties, |
| 4827 | Handle<Name> name, |
| 4828 | Register r0) { |
| 4829 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4830 | |
| 4831 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 4832 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 4833 | // undefined value), it guarantees the hash table doesn't contain the |
| 4834 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4835 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4836 | for (int i = 0; i < kInlinedProbes; i++) { |
| 4837 | // Compute the masked index: (hash + i + i * i) & mask. |
| 4838 | Register index = r0; |
| 4839 | // Capacity is smi 2^n. |
| 4840 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 4841 | __ dec(index); |
| 4842 | __ and_(index, |
| 4843 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4844 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4845 | |
| 4846 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4847 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4848 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 4849 | Register entity_name = r0; |
| 4850 | // Having undefined at this place means the name is not contained. |
| 4851 | ASSERT_EQ(kSmiTagSize, 1); |
| 4852 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 4853 | kElementsStartOffset - kHeapObjectTag)); |
| 4854 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 4855 | __ j(equal, done); |
| 4856 | |
| 4857 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4858 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4859 | __ j(equal, miss); |
| 4860 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4861 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4862 | // Check for the hole and skip. |
| 4863 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4864 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 4865 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4866 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4867 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4868 | __ JumpIfNotUniqueName(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 4869 | miss); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4870 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4871 | } |
| 4872 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4873 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 4874 | __ push(Immediate(Handle<Object>(name))); |
| 4875 | __ push(Immediate(name->Hash())); |
| 4876 | __ CallStub(&stub); |
| 4877 | __ test(r0, r0); |
| 4878 | __ j(not_zero, miss); |
| 4879 | __ jmp(done); |
| 4880 | } |
| 4881 | |
| 4882 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4883 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4884 | // |done| label if a property with the given name is found leaving the |
| 4885 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 4886 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4887 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 4888 | Label* miss, |
| 4889 | Label* done, |
| 4890 | Register elements, |
| 4891 | Register name, |
| 4892 | Register r0, |
| 4893 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 4894 | ASSERT(!elements.is(r0)); |
| 4895 | ASSERT(!elements.is(r1)); |
| 4896 | ASSERT(!name.is(r0)); |
| 4897 | ASSERT(!name.is(r1)); |
| 4898 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4899 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4900 | |
| 4901 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 4902 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 4903 | __ dec(r1); |
| 4904 | |
| 4905 | // Generate an unrolled loop that performs a few probes before |
| 4906 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 4907 | // cover ~93% of loads from dictionaries. |
| 4908 | for (int i = 0; i < kInlinedProbes; i++) { |
| 4909 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4910 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 4911 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4912 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4913 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4914 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4915 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4916 | |
| 4917 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4918 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4919 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 4920 | |
| 4921 | // Check if the key is identical to the name. |
| 4922 | __ cmp(name, Operand(elements, |
| 4923 | r0, |
| 4924 | times_4, |
| 4925 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4926 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4927 | } |
| 4928 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4929 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4930 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4931 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 4932 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4933 | __ push(r0); |
| 4934 | __ CallStub(&stub); |
| 4935 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4936 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4937 | __ j(zero, miss); |
| 4938 | __ jmp(done); |
| 4939 | } |
| 4940 | |
| 4941 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4942 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4943 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 4944 | // 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] | 4945 | // Stack frame on entry: |
| 4946 | // esp[0 * kPointerSize]: return address. |
| 4947 | // esp[1 * kPointerSize]: key's hash. |
| 4948 | // esp[2 * kPointerSize]: key. |
| 4949 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4950 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4951 | // result_: used as scratch. |
| 4952 | // index_: will hold an index of entry if lookup is successful. |
| 4953 | // might alias with result_. |
| 4954 | // Returns: |
| 4955 | // result_ is zero if lookup failed, non zero otherwise. |
| 4956 | |
| 4957 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 4958 | |
| 4959 | Register scratch = result_; |
| 4960 | |
| 4961 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 4962 | __ dec(scratch); |
| 4963 | __ SmiUntag(scratch); |
| 4964 | __ push(scratch); |
| 4965 | |
| 4966 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 4967 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 4968 | // undefined value), it guarantees the hash table doesn't contain the |
| 4969 | // property. It's true even if some slots represent deleted properties |
| 4970 | // (their names are the null value). |
| 4971 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 4972 | // Compute the masked index: (hash + i + i * i) & mask. |
| 4973 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 4974 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4975 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4976 | } |
| 4977 | __ and_(scratch, Operand(esp, 0)); |
| 4978 | |
| 4979 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4980 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4981 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 4982 | |
| 4983 | // Having undefined at this place means the name is not contained. |
| 4984 | ASSERT_EQ(kSmiTagSize, 1); |
| 4985 | __ mov(scratch, Operand(dictionary_, |
| 4986 | index_, |
| 4987 | times_pointer_size, |
| 4988 | kElementsStartOffset - kHeapObjectTag)); |
| 4989 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 4990 | __ j(equal, ¬_in_dictionary); |
| 4991 | |
| 4992 | // Stop if found the property. |
| 4993 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 4994 | __ j(equal, &in_dictionary); |
| 4995 | |
| 4996 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4997 | // 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] | 4998 | // 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] | 4999 | // key we are looking for. |
| 5000 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5001 | // Check if the entry name is not a unique name. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5002 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5003 | __ JumpIfNotUniqueName(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 5004 | &maybe_in_dictionary); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5005 | } |
| 5006 | } |
| 5007 | |
| 5008 | __ bind(&maybe_in_dictionary); |
| 5009 | // If we are doing negative lookup then probing failure should be |
| 5010 | // treated as a lookup success. For positive lookup probing failure |
| 5011 | // should be treated as lookup failure. |
| 5012 | if (mode_ == POSITIVE_LOOKUP) { |
| 5013 | __ mov(result_, Immediate(0)); |
| 5014 | __ Drop(1); |
| 5015 | __ ret(2 * kPointerSize); |
| 5016 | } |
| 5017 | |
| 5018 | __ bind(&in_dictionary); |
| 5019 | __ mov(result_, Immediate(1)); |
| 5020 | __ Drop(1); |
| 5021 | __ ret(2 * kPointerSize); |
| 5022 | |
| 5023 | __ bind(¬_in_dictionary); |
| 5024 | __ mov(result_, Immediate(0)); |
| 5025 | __ Drop(1); |
| 5026 | __ ret(2 * kPointerSize); |
| 5027 | } |
| 5028 | |
| 5029 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5030 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 5031 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5032 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5033 | stub.GetCode(isolate); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5034 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5035 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5036 | stub2.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5037 | } |
| 5038 | } |
| 5039 | |
| 5040 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5041 | bool CodeStub::CanUseFPRegisters() { |
| 5042 | return CpuFeatures::IsSupported(SSE2); |
| 5043 | } |
| 5044 | |
| 5045 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5046 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 5047 | // the value has just been written into the object, now this stub makes sure |
| 5048 | // we keep the GC informed. The word in the object where the value has been |
| 5049 | // written is in the address register. |
| 5050 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 5051 | Label skip_to_incremental_noncompacting; |
| 5052 | Label skip_to_incremental_compacting; |
| 5053 | |
| 5054 | // The first two instructions are generated with labels so as to get the |
| 5055 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 5056 | // forth between a compare instructions (a nop in this position) and the |
| 5057 | // real branch when we start and stop incremental heap marking. |
| 5058 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 5059 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 5060 | |
| 5061 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 5062 | __ RememberedSetHelper(object_, |
| 5063 | address_, |
| 5064 | value_, |
| 5065 | save_fp_regs_mode_, |
| 5066 | MacroAssembler::kReturnAtEnd); |
| 5067 | } else { |
| 5068 | __ ret(0); |
| 5069 | } |
| 5070 | |
| 5071 | __ bind(&skip_to_incremental_noncompacting); |
| 5072 | GenerateIncremental(masm, INCREMENTAL); |
| 5073 | |
| 5074 | __ bind(&skip_to_incremental_compacting); |
| 5075 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 5076 | |
| 5077 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 5078 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 5079 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 5080 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 5081 | } |
| 5082 | |
| 5083 | |
| 5084 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 5085 | regs_.Save(masm); |
| 5086 | |
| 5087 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 5088 | Label dont_need_remembered_set; |
| 5089 | |
| 5090 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 5091 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 5092 | regs_.scratch0(), |
| 5093 | &dont_need_remembered_set); |
| 5094 | |
| 5095 | __ CheckPageFlag(regs_.object(), |
| 5096 | regs_.scratch0(), |
| 5097 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 5098 | not_zero, |
| 5099 | &dont_need_remembered_set); |
| 5100 | |
| 5101 | // First notify the incremental marker if necessary, then update the |
| 5102 | // remembered set. |
| 5103 | CheckNeedsToInformIncrementalMarker( |
| 5104 | masm, |
| 5105 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 5106 | mode); |
| 5107 | InformIncrementalMarker(masm, mode); |
| 5108 | regs_.Restore(masm); |
| 5109 | __ RememberedSetHelper(object_, |
| 5110 | address_, |
| 5111 | value_, |
| 5112 | save_fp_regs_mode_, |
| 5113 | MacroAssembler::kReturnAtEnd); |
| 5114 | |
| 5115 | __ bind(&dont_need_remembered_set); |
| 5116 | } |
| 5117 | |
| 5118 | CheckNeedsToInformIncrementalMarker( |
| 5119 | masm, |
| 5120 | kReturnOnNoNeedToInformIncrementalMarker, |
| 5121 | mode); |
| 5122 | InformIncrementalMarker(masm, mode); |
| 5123 | regs_.Restore(masm); |
| 5124 | __ ret(0); |
| 5125 | } |
| 5126 | |
| 5127 | |
| 5128 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 5129 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 5130 | int argument_count = 3; |
| 5131 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 5132 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 5133 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5134 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5135 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5136 | |
| 5137 | AllowExternalCallThatCantCauseGC scope(masm); |
| 5138 | if (mode == INCREMENTAL_COMPACTION) { |
| 5139 | __ CallCFunction( |
| 5140 | ExternalReference::incremental_evacuation_record_write_function( |
| 5141 | masm->isolate()), |
| 5142 | argument_count); |
| 5143 | } else { |
| 5144 | ASSERT(mode == INCREMENTAL); |
| 5145 | __ CallCFunction( |
| 5146 | ExternalReference::incremental_marking_record_write_function( |
| 5147 | masm->isolate()), |
| 5148 | argument_count); |
| 5149 | } |
| 5150 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 5151 | } |
| 5152 | |
| 5153 | |
| 5154 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 5155 | MacroAssembler* masm, |
| 5156 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 5157 | Mode mode) { |
| 5158 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 5159 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5160 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 5161 | __ and_(regs_.scratch0(), regs_.object()); |
| 5162 | __ mov(regs_.scratch1(), |
| 5163 | Operand(regs_.scratch0(), |
| 5164 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 5165 | __ sub(regs_.scratch1(), Immediate(1)); |
| 5166 | __ mov(Operand(regs_.scratch0(), |
| 5167 | MemoryChunk::kWriteBarrierCounterOffset), |
| 5168 | regs_.scratch1()); |
| 5169 | __ j(negative, &need_incremental); |
| 5170 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5171 | // Let's look at the color of the object: If it is not black we don't have |
| 5172 | // to inform the incremental marker. |
| 5173 | __ JumpIfBlack(regs_.object(), |
| 5174 | regs_.scratch0(), |
| 5175 | regs_.scratch1(), |
| 5176 | &object_is_black, |
| 5177 | Label::kNear); |
| 5178 | |
| 5179 | regs_.Restore(masm); |
| 5180 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 5181 | __ RememberedSetHelper(object_, |
| 5182 | address_, |
| 5183 | value_, |
| 5184 | save_fp_regs_mode_, |
| 5185 | MacroAssembler::kReturnAtEnd); |
| 5186 | } else { |
| 5187 | __ ret(0); |
| 5188 | } |
| 5189 | |
| 5190 | __ bind(&object_is_black); |
| 5191 | |
| 5192 | // Get the value from the slot. |
| 5193 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 5194 | |
| 5195 | if (mode == INCREMENTAL_COMPACTION) { |
| 5196 | Label ensure_not_white; |
| 5197 | |
| 5198 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 5199 | regs_.scratch1(), // Scratch. |
| 5200 | MemoryChunk::kEvacuationCandidateMask, |
| 5201 | zero, |
| 5202 | &ensure_not_white, |
| 5203 | Label::kNear); |
| 5204 | |
| 5205 | __ CheckPageFlag(regs_.object(), |
| 5206 | regs_.scratch1(), // Scratch. |
| 5207 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 5208 | not_zero, |
| 5209 | &ensure_not_white, |
| 5210 | Label::kNear); |
| 5211 | |
| 5212 | __ jmp(&need_incremental); |
| 5213 | |
| 5214 | __ bind(&ensure_not_white); |
| 5215 | } |
| 5216 | |
| 5217 | // We need an extra register for this, so we push the object register |
| 5218 | // temporarily. |
| 5219 | __ push(regs_.object()); |
| 5220 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 5221 | regs_.scratch1(), // Scratch. |
| 5222 | regs_.object(), // Scratch. |
| 5223 | &need_incremental_pop_object, |
| 5224 | Label::kNear); |
| 5225 | __ pop(regs_.object()); |
| 5226 | |
| 5227 | regs_.Restore(masm); |
| 5228 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 5229 | __ RememberedSetHelper(object_, |
| 5230 | address_, |
| 5231 | value_, |
| 5232 | save_fp_regs_mode_, |
| 5233 | MacroAssembler::kReturnAtEnd); |
| 5234 | } else { |
| 5235 | __ ret(0); |
| 5236 | } |
| 5237 | |
| 5238 | __ bind(&need_incremental_pop_object); |
| 5239 | __ pop(regs_.object()); |
| 5240 | |
| 5241 | __ bind(&need_incremental); |
| 5242 | |
| 5243 | // Fall through when we need to inform the incremental marker. |
| 5244 | } |
| 5245 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5246 | |
| 5247 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 5248 | // ----------- S t a t e ------------- |
| 5249 | // -- eax : element value to store |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5250 | // -- ecx : element index as smi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5251 | // -- esp[0] : return address |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 5252 | // -- esp[4] : array literal index in function |
| 5253 | // -- esp[8] : array literal |
| 5254 | // clobbers ebx, edx, edi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5255 | // ----------------------------------- |
| 5256 | |
| 5257 | Label element_done; |
| 5258 | Label double_elements; |
| 5259 | Label smi_element; |
| 5260 | Label slow_elements; |
| 5261 | Label slow_elements_from_double; |
| 5262 | Label fast_elements; |
| 5263 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 5264 | // Get array literal index, array literal and its map. |
| 5265 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 5266 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 5267 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 5268 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5269 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5270 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5271 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5272 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5273 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5274 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5275 | // Store into the array literal requires a elements transition. Call into |
| 5276 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5277 | |
| 5278 | __ bind(&slow_elements); |
| 5279 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 5280 | // call. |
| 5281 | __ push(ebx); |
| 5282 | __ push(ecx); |
| 5283 | __ push(eax); |
| 5284 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 5285 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 5286 | __ push(edx); |
| 5287 | __ push(edi); // Return return address so that tail call returns to right |
| 5288 | // place. |
| 5289 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 5290 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5291 | __ bind(&slow_elements_from_double); |
| 5292 | __ pop(edx); |
| 5293 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5294 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5295 | // 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] | 5296 | __ bind(&fast_elements); |
| 5297 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 5298 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 5299 | FixedArrayBase::kHeaderSize)); |
| 5300 | __ mov(Operand(ecx, 0), eax); |
| 5301 | // Update the write barrier for the array store. |
| 5302 | __ RecordWrite(ebx, ecx, eax, |
| 5303 | kDontSaveFPRegs, |
| 5304 | EMIT_REMEMBERED_SET, |
| 5305 | OMIT_SMI_CHECK); |
| 5306 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5307 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5308 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 5309 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5310 | __ bind(&smi_element); |
| 5311 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 5312 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 5313 | FixedArrayBase::kHeaderSize), eax); |
| 5314 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5315 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5316 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5317 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5318 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5319 | __ push(edx); |
| 5320 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 5321 | __ StoreNumberToDoubleElements(eax, |
| 5322 | edx, |
| 5323 | ecx, |
| 5324 | edi, |
| 5325 | xmm0, |
| 5326 | &slow_elements_from_double, |
| 5327 | false); |
| 5328 | __ pop(edx); |
| 5329 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5330 | } |
| 5331 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5332 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5333 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5334 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5335 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 5336 | int parameter_count_offset = |
| 5337 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 5338 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5339 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 5340 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5341 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 5342 | ? kPointerSize |
| 5343 | : 0; |
| 5344 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 5345 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5346 | } |
| 5347 | |
| 5348 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5349 | void StubFailureTailCallTrampolineStub::Generate(MacroAssembler* masm) { |
| 5350 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
| 5351 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
| 5352 | __ mov(edi, eax); |
| 5353 | int parameter_count_offset = |
| 5354 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 5355 | __ mov(eax, MemOperand(ebp, parameter_count_offset)); |
| 5356 | // The parameter count above includes the receiver for the arguments passed to |
| 5357 | // the deoptimization handler. Subtract the receiver for the parameter count |
| 5358 | // for the call. |
| 5359 | __ sub(eax, Immediate(1)); |
| 5360 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 5361 | ParameterCount argument_count(eax); |
| 5362 | __ InvokeFunction( |
| 5363 | edi, argument_count, JUMP_FUNCTION, NullCallWrapper(), CALL_AS_METHOD); |
| 5364 | } |
| 5365 | |
| 5366 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5367 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5368 | if (masm->isolate()->function_entry_hook() != NULL) { |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5369 | ProfileEntryHookStub stub; |
| 5370 | masm->CallStub(&stub); |
| 5371 | } |
| 5372 | } |
| 5373 | |
| 5374 | |
| 5375 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5376 | // Save volatile registers. |
| 5377 | const int kNumSavedRegisters = 3; |
| 5378 | __ push(eax); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5379 | __ push(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5380 | __ push(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5381 | |
| 5382 | // Calculate and push the original stack pointer. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 5383 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5384 | __ push(eax); |
| 5385 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 5386 | // Retrieve our return address and use it to calculate the calling |
| 5387 | // function's address. |
| 5388 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5389 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 5390 | __ push(eax); |
| 5391 | |
| 5392 | // Call the entry hook. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5393 | ASSERT(masm->isolate()->function_entry_hook() != NULL); |
| 5394 | __ call(FUNCTION_ADDR(masm->isolate()->function_entry_hook()), |
| 5395 | RelocInfo::RUNTIME_ENTRY); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5396 | __ add(esp, Immediate(2 * kPointerSize)); |
| 5397 | |
| 5398 | // Restore ecx. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5399 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5400 | __ pop(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5401 | __ pop(eax); |
| 5402 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5403 | __ ret(0); |
| 5404 | } |
| 5405 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5406 | |
| 5407 | template<class T> |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5408 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 5409 | AllocationSiteOverrideMode mode) { |
| 5410 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 5411 | T stub(GetInitialFastElementsKind(), |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5412 | mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5413 | __ TailCallStub(&stub); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5414 | } else if (mode == DONT_OVERRIDE) { |
| 5415 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 5416 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5417 | for (int i = 0; i <= last_index; ++i) { |
| 5418 | Label next; |
| 5419 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 5420 | __ cmp(edx, kind); |
| 5421 | __ j(not_equal, &next); |
| 5422 | T stub(kind); |
| 5423 | __ TailCallStub(&stub); |
| 5424 | __ bind(&next); |
| 5425 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5426 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5427 | // If we reached this point there is a problem. |
| 5428 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 5429 | } else { |
| 5430 | UNREACHABLE(); |
| 5431 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5432 | } |
| 5433 | |
| 5434 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5435 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 5436 | AllocationSiteOverrideMode mode) { |
| 5437 | // ebx - type info cell (if mode != DISABLE_ALLOCATION_SITES) |
| 5438 | // edx - kind (if mode != DISABLE_ALLOCATION_SITES) |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5439 | // eax - number of arguments |
| 5440 | // edi - constructor? |
| 5441 | // esp[0] - return address |
| 5442 | // esp[4] - last argument |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5443 | Label normal_sequence; |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5444 | if (mode == DONT_OVERRIDE) { |
| 5445 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 5446 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 5447 | ASSERT(FAST_ELEMENTS == 2); |
| 5448 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 5449 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 5450 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 5451 | |
| 5452 | // is the low bit set? If so, we are holey and that is good. |
| 5453 | __ test_b(edx, 1); |
| 5454 | __ j(not_zero, &normal_sequence); |
| 5455 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5456 | |
| 5457 | // look at the first argument |
| 5458 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 5459 | __ test(ecx, ecx); |
| 5460 | __ j(zero, &normal_sequence); |
| 5461 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5462 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 5463 | ElementsKind initial = GetInitialFastElementsKind(); |
| 5464 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5465 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5466 | ArraySingleArgumentConstructorStub stub_holey(holey_initial, |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5467 | DISABLE_ALLOCATION_SITES); |
| 5468 | __ TailCallStub(&stub_holey); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5469 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5470 | __ bind(&normal_sequence); |
| 5471 | ArraySingleArgumentConstructorStub stub(initial, |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5472 | DISABLE_ALLOCATION_SITES); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5473 | __ TailCallStub(&stub); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5474 | } else if (mode == DONT_OVERRIDE) { |
| 5475 | // We are going to create a holey array, but our kind is non-holey. |
| 5476 | // Fix kind and retry. |
| 5477 | __ inc(edx); |
| 5478 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
| 5479 | if (FLAG_debug_code) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5480 | Handle<Map> allocation_site_map = |
| 5481 | masm->isolate()->factory()->allocation_site_map(); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5482 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 5483 | __ Assert(equal, kExpectedAllocationSiteInCell); |
| 5484 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5485 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5486 | // Save the resulting elements kind in type info. We can't just store r3 |
| 5487 | // in the AllocationSite::transition_info field because elements kind is |
| 5488 | // restricted to a portion of the field...upper bits need to be left alone. |
| 5489 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 5490 | __ add(FieldOperand(ecx, AllocationSite::kTransitionInfoOffset), |
| 5491 | Immediate(Smi::FromInt(kFastElementsKindPackedToHoley))); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5492 | |
| 5493 | __ bind(&normal_sequence); |
| 5494 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 5495 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5496 | for (int i = 0; i <= last_index; ++i) { |
| 5497 | Label next; |
| 5498 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 5499 | __ cmp(edx, kind); |
| 5500 | __ j(not_equal, &next); |
| 5501 | ArraySingleArgumentConstructorStub stub(kind); |
| 5502 | __ TailCallStub(&stub); |
| 5503 | __ bind(&next); |
| 5504 | } |
| 5505 | |
| 5506 | // If we reached this point there is a problem. |
| 5507 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 5508 | } else { |
| 5509 | UNREACHABLE(); |
| 5510 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5511 | } |
| 5512 | |
| 5513 | |
| 5514 | template<class T> |
| 5515 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 5516 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 5517 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5518 | for (int i = 0; i <= to_index; ++i) { |
| 5519 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5520 | T stub(kind); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5521 | stub.GetCode(isolate); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 5522 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame^] | 5523 | T stub1(kind, DISABLE_ALLOCATION_SITES); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5524 | stub1.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5525 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5526 | } |
| 5527 | } |
| 5528 | |
| 5529 | |
| 5530 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 5531 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 5532 | isolate); |
| 5533 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 5534 | isolate); |
| 5535 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 5536 | isolate); |
| 5537 | } |
| 5538 | |
| 5539 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5540 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 5541 | Isolate* isolate) { |
| 5542 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 5543 | for (int i = 0; i < 2; i++) { |
| 5544 | // For internal arrays we only need a few things |
| 5545 | InternalArrayNoArgumentConstructorStub stubh1(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5546 | stubh1.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5547 | InternalArraySingleArgumentConstructorStub stubh2(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5548 | stubh2.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5549 | InternalArrayNArgumentsConstructorStub stubh3(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5550 | stubh3.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5551 | } |
| 5552 | } |
| 5553 | |
| 5554 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5555 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 5556 | MacroAssembler* masm, |
| 5557 | AllocationSiteOverrideMode mode) { |
| 5558 | if (argument_count_ == ANY) { |
| 5559 | Label not_zero_case, not_one_case; |
| 5560 | __ test(eax, eax); |
| 5561 | __ j(not_zero, ¬_zero_case); |
| 5562 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 5563 | |
| 5564 | __ bind(¬_zero_case); |
| 5565 | __ cmp(eax, 1); |
| 5566 | __ j(greater, ¬_one_case); |
| 5567 | CreateArrayDispatchOneArgument(masm, mode); |
| 5568 | |
| 5569 | __ bind(¬_one_case); |
| 5570 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 5571 | } else if (argument_count_ == NONE) { |
| 5572 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 5573 | } else if (argument_count_ == ONE) { |
| 5574 | CreateArrayDispatchOneArgument(masm, mode); |
| 5575 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 5576 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 5577 | } else { |
| 5578 | UNREACHABLE(); |
| 5579 | } |
| 5580 | } |
| 5581 | |
| 5582 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5583 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 5584 | // ----------- S t a t e ------------- |
| 5585 | // -- eax : argc (only if argument_count_ == ANY) |
| 5586 | // -- ebx : type info cell |
| 5587 | // -- edi : constructor |
| 5588 | // -- esp[0] : return address |
| 5589 | // -- esp[4] : last argument |
| 5590 | // ----------------------------------- |
| 5591 | Handle<Object> undefined_sentinel( |
| 5592 | masm->isolate()->heap()->undefined_value(), |
| 5593 | masm->isolate()); |
| 5594 | |
| 5595 | if (FLAG_debug_code) { |
| 5596 | // The array construct code is only set for the global and natives |
| 5597 | // builtin Array functions which always have maps. |
| 5598 | |
| 5599 | // Initial map for the builtin Array function should be a map. |
| 5600 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5601 | // Will both indicate a NULL and a Smi. |
| 5602 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5603 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5604 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5605 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5606 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5607 | // We should either have undefined in ebx or a valid cell |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5608 | Label okay_here; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5609 | Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5610 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 5611 | __ j(equal, &okay_here); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5612 | __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5613 | __ Assert(equal, kExpectedPropertyCellInRegisterEbx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5614 | __ bind(&okay_here); |
| 5615 | } |
| 5616 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5617 | Label no_info; |
| 5618 | // If the type cell is undefined, or contains anything other than an |
| 5619 | // AllocationSite, call an array constructor that doesn't use AllocationSites. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5620 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 5621 | __ j(equal, &no_info); |
| 5622 | __ mov(edx, FieldOperand(ebx, Cell::kValueOffset)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5623 | __ cmp(FieldOperand(edx, 0), Immediate( |
| 5624 | masm->isolate()->factory()->allocation_site_map())); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 5625 | __ j(not_equal, &no_info); |
| 5626 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5627 | // Only look at the lower 16 bits of the transition info. |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 5628 | __ mov(edx, FieldOperand(edx, AllocationSite::kTransitionInfoOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5629 | __ SmiUntag(edx); |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5630 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 5631 | __ and_(edx, Immediate(AllocationSite::ElementsKindBits::kMask)); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5632 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 5633 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5634 | __ bind(&no_info); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5635 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5636 | } |
| 5637 | |
| 5638 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5639 | void InternalArrayConstructorStub::GenerateCase( |
| 5640 | MacroAssembler* masm, ElementsKind kind) { |
| 5641 | Label not_zero_case, not_one_case; |
| 5642 | Label normal_sequence; |
| 5643 | |
| 5644 | __ test(eax, eax); |
| 5645 | __ j(not_zero, ¬_zero_case); |
| 5646 | InternalArrayNoArgumentConstructorStub stub0(kind); |
| 5647 | __ TailCallStub(&stub0); |
| 5648 | |
| 5649 | __ bind(¬_zero_case); |
| 5650 | __ cmp(eax, 1); |
| 5651 | __ j(greater, ¬_one_case); |
| 5652 | |
| 5653 | if (IsFastPackedElementsKind(kind)) { |
| 5654 | // We might need to create a holey array |
| 5655 | // look at the first argument |
| 5656 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 5657 | __ test(ecx, ecx); |
| 5658 | __ j(zero, &normal_sequence); |
| 5659 | |
| 5660 | InternalArraySingleArgumentConstructorStub |
| 5661 | stub1_holey(GetHoleyElementsKind(kind)); |
| 5662 | __ TailCallStub(&stub1_holey); |
| 5663 | } |
| 5664 | |
| 5665 | __ bind(&normal_sequence); |
| 5666 | InternalArraySingleArgumentConstructorStub stub1(kind); |
| 5667 | __ TailCallStub(&stub1); |
| 5668 | |
| 5669 | __ bind(¬_one_case); |
| 5670 | InternalArrayNArgumentsConstructorStub stubN(kind); |
| 5671 | __ TailCallStub(&stubN); |
| 5672 | } |
| 5673 | |
| 5674 | |
| 5675 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 5676 | // ----------- S t a t e ------------- |
| 5677 | // -- eax : argc |
| 5678 | // -- ebx : type info cell |
| 5679 | // -- edi : constructor |
| 5680 | // -- esp[0] : return address |
| 5681 | // -- esp[4] : last argument |
| 5682 | // ----------------------------------- |
| 5683 | |
| 5684 | if (FLAG_debug_code) { |
| 5685 | // The array construct code is only set for the global and natives |
| 5686 | // builtin Array functions which always have maps. |
| 5687 | |
| 5688 | // Initial map for the builtin Array function should be a map. |
| 5689 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5690 | // Will both indicate a NULL and a Smi. |
| 5691 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5692 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5693 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5694 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5695 | } |
| 5696 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5697 | // Figure out the right elements kind |
| 5698 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5699 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5700 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 5701 | // but the following masking takes care of that anyway. |
| 5702 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 5703 | // Retrieve elements_kind from bit field 2. |
| 5704 | __ and_(ecx, Map::kElementsKindMask); |
| 5705 | __ shr(ecx, Map::kElementsKindShift); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5706 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5707 | if (FLAG_debug_code) { |
| 5708 | Label done; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5709 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5710 | __ j(equal, &done); |
| 5711 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 5712 | __ Assert(equal, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5713 | kInvalidElementsKindForInternalArrayOrInternalPackedArray); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5714 | __ bind(&done); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5715 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5716 | |
| 5717 | Label fast_elements_case; |
| 5718 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 5719 | __ j(equal, &fast_elements_case); |
| 5720 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 5721 | |
| 5722 | __ bind(&fast_elements_case); |
| 5723 | GenerateCase(masm, FAST_ELEMENTS); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5724 | } |
| 5725 | |
| 5726 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5727 | #undef __ |
| 5728 | |
| 5729 | } } // namespace v8::internal |
| 5730 | |
| 5731 | #endif // V8_TARGET_ARCH_IA32 |