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 | |
machenbach@chromium.org | 26ca35c | 2014-01-16 08:22:55 +0000 | [diff] [blame] | 367 | void CallDescriptors::InitializeForIsolate(Isolate* isolate) { |
| 368 | { |
| 369 | CallInterfaceDescriptor* descriptor = |
| 370 | isolate->call_descriptor(Isolate::ArgumentAdaptorCall); |
| 371 | static Register registers[] = { edi, // JSFunction |
| 372 | esi, // context |
| 373 | eax, // actual number of arguments |
| 374 | ebx, // expected number of arguments |
| 375 | }; |
| 376 | static Representation representations[] = { |
| 377 | Representation::Tagged(), // JSFunction |
| 378 | Representation::Tagged(), // context |
| 379 | Representation::Integer32(), // actual number of arguments |
| 380 | Representation::Integer32(), // expected number of arguments |
| 381 | }; |
| 382 | descriptor->register_param_count_ = 4; |
| 383 | descriptor->register_params_ = registers; |
| 384 | descriptor->param_representations_ = representations; |
| 385 | } |
| 386 | { |
| 387 | CallInterfaceDescriptor* descriptor = |
| 388 | isolate->call_descriptor(Isolate::KeyedCall); |
| 389 | static Register registers[] = { esi, // context |
| 390 | ecx, // key |
| 391 | }; |
| 392 | static Representation representations[] = { |
| 393 | Representation::Tagged(), // context |
| 394 | Representation::Tagged(), // key |
| 395 | }; |
| 396 | descriptor->register_param_count_ = 2; |
| 397 | descriptor->register_params_ = registers; |
| 398 | descriptor->param_representations_ = representations; |
| 399 | } |
| 400 | { |
| 401 | CallInterfaceDescriptor* descriptor = |
| 402 | isolate->call_descriptor(Isolate::NamedCall); |
| 403 | static Register registers[] = { esi, // context |
| 404 | ecx, // name |
| 405 | }; |
| 406 | static Representation representations[] = { |
| 407 | Representation::Tagged(), // context |
| 408 | Representation::Tagged(), // name |
| 409 | }; |
| 410 | descriptor->register_param_count_ = 2; |
| 411 | descriptor->register_params_ = registers; |
| 412 | descriptor->param_representations_ = representations; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 417 | #define __ ACCESS_MASM(masm) |
whesse@chromium.org | 7a392b3 | 2011-01-31 11:30:36 +0000 | [diff] [blame] | 418 | |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 419 | |
| 420 | void HydrogenCodeStub::GenerateLightweightMiss(MacroAssembler* masm) { |
| 421 | // Update the static counter each time a new code stub is generated. |
| 422 | Isolate* isolate = masm->isolate(); |
| 423 | isolate->counters()->code_stubs()->Increment(); |
| 424 | |
| 425 | CodeStubInterfaceDescriptor* descriptor = GetInterfaceDescriptor(isolate); |
| 426 | int param_count = descriptor->register_param_count_; |
| 427 | { |
| 428 | // Call the runtime system in a fresh internal frame. |
| 429 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 430 | ASSERT(descriptor->register_param_count_ == 0 || |
| 431 | eax.is(descriptor->register_params_[param_count - 1])); |
| 432 | // Push arguments |
| 433 | for (int i = 0; i < param_count; ++i) { |
| 434 | __ push(descriptor->register_params_[i]); |
| 435 | } |
svenpanne@chromium.org | a53e8e0 | 2013-05-24 12:35:50 +0000 | [diff] [blame] | 436 | ExternalReference miss = descriptor->miss_handler(); |
ulan@chromium.org | 77ca49a | 2013-04-22 09:43:56 +0000 | [diff] [blame] | 437 | __ CallExternalReference(miss, descriptor->register_param_count_); |
| 438 | } |
| 439 | |
| 440 | __ ret(0); |
| 441 | } |
| 442 | |
| 443 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 444 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 445 | // Try to allocate the context in new space. |
| 446 | Label gc; |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 447 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 448 | __ Allocate((length * kPointerSize) + FixedArray::kHeaderSize, |
| 449 | eax, ebx, ecx, &gc, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 450 | |
| 451 | // Get the function from the stack. |
| 452 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 453 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 454 | // Set up the object header. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 455 | Factory* factory = masm->isolate()->factory(); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 456 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 457 | factory->function_context_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 458 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 459 | Immediate(Smi::FromInt(length))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 460 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 461 | // Set up the fixed slots. |
lrn@chromium.org | 5d00b60 | 2011-01-05 09:51:43 +0000 | [diff] [blame] | 462 | __ Set(ebx, Immediate(0)); // Set to NULL. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 463 | __ mov(Operand(eax, Context::SlotOffset(Context::CLOSURE_INDEX)), ecx); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 464 | __ mov(Operand(eax, Context::SlotOffset(Context::PREVIOUS_INDEX)), esi); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 465 | __ mov(Operand(eax, Context::SlotOffset(Context::EXTENSION_INDEX)), ebx); |
| 466 | |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 467 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 468 | __ mov(ebx, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 469 | __ mov(Operand(eax, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX)), ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 470 | |
| 471 | // Initialize the rest of the slots to undefined. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 472 | __ mov(ebx, factory->undefined_value()); |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 473 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 474 | __ mov(Operand(eax, Context::SlotOffset(i)), ebx); |
| 475 | } |
| 476 | |
| 477 | // Return and remove the on-stack parameter. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 478 | __ mov(esi, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 479 | __ ret(1 * kPointerSize); |
| 480 | |
| 481 | // Need to collect. Call into runtime system. |
| 482 | __ bind(&gc); |
svenpanne@chromium.org | 6d786c9 | 2011-06-15 10:58:27 +0000 | [diff] [blame] | 483 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 487 | void FastNewBlockContextStub::Generate(MacroAssembler* masm) { |
| 488 | // Stack layout on entry: |
| 489 | // |
| 490 | // [esp + (1 * kPointerSize)]: function |
| 491 | // [esp + (2 * kPointerSize)]: serialized scope info |
| 492 | |
| 493 | // Try to allocate the context in new space. |
| 494 | Label gc; |
| 495 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
svenpanne@chromium.org | 2bda543 | 2013-03-15 12:39:50 +0000 | [diff] [blame] | 496 | __ Allocate(FixedArray::SizeFor(length), eax, ebx, ecx, &gc, TAG_OBJECT); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 497 | |
| 498 | // Get the function or sentinel from the stack. |
| 499 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
| 500 | |
| 501 | // Get the serialized scope info from the stack. |
| 502 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 503 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 504 | // Set up the object header. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 505 | Factory* factory = masm->isolate()->factory(); |
| 506 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), |
| 507 | factory->block_context_map()); |
| 508 | __ mov(FieldOperand(eax, Context::kLengthOffset), |
| 509 | Immediate(Smi::FromInt(length))); |
| 510 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 511 | // 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] | 512 | // sentinel instead of a function. The block context should get the |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 513 | // canonical empty function of the native context as its closure which |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 514 | // we still have to look up. |
| 515 | Label after_sentinel; |
| 516 | __ JumpIfNotSmi(ecx, &after_sentinel, Label::kNear); |
| 517 | if (FLAG_debug_code) { |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 518 | __ cmp(ecx, 0); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 519 | __ Assert(equal, kExpected0AsASmiSentinel); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 520 | } |
| 521 | __ mov(ecx, GlobalObjectOperand()); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 522 | __ mov(ecx, FieldOperand(ecx, GlobalObject::kNativeContextOffset)); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 523 | __ mov(ecx, ContextOperand(ecx, Context::CLOSURE_INDEX)); |
| 524 | __ bind(&after_sentinel); |
| 525 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 526 | // Set up the fixed slots. |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 527 | __ mov(ContextOperand(eax, Context::CLOSURE_INDEX), ecx); |
| 528 | __ mov(ContextOperand(eax, Context::PREVIOUS_INDEX), esi); |
| 529 | __ mov(ContextOperand(eax, Context::EXTENSION_INDEX), ebx); |
| 530 | |
| 531 | // Copy the global object from the previous context. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 532 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 533 | __ mov(ContextOperand(eax, Context::GLOBAL_OBJECT_INDEX), ebx); |
svenpanne@chromium.org | a8bb4d9 | 2011-10-10 13:20:40 +0000 | [diff] [blame] | 534 | |
| 535 | // Initialize the rest of the slots to the hole value. |
| 536 | if (slots_ == 1) { |
| 537 | __ mov(ContextOperand(eax, Context::MIN_CONTEXT_SLOTS), |
| 538 | factory->the_hole_value()); |
| 539 | } else { |
| 540 | __ mov(ebx, factory->the_hole_value()); |
| 541 | for (int i = 0; i < slots_; i++) { |
| 542 | __ mov(ContextOperand(eax, i + Context::MIN_CONTEXT_SLOTS), ebx); |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | // Return and remove the on-stack parameters. |
| 547 | __ mov(esi, eax); |
| 548 | __ ret(2 * kPointerSize); |
| 549 | |
| 550 | // Need to collect. Call into runtime system. |
| 551 | __ bind(&gc); |
| 552 | __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
| 553 | } |
| 554 | |
| 555 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 556 | void StoreBufferOverflowStub::Generate(MacroAssembler* masm) { |
| 557 | // We don't allow a GC during a store buffer overflow so there is no need to |
| 558 | // store the registers in any particular way, but we do have to store and |
| 559 | // restore them. |
| 560 | __ pushad(); |
| 561 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 562 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 563 | __ sub(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 564 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 565 | XMMRegister reg = XMMRegister::from_code(i); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 566 | __ movsd(Operand(esp, i * kDoubleSize), reg); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 567 | } |
| 568 | } |
| 569 | const int argument_count = 1; |
| 570 | |
| 571 | AllowExternalCallThatCantCauseGC scope(masm); |
| 572 | __ PrepareCallCFunction(argument_count, ecx); |
| 573 | __ mov(Operand(esp, 0 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 574 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 575 | __ CallCFunction( |
| 576 | ExternalReference::store_buffer_overflow_function(masm->isolate()), |
| 577 | argument_count); |
| 578 | if (save_doubles_ == kSaveFPRegs) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 579 | CpuFeatureScope scope(masm, SSE2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 580 | for (int i = 0; i < XMMRegister::kNumRegisters; i++) { |
| 581 | XMMRegister reg = XMMRegister::from_code(i); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 582 | __ movsd(reg, Operand(esp, i * kDoubleSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 583 | } |
| 584 | __ add(esp, Immediate(kDoubleSize * XMMRegister::kNumRegisters)); |
| 585 | } |
| 586 | __ popad(); |
| 587 | __ ret(0); |
| 588 | } |
| 589 | |
| 590 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 591 | class FloatingPointHelper : public AllStatic { |
| 592 | public: |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 593 | enum ArgLocation { |
| 594 | ARGS_ON_STACK, |
| 595 | ARGS_IN_REGISTERS |
| 596 | }; |
| 597 | |
| 598 | // Code pattern for loading a floating point value. Input value must |
| 599 | // be either a smi or a heap number object (fp value). Requirements: |
| 600 | // operand in register number. Returns operand as floating point number |
| 601 | // on FPU stack. |
| 602 | static void LoadFloatOperand(MacroAssembler* masm, Register number); |
| 603 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 604 | // Test if operands are smi or number objects (fp). Requirements: |
| 605 | // operand_1 in eax, operand_2 in edx; falls through on float |
| 606 | // operands, jumps to the non_float label otherwise. |
| 607 | static void CheckFloatOperands(MacroAssembler* masm, |
| 608 | Label* non_float, |
| 609 | Register scratch); |
| 610 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 611 | // Test if operands are numbers (smi or HeapNumber objects), and load |
| 612 | // them into xmm0 and xmm1 if they are. Jump to label not_numbers if |
| 613 | // either operand is not a number. Operands are in edx and eax. |
| 614 | // Leaves operands unchanged. |
| 615 | static void LoadSSE2Operands(MacroAssembler* masm, Label* not_numbers); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 616 | }; |
| 617 | |
| 618 | |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 619 | void DoubleToIStub::Generate(MacroAssembler* masm) { |
| 620 | Register input_reg = this->source(); |
| 621 | Register final_result_reg = this->destination(); |
| 622 | ASSERT(is_truncating()); |
| 623 | |
| 624 | Label check_negative, process_64_bits, done, done_no_stash; |
| 625 | |
| 626 | int double_offset = offset(); |
| 627 | |
| 628 | // Account for return address and saved regs if input is esp. |
| 629 | if (input_reg.is(esp)) double_offset += 3 * kPointerSize; |
| 630 | |
| 631 | MemOperand mantissa_operand(MemOperand(input_reg, double_offset)); |
| 632 | MemOperand exponent_operand(MemOperand(input_reg, |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 633 | double_offset + kDoubleSize / 2)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 634 | |
| 635 | Register scratch1; |
| 636 | { |
| 637 | Register scratch_candidates[3] = { ebx, edx, edi }; |
| 638 | for (int i = 0; i < 3; i++) { |
| 639 | scratch1 = scratch_candidates[i]; |
| 640 | if (!final_result_reg.is(scratch1) && !input_reg.is(scratch1)) break; |
| 641 | } |
| 642 | } |
| 643 | // Since we must use ecx for shifts below, use some other register (eax) |
| 644 | // to calculate the result if ecx is the requested return register. |
| 645 | Register result_reg = final_result_reg.is(ecx) ? eax : final_result_reg; |
| 646 | // Save ecx if it isn't the return register and therefore volatile, or if it |
| 647 | // is the return register, then save the temp register we use in its stead for |
| 648 | // the result. |
| 649 | Register save_reg = final_result_reg.is(ecx) ? eax : ecx; |
| 650 | __ push(scratch1); |
| 651 | __ push(save_reg); |
| 652 | |
| 653 | bool stash_exponent_copy = !input_reg.is(esp); |
| 654 | __ mov(scratch1, mantissa_operand); |
| 655 | if (CpuFeatures::IsSupported(SSE3)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 656 | CpuFeatureScope scope(masm, SSE3); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 657 | // Load x87 register with heap number. |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 658 | __ fld_d(mantissa_operand); |
| 659 | } |
| 660 | __ mov(ecx, exponent_operand); |
| 661 | if (stash_exponent_copy) __ push(ecx); |
| 662 | |
| 663 | __ and_(ecx, HeapNumber::kExponentMask); |
| 664 | __ shr(ecx, HeapNumber::kExponentShift); |
| 665 | __ lea(result_reg, MemOperand(ecx, -HeapNumber::kExponentBias)); |
| 666 | __ cmp(result_reg, Immediate(HeapNumber::kMantissaBits)); |
| 667 | __ j(below, &process_64_bits); |
| 668 | |
| 669 | // Result is entirely in lower 32-bits of mantissa |
| 670 | int delta = HeapNumber::kExponentBias + Double::kPhysicalSignificandSize; |
| 671 | if (CpuFeatures::IsSupported(SSE3)) { |
| 672 | __ fstp(0); |
| 673 | } |
| 674 | __ sub(ecx, Immediate(delta)); |
| 675 | __ xor_(result_reg, result_reg); |
| 676 | __ cmp(ecx, Immediate(31)); |
| 677 | __ j(above, &done); |
| 678 | __ shl_cl(scratch1); |
| 679 | __ jmp(&check_negative); |
| 680 | |
| 681 | __ bind(&process_64_bits); |
| 682 | if (CpuFeatures::IsSupported(SSE3)) { |
| 683 | CpuFeatureScope scope(masm, SSE3); |
| 684 | if (stash_exponent_copy) { |
| 685 | // Already a copy of the exponent on the stack, overwrite it. |
| 686 | STATIC_ASSERT(kDoubleSize == 2 * kPointerSize); |
| 687 | __ sub(esp, Immediate(kDoubleSize / 2)); |
| 688 | } else { |
| 689 | // Reserve space for 64 bit answer. |
| 690 | __ sub(esp, Immediate(kDoubleSize)); // Nolint. |
| 691 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 692 | // Do conversion, which cannot fail because we checked the exponent. |
| 693 | __ fisttp_d(Operand(esp, 0)); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 694 | __ mov(result_reg, Operand(esp, 0)); // Load low word of answer as result |
| 695 | __ add(esp, Immediate(kDoubleSize)); |
| 696 | __ jmp(&done_no_stash); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 697 | } else { |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 698 | // Result must be extracted from shifted 32-bit mantissa |
| 699 | __ sub(ecx, Immediate(delta)); |
| 700 | __ neg(ecx); |
| 701 | if (stash_exponent_copy) { |
| 702 | __ mov(result_reg, MemOperand(esp, 0)); |
| 703 | } else { |
| 704 | __ mov(result_reg, exponent_operand); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 705 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 706 | __ and_(result_reg, |
| 707 | Immediate(static_cast<uint32_t>(Double::kSignificandMask >> 32))); |
| 708 | __ add(result_reg, |
| 709 | Immediate(static_cast<uint32_t>(Double::kHiddenBit >> 32))); |
| 710 | __ shrd(result_reg, scratch1); |
| 711 | __ shr_cl(result_reg); |
| 712 | __ test(ecx, Immediate(32)); |
| 713 | if (CpuFeatures::IsSupported(CMOV)) { |
| 714 | CpuFeatureScope use_cmov(masm, CMOV); |
| 715 | __ cmov(not_equal, scratch1, result_reg); |
| 716 | } else { |
| 717 | Label skip_mov; |
| 718 | __ j(equal, &skip_mov, Label::kNear); |
| 719 | __ mov(scratch1, result_reg); |
| 720 | __ bind(&skip_mov); |
| 721 | } |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 722 | } |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 723 | |
| 724 | // If the double was negative, negate the integer result. |
| 725 | __ bind(&check_negative); |
| 726 | __ mov(result_reg, scratch1); |
| 727 | __ neg(result_reg); |
| 728 | if (stash_exponent_copy) { |
| 729 | __ cmp(MemOperand(esp, 0), Immediate(0)); |
| 730 | } else { |
| 731 | __ cmp(exponent_operand, Immediate(0)); |
| 732 | } |
| 733 | if (CpuFeatures::IsSupported(CMOV)) { |
| 734 | CpuFeatureScope use_cmov(masm, CMOV); |
| 735 | __ cmov(greater, result_reg, scratch1); |
| 736 | } else { |
| 737 | Label skip_mov; |
| 738 | __ j(less_equal, &skip_mov, Label::kNear); |
| 739 | __ mov(result_reg, scratch1); |
| 740 | __ bind(&skip_mov); |
| 741 | } |
| 742 | |
| 743 | // Restore registers |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 744 | __ bind(&done); |
danno@chromium.org | 169691d | 2013-07-15 08:01:13 +0000 | [diff] [blame] | 745 | if (stash_exponent_copy) { |
| 746 | __ add(esp, Immediate(kDoubleSize / 2)); |
| 747 | } |
| 748 | __ bind(&done_no_stash); |
| 749 | if (!final_result_reg.is(result_reg)) { |
| 750 | ASSERT(final_result_reg.is(ecx)); |
| 751 | __ mov(final_result_reg, result_reg); |
| 752 | } |
| 753 | __ pop(save_reg); |
| 754 | __ pop(scratch1); |
| 755 | __ ret(0); |
sgjesse@chromium.org | 8e8294a | 2011-05-02 14:30:53 +0000 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 759 | void FloatingPointHelper::LoadFloatOperand(MacroAssembler* masm, |
| 760 | Register number) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 761 | Label load_smi, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 762 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 763 | __ JumpIfSmi(number, &load_smi, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 764 | __ fld_d(FieldOperand(number, HeapNumber::kValueOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 765 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 766 | |
| 767 | __ bind(&load_smi); |
| 768 | __ SmiUntag(number); |
| 769 | __ push(number); |
| 770 | __ fild_s(Operand(esp, 0)); |
| 771 | __ pop(number); |
| 772 | |
| 773 | __ bind(&done); |
| 774 | } |
| 775 | |
| 776 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 777 | void FloatingPointHelper::LoadSSE2Operands(MacroAssembler* masm, |
| 778 | Label* not_numbers) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 779 | 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] | 780 | // Load operand in edx into xmm0, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 781 | __ JumpIfSmi(edx, &load_smi_edx, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 782 | Factory* factory = masm->isolate()->factory(); |
| 783 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 784 | __ 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] | 785 | __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 786 | __ bind(&load_eax); |
| 787 | // Load operand in eax into xmm1, or branch to not_numbers. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 788 | __ JumpIfSmi(eax, &load_smi_eax, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 789 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), factory->heap_number_map()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 790 | __ j(equal, &load_float_eax, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 791 | __ jmp(not_numbers); // Argument in eax is not a number. |
| 792 | __ bind(&load_smi_edx); |
| 793 | __ SmiUntag(edx); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 794 | __ Cvtsi2sd(xmm0, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 795 | __ SmiTag(edx); // Retag smi for heap number overwriting test. |
| 796 | __ jmp(&load_eax); |
| 797 | __ bind(&load_smi_eax); |
| 798 | __ SmiUntag(eax); // Untag smi before converting to float. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 799 | __ Cvtsi2sd(xmm1, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 800 | __ SmiTag(eax); // Retag smi for heap number overwriting test. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 801 | __ jmp(&done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 802 | __ bind(&load_float_eax); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 803 | __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 804 | __ bind(&done); |
| 805 | } |
| 806 | |
| 807 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 808 | void FloatingPointHelper::CheckFloatOperands(MacroAssembler* masm, |
| 809 | Label* non_float, |
| 810 | Register scratch) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 811 | Label test_other, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 812 | // Test if both operands are floats or smi -> scratch=k_is_float; |
| 813 | // Otherwise scratch = k_not_float. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 814 | __ JumpIfSmi(edx, &test_other, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 815 | __ mov(scratch, FieldOperand(edx, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 816 | Factory* factory = masm->isolate()->factory(); |
| 817 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 818 | __ j(not_equal, non_float); // argument in edx is not a number -> NaN |
| 819 | |
| 820 | __ bind(&test_other); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 821 | __ JumpIfSmi(eax, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 822 | __ mov(scratch, FieldOperand(eax, HeapObject::kMapOffset)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 823 | __ cmp(scratch, factory->heap_number_map()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 824 | __ j(not_equal, non_float); // argument in eax is not a number -> NaN |
| 825 | |
| 826 | // Fall-through: Both operands are numbers. |
| 827 | __ bind(&done); |
| 828 | } |
| 829 | |
| 830 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 831 | void MathPowStub::Generate(MacroAssembler* masm) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 832 | CpuFeatureScope use_sse2(masm, SSE2); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 833 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 834 | const Register exponent = eax; |
| 835 | const Register base = edx; |
| 836 | const Register scratch = ecx; |
| 837 | const XMMRegister double_result = xmm3; |
| 838 | const XMMRegister double_base = xmm2; |
| 839 | const XMMRegister double_exponent = xmm1; |
| 840 | const XMMRegister double_scratch = xmm4; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 841 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 842 | Label call_runtime, done, exponent_not_smi, int_exponent; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 843 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 844 | // Save 1 in double_result - we need this several times later on. |
| 845 | __ mov(scratch, Immediate(1)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 846 | __ Cvtsi2sd(double_result, scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 847 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 848 | if (exponent_type_ == ON_STACK) { |
| 849 | Label base_is_smi, unpack_exponent; |
| 850 | // The exponent and base are supplied as arguments on the stack. |
| 851 | // This can only happen if the stub is called from non-optimized code. |
| 852 | // Load input parameters from stack. |
| 853 | __ mov(base, Operand(esp, 2 * kPointerSize)); |
| 854 | __ mov(exponent, Operand(esp, 1 * kPointerSize)); |
| 855 | |
| 856 | __ JumpIfSmi(base, &base_is_smi, Label::kNear); |
| 857 | __ cmp(FieldOperand(base, HeapObject::kMapOffset), |
| 858 | factory->heap_number_map()); |
| 859 | __ j(not_equal, &call_runtime); |
| 860 | |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 861 | __ movsd(double_base, FieldOperand(base, HeapNumber::kValueOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 862 | __ jmp(&unpack_exponent, Label::kNear); |
| 863 | |
| 864 | __ bind(&base_is_smi); |
| 865 | __ SmiUntag(base); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 866 | __ Cvtsi2sd(double_base, base); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 867 | |
| 868 | __ bind(&unpack_exponent); |
| 869 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 870 | __ SmiUntag(exponent); |
| 871 | __ jmp(&int_exponent); |
| 872 | |
| 873 | __ bind(&exponent_not_smi); |
| 874 | __ cmp(FieldOperand(exponent, HeapObject::kMapOffset), |
| 875 | factory->heap_number_map()); |
| 876 | __ j(not_equal, &call_runtime); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 877 | __ movsd(double_exponent, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 878 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 879 | } else if (exponent_type_ == TAGGED) { |
| 880 | __ JumpIfNotSmi(exponent, &exponent_not_smi, Label::kNear); |
| 881 | __ SmiUntag(exponent); |
| 882 | __ jmp(&int_exponent); |
| 883 | |
| 884 | __ bind(&exponent_not_smi); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 885 | __ movsd(double_exponent, |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 886 | FieldOperand(exponent, HeapNumber::kValueOffset)); |
| 887 | } |
| 888 | |
| 889 | if (exponent_type_ != INTEGER) { |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 890 | Label fast_power, try_arithmetic_simplification; |
| 891 | __ DoubleToI(exponent, double_exponent, double_scratch, |
| 892 | TREAT_MINUS_ZERO_AS_ZERO, &try_arithmetic_simplification); |
| 893 | __ jmp(&int_exponent); |
| 894 | |
| 895 | __ bind(&try_arithmetic_simplification); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 896 | // Skip to runtime if possibly NaN (indicated by the indefinite integer). |
jkummerow@chromium.org | 8fa5bd9 | 2013-09-02 11:45:09 +0000 | [diff] [blame] | 897 | __ cvttsd2si(exponent, Operand(double_exponent)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 898 | __ cmp(exponent, Immediate(0x80000000u)); |
| 899 | __ j(equal, &call_runtime); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 900 | |
| 901 | if (exponent_type_ == ON_STACK) { |
| 902 | // Detect square root case. Crankshaft detects constant +/-0.5 at |
| 903 | // compile time and uses DoMathPowHalf instead. We then skip this check |
| 904 | // for non-constant cases of +/-0.5 as these hardly occur. |
| 905 | Label continue_sqrt, continue_rsqrt, not_plus_half; |
| 906 | // Test for 0.5. |
| 907 | // Load double_scratch with 0.5. |
| 908 | __ mov(scratch, Immediate(0x3F000000u)); |
| 909 | __ movd(double_scratch, scratch); |
| 910 | __ cvtss2sd(double_scratch, double_scratch); |
| 911 | // Already ruled out NaNs for exponent. |
| 912 | __ ucomisd(double_scratch, double_exponent); |
| 913 | __ j(not_equal, ¬_plus_half, Label::kNear); |
| 914 | |
| 915 | // Calculates square root of base. Check for the special case of |
| 916 | // Math.pow(-Infinity, 0.5) == Infinity (ECMA spec, 15.8.2.13). |
| 917 | // According to IEEE-754, single-precision -Infinity has the highest |
| 918 | // 9 bits set and the lowest 23 bits cleared. |
| 919 | __ mov(scratch, 0xFF800000u); |
| 920 | __ movd(double_scratch, scratch); |
| 921 | __ cvtss2sd(double_scratch, double_scratch); |
| 922 | __ ucomisd(double_base, double_scratch); |
| 923 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 924 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 925 | __ j(not_equal, &continue_sqrt, Label::kNear); |
| 926 | __ j(carry, &continue_sqrt, Label::kNear); |
| 927 | |
| 928 | // Set result to Infinity in the special case. |
| 929 | __ xorps(double_result, double_result); |
| 930 | __ subsd(double_result, double_scratch); |
| 931 | __ jmp(&done); |
| 932 | |
| 933 | __ bind(&continue_sqrt); |
| 934 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 935 | __ xorps(double_scratch, double_scratch); |
| 936 | __ addsd(double_scratch, double_base); // Convert -0 to +0. |
| 937 | __ sqrtsd(double_result, double_scratch); |
| 938 | __ jmp(&done); |
| 939 | |
| 940 | // Test for -0.5. |
| 941 | __ bind(¬_plus_half); |
| 942 | // Load double_exponent with -0.5 by substracting 1. |
| 943 | __ subsd(double_scratch, double_result); |
| 944 | // Already ruled out NaNs for exponent. |
| 945 | __ ucomisd(double_scratch, double_exponent); |
| 946 | __ j(not_equal, &fast_power, Label::kNear); |
| 947 | |
| 948 | // Calculates reciprocal of square root of base. Check for the special |
| 949 | // case of Math.pow(-Infinity, -0.5) == 0 (ECMA spec, 15.8.2.13). |
| 950 | // According to IEEE-754, single-precision -Infinity has the highest |
| 951 | // 9 bits set and the lowest 23 bits cleared. |
| 952 | __ mov(scratch, 0xFF800000u); |
| 953 | __ movd(double_scratch, scratch); |
| 954 | __ cvtss2sd(double_scratch, double_scratch); |
| 955 | __ ucomisd(double_base, double_scratch); |
| 956 | // Comparing -Infinity with NaN results in "unordered", which sets the |
| 957 | // zero flag as if both were equal. However, it also sets the carry flag. |
| 958 | __ j(not_equal, &continue_rsqrt, Label::kNear); |
| 959 | __ j(carry, &continue_rsqrt, Label::kNear); |
| 960 | |
| 961 | // Set result to 0 in the special case. |
| 962 | __ xorps(double_result, double_result); |
| 963 | __ jmp(&done); |
| 964 | |
| 965 | __ bind(&continue_rsqrt); |
| 966 | // sqrtsd returns -0 when input is -0. ECMA spec requires +0. |
| 967 | __ xorps(double_exponent, double_exponent); |
| 968 | __ addsd(double_exponent, double_base); // Convert -0 to +0. |
| 969 | __ sqrtsd(double_exponent, double_exponent); |
| 970 | __ divsd(double_result, double_exponent); |
| 971 | __ jmp(&done); |
| 972 | } |
| 973 | |
| 974 | // Using FPU instructions to calculate power. |
| 975 | Label fast_power_failed; |
| 976 | __ bind(&fast_power); |
| 977 | __ fnclex(); // Clear flags to catch exceptions later. |
| 978 | // Transfer (B)ase and (E)xponent onto the FPU register stack. |
| 979 | __ sub(esp, Immediate(kDoubleSize)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 980 | __ movsd(Operand(esp, 0), double_exponent); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 981 | __ fld_d(Operand(esp, 0)); // E |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 982 | __ movsd(Operand(esp, 0), double_base); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 983 | __ fld_d(Operand(esp, 0)); // B, E |
| 984 | |
| 985 | // Exponent is in st(1) and base is in st(0) |
| 986 | // B ^ E = (2^(E * log2(B)) - 1) + 1 = (2^X - 1) + 1 for X = E * log2(B) |
| 987 | // FYL2X calculates st(1) * log2(st(0)) |
| 988 | __ fyl2x(); // X |
| 989 | __ fld(0); // X, X |
| 990 | __ frndint(); // rnd(X), X |
| 991 | __ fsub(1); // rnd(X), X-rnd(X) |
| 992 | __ fxch(1); // X - rnd(X), rnd(X) |
| 993 | // F2XM1 calculates 2^st(0) - 1 for -1 < st(0) < 1 |
| 994 | __ f2xm1(); // 2^(X-rnd(X)) - 1, rnd(X) |
| 995 | __ fld1(); // 1, 2^(X-rnd(X)) - 1, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 996 | __ faddp(1); // 2^(X-rnd(X)), rnd(X) |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 997 | // FSCALE calculates st(0) * 2^st(1) |
| 998 | __ fscale(); // 2^X, rnd(X) |
danno@chromium.org | 1f34ad3 | 2012-11-26 14:53:56 +0000 | [diff] [blame] | 999 | __ fstp(1); // 2^X |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1000 | // Bail out to runtime in case of exceptions in the status word. |
| 1001 | __ fnstsw_ax(); |
| 1002 | __ test_b(eax, 0x5F); // We check for all but precision exception. |
| 1003 | __ j(not_zero, &fast_power_failed, Label::kNear); |
| 1004 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1005 | __ movsd(double_result, Operand(esp, 0)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1006 | __ add(esp, Immediate(kDoubleSize)); |
| 1007 | __ jmp(&done); |
| 1008 | |
| 1009 | __ bind(&fast_power_failed); |
| 1010 | __ fninit(); |
| 1011 | __ add(esp, Immediate(kDoubleSize)); |
| 1012 | __ jmp(&call_runtime); |
| 1013 | } |
| 1014 | |
| 1015 | // Calculate power with integer exponent. |
| 1016 | __ bind(&int_exponent); |
| 1017 | const XMMRegister double_scratch2 = double_exponent; |
| 1018 | __ mov(scratch, exponent); // Back up exponent. |
| 1019 | __ movsd(double_scratch, double_base); // Back up base. |
| 1020 | __ movsd(double_scratch2, double_result); // Load double_exponent with 1. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1021 | |
| 1022 | // Get absolute value of exponent. |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 1023 | Label no_neg, while_true, while_false; |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1024 | __ test(scratch, scratch); |
| 1025 | __ j(positive, &no_neg, Label::kNear); |
| 1026 | __ neg(scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1027 | __ bind(&no_neg); |
| 1028 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1029 | __ j(zero, &while_false, Label::kNear); |
| 1030 | __ shr(scratch, 1); |
| 1031 | // Above condition means CF==0 && ZF==0. This means that the |
| 1032 | // bit that has been shifted out is 0 and the result is not 0. |
| 1033 | __ j(above, &while_true, Label::kNear); |
| 1034 | __ movsd(double_result, double_scratch); |
| 1035 | __ j(zero, &while_false, Label::kNear); |
| 1036 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1037 | __ bind(&while_true); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1038 | __ shr(scratch, 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1039 | __ mulsd(double_scratch, double_scratch); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1040 | __ j(above, &while_true, Label::kNear); |
| 1041 | __ mulsd(double_result, double_scratch); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1042 | __ j(not_zero, &while_true); |
| 1043 | |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 1044 | __ bind(&while_false); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1045 | // scratch has the original value of the exponent - if the exponent is |
| 1046 | // negative, return 1/result. |
| 1047 | __ test(exponent, exponent); |
| 1048 | __ j(positive, &done); |
| 1049 | __ divsd(double_scratch2, double_result); |
| 1050 | __ movsd(double_result, double_scratch2); |
| 1051 | // Test whether result is zero. Bail out to check for subnormal result. |
| 1052 | // Due to subnormals, x^-y == (1/x)^y does not hold in all cases. |
| 1053 | __ xorps(double_scratch2, double_scratch2); |
| 1054 | __ ucomisd(double_scratch2, double_result); // Result cannot be NaN. |
| 1055 | // double_exponent aliased as double_scratch2 has already been overwritten |
| 1056 | // and may not have contained the exponent value in the first place when the |
| 1057 | // exponent is a smi. We reset it with exponent value before bailing out. |
| 1058 | __ j(not_equal, &done); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1059 | __ Cvtsi2sd(double_exponent, exponent); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1060 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1061 | // Returning or bailing out. |
| 1062 | Counters* counters = masm->isolate()->counters(); |
| 1063 | if (exponent_type_ == ON_STACK) { |
| 1064 | // The arguments are still on the stack. |
| 1065 | __ bind(&call_runtime); |
| 1066 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1067 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1068 | // The stub is called from non-optimized code, which expects the result |
| 1069 | // as heap number in exponent. |
| 1070 | __ bind(&done); |
| 1071 | __ AllocateHeapNumber(eax, scratch, base, &call_runtime); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1072 | __ movsd(FieldOperand(eax, HeapNumber::kValueOffset), double_result); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1073 | __ IncrementCounter(counters->math_pow(), 1); |
| 1074 | __ ret(2 * kPointerSize); |
| 1075 | } else { |
| 1076 | __ bind(&call_runtime); |
| 1077 | { |
| 1078 | AllowExternalCallThatCantCauseGC scope(masm); |
| 1079 | __ PrepareCallCFunction(4, scratch); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1080 | __ movsd(Operand(esp, 0 * kDoubleSize), double_base); |
| 1081 | __ movsd(Operand(esp, 1 * kDoubleSize), double_exponent); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1082 | __ CallCFunction( |
| 1083 | ExternalReference::power_double_double_function(masm->isolate()), 4); |
| 1084 | } |
| 1085 | // Return value is in st(0) on ia32. |
| 1086 | // Store it into the (fixed) result register. |
| 1087 | __ sub(esp, Immediate(kDoubleSize)); |
| 1088 | __ fstp_d(Operand(esp, 0)); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 1089 | __ movsd(double_result, Operand(esp, 0)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1090 | __ add(esp, Immediate(kDoubleSize)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1091 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 1092 | __ bind(&done); |
| 1093 | __ IncrementCounter(counters->math_pow(), 1); |
| 1094 | __ ret(0); |
| 1095 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1099 | void FunctionPrototypeStub::Generate(MacroAssembler* masm) { |
| 1100 | // ----------- S t a t e ------------- |
| 1101 | // -- ecx : name |
| 1102 | // -- edx : receiver |
| 1103 | // -- esp[0] : return address |
| 1104 | // ----------------------------------- |
| 1105 | Label miss; |
| 1106 | |
| 1107 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1108 | __ cmp(ecx, Immediate(masm->isolate()->factory()->prototype_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1109 | __ j(not_equal, &miss); |
| 1110 | } |
| 1111 | |
| 1112 | StubCompiler::GenerateLoadFunctionPrototype(masm, edx, eax, ebx, &miss); |
| 1113 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1114 | StubCompiler::TailCallBuiltin( |
| 1115 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | |
| 1119 | void StringLengthStub::Generate(MacroAssembler* masm) { |
| 1120 | // ----------- S t a t e ------------- |
| 1121 | // -- ecx : name |
| 1122 | // -- edx : receiver |
| 1123 | // -- esp[0] : return address |
| 1124 | // ----------------------------------- |
| 1125 | Label miss; |
| 1126 | |
| 1127 | if (kind() == Code::KEYED_LOAD_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1128 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1129 | __ j(not_equal, &miss); |
| 1130 | } |
| 1131 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1132 | StubCompiler::GenerateLoadStringLength(masm, edx, eax, ebx, &miss); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1133 | __ bind(&miss); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1134 | StubCompiler::TailCallBuiltin( |
| 1135 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | 6bec009 | 2013-01-23 13:46:53 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1139 | void StoreArrayLengthStub::Generate(MacroAssembler* masm) { |
| 1140 | // ----------- S t a t e ------------- |
| 1141 | // -- eax : value |
| 1142 | // -- ecx : name |
| 1143 | // -- edx : receiver |
| 1144 | // -- esp[0] : return address |
| 1145 | // ----------------------------------- |
| 1146 | // |
| 1147 | // This accepts as a receiver anything JSArray::SetElementsLength accepts |
| 1148 | // (currently anything except for external arrays which means anything with |
| 1149 | // elements of FixedArray type). Value must be a number, but only smis are |
| 1150 | // accepted as the most common case. |
| 1151 | |
| 1152 | Label miss; |
| 1153 | |
| 1154 | Register receiver = edx; |
| 1155 | Register value = eax; |
| 1156 | Register scratch = ebx; |
| 1157 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 1158 | if (kind() == Code::KEYED_STORE_IC) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 1159 | __ cmp(ecx, Immediate(masm->isolate()->factory()->length_string())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1160 | __ j(not_equal, &miss); |
| 1161 | } |
| 1162 | |
| 1163 | // Check that the receiver isn't a smi. |
| 1164 | __ JumpIfSmi(receiver, &miss); |
| 1165 | |
| 1166 | // Check that the object is a JS array. |
| 1167 | __ CmpObjectType(receiver, JS_ARRAY_TYPE, scratch); |
| 1168 | __ j(not_equal, &miss); |
| 1169 | |
| 1170 | // Check that elements are FixedArray. |
| 1171 | // We rely on StoreIC_ArrayLength below to deal with all types of |
| 1172 | // fast elements (including COW). |
| 1173 | __ mov(scratch, FieldOperand(receiver, JSArray::kElementsOffset)); |
| 1174 | __ CmpObjectType(scratch, FIXED_ARRAY_TYPE, scratch); |
| 1175 | __ j(not_equal, &miss); |
| 1176 | |
| 1177 | // Check that the array has fast properties, otherwise the length |
| 1178 | // property might have been redefined. |
| 1179 | __ mov(scratch, FieldOperand(receiver, JSArray::kPropertiesOffset)); |
| 1180 | __ CompareRoot(FieldOperand(scratch, FixedArray::kMapOffset), |
| 1181 | Heap::kHashTableMapRootIndex); |
| 1182 | __ j(equal, &miss); |
| 1183 | |
| 1184 | // Check that value is a smi. |
| 1185 | __ JumpIfNotSmi(value, &miss); |
| 1186 | |
| 1187 | // Prepare tail call to StoreIC_ArrayLength. |
| 1188 | __ pop(scratch); |
| 1189 | __ push(receiver); |
| 1190 | __ push(value); |
| 1191 | __ push(scratch); // return address |
| 1192 | |
| 1193 | ExternalReference ref = |
| 1194 | ExternalReference(IC_Utility(IC::kStoreIC_ArrayLength), masm->isolate()); |
| 1195 | __ TailCallExternalReference(ref, 2, 1); |
| 1196 | |
| 1197 | __ bind(&miss); |
| 1198 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 1199 | StubCompiler::TailCallBuiltin( |
| 1200 | masm, BaseLoadStoreStubCompiler::MissBuiltin(kind())); |
mvstanton@chromium.org | d16d853 | 2013-01-25 13:29:10 +0000 | [diff] [blame] | 1201 | } |
| 1202 | |
| 1203 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1204 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 1205 | // The key is in edx and the parameter count is in eax. |
| 1206 | |
| 1207 | // The displacement is used for skipping the frame pointer on the |
| 1208 | // stack. It is the offset of the last parameter (if any) relative |
| 1209 | // to the frame pointer. |
| 1210 | static const int kDisplacement = 1 * kPointerSize; |
| 1211 | |
| 1212 | // Check that the key is a smi. |
| 1213 | Label slow; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1214 | __ JumpIfNotSmi(edx, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1215 | |
| 1216 | // Check if the calling frame is an arguments adaptor frame. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1217 | Label adaptor; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1218 | __ mov(ebx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1219 | __ mov(ecx, Operand(ebx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1220 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1221 | __ j(equal, &adaptor, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1222 | |
| 1223 | // Check index against formal parameters count limit passed in |
| 1224 | // through register eax. Use unsigned comparison to get negative |
| 1225 | // check for free. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1226 | __ cmp(edx, eax); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1227 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1228 | |
| 1229 | // Read the argument from the stack and return it. |
| 1230 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1231 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 1232 | __ lea(ebx, Operand(ebp, eax, times_2, 0)); |
| 1233 | __ neg(edx); |
| 1234 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 1235 | __ ret(0); |
| 1236 | |
| 1237 | // Arguments adaptor case: Check index against actual arguments |
| 1238 | // limit found in the arguments adaptor frame. Use unsigned |
| 1239 | // comparison to get negative check for free. |
| 1240 | __ bind(&adaptor); |
| 1241 | __ mov(ecx, Operand(ebx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1242 | __ cmp(edx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1243 | __ j(above_equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1244 | |
| 1245 | // Read the argument from the stack and return it. |
| 1246 | STATIC_ASSERT(kSmiTagSize == 1); |
| 1247 | STATIC_ASSERT(kSmiTag == 0); // Shifting code depends on these. |
| 1248 | __ lea(ebx, Operand(ebx, ecx, times_2, 0)); |
| 1249 | __ neg(edx); |
| 1250 | __ mov(eax, Operand(ebx, edx, times_2, kDisplacement)); |
| 1251 | __ ret(0); |
| 1252 | |
| 1253 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 1254 | // by calling the runtime system. |
| 1255 | __ bind(&slow); |
| 1256 | __ pop(ebx); // Return address. |
| 1257 | __ push(edx); |
| 1258 | __ push(ebx); |
| 1259 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 1260 | } |
| 1261 | |
| 1262 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1263 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1264 | // esp[0] : return address |
| 1265 | // esp[4] : number of parameters |
| 1266 | // esp[8] : receiver displacement |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1267 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1268 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1269 | // Check if the calling frame is an arguments adaptor frame. |
| 1270 | Label runtime; |
| 1271 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1272 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1273 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1274 | __ j(not_equal, &runtime, Label::kNear); |
| 1275 | |
| 1276 | // Patch the arguments.length and the parameters pointer. |
| 1277 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1278 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
| 1279 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1280 | StandardFrameConstants::kCallerSPOffset)); |
| 1281 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1282 | |
| 1283 | __ bind(&runtime); |
| 1284 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 1285 | } |
| 1286 | |
| 1287 | |
| 1288 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1289 | Isolate* isolate = masm->isolate(); |
| 1290 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1291 | // esp[0] : return address |
| 1292 | // esp[4] : number of parameters (tagged) |
| 1293 | // esp[8] : receiver displacement |
| 1294 | // esp[12] : function |
| 1295 | |
| 1296 | // ebx = parameter count (tagged) |
| 1297 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1298 | |
| 1299 | // Check if the calling frame is an arguments adaptor frame. |
| 1300 | // TODO(rossberg): Factor out some of the bits that are shared with the other |
| 1301 | // Generate* functions. |
| 1302 | Label runtime; |
| 1303 | Label adaptor_frame, try_allocate; |
| 1304 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1305 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1306 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1307 | __ j(equal, &adaptor_frame, Label::kNear); |
| 1308 | |
| 1309 | // No adaptor, parameter count = argument count. |
| 1310 | __ mov(ecx, ebx); |
| 1311 | __ jmp(&try_allocate, Label::kNear); |
| 1312 | |
| 1313 | // We have an adaptor frame. Patch the parameters pointer. |
| 1314 | __ bind(&adaptor_frame); |
| 1315 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1316 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1317 | StandardFrameConstants::kCallerSPOffset)); |
| 1318 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1319 | |
| 1320 | // ebx = parameter count (tagged) |
| 1321 | // ecx = argument count (tagged) |
| 1322 | // esp[4] = parameter count (tagged) |
| 1323 | // esp[8] = address of receiver argument |
| 1324 | // Compute the mapped parameter count = min(ebx, ecx) in ebx. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1325 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1326 | __ j(less_equal, &try_allocate, Label::kNear); |
| 1327 | __ mov(ebx, ecx); |
| 1328 | |
| 1329 | __ bind(&try_allocate); |
| 1330 | |
| 1331 | // Save mapped parameter count. |
| 1332 | __ push(ebx); |
| 1333 | |
| 1334 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 1335 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 1336 | const int kParameterMapHeaderSize = |
| 1337 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 1338 | Label no_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1339 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1340 | __ j(zero, &no_parameter_map, Label::kNear); |
| 1341 | __ lea(ebx, Operand(ebx, times_2, kParameterMapHeaderSize)); |
| 1342 | __ bind(&no_parameter_map); |
| 1343 | |
| 1344 | // 2. Backing store. |
| 1345 | __ lea(ebx, Operand(ebx, ecx, times_2, FixedArray::kHeaderSize)); |
| 1346 | |
| 1347 | // 3. Arguments object. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1348 | __ add(ebx, Immediate(Heap::kArgumentsObjectSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1349 | |
| 1350 | // Do the allocation of all three objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1351 | __ Allocate(ebx, eax, edx, edi, &runtime, TAG_OBJECT); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1352 | |
| 1353 | // eax = address of new object(s) (tagged) |
| 1354 | // ecx = argument count (tagged) |
| 1355 | // esp[0] = mapped parameter count (tagged) |
| 1356 | // esp[8] = parameter count (tagged) |
| 1357 | // esp[12] = address of receiver argument |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1358 | // Get the arguments boilerplate from the current native context into edi. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1359 | Label has_mapped_parameters, copy; |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1360 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 1361 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1362 | __ mov(ebx, Operand(esp, 0 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1363 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1364 | __ j(not_zero, &has_mapped_parameters, Label::kNear); |
| 1365 | __ mov(edi, Operand(edi, |
| 1366 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX))); |
| 1367 | __ jmp(©, Label::kNear); |
| 1368 | |
| 1369 | __ bind(&has_mapped_parameters); |
| 1370 | __ mov(edi, Operand(edi, |
| 1371 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX))); |
| 1372 | __ bind(©); |
| 1373 | |
| 1374 | // eax = address of new object (tagged) |
| 1375 | // ebx = mapped parameter count (tagged) |
| 1376 | // ecx = argument count (tagged) |
| 1377 | // edi = address of boilerplate object (tagged) |
| 1378 | // esp[0] = mapped parameter count (tagged) |
| 1379 | // esp[8] = parameter count (tagged) |
| 1380 | // esp[12] = address of receiver argument |
| 1381 | // Copy the JS object part. |
| 1382 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 1383 | __ mov(edx, FieldOperand(edi, i)); |
| 1384 | __ mov(FieldOperand(eax, i), edx); |
| 1385 | } |
| 1386 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1387 | // Set up the callee in-object property. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1388 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 1389 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
| 1390 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 1391 | Heap::kArgumentsCalleeIndex * kPointerSize), |
| 1392 | edx); |
| 1393 | |
| 1394 | // Use the length (smi tagged) and set that as an in-object property too. |
| 1395 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 1396 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
| 1397 | Heap::kArgumentsLengthIndex * kPointerSize), |
| 1398 | ecx); |
| 1399 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1400 | // Set up the elements pointer in the allocated arguments object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1401 | // If we allocated a parameter map, edi will point there, otherwise to the |
| 1402 | // backing store. |
| 1403 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSize)); |
| 1404 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 1405 | |
| 1406 | // eax = address of new object (tagged) |
| 1407 | // ebx = mapped parameter count (tagged) |
| 1408 | // ecx = argument count (tagged) |
| 1409 | // edi = address of parameter map or backing store (tagged) |
| 1410 | // esp[0] = mapped parameter count (tagged) |
| 1411 | // esp[8] = parameter count (tagged) |
| 1412 | // esp[12] = address of receiver argument |
| 1413 | // Free a register. |
| 1414 | __ push(eax); |
| 1415 | |
| 1416 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 1417 | Label skip_parameter_map; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1418 | __ test(ebx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1419 | __ j(zero, &skip_parameter_map); |
| 1420 | |
| 1421 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1422 | Immediate(isolate->factory()->non_strict_arguments_elements_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1423 | __ lea(eax, Operand(ebx, reinterpret_cast<intptr_t>(Smi::FromInt(2)))); |
| 1424 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), eax); |
| 1425 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 0 * kPointerSize), esi); |
| 1426 | __ lea(eax, Operand(edi, ebx, times_2, kParameterMapHeaderSize)); |
| 1427 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize + 1 * kPointerSize), eax); |
| 1428 | |
| 1429 | // Copy the parameter slots and the holes in the arguments. |
| 1430 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 1431 | // where parameters are stored in reverse order, at |
| 1432 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 1433 | // The mapped parameter thus need to get indices |
| 1434 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 1435 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 1436 | // We loop from right to left. |
| 1437 | Label parameters_loop, parameters_test; |
| 1438 | __ push(ecx); |
| 1439 | __ mov(eax, Operand(esp, 2 * kPointerSize)); |
| 1440 | __ mov(ebx, Immediate(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 1441 | __ add(ebx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1442 | __ sub(ebx, eax); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1443 | __ mov(ecx, isolate->factory()->the_hole_value()); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1444 | __ mov(edx, edi); |
| 1445 | __ lea(edi, Operand(edi, eax, times_2, kParameterMapHeaderSize)); |
| 1446 | // eax = loop variable (tagged) |
| 1447 | // ebx = mapping index (tagged) |
| 1448 | // ecx = the hole value |
| 1449 | // edx = address of parameter map (tagged) |
| 1450 | // edi = address of backing store (tagged) |
| 1451 | // esp[0] = argument count (tagged) |
| 1452 | // esp[4] = address of new object (tagged) |
| 1453 | // esp[8] = mapped parameter count (tagged) |
| 1454 | // esp[16] = parameter count (tagged) |
| 1455 | // esp[20] = address of receiver argument |
| 1456 | __ jmp(¶meters_test, Label::kNear); |
| 1457 | |
| 1458 | __ bind(¶meters_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1459 | __ sub(eax, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1460 | __ mov(FieldOperand(edx, eax, times_2, kParameterMapHeaderSize), ebx); |
| 1461 | __ mov(FieldOperand(edi, eax, times_2, FixedArray::kHeaderSize), ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1462 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1463 | __ bind(¶meters_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1464 | __ test(eax, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1465 | __ j(not_zero, ¶meters_loop, Label::kNear); |
| 1466 | __ pop(ecx); |
| 1467 | |
| 1468 | __ bind(&skip_parameter_map); |
| 1469 | |
| 1470 | // ecx = argument count (tagged) |
| 1471 | // edi = address of backing store (tagged) |
| 1472 | // esp[0] = address of new object (tagged) |
| 1473 | // esp[4] = mapped parameter count (tagged) |
| 1474 | // esp[12] = parameter count (tagged) |
| 1475 | // esp[16] = address of receiver argument |
| 1476 | // Copy arguments header and remaining slots (if there are any). |
| 1477 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1478 | Immediate(isolate->factory()->fixed_array_map())); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1479 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 1480 | |
| 1481 | Label arguments_loop, arguments_test; |
| 1482 | __ mov(ebx, Operand(esp, 1 * kPointerSize)); |
| 1483 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1484 | __ sub(edx, ebx); // Is there a smarter way to do negative scaling? |
| 1485 | __ sub(edx, ebx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1486 | __ jmp(&arguments_test, Label::kNear); |
| 1487 | |
| 1488 | __ bind(&arguments_loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1489 | __ sub(edx, Immediate(kPointerSize)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1490 | __ mov(eax, Operand(edx, 0)); |
| 1491 | __ mov(FieldOperand(edi, ebx, times_2, FixedArray::kHeaderSize), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1492 | __ add(ebx, Immediate(Smi::FromInt(1))); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1493 | |
| 1494 | __ bind(&arguments_test); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1495 | __ cmp(ebx, ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1496 | __ j(less, &arguments_loop, Label::kNear); |
| 1497 | |
| 1498 | // Restore. |
| 1499 | __ pop(eax); // Address of arguments object. |
| 1500 | __ pop(ebx); // Parameter count. |
| 1501 | |
| 1502 | // Return and remove the on-stack parameters. |
| 1503 | __ ret(3 * kPointerSize); |
| 1504 | |
| 1505 | // Do the runtime call to allocate the arguments object. |
| 1506 | __ bind(&runtime); |
| 1507 | __ pop(eax); // Remove saved parameter count. |
| 1508 | __ mov(Operand(esp, 1 * kPointerSize), ecx); // Patch argument count. |
danno@chromium.org | 72204d5 | 2012-10-31 10:02:10 +0000 | [diff] [blame] | 1509 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1510 | } |
| 1511 | |
| 1512 | |
| 1513 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1514 | Isolate* isolate = masm->isolate(); |
| 1515 | |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1516 | // esp[0] : return address |
| 1517 | // esp[4] : number of parameters |
| 1518 | // esp[8] : receiver displacement |
| 1519 | // esp[12] : function |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1520 | |
| 1521 | // Check if the calling frame is an arguments adaptor frame. |
| 1522 | Label adaptor_frame, try_allocate, runtime; |
| 1523 | __ mov(edx, Operand(ebp, StandardFrameConstants::kCallerFPOffset)); |
| 1524 | __ mov(ecx, Operand(edx, StandardFrameConstants::kContextOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1525 | __ cmp(ecx, Immediate(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1526 | __ j(equal, &adaptor_frame, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1527 | |
| 1528 | // Get the length from the frame. |
| 1529 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1530 | __ jmp(&try_allocate, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1531 | |
| 1532 | // Patch the arguments.length and the parameters pointer. |
| 1533 | __ bind(&adaptor_frame); |
| 1534 | __ mov(ecx, Operand(edx, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 1535 | __ mov(Operand(esp, 1 * kPointerSize), ecx); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1536 | __ lea(edx, Operand(edx, ecx, times_2, |
| 1537 | StandardFrameConstants::kCallerSPOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1538 | __ mov(Operand(esp, 2 * kPointerSize), edx); |
| 1539 | |
| 1540 | // Try the new space allocation. Start out with computing the size of |
| 1541 | // the arguments object and the elements array. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1542 | Label add_arguments_object; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1543 | __ bind(&try_allocate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1544 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1545 | __ j(zero, &add_arguments_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1546 | __ lea(ecx, Operand(ecx, times_2, FixedArray::kHeaderSize)); |
| 1547 | __ bind(&add_arguments_object); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1548 | __ add(ecx, Immediate(Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1549 | |
| 1550 | // Do the allocation of both objects in one go. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 1551 | __ Allocate(ecx, eax, edx, ebx, &runtime, TAG_OBJECT); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1552 | |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 1553 | // Get the arguments boilerplate from the current native context. |
| 1554 | __ mov(edi, Operand(esi, Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX))); |
| 1555 | __ mov(edi, FieldOperand(edi, GlobalObject::kNativeContextOffset)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1556 | const int offset = |
| 1557 | Context::SlotOffset(Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX); |
| 1558 | __ mov(edi, Operand(edi, offset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1559 | |
| 1560 | // Copy the JS object part. |
| 1561 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 1562 | __ mov(ebx, FieldOperand(edi, i)); |
| 1563 | __ mov(FieldOperand(eax, i), ebx); |
| 1564 | } |
| 1565 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1566 | // 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] | 1567 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1568 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1569 | __ mov(FieldOperand(eax, JSObject::kHeaderSize + |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1570 | Heap::kArgumentsLengthIndex * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1571 | ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1572 | |
| 1573 | // If there are no actual arguments, we're done. |
| 1574 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1575 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1576 | __ j(zero, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1577 | |
| 1578 | // Get the parameters pointer from the stack. |
| 1579 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
| 1580 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 1581 | // Set up the elements pointer in the allocated arguments object and |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1582 | // initialize the header in the elements fixed array. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1583 | __ lea(edi, Operand(eax, Heap::kArgumentsObjectSizeStrict)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1584 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), edi); |
| 1585 | __ mov(FieldOperand(edi, FixedArray::kMapOffset), |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 1586 | Immediate(isolate->factory()->fixed_array_map())); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1587 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1588 | __ mov(FieldOperand(edi, FixedArray::kLengthOffset), ecx); |
| 1589 | // Untag the length for the loop below. |
| 1590 | __ SmiUntag(ecx); |
| 1591 | |
| 1592 | // Copy the fixed array slots. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1593 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1594 | __ bind(&loop); |
| 1595 | __ mov(ebx, Operand(edx, -1 * kPointerSize)); // Skip receiver. |
| 1596 | __ mov(FieldOperand(edi, FixedArray::kHeaderSize), ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1597 | __ add(edi, Immediate(kPointerSize)); |
| 1598 | __ sub(edx, Immediate(kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1599 | __ dec(ecx); |
| 1600 | __ j(not_zero, &loop); |
| 1601 | |
| 1602 | // Return and remove the on-stack parameters. |
| 1603 | __ bind(&done); |
| 1604 | __ ret(3 * kPointerSize); |
| 1605 | |
| 1606 | // Do the runtime call to allocate the arguments object. |
| 1607 | __ bind(&runtime); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1608 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | |
| 1612 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 1613 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 1614 | // time or if regexp entry in generated code is turned off runtime switch or |
| 1615 | // at compilation. |
| 1616 | #ifdef V8_INTERPRETED_REGEXP |
| 1617 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 1618 | #else // V8_INTERPRETED_REGEXP |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1619 | |
| 1620 | // Stack frame on entry. |
| 1621 | // esp[0]: return address |
| 1622 | // esp[4]: last_match_info (expected JSArray) |
| 1623 | // esp[8]: previous index |
| 1624 | // esp[12]: subject string |
| 1625 | // esp[16]: JSRegExp object |
| 1626 | |
| 1627 | static const int kLastMatchInfoOffset = 1 * kPointerSize; |
| 1628 | static const int kPreviousIndexOffset = 2 * kPointerSize; |
| 1629 | static const int kSubjectOffset = 3 * kPointerSize; |
| 1630 | static const int kJSRegExpOffset = 4 * kPointerSize; |
| 1631 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1632 | Label runtime; |
| 1633 | Factory* factory = masm->isolate()->factory(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1634 | |
| 1635 | // Ensure that a RegExp stack is allocated. |
| 1636 | ExternalReference address_of_regexp_stack_memory_address = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1637 | ExternalReference::address_of_regexp_stack_memory_address( |
| 1638 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1639 | ExternalReference address_of_regexp_stack_memory_size = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1640 | ExternalReference::address_of_regexp_stack_memory_size(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1641 | __ mov(ebx, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1642 | __ test(ebx, ebx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1643 | __ j(zero, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1644 | |
| 1645 | // Check that the first argument is a JSRegExp object. |
| 1646 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 1647 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 1648 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1649 | __ CmpObjectType(eax, JS_REGEXP_TYPE, ecx); |
| 1650 | __ j(not_equal, &runtime); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1651 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1652 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 1653 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 1654 | if (FLAG_debug_code) { |
| 1655 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1656 | __ Check(not_zero, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1657 | __ CmpObjectType(ecx, FIXED_ARRAY_TYPE, ebx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 1658 | __ Check(equal, kUnexpectedTypeForRegExpDataFixedArrayExpected); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1659 | } |
| 1660 | |
| 1661 | // ecx: RegExp data (FixedArray) |
| 1662 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 1663 | __ mov(ebx, FieldOperand(ecx, JSRegExp::kDataTagOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1664 | __ cmp(ebx, Immediate(Smi::FromInt(JSRegExp::IRREGEXP))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1665 | __ j(not_equal, &runtime); |
| 1666 | |
| 1667 | // ecx: RegExp data (FixedArray) |
| 1668 | // Check that the number of captures fit in the static offsets vector buffer. |
| 1669 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1670 | // Check (number_of_captures + 1) * 2 <= offsets vector size |
| 1671 | // Or number_of_captures * 2 <= offsets vector size - 2 |
| 1672 | // Multiplying by 2 comes for free since edx is smi-tagged. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1673 | STATIC_ASSERT(kSmiTag == 0); |
| 1674 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1675 | STATIC_ASSERT(Isolate::kJSRegexpStaticOffsetsVectorSize >= 2); |
| 1676 | __ cmp(edx, Isolate::kJSRegexpStaticOffsetsVectorSize - 2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1677 | __ j(above, &runtime); |
| 1678 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1679 | // Reset offset for possibly sliced string. |
| 1680 | __ Set(edi, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1681 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1682 | __ JumpIfSmi(eax, &runtime); |
| 1683 | __ mov(edx, eax); // Make a copy of the original subject string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1684 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 1685 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1686 | |
| 1687 | // eax: subject string |
| 1688 | // edx: subject string |
| 1689 | // ebx: subject string instance type |
| 1690 | // ecx: RegExp data (FixedArray) |
| 1691 | // Handle subject string according to its encoding and representation: |
| 1692 | // (1) Sequential two byte? If yes, go to (9). |
| 1693 | // (2) Sequential one byte? If yes, go to (6). |
| 1694 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 1695 | // (4) Cons string. If the string is flat, replace subject with first string. |
| 1696 | // Otherwise bailout. |
| 1697 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 1698 | // (5b) Is subject external? If yes, go to (8). |
| 1699 | // (6) One byte sequential. Load regexp code for one byte. |
| 1700 | // (E) Carry on. |
| 1701 | /// [...] |
| 1702 | |
| 1703 | // Deferred code at the end of the stub: |
| 1704 | // (7) Not a long external string? If yes, go to (10). |
| 1705 | // (8) External string. Make it, offset-wise, look like a sequential string. |
| 1706 | // (8a) Is the external string one byte? If yes, go to (6). |
| 1707 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 1708 | // (10) Short external string or not a string? If yes, bail out to runtime. |
| 1709 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 1710 | |
| 1711 | Label seq_one_byte_string /* 6 */, seq_two_byte_string /* 9 */, |
| 1712 | external_string /* 8 */, check_underlying /* 5a */, |
| 1713 | not_seq_nor_cons /* 7 */, check_code /* E */, |
| 1714 | not_long_external /* 10 */; |
| 1715 | |
| 1716 | // (1) Sequential two byte? If yes, go to (9). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1717 | __ and_(ebx, kIsNotStringMask | |
| 1718 | kStringRepresentationMask | |
| 1719 | kStringEncodingMask | |
| 1720 | kShortExternalStringMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1721 | STATIC_ASSERT((kStringTag | kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1722 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 1723 | |
| 1724 | // (2) Sequential one byte? If yes, go to (6). |
| 1725 | // Any other sequential string must be one byte. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1726 | __ and_(ebx, Immediate(kIsNotStringMask | |
| 1727 | kStringRepresentationMask | |
| 1728 | kShortExternalStringMask)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1729 | __ j(zero, &seq_one_byte_string, Label::kNear); // Go to (6). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1730 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1731 | // (3) Anything but sequential or cons? If yes, go to (7). |
| 1732 | // We check whether the subject string is a cons, since sequential strings |
| 1733 | // have already been covered. |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 1734 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 1735 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1736 | STATIC_ASSERT(kIsNotStringMask > kExternalStringTag); |
| 1737 | STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1738 | __ cmp(ebx, Immediate(kExternalStringTag)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1739 | __ j(greater_equal, ¬_seq_nor_cons); // Go to (7). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 1740 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1741 | // (4) Cons string. Check that it's flat. |
| 1742 | // Replace subject with first string and reload instance type. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1743 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), factory->empty_string()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1744 | __ j(not_equal, &runtime); |
| 1745 | __ mov(eax, FieldOperand(eax, ConsString::kFirstOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1746 | __ bind(&check_underlying); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1747 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1748 | __ mov(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 1749 | |
| 1750 | // (5a) Is subject sequential two byte? If yes, go to (9). |
| 1751 | __ test_b(ebx, kStringRepresentationMask | kStringEncodingMask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1752 | STATIC_ASSERT((kSeqStringTag | kTwoByteStringTag) == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1753 | __ j(zero, &seq_two_byte_string); // Go to (9). |
| 1754 | // (5b) Is subject external? If yes, go to (8). |
| 1755 | __ test_b(ebx, kStringRepresentationMask); |
| 1756 | // The underlying external string is never a short external string. |
| 1757 | STATIC_CHECK(ExternalString::kMaxShortLength < ConsString::kMinLength); |
| 1758 | STATIC_CHECK(ExternalString::kMaxShortLength < SlicedString::kMinLength); |
| 1759 | __ j(not_zero, &external_string); // Go to (8). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1760 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1761 | // eax: sequential subject string (or look-alike, external string) |
| 1762 | // edx: original subject string |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1763 | // ecx: RegExp data (FixedArray) |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1764 | // (6) One byte sequential. Load regexp code for one byte. |
| 1765 | __ bind(&seq_one_byte_string); |
| 1766 | // Load previous index and check range before edx is overwritten. We have |
| 1767 | // to use edx instead of eax here because it might have been only made to |
| 1768 | // look like a sequential string when it actually is an external string. |
| 1769 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 1770 | __ JumpIfNotSmi(ebx, &runtime); |
| 1771 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 1772 | __ j(above_equal, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1773 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataAsciiCodeOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1774 | __ Set(ecx, Immediate(1)); // Type is one byte. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1775 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1776 | // (E) Carry on. String handling is done. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1777 | __ bind(&check_code); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1778 | // edx: irregexp code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1779 | // Check that the irregexp code has been generated for the actual string |
| 1780 | // 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] | 1781 | // a smi (code flushing support). |
| 1782 | __ JumpIfSmi(edx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1783 | |
| 1784 | // eax: subject string |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1785 | // ebx: previous index (smi) |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1786 | // edx: code |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1787 | // 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] | 1788 | // All checks done. Now push arguments for native regexp code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1789 | Counters* counters = masm->isolate()->counters(); |
| 1790 | __ IncrementCounter(counters->regexp_entry_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1791 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1792 | // Isolates: note we add an additional parameter here (isolate pointer). |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1793 | static const int kRegExpExecuteArguments = 9; |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1794 | __ EnterApiExitFrame(kRegExpExecuteArguments); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1795 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1796 | // Argument 9: Pass current isolate address. |
| 1797 | __ mov(Operand(esp, 8 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 1798 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1799 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1800 | // Argument 8: Indicate that this is a direct call from JavaScript. |
| 1801 | __ mov(Operand(esp, 7 * kPointerSize), Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1802 | |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1803 | // Argument 7: Start (high end) of backtracking stack memory area. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1804 | __ mov(esi, Operand::StaticVariable(address_of_regexp_stack_memory_address)); |
| 1805 | __ add(esi, Operand::StaticVariable(address_of_regexp_stack_memory_size)); |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1806 | __ mov(Operand(esp, 6 * kPointerSize), esi); |
| 1807 | |
| 1808 | // Argument 6: Set the number of capture registers to zero to force global |
| 1809 | // regexps to behave as non-global. This does not affect non-global regexps. |
| 1810 | __ mov(Operand(esp, 5 * kPointerSize), Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1811 | |
| 1812 | // Argument 5: static offsets vector buffer. |
| 1813 | __ mov(Operand(esp, 4 * kPointerSize), |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1814 | Immediate(ExternalReference::address_of_static_offsets_vector( |
| 1815 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1816 | |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1817 | // Argument 2: Previous index. |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1818 | __ SmiUntag(ebx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1819 | __ mov(Operand(esp, 1 * kPointerSize), ebx); |
| 1820 | |
| 1821 | // Argument 1: Original subject string. |
| 1822 | // The original subject is in the previous stack frame. Therefore we have to |
| 1823 | // use ebp, which points exactly to one pointer size below the previous esp. |
| 1824 | // (Because creating a new stack frame pushes the previous ebp onto the stack |
| 1825 | // and thereby moves up esp by one kPointerSize.) |
| 1826 | __ mov(esi, Operand(ebp, kSubjectOffset + kPointerSize)); |
| 1827 | __ mov(Operand(esp, 0 * kPointerSize), esi); |
| 1828 | |
| 1829 | // esi: original subject string |
| 1830 | // eax: underlying subject string |
| 1831 | // ebx: previous index |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 1832 | // 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] | 1833 | // edx: code |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1834 | // Argument 4: End of string data |
| 1835 | // Argument 3: Start of string data |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1836 | // Prepare start and end index of the input. |
| 1837 | // Load the length from the original sliced string if that is the case. |
| 1838 | __ mov(esi, FieldOperand(esi, String::kLengthOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1839 | __ add(esi, edi); // Calculate input end wrt offset. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1840 | __ SmiUntag(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1841 | __ add(ebx, edi); // Calculate input start wrt offset. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1842 | |
| 1843 | // ebx: start index of the input string |
| 1844 | // esi: end index of the input string |
| 1845 | Label setup_two_byte, setup_rest; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1846 | __ test(ecx, ecx); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1847 | __ j(zero, &setup_two_byte, Label::kNear); |
| 1848 | __ SmiUntag(esi); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1849 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1850 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 1851 | __ lea(ecx, FieldOperand(eax, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1852 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1853 | __ jmp(&setup_rest, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1854 | |
| 1855 | __ bind(&setup_two_byte); |
| 1856 | STATIC_ASSERT(kSmiTag == 0); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1857 | STATIC_ASSERT(kSmiTagSize == 1); // esi is smi (powered by 2). |
| 1858 | __ lea(ecx, FieldOperand(eax, esi, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1859 | __ mov(Operand(esp, 3 * kPointerSize), ecx); // Argument 4. |
| 1860 | __ lea(ecx, FieldOperand(eax, ebx, times_2, SeqTwoByteString::kHeaderSize)); |
| 1861 | __ mov(Operand(esp, 2 * kPointerSize), ecx); // Argument 3. |
| 1862 | |
| 1863 | __ bind(&setup_rest); |
| 1864 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1865 | // Locate the code entry and call it. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1866 | __ add(edx, Immediate(Code::kHeaderSize - kHeapObjectTag)); |
| 1867 | __ call(edx); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1868 | |
| 1869 | // Drop arguments and come back to JS mode. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 1870 | __ LeaveApiExitFrame(true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1871 | |
| 1872 | // Check the result. |
| 1873 | Label success; |
mstarzinger@chromium.org | 15613d0 | 2012-05-23 12:04:37 +0000 | [diff] [blame] | 1874 | __ cmp(eax, 1); |
| 1875 | // We expect exactly one result since we force the called regexp to behave |
| 1876 | // as non-global. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1877 | __ j(equal, &success); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1878 | Label failure; |
| 1879 | __ cmp(eax, NativeRegExpMacroAssembler::FAILURE); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 1880 | __ j(equal, &failure); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1881 | __ cmp(eax, NativeRegExpMacroAssembler::EXCEPTION); |
| 1882 | // If not exception it can only be retry. Handle that in the runtime system. |
| 1883 | __ j(not_equal, &runtime); |
| 1884 | // Result must now be exception. If there is no pending exception already a |
| 1885 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 1886 | // haven't created the exception yet. Handle that in the runtime system. |
| 1887 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 1888 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1889 | masm->isolate()); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1890 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1891 | __ mov(eax, Operand::StaticVariable(pending_exception)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1892 | __ cmp(edx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1893 | __ j(equal, &runtime); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1894 | // For exception, throw the exception again. |
| 1895 | |
| 1896 | // Clear the pending exception variable. |
| 1897 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 1898 | |
| 1899 | // Special handling of termination exceptions which are uncatchable |
| 1900 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 1901 | __ cmp(eax, factory->termination_exception()); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1902 | Label throw_termination_exception; |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 1903 | __ j(equal, &throw_termination_exception, Label::kNear); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1904 | |
| 1905 | // Handle normal exception by following handler chain. |
| 1906 | __ Throw(eax); |
| 1907 | |
| 1908 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 1909 | __ ThrowUncatchable(eax); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1910 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1911 | __ bind(&failure); |
kmillikin@chromium.org | 49edbdf | 2011-02-16 12:32:18 +0000 | [diff] [blame] | 1912 | // For failure to match, return null. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1913 | __ mov(eax, factory->null_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1914 | __ ret(4 * kPointerSize); |
| 1915 | |
| 1916 | // Load RegExp data. |
| 1917 | __ bind(&success); |
| 1918 | __ mov(eax, Operand(esp, kJSRegExpOffset)); |
| 1919 | __ mov(ecx, FieldOperand(eax, JSRegExp::kDataOffset)); |
| 1920 | __ mov(edx, FieldOperand(ecx, JSRegExp::kIrregexpCaptureCountOffset)); |
| 1921 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 1922 | STATIC_ASSERT(kSmiTag == 0); |
| 1923 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1924 | __ add(edx, Immediate(2)); // edx was a smi. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1925 | |
| 1926 | // edx: Number of capture registers |
| 1927 | // 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] | 1928 | // Check that the fourth object is a JSArray object. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1929 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1930 | __ JumpIfSmi(eax, &runtime); |
| 1931 | __ CmpObjectType(eax, JS_ARRAY_TYPE, ebx); |
| 1932 | __ j(not_equal, &runtime); |
| 1933 | // Check that the JSArray is in fast case. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1934 | __ mov(ebx, FieldOperand(eax, JSArray::kElementsOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1935 | __ mov(eax, FieldOperand(ebx, HeapObject::kMapOffset)); |
| 1936 | __ cmp(eax, factory->fixed_array_map()); |
| 1937 | __ j(not_equal, &runtime); |
| 1938 | // Check that the last match info has space for the capture registers and the |
| 1939 | // additional information. |
| 1940 | __ mov(eax, FieldOperand(ebx, FixedArray::kLengthOffset)); |
| 1941 | __ SmiUntag(eax); |
| 1942 | __ sub(eax, Immediate(RegExpImpl::kLastMatchOverhead)); |
| 1943 | __ cmp(edx, eax); |
| 1944 | __ j(greater, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1945 | |
| 1946 | // ebx: last_match_info backing store (FixedArray) |
| 1947 | // edx: number of capture registers |
| 1948 | // Store the capture count. |
| 1949 | __ SmiTag(edx); // Number of capture registers to smi. |
| 1950 | __ mov(FieldOperand(ebx, RegExpImpl::kLastCaptureCountOffset), edx); |
| 1951 | __ SmiUntag(edx); // Number of capture registers back from smi. |
| 1952 | // Store last subject and last input. |
| 1953 | __ mov(eax, Operand(esp, kSubjectOffset)); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1954 | __ mov(ecx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1955 | __ mov(FieldOperand(ebx, RegExpImpl::kLastSubjectOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1956 | __ RecordWriteField(ebx, |
| 1957 | RegExpImpl::kLastSubjectOffset, |
| 1958 | eax, |
| 1959 | edi, |
| 1960 | kDontSaveFPRegs); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1961 | __ mov(eax, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1962 | __ mov(FieldOperand(ebx, RegExpImpl::kLastInputOffset), eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1963 | __ RecordWriteField(ebx, |
| 1964 | RegExpImpl::kLastInputOffset, |
| 1965 | eax, |
| 1966 | edi, |
| 1967 | kDontSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1968 | |
| 1969 | // Get the static offsets vector filled by the native regexp code. |
| 1970 | ExternalReference address_of_static_offsets_vector = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 1971 | ExternalReference::address_of_static_offsets_vector(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1972 | __ mov(ecx, Immediate(address_of_static_offsets_vector)); |
| 1973 | |
| 1974 | // ebx: last_match_info backing store (FixedArray) |
| 1975 | // ecx: offsets vector |
| 1976 | // edx: number of capture registers |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1977 | Label next_capture, done; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1978 | // Capture register counter starts from number of capture registers and |
| 1979 | // counts down until wraping after zero. |
| 1980 | __ bind(&next_capture); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 1981 | __ sub(edx, Immediate(1)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 1982 | __ j(negative, &done, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 1983 | // Read the value from the static offsets vector buffer. |
| 1984 | __ mov(edi, Operand(ecx, edx, times_int_size, 0)); |
| 1985 | __ SmiTag(edi); |
| 1986 | // Store the smi value in the last match info. |
| 1987 | __ mov(FieldOperand(ebx, |
| 1988 | edx, |
| 1989 | times_pointer_size, |
| 1990 | RegExpImpl::kFirstCaptureOffset), |
| 1991 | edi); |
| 1992 | __ jmp(&next_capture); |
| 1993 | __ bind(&done); |
| 1994 | |
| 1995 | // Return last match info. |
| 1996 | __ mov(eax, Operand(esp, kLastMatchInfoOffset)); |
| 1997 | __ ret(4 * kPointerSize); |
| 1998 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 1999 | // Do the runtime call to execute the regexp. |
| 2000 | __ bind(&runtime); |
| 2001 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 2002 | |
| 2003 | // Deferred code for string handling. |
| 2004 | // (7) Not a long external string? If yes, go to (10). |
| 2005 | __ bind(¬_seq_nor_cons); |
| 2006 | // Compare flags are still set from (3). |
| 2007 | __ j(greater, ¬_long_external, Label::kNear); // Go to (10). |
| 2008 | |
| 2009 | // (8) External string. Short external strings have been ruled out. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2010 | __ bind(&external_string); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 2011 | // Reload instance type. |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2012 | __ mov(ebx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 2013 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 2014 | if (FLAG_debug_code) { |
| 2015 | // Assert that we do not have a cons or slice (indirect strings) here. |
| 2016 | // Sequential strings have already been ruled out. |
| 2017 | __ test_b(ebx, kIsIndirectStringMask); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2018 | __ Assert(zero, kExternalStringExpectedButNotFound); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2019 | } |
| 2020 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
| 2021 | // 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] | 2022 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2023 | __ sub(eax, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 2024 | STATIC_ASSERT(kTwoByteStringTag == 0); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 2025 | // (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] | 2026 | __ test_b(ebx, kStringEncodingMask); |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 2027 | __ j(not_zero, &seq_one_byte_string); // Goto (6). |
mstarzinger@chromium.org | 1b3afd1 | 2011-11-29 14:28:56 +0000 | [diff] [blame] | 2028 | |
mstarzinger@chromium.org | 71fc346 | 2013-02-27 09:34:27 +0000 | [diff] [blame] | 2029 | // eax: sequential subject string (or look-alike, external string) |
| 2030 | // edx: original subject string |
| 2031 | // ecx: RegExp data (FixedArray) |
| 2032 | // (9) Two byte sequential. Load regexp code for one byte. Go to (E). |
| 2033 | __ bind(&seq_two_byte_string); |
| 2034 | // Load previous index and check range before edx is overwritten. We have |
| 2035 | // to use edx instead of eax here because it might have been only made to |
| 2036 | // look like a sequential string when it actually is an external string. |
| 2037 | __ mov(ebx, Operand(esp, kPreviousIndexOffset)); |
| 2038 | __ JumpIfNotSmi(ebx, &runtime); |
| 2039 | __ cmp(ebx, FieldOperand(edx, String::kLengthOffset)); |
| 2040 | __ j(above_equal, &runtime); |
| 2041 | __ mov(edx, FieldOperand(ecx, JSRegExp::kDataUC16CodeOffset)); |
| 2042 | __ Set(ecx, Immediate(0)); // Type is two byte. |
| 2043 | __ jmp(&check_code); // Go to (E). |
| 2044 | |
| 2045 | // (10) Not a string or a short external string? If yes, bail out to runtime. |
| 2046 | __ bind(¬_long_external); |
| 2047 | // Catch non-string subject or short external string. |
| 2048 | STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0); |
| 2049 | __ test(ebx, Immediate(kIsNotStringMask | kShortExternalStringTag)); |
| 2050 | __ j(not_zero, &runtime); |
| 2051 | |
| 2052 | // (11) Sliced string. Replace subject with parent. Go to (5a). |
| 2053 | // Load offset into edi and replace subject string with parent. |
| 2054 | __ mov(edi, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 2055 | __ mov(eax, FieldOperand(eax, SlicedString::kParentOffset)); |
| 2056 | __ jmp(&check_underlying); // Go to (5a). |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2057 | #endif // V8_INTERPRETED_REGEXP |
| 2058 | } |
| 2059 | |
| 2060 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2061 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 2062 | const int kMaxInlineLength = 100; |
| 2063 | Label slowcase; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2064 | Label done; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2065 | __ mov(ebx, Operand(esp, kPointerSize * 3)); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 2066 | __ JumpIfNotSmi(ebx, &slowcase); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2067 | __ cmp(ebx, Immediate(Smi::FromInt(kMaxInlineLength))); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2068 | __ j(above, &slowcase); |
| 2069 | // Smi-tagging is equivalent to multiplying by 2. |
| 2070 | STATIC_ASSERT(kSmiTag == 0); |
| 2071 | STATIC_ASSERT(kSmiTagSize == 1); |
| 2072 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 2073 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 2074 | // Elements: [Map][Length][..elements..] |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2075 | __ Allocate(JSRegExpResult::kSize + FixedArray::kHeaderSize, |
| 2076 | times_pointer_size, |
| 2077 | ebx, // In: Number of elements as a smi |
| 2078 | REGISTER_VALUE_IS_SMI, |
| 2079 | eax, // Out: Start of allocation (tagged). |
| 2080 | ecx, // Out: End of allocation. |
| 2081 | edx, // Scratch register |
| 2082 | &slowcase, |
| 2083 | TAG_OBJECT); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2084 | // eax: Start of allocated area, object-tagged. |
| 2085 | |
| 2086 | // Set JSArray map to global.regexp_result_map(). |
| 2087 | // Set empty properties FixedArray. |
| 2088 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 2089 | // Interleave operations for better latency. |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2090 | __ mov(edx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2091 | Factory* factory = masm->isolate()->factory(); |
| 2092 | __ mov(ecx, Immediate(factory->empty_fixed_array())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2093 | __ lea(ebx, Operand(eax, JSRegExpResult::kSize)); |
yangguo@chromium.org | 46839fb | 2012-08-28 09:06:19 +0000 | [diff] [blame] | 2094 | __ mov(edx, FieldOperand(edx, GlobalObject::kNativeContextOffset)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2095 | __ mov(FieldOperand(eax, JSObject::kElementsOffset), ebx); |
| 2096 | __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), ecx); |
| 2097 | __ mov(edx, ContextOperand(edx, Context::REGEXP_RESULT_MAP_INDEX)); |
| 2098 | __ mov(FieldOperand(eax, HeapObject::kMapOffset), edx); |
| 2099 | |
| 2100 | // Set input, index and length fields from arguments. |
| 2101 | __ mov(ecx, Operand(esp, kPointerSize * 1)); |
| 2102 | __ mov(FieldOperand(eax, JSRegExpResult::kInputOffset), ecx); |
| 2103 | __ mov(ecx, Operand(esp, kPointerSize * 2)); |
| 2104 | __ mov(FieldOperand(eax, JSRegExpResult::kIndexOffset), ecx); |
| 2105 | __ mov(ecx, Operand(esp, kPointerSize * 3)); |
| 2106 | __ mov(FieldOperand(eax, JSArray::kLengthOffset), ecx); |
| 2107 | |
| 2108 | // Fill out the elements FixedArray. |
| 2109 | // eax: JSArray. |
| 2110 | // ebx: FixedArray. |
| 2111 | // ecx: Number of elements in array, as smi. |
| 2112 | |
| 2113 | // Set map. |
| 2114 | __ mov(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2115 | Immediate(factory->fixed_array_map())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2116 | // Set length. |
| 2117 | __ mov(FieldOperand(ebx, FixedArray::kLengthOffset), ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2118 | // Fill contents of fixed-array with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2119 | __ SmiUntag(ecx); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2120 | __ mov(edx, Immediate(factory->undefined_value())); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2121 | __ lea(ebx, FieldOperand(ebx, FixedArray::kHeaderSize)); |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2122 | // Fill fixed array elements with undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2123 | // eax: JSArray. |
| 2124 | // ecx: Number of elements to fill. |
| 2125 | // ebx: Start of elements in FixedArray. |
ulan@chromium.org | 56c14af | 2012-09-20 12:51:09 +0000 | [diff] [blame] | 2126 | // edx: undefined. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2127 | Label loop; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2128 | __ test(ecx, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2129 | __ bind(&loop); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2130 | __ 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] | 2131 | __ sub(ecx, Immediate(1)); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 2132 | __ mov(Operand(ebx, ecx, times_pointer_size, 0), edx); |
| 2133 | __ jmp(&loop); |
| 2134 | |
| 2135 | __ bind(&done); |
| 2136 | __ ret(3 * kPointerSize); |
| 2137 | |
| 2138 | __ bind(&slowcase); |
| 2139 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 2140 | } |
| 2141 | |
| 2142 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2143 | static int NegativeComparisonResult(Condition cc) { |
| 2144 | ASSERT(cc != equal); |
| 2145 | ASSERT((cc == less) || (cc == less_equal) |
| 2146 | || (cc == greater) || (cc == greater_equal)); |
| 2147 | return (cc == greater || cc == greater_equal) ? LESS : GREATER; |
| 2148 | } |
| 2149 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2150 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2151 | static void CheckInputType(MacroAssembler* masm, |
| 2152 | Register input, |
| 2153 | CompareIC::State expected, |
| 2154 | Label* fail) { |
| 2155 | Label ok; |
| 2156 | if (expected == CompareIC::SMI) { |
| 2157 | __ JumpIfNotSmi(input, fail); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2158 | } else if (expected == CompareIC::NUMBER) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2159 | __ JumpIfSmi(input, &ok); |
| 2160 | __ cmp(FieldOperand(input, HeapObject::kMapOffset), |
| 2161 | Immediate(masm->isolate()->factory()->heap_number_map())); |
| 2162 | __ j(not_equal, fail); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2163 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2164 | // 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] | 2165 | // hydrogen doesn't care, the stub doesn't have to care either. |
| 2166 | __ bind(&ok); |
| 2167 | } |
| 2168 | |
| 2169 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2170 | static void BranchIfNotInternalizedString(MacroAssembler* masm, |
| 2171 | Label* label, |
| 2172 | Register object, |
| 2173 | Register scratch) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2174 | __ JumpIfSmi(object, label); |
| 2175 | __ mov(scratch, FieldOperand(object, HeapObject::kMapOffset)); |
| 2176 | __ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 2177 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 2178 | __ test(scratch, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 2179 | __ j(not_zero, label); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2180 | } |
| 2181 | |
| 2182 | |
| 2183 | void ICCompareStub::GenerateGeneric(MacroAssembler* masm) { |
| 2184 | Label check_unequal_objects; |
| 2185 | Condition cc = GetCondition(); |
| 2186 | |
| 2187 | Label miss; |
| 2188 | CheckInputType(masm, edx, left_, &miss); |
| 2189 | CheckInputType(masm, eax, right_, &miss); |
| 2190 | |
| 2191 | // Compare two smis. |
| 2192 | Label non_smi, smi_done; |
| 2193 | __ mov(ecx, edx); |
| 2194 | __ or_(ecx, eax); |
| 2195 | __ JumpIfNotSmi(ecx, &non_smi, Label::kNear); |
| 2196 | __ sub(edx, eax); // Return on the result of the subtraction. |
| 2197 | __ j(no_overflow, &smi_done, Label::kNear); |
| 2198 | __ not_(edx); // Correct sign in case of overflow. edx is never 0 here. |
| 2199 | __ bind(&smi_done); |
| 2200 | __ mov(eax, edx); |
| 2201 | __ ret(0); |
| 2202 | __ bind(&non_smi); |
erik.corry@gmail.com | d88afa2 | 2010-09-15 12:33:05 +0000 | [diff] [blame] | 2203 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2204 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 2205 | // it is certain that at least one operand isn't a smi. |
| 2206 | |
| 2207 | // Identical objects can be compared fast, but there are some tricky cases |
| 2208 | // for NaN and undefined. |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2209 | Label generic_heap_number_comparison; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2210 | { |
| 2211 | Label not_identical; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2212 | __ cmp(eax, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2213 | __ j(not_equal, ¬_identical); |
| 2214 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2215 | if (cc != equal) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2216 | // Check for undefined. undefined OP undefined is false even though |
| 2217 | // undefined == undefined. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2218 | Label check_for_nan; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2219 | __ cmp(edx, masm->isolate()->factory()->undefined_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2220 | __ j(not_equal, &check_for_nan, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2221 | __ Set(eax, Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2222 | __ ret(0); |
| 2223 | __ bind(&check_for_nan); |
| 2224 | } |
| 2225 | |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2226 | // Test for NaN. Compare heap numbers in a general way, |
| 2227 | // to hanlde NaNs correctly. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2228 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 2229 | Immediate(masm->isolate()->factory()->heap_number_map())); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2230 | __ j(equal, &generic_heap_number_comparison, Label::kNear); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2231 | if (cc != equal) { |
| 2232 | // Call runtime on identical JSObjects. Otherwise return equal. |
| 2233 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
| 2234 | __ j(above_equal, ¬_identical); |
| 2235 | } |
| 2236 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 2237 | __ ret(0); |
| 2238 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2239 | |
| 2240 | __ bind(¬_identical); |
| 2241 | } |
| 2242 | |
| 2243 | // Strict equality can quickly decide whether objects are equal. |
| 2244 | // 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] | 2245 | if (cc == equal && strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2246 | Label slow; // Fallthrough label. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2247 | Label not_smis; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2248 | // If we're doing a strict equality comparison, we don't have to do |
| 2249 | // type conversion, so we generate code to do fast comparison for objects |
| 2250 | // and oddballs. Non-smi numbers and strings still go through the usual |
| 2251 | // slow-case code. |
| 2252 | // If either is a Smi (we know that not both are), then they can only |
| 2253 | // be equal if the other is a HeapNumber. If so, use the slow case. |
| 2254 | STATIC_ASSERT(kSmiTag == 0); |
| 2255 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 2256 | __ mov(ecx, Immediate(kSmiTagMask)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2257 | __ and_(ecx, eax); |
| 2258 | __ test(ecx, edx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2259 | __ j(not_zero, ¬_smis, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2260 | // One operand is a smi. |
| 2261 | |
| 2262 | // Check whether the non-smi is a heap number. |
| 2263 | STATIC_ASSERT(kSmiTagMask == 1); |
| 2264 | // 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] | 2265 | __ sub(ecx, Immediate(0x01)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2266 | __ mov(ebx, edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2267 | __ xor_(ebx, eax); |
| 2268 | __ and_(ebx, ecx); // ebx holds either 0 or eax ^ edx. |
| 2269 | __ xor_(ebx, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2270 | // if eax was smi, ebx is now edx, else eax. |
| 2271 | |
| 2272 | // Check if the non-smi operand is a heap number. |
| 2273 | __ cmp(FieldOperand(ebx, HeapObject::kMapOffset), |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2274 | Immediate(masm->isolate()->factory()->heap_number_map())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2275 | // If heap number, handle it in the slow case. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2276 | __ j(equal, &slow, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2277 | // Return non-equal (ebx is not zero) |
| 2278 | __ mov(eax, ebx); |
| 2279 | __ ret(0); |
| 2280 | |
| 2281 | __ bind(¬_smis); |
| 2282 | // If either operand is a JSObject or an oddball value, then they are not |
| 2283 | // equal since their pointers are different |
| 2284 | // There is no test for undetectability in strict equality. |
| 2285 | |
| 2286 | // Get the type of the first operand. |
| 2287 | // 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] | 2288 | Label first_non_object; |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2289 | STATIC_ASSERT(LAST_TYPE == LAST_SPEC_OBJECT_TYPE); |
| 2290 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2291 | __ j(below, &first_non_object, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2292 | |
| 2293 | // Return non-zero (eax is not zero) |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2294 | Label return_not_equal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2295 | STATIC_ASSERT(kHeapObjectTag != 0); |
| 2296 | __ bind(&return_not_equal); |
| 2297 | __ ret(0); |
| 2298 | |
| 2299 | __ bind(&first_non_object); |
| 2300 | // Check for oddballs: true, false, null, undefined. |
| 2301 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 2302 | __ j(equal, &return_not_equal); |
| 2303 | |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2304 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2305 | __ j(above_equal, &return_not_equal); |
| 2306 | |
| 2307 | // Check for oddballs: true, false, null, undefined. |
| 2308 | __ CmpInstanceType(ecx, ODDBALL_TYPE); |
| 2309 | __ j(equal, &return_not_equal); |
| 2310 | |
| 2311 | // Fall through to the general case. |
| 2312 | __ bind(&slow); |
| 2313 | } |
| 2314 | |
| 2315 | // Generate the number comparison code. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2316 | Label non_number_comparison; |
| 2317 | Label unordered; |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 2318 | __ bind(&generic_heap_number_comparison); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2319 | if (CpuFeatures::IsSupported(SSE2)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 2320 | CpuFeatureScope use_sse2(masm, SSE2); |
| 2321 | CpuFeatureScope use_cmov(masm, CMOV); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2322 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2323 | FloatingPointHelper::LoadSSE2Operands(masm, &non_number_comparison); |
| 2324 | __ ucomisd(xmm0, xmm1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2325 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2326 | // Don't base result on EFLAGS when a NaN is involved. |
| 2327 | __ j(parity_even, &unordered, Label::kNear); |
| 2328 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 2329 | __ mov(eax, 0); // equal |
| 2330 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
| 2331 | __ cmov(above, eax, ecx); |
| 2332 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
| 2333 | __ cmov(below, eax, ecx); |
| 2334 | __ ret(0); |
| 2335 | } else { |
| 2336 | FloatingPointHelper::CheckFloatOperands( |
| 2337 | masm, &non_number_comparison, ebx); |
| 2338 | FloatingPointHelper::LoadFloatOperand(masm, eax); |
| 2339 | FloatingPointHelper::LoadFloatOperand(masm, edx); |
| 2340 | __ FCmp(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2341 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2342 | // Don't base result on EFLAGS when a NaN is involved. |
| 2343 | __ j(parity_even, &unordered, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2344 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2345 | Label below_label, above_label; |
| 2346 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 2347 | __ j(below, &below_label, Label::kNear); |
| 2348 | __ j(above, &above_label, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2349 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2350 | __ Set(eax, Immediate(0)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2351 | __ ret(0); |
| 2352 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2353 | __ bind(&below_label); |
| 2354 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 2355 | __ ret(0); |
| 2356 | |
| 2357 | __ bind(&above_label); |
| 2358 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 2359 | __ ret(0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2360 | } |
| 2361 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2362 | // If one of the numbers was NaN, then the result is always false. |
| 2363 | // The cc is never not-equal. |
| 2364 | __ bind(&unordered); |
| 2365 | ASSERT(cc != not_equal); |
| 2366 | if (cc == less || cc == less_equal) { |
| 2367 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 2368 | } else { |
| 2369 | __ mov(eax, Immediate(Smi::FromInt(-1))); |
| 2370 | } |
| 2371 | __ ret(0); |
| 2372 | |
| 2373 | // The number comparison code did not provide a valid result. |
| 2374 | __ bind(&non_number_comparison); |
| 2375 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2376 | // Fast negative check for internalized-to-internalized equality. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2377 | Label check_for_strings; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2378 | if (cc == equal) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2379 | BranchIfNotInternalizedString(masm, &check_for_strings, eax, ecx); |
| 2380 | BranchIfNotInternalizedString(masm, &check_for_strings, edx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2381 | |
| 2382 | // We've already checked for object identity, so if both operands |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2383 | // are internalized they aren't equal. Register eax already holds a |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2384 | // non-zero value, which indicates not equal, so just return. |
| 2385 | __ ret(0); |
| 2386 | } |
| 2387 | |
| 2388 | __ bind(&check_for_strings); |
| 2389 | |
| 2390 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, |
| 2391 | &check_unequal_objects); |
| 2392 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 2393 | // Inline comparison of ASCII strings. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2394 | if (cc == equal) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2395 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2396 | edx, |
| 2397 | eax, |
| 2398 | ecx, |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 2399 | ebx); |
| 2400 | } else { |
| 2401 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 2402 | edx, |
| 2403 | eax, |
| 2404 | ecx, |
| 2405 | ebx, |
| 2406 | edi); |
| 2407 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2408 | #ifdef DEBUG |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 2409 | __ Abort(kUnexpectedFallThroughFromStringComparison); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2410 | #endif |
| 2411 | |
| 2412 | __ bind(&check_unequal_objects); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2413 | if (cc == equal && !strict()) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2414 | // Non-strict equality. Objects are unequal if |
| 2415 | // they are both JSObjects and not undetectable, |
| 2416 | // and their pointers are different. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2417 | Label not_both_objects; |
| 2418 | Label return_unequal; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2419 | // At most one is a smi, so we can test for smi by adding the two. |
| 2420 | // A smi plus a heap object has the low bit set, a heap object plus |
| 2421 | // a heap object has the low bit clear. |
| 2422 | STATIC_ASSERT(kSmiTag == 0); |
| 2423 | STATIC_ASSERT(kSmiTagMask == 1); |
| 2424 | __ lea(ecx, Operand(eax, edx, times_1, 0)); |
| 2425 | __ test(ecx, Immediate(kSmiTagMask)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2426 | __ j(not_zero, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2427 | __ CmpObjectType(eax, FIRST_SPEC_OBJECT_TYPE, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2428 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | d2be901 | 2011-06-01 06:00:58 +0000 | [diff] [blame] | 2429 | __ CmpObjectType(edx, FIRST_SPEC_OBJECT_TYPE, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2430 | __ j(below, ¬_both_objects, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2431 | // We do not bail out after this point. Both are JSObjects, and |
| 2432 | // they are equal if and only if both are undetectable. |
| 2433 | // The and of the undetectable flags is 1 if and only if they are equal. |
| 2434 | __ test_b(FieldOperand(ecx, Map::kBitFieldOffset), |
| 2435 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2436 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2437 | __ test_b(FieldOperand(ebx, Map::kBitFieldOffset), |
| 2438 | 1 << Map::kIsUndetectable); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2439 | __ j(zero, &return_unequal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2440 | // The objects are both undetectable, so they both compare as the value |
| 2441 | // undefined, and are equal. |
| 2442 | __ Set(eax, Immediate(EQUAL)); |
| 2443 | __ bind(&return_unequal); |
| 2444 | // Return non-equal by returning the non-zero object pointer in eax, |
| 2445 | // or return equal if we fell through to here. |
| 2446 | __ ret(0); // rax, rdx were pushed |
| 2447 | __ bind(¬_both_objects); |
| 2448 | } |
| 2449 | |
| 2450 | // Push arguments below the return address. |
| 2451 | __ pop(ecx); |
| 2452 | __ push(edx); |
| 2453 | __ push(eax); |
| 2454 | |
| 2455 | // Figure out which native to call and setup the arguments. |
| 2456 | Builtins::JavaScript builtin; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2457 | if (cc == equal) { |
| 2458 | builtin = strict() ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2459 | } else { |
| 2460 | builtin = Builtins::COMPARE; |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2461 | __ push(Immediate(Smi::FromInt(NegativeComparisonResult(cc)))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2462 | } |
| 2463 | |
| 2464 | // Restore return address on the stack. |
| 2465 | __ push(ecx); |
| 2466 | |
| 2467 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 2468 | // tagged as a small integer. |
| 2469 | __ InvokeBuiltin(builtin, JUMP_FUNCTION); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2470 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 2471 | __ bind(&miss); |
| 2472 | GenerateMiss(masm); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2476 | static void GenerateRecordCallTarget(MacroAssembler* masm) { |
| 2477 | // Cache the called function in a global property cell. Cache states |
| 2478 | // are uninitialized, monomorphic (indicated by a JSFunction), and |
| 2479 | // megamorphic. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2480 | // eax : number of arguments to the construct function |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2481 | // ebx : cache cell for call target |
| 2482 | // edi : the function to call |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2483 | Isolate* isolate = masm->isolate(); |
| 2484 | Label initialize, done, miss, megamorphic, not_array_function; |
| 2485 | |
| 2486 | // Load the cache state into ecx. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2487 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2488 | |
| 2489 | // A monomorphic cache hit or an already megamorphic state: invoke the |
| 2490 | // function without changing the state. |
| 2491 | __ cmp(ecx, edi); |
| 2492 | __ j(equal, &done); |
| 2493 | __ cmp(ecx, Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 2494 | __ j(equal, &done); |
| 2495 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2496 | // If we came here, we need to see if we are the array function. |
| 2497 | // If we didn't have a matching function, and we didn't find the megamorph |
| 2498 | // sentinel, then we have in the cell either some other function or an |
| 2499 | // AllocationSite. Do a map check on the object in ecx. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2500 | Handle<Map> allocation_site_map = |
| 2501 | masm->isolate()->factory()->allocation_site_map(); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2502 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 2503 | __ j(not_equal, &miss); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2504 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2505 | // Load the global or builtins object from the current context |
| 2506 | __ LoadGlobalContext(ecx); |
| 2507 | // Make sure the function is the Array() function |
| 2508 | __ cmp(edi, Operand(ecx, |
| 2509 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 2510 | __ j(not_equal, &megamorphic); |
| 2511 | __ jmp(&done); |
| 2512 | |
| 2513 | __ bind(&miss); |
| 2514 | |
| 2515 | // A monomorphic miss (i.e, here the cache is not uninitialized) goes |
| 2516 | // megamorphic. |
| 2517 | __ cmp(ecx, Immediate(TypeFeedbackCells::UninitializedSentinel(isolate))); |
| 2518 | __ j(equal, &initialize); |
| 2519 | // MegamorphicSentinel is an immortal immovable object (undefined) so no |
| 2520 | // write-barrier is needed. |
| 2521 | __ bind(&megamorphic); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2522 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2523 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
| 2524 | __ jmp(&done, Label::kNear); |
| 2525 | |
| 2526 | // An uninitialized cache is patched with the function or sentinel to |
| 2527 | // indicate the ElementsKind if function is the Array constructor. |
| 2528 | __ bind(&initialize); |
| 2529 | __ LoadGlobalContext(ecx); |
| 2530 | // Make sure the function is the Array() function |
| 2531 | __ cmp(edi, Operand(ecx, |
| 2532 | Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); |
| 2533 | __ j(not_equal, ¬_array_function); |
| 2534 | |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2535 | // The target function is the Array constructor, |
| 2536 | // Create an AllocationSite if we don't already have it, store it in the cell |
| 2537 | { |
| 2538 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 2539 | |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2540 | // Arguments register must be smi-tagged to call out. |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2541 | __ SmiTag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2542 | __ push(eax); |
| 2543 | __ push(edi); |
| 2544 | __ push(ebx); |
| 2545 | |
| 2546 | CreateAllocationSiteStub create_stub; |
| 2547 | __ CallStub(&create_stub); |
| 2548 | |
| 2549 | __ pop(ebx); |
| 2550 | __ pop(edi); |
| 2551 | __ pop(eax); |
verwaest@chromium.org | 662436e | 2013-08-28 08:41:27 +0000 | [diff] [blame] | 2552 | __ SmiUntag(eax); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2553 | } |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2554 | __ jmp(&done); |
| 2555 | |
| 2556 | __ bind(¬_array_function); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2557 | __ mov(FieldOperand(ebx, Cell::kValueOffset), edi); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2558 | // No need for a write barrier here - cells are rescanned. |
| 2559 | |
| 2560 | __ bind(&done); |
| 2561 | } |
| 2562 | |
| 2563 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2564 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2565 | // ebx : cache cell for call target |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 2566 | // edi : the function to call |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2567 | Isolate* isolate = masm->isolate(); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2568 | Label slow, non_function; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2569 | |
rossberg@chromium.org | 9ed2746 | 2014-01-07 14:16:41 +0000 | [diff] [blame] | 2570 | // Check that the function really is a JavaScript function. |
| 2571 | __ JumpIfSmi(edi, &non_function); |
| 2572 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2573 | // Goto slow case if we do not have a function. |
| 2574 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2575 | __ j(not_equal, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2576 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2577 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2578 | GenerateRecordCallTarget(masm); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2579 | } |
| 2580 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2581 | // Fast-case: Just invoke the function. |
| 2582 | ParameterCount actual(argc_); |
danno@chromium.org | 40cb878 | 2011-05-25 07:58:50 +0000 | [diff] [blame] | 2583 | |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 2584 | __ InvokeFunction(edi, actual, JUMP_FUNCTION, NullCallWrapper()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2585 | |
| 2586 | // Slow-case: Non-function called. |
| 2587 | __ bind(&slow); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2588 | if (RecordCallTarget()) { |
| 2589 | // 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] | 2590 | // non-function case. MegamorphicSentinel is an immortal immovable |
| 2591 | // object (undefined) so no write barrier is needed. |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 2592 | __ mov(FieldOperand(ebx, Cell::kValueOffset), |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2593 | Immediate(TypeFeedbackCells::MegamorphicSentinel(isolate))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2594 | } |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 2595 | // Check for function proxy. |
| 2596 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 2597 | __ j(not_equal, &non_function); |
| 2598 | __ pop(ecx); |
| 2599 | __ push(edi); // put proxy as additional argument under return address |
| 2600 | __ push(ecx); |
| 2601 | __ Set(eax, Immediate(argc_ + 1)); |
| 2602 | __ Set(ebx, Immediate(0)); |
lrn@chromium.org | 34e6078 | 2011-09-15 07:25:40 +0000 | [diff] [blame] | 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)); |
| 2615 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2616 | Handle<Code> adaptor = isolate->builtins()->ArgumentsAdaptorTrampoline(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2617 | __ jmp(adaptor, RelocInfo::CODE_TARGET); |
| 2618 | } |
| 2619 | |
| 2620 | |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2621 | void CallConstructStub::Generate(MacroAssembler* masm) { |
| 2622 | // eax : number of arguments |
| 2623 | // ebx : cache cell for call target |
| 2624 | // edi : constructor function |
| 2625 | Label slow, non_function_call; |
| 2626 | |
| 2627 | // Check that function is not a smi. |
| 2628 | __ JumpIfSmi(edi, &non_function_call); |
| 2629 | // Check that function is a JSFunction. |
| 2630 | __ CmpObjectType(edi, JS_FUNCTION_TYPE, ecx); |
| 2631 | __ j(not_equal, &slow); |
| 2632 | |
| 2633 | if (RecordCallTarget()) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2634 | GenerateRecordCallTarget(masm); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | // Jump to the function-specific construct stub. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2638 | Register jmp_reg = ecx; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 2639 | __ mov(jmp_reg, FieldOperand(edi, JSFunction::kSharedFunctionInfoOffset)); |
| 2640 | __ mov(jmp_reg, FieldOperand(jmp_reg, |
| 2641 | SharedFunctionInfo::kConstructStubOffset)); |
| 2642 | __ lea(jmp_reg, FieldOperand(jmp_reg, Code::kHeaderSize)); |
| 2643 | __ jmp(jmp_reg); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2644 | |
| 2645 | // edi: called object |
| 2646 | // eax: number of arguments |
| 2647 | // ecx: object map |
| 2648 | Label do_call; |
| 2649 | __ bind(&slow); |
| 2650 | __ CmpInstanceType(ecx, JS_FUNCTION_PROXY_TYPE); |
| 2651 | __ j(not_equal, &non_function_call); |
| 2652 | __ GetBuiltinEntry(edx, Builtins::CALL_FUNCTION_PROXY_AS_CONSTRUCTOR); |
| 2653 | __ jmp(&do_call); |
| 2654 | |
| 2655 | __ bind(&non_function_call); |
| 2656 | __ GetBuiltinEntry(edx, Builtins::CALL_NON_FUNCTION_AS_CONSTRUCTOR); |
| 2657 | __ bind(&do_call); |
| 2658 | // Set expected number of arguments to zero (not changing eax). |
| 2659 | __ Set(ebx, Immediate(0)); |
| 2660 | Handle<Code> arguments_adaptor = |
| 2661 | masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(); |
danno@chromium.org | fa458e4 | 2012-02-01 10:48:36 +0000 | [diff] [blame] | 2662 | __ jmp(arguments_adaptor, RelocInfo::CODE_TARGET); |
| 2663 | } |
| 2664 | |
| 2665 | |
danno@chromium.org | 4d3fe4e | 2011-03-10 10:14:28 +0000 | [diff] [blame] | 2666 | bool CEntryStub::NeedsImmovableCode() { |
| 2667 | return false; |
| 2668 | } |
| 2669 | |
| 2670 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2671 | void CodeStub::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 2672 | CEntryStub::GenerateAheadOfTime(isolate); |
| 2673 | StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime(isolate); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2674 | StubFailureTrampolineStub::GenerateAheadOfTime(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2675 | // 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] | 2676 | ArrayConstructorStubBase::GenerateStubsAheadOfTime(isolate); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 2677 | CreateAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2678 | if (Serializer::enabled()) { |
| 2679 | PlatformFeatureScope sse2(SSE2); |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2680 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 2681 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2682 | } else { |
machenbach@chromium.org | ce9c514 | 2013-12-03 08:00:39 +0000 | [diff] [blame] | 2683 | BinaryOpICStub::GenerateAheadOfTime(isolate); |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 2684 | BinaryOpICWithAllocationSiteStub::GenerateAheadOfTime(isolate); |
mvstanton@chromium.org | 182d2db | 2013-10-10 11:03:05 +0000 | [diff] [blame] | 2685 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2689 | void CodeStub::GenerateFPStubs(Isolate* isolate) { |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2690 | if (CpuFeatures::IsSupported(SSE2)) { |
| 2691 | CEntryStub save_doubles(1, kSaveFPRegs); |
| 2692 | // Stubs might already be in the snapshot, detect that and don't regenerate, |
| 2693 | // which would lead to code stub initialization state being messed up. |
| 2694 | Code* save_doubles_code; |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2695 | if (!save_doubles.FindCodeInCache(&save_doubles_code, isolate)) { |
| 2696 | save_doubles_code = *(save_doubles.GetCode(isolate)); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2697 | } |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2698 | isolate->set_fp_stubs_generated(true); |
yangguo@chromium.org | a6bbcc8 | 2012-12-21 12:35:02 +0000 | [diff] [blame] | 2699 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 2703 | void CEntryStub::GenerateAheadOfTime(Isolate* isolate) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2704 | CEntryStub stub(1, kDontSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 2705 | stub.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2709 | static void JumpIfOOM(MacroAssembler* masm, |
| 2710 | Register value, |
| 2711 | Register scratch, |
| 2712 | Label* oom_label) { |
| 2713 | __ mov(scratch, value); |
| 2714 | STATIC_ASSERT(Failure::OUT_OF_MEMORY_EXCEPTION == 3); |
| 2715 | STATIC_ASSERT(kFailureTag == 3); |
| 2716 | __ and_(scratch, 0xf); |
| 2717 | __ cmp(scratch, 0xf); |
| 2718 | __ j(equal, oom_label); |
| 2719 | } |
| 2720 | |
| 2721 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2722 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 2723 | Label* throw_normal_exception, |
| 2724 | Label* throw_termination_exception, |
| 2725 | Label* throw_out_of_memory_exception, |
| 2726 | bool do_gc, |
ager@chromium.org | 0ee099b | 2011-01-25 14:06:47 +0000 | [diff] [blame] | 2727 | bool always_allocate_scope) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2728 | // eax: result parameter for PerformGC, if any |
| 2729 | // ebx: pointer to C function (C callee-saved) |
| 2730 | // ebp: frame pointer (restored after C call) |
| 2731 | // esp: stack pointer (restored after C call) |
| 2732 | // edi: number of arguments including receiver (C callee-saved) |
| 2733 | // esi: pointer to the first argument (C callee-saved) |
| 2734 | |
| 2735 | // Result returned in eax, or eax+edx if result_size_ is 2. |
| 2736 | |
| 2737 | // Check stack alignment. |
| 2738 | if (FLAG_debug_code) { |
| 2739 | __ CheckStackAlignment(); |
| 2740 | } |
| 2741 | |
| 2742 | if (do_gc) { |
| 2743 | // Pass failure code returned from last attempt as first argument to |
| 2744 | // PerformGC. No need to use PrepareCallCFunction/CallCFunction here as the |
| 2745 | // stack alignment is known to be correct. This function takes one argument |
| 2746 | // which is passed on the stack, and we know that the stack has been |
| 2747 | // prepared to pass at least one argument. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 2748 | __ mov(Operand(esp, 1 * kPointerSize), |
| 2749 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2750 | __ mov(Operand(esp, 0 * kPointerSize), eax); // Result. |
| 2751 | __ call(FUNCTION_ADDR(Runtime::PerformGC), RelocInfo::RUNTIME_ENTRY); |
| 2752 | } |
| 2753 | |
| 2754 | ExternalReference scope_depth = |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2755 | ExternalReference::heap_always_allocate_scope_depth(masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2756 | if (always_allocate_scope) { |
| 2757 | __ inc(Operand::StaticVariable(scope_depth)); |
| 2758 | } |
| 2759 | |
| 2760 | // Call C function. |
| 2761 | __ mov(Operand(esp, 0 * kPointerSize), edi); // argc. |
| 2762 | __ mov(Operand(esp, 1 * kPointerSize), esi); // argv. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2763 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 2764 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2765 | __ call(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2766 | // Result is in eax or edx:eax - do not destroy these registers! |
| 2767 | |
| 2768 | if (always_allocate_scope) { |
| 2769 | __ dec(Operand::StaticVariable(scope_depth)); |
| 2770 | } |
| 2771 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 2772 | // Runtime functions should not return 'the hole'. Allowing it to escape may |
| 2773 | // lead to crashes in the IC code later. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2774 | if (FLAG_debug_code) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2775 | Label okay; |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2776 | __ cmp(eax, masm->isolate()->factory()->the_hole_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2777 | __ j(not_equal, &okay, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2778 | __ int3(); |
| 2779 | __ bind(&okay); |
| 2780 | } |
| 2781 | |
| 2782 | // Check for failure result. |
| 2783 | Label failure_returned; |
| 2784 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 2785 | __ lea(ecx, Operand(eax, 1)); |
| 2786 | // Lower 2 bits of ecx are 0 iff eax has failure tag. |
| 2787 | __ test(ecx, Immediate(kFailureTagMask)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 2788 | __ j(zero, &failure_returned); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2789 | |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2790 | ExternalReference pending_exception_address( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2791 | Isolate::kPendingExceptionAddress, masm->isolate()); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2792 | |
| 2793 | // Check that there is no pending exception, otherwise we |
| 2794 | // should have returned some failure value. |
| 2795 | if (FLAG_debug_code) { |
| 2796 | __ push(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2797 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 2798 | Label okay; |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2799 | __ cmp(edx, Operand::StaticVariable(pending_exception_address)); |
| 2800 | // 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] | 2801 | __ j(equal, &okay, Label::kNear); |
erik.corry@gmail.com | d91075f | 2011-02-10 07:45:38 +0000 | [diff] [blame] | 2802 | __ int3(); |
| 2803 | __ bind(&okay); |
| 2804 | __ pop(edx); |
| 2805 | } |
| 2806 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2807 | // Exit the JavaScript to C++ exit frame. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2808 | __ LeaveExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2809 | __ ret(0); |
| 2810 | |
| 2811 | // Handling of failure. |
| 2812 | __ bind(&failure_returned); |
| 2813 | |
| 2814 | Label retry; |
| 2815 | // If the returned exception is RETRY_AFTER_GC continue at retry label |
| 2816 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 2817 | __ test(eax, Immediate(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2818 | __ j(zero, &retry, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2819 | |
| 2820 | // Special handling of out of memory exceptions. |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2821 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2822 | |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2823 | // Retrieve the pending exception. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2824 | __ mov(eax, Operand::StaticVariable(pending_exception_address)); |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 2825 | |
| 2826 | // See if we just retrieved an OOM exception. |
| 2827 | JumpIfOOM(masm, eax, ecx, throw_out_of_memory_exception); |
| 2828 | |
| 2829 | // Clear the pending exception. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2830 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2831 | __ mov(Operand::StaticVariable(pending_exception_address), edx); |
| 2832 | |
| 2833 | // Special handling of termination exceptions which are uncatchable |
| 2834 | // by javascript code. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2835 | __ cmp(eax, masm->isolate()->factory()->termination_exception()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2836 | __ j(equal, throw_termination_exception); |
| 2837 | |
| 2838 | // Handle normal exception. |
| 2839 | __ jmp(throw_normal_exception); |
| 2840 | |
| 2841 | // Retry. |
| 2842 | __ bind(&retry); |
| 2843 | } |
| 2844 | |
| 2845 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2846 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 2847 | // eax: number of arguments including receiver |
| 2848 | // ebx: pointer to C function (C callee-saved) |
| 2849 | // ebp: frame pointer (restored after C call) |
| 2850 | // esp: stack pointer (restored after C call) |
| 2851 | // esi: current context (C callee-saved) |
| 2852 | // edi: JS function of the caller (C callee-saved) |
| 2853 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2854 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 2855 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2856 | // NOTE: Invocations of builtins may return failure objects instead |
| 2857 | // of a proper result. The builtin entry handles this by performing |
| 2858 | // a garbage collection and retrying the builtin (twice). |
| 2859 | |
| 2860 | // Enter the exit frame that transitions from JavaScript to C++. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2861 | __ EnterExitFrame(save_doubles_ == kSaveFPRegs); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2862 | |
| 2863 | // eax: result parameter for PerformGC, if any (setup below) |
| 2864 | // ebx: pointer to builtin function (C callee-saved) |
| 2865 | // ebp: frame pointer (restored after C call) |
| 2866 | // esp: stack pointer (restored after C call) |
| 2867 | // edi: number of arguments including receiver (C callee-saved) |
| 2868 | // esi: argv pointer (C callee-saved) |
| 2869 | |
| 2870 | Label throw_normal_exception; |
| 2871 | Label throw_termination_exception; |
| 2872 | Label throw_out_of_memory_exception; |
| 2873 | |
| 2874 | // Call into the runtime system. |
| 2875 | GenerateCore(masm, |
| 2876 | &throw_normal_exception, |
| 2877 | &throw_termination_exception, |
| 2878 | &throw_out_of_memory_exception, |
| 2879 | false, |
| 2880 | false); |
| 2881 | |
| 2882 | // Do space-specific GC and retry runtime call. |
| 2883 | GenerateCore(masm, |
| 2884 | &throw_normal_exception, |
| 2885 | &throw_termination_exception, |
| 2886 | &throw_out_of_memory_exception, |
| 2887 | true, |
| 2888 | false); |
| 2889 | |
| 2890 | // Do full GC and retry runtime call one final time. |
| 2891 | Failure* failure = Failure::InternalError(); |
| 2892 | __ mov(eax, Immediate(reinterpret_cast<int32_t>(failure))); |
| 2893 | GenerateCore(masm, |
| 2894 | &throw_normal_exception, |
| 2895 | &throw_termination_exception, |
| 2896 | &throw_out_of_memory_exception, |
| 2897 | true, |
| 2898 | true); |
| 2899 | |
| 2900 | __ bind(&throw_out_of_memory_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2901 | // Set external caught exception to false. |
| 2902 | Isolate* isolate = masm->isolate(); |
| 2903 | ExternalReference external_caught(Isolate::kExternalCaughtExceptionAddress, |
| 2904 | isolate); |
| 2905 | __ mov(Operand::StaticVariable(external_caught), Immediate(false)); |
| 2906 | |
| 2907 | // Set pending exception and eax to out of memory exception. |
| 2908 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
| 2909 | isolate); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 2910 | Label already_have_failure; |
| 2911 | JumpIfOOM(masm, eax, ecx, &already_have_failure); |
| 2912 | __ mov(eax, reinterpret_cast<int32_t>(Failure::OutOfMemoryException(0x1))); |
| 2913 | __ bind(&already_have_failure); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2914 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 2915 | // Fall through to the next label. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2916 | |
| 2917 | __ bind(&throw_termination_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2918 | __ ThrowUncatchable(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2919 | |
| 2920 | __ bind(&throw_normal_exception); |
ulan@chromium.org | 65a89c2 | 2012-02-14 11:46:07 +0000 | [diff] [blame] | 2921 | __ Throw(eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | |
| 2925 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2926 | Label invoke, handler_entry, exit; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2927 | Label not_outermost_js, not_outermost_js_2; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2928 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 2929 | ProfileEntryHookStub::MaybeCallEntryHook(masm); |
| 2930 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 2931 | // Set up frame. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2932 | __ push(ebp); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2933 | __ mov(ebp, esp); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2934 | |
| 2935 | // Push marker in two places. |
| 2936 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 2937 | __ push(Immediate(Smi::FromInt(marker))); // context slot |
| 2938 | __ push(Immediate(Smi::FromInt(marker))); // function slot |
| 2939 | // Save callee-saved registers (C calling conventions). |
| 2940 | __ push(edi); |
| 2941 | __ push(esi); |
| 2942 | __ push(ebx); |
| 2943 | |
| 2944 | // Save copies of the top frame descriptor on the stack. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2945 | ExternalReference c_entry_fp(Isolate::kCEntryFPAddress, masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2946 | __ push(Operand::StaticVariable(c_entry_fp)); |
| 2947 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2948 | // 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] | 2949 | ExternalReference js_entry_sp(Isolate::kJSEntrySPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2950 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2951 | __ cmp(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 2952 | __ j(not_equal, ¬_outermost_js, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2953 | __ mov(Operand::StaticVariable(js_entry_sp), ebp); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2954 | __ push(Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
danno@chromium.org | 2c26cb1 | 2012-05-03 09:06:43 +0000 | [diff] [blame] | 2955 | __ jmp(&invoke, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2956 | __ bind(¬_outermost_js); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 2957 | __ push(Immediate(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2958 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2959 | // Jump to a faked try block that does the invoke, with a faked catch |
| 2960 | // block that sets the pending exception. |
| 2961 | __ jmp(&invoke); |
| 2962 | __ bind(&handler_entry); |
| 2963 | handler_offset_ = handler_entry.pos(); |
| 2964 | // Caught exception: Store result (exception) in the pending exception |
| 2965 | // field in the JSEnv and return a failure sentinel. |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 2966 | ExternalReference pending_exception(Isolate::kPendingExceptionAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2967 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2968 | __ mov(Operand::StaticVariable(pending_exception), eax); |
| 2969 | __ mov(eax, reinterpret_cast<int32_t>(Failure::Exception())); |
| 2970 | __ jmp(&exit); |
| 2971 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2972 | // Invoke: Link this frame into the handler chain. There's only one |
| 2973 | // handler block in this code object, so its index is 0. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2974 | __ bind(&invoke); |
yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 2975 | __ PushTryHandler(StackHandler::JS_ENTRY, 0); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2976 | |
| 2977 | // Clear any pending exceptions. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2978 | __ mov(edx, Immediate(masm->isolate()->factory()->the_hole_value())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2979 | __ mov(Operand::StaticVariable(pending_exception), edx); |
| 2980 | |
| 2981 | // Fake a receiver (NULL). |
| 2982 | __ push(Immediate(0)); // receiver |
| 2983 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2984 | // Invoke the function by calling through JS entry trampoline builtin and |
| 2985 | // pop the faked function when we return. Notice that we cannot store a |
| 2986 | // reference to the trampoline code directly in this stub, because the |
| 2987 | // builtin stubs may not have been generated yet. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2988 | if (is_construct) { |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 2989 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 2990 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2991 | __ mov(edx, Immediate(construct_entry)); |
| 2992 | } else { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 2993 | ExternalReference entry(Builtins::kJSEntryTrampoline, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 2994 | masm->isolate()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 2995 | __ mov(edx, Immediate(entry)); |
| 2996 | } |
| 2997 | __ mov(edx, Operand(edx, 0)); // deref address |
| 2998 | __ lea(edx, FieldOperand(edx, Code::kHeaderSize)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 2999 | __ call(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3000 | |
| 3001 | // Unlink this frame from the handler chain. |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3002 | __ PopTryHandler(); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3003 | |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3004 | __ bind(&exit); |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3005 | // Check if the current stack frame is marked as the outermost JS frame. |
| 3006 | __ pop(ebx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3007 | __ cmp(ebx, Immediate(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3008 | __ j(not_equal, ¬_outermost_js_2); |
| 3009 | __ mov(Operand::StaticVariable(js_entry_sp), Immediate(0)); |
| 3010 | __ bind(¬_outermost_js_2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3011 | |
| 3012 | // Restore the top frame descriptor from the stack. |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3013 | __ pop(Operand::StaticVariable(ExternalReference( |
kmillikin@chromium.org | 83e1682 | 2011-09-13 08:21:47 +0000 | [diff] [blame] | 3014 | Isolate::kCEntryFPAddress, |
sgjesse@chromium.org | ea88ce9 | 2011-03-23 11:19:56 +0000 | [diff] [blame] | 3015 | masm->isolate()))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3016 | |
| 3017 | // Restore callee-saved registers (C calling conventions). |
| 3018 | __ pop(ebx); |
| 3019 | __ pop(esi); |
| 3020 | __ pop(edi); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3021 | __ add(esp, Immediate(2 * kPointerSize)); // remove markers |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3022 | |
| 3023 | // Restore frame pointer and return. |
| 3024 | __ pop(ebp); |
| 3025 | __ ret(0); |
| 3026 | } |
| 3027 | |
| 3028 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3029 | // Generate stub code for instanceof. |
| 3030 | // This code can patch a call site inlined cache of the instance of check, |
| 3031 | // which looks like this. |
| 3032 | // |
| 3033 | // 81 ff XX XX XX XX cmp edi, <the hole, patched to a map> |
| 3034 | // 75 0a jne <some near label> |
| 3035 | // b8 XX XX XX XX mov eax, <the hole, patched to either true or false> |
| 3036 | // |
| 3037 | // If call site patching is requested the stack will have the delta from the |
| 3038 | // return address to the cmp instruction just below the return address. This |
| 3039 | // also means that call site patching can only take place with arguments in |
| 3040 | // registers. TOS looks like this when call site patching is requested |
| 3041 | // |
| 3042 | // esp[0] : return address |
| 3043 | // esp[4] : delta from return address to cmp instruction |
| 3044 | // |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3045 | void InstanceofStub::Generate(MacroAssembler* masm) { |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3046 | // Call site inlining and patching implies arguments in registers. |
| 3047 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 3048 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3049 | // Fixed register usage throughout the stub. |
| 3050 | Register object = eax; // Object (lhs). |
| 3051 | Register map = ebx; // Map of the object. |
| 3052 | Register function = edx; // Function (rhs). |
| 3053 | Register prototype = edi; // Prototype of the function. |
| 3054 | Register scratch = ecx; |
| 3055 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3056 | // Constants describing the call site code to patch. |
| 3057 | static const int kDeltaToCmpImmediate = 2; |
| 3058 | static const int kDeltaToMov = 8; |
| 3059 | static const int kDeltaToMovImmediate = 9; |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3060 | static const int8_t kCmpEdiOperandByte1 = BitCast<int8_t, uint8_t>(0x3b); |
| 3061 | static const int8_t kCmpEdiOperandByte2 = BitCast<int8_t, uint8_t>(0x3d); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3062 | static const int8_t kMovEaxImmediateByte = BitCast<int8_t, uint8_t>(0xb8); |
| 3063 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3064 | ASSERT_EQ(object.code(), InstanceofStub::left().code()); |
| 3065 | ASSERT_EQ(function.code(), InstanceofStub::right().code()); |
| 3066 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3067 | // Get the object and function - they are always both needed. |
| 3068 | Label slow, not_js_object; |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3069 | if (!HasArgsInRegisters()) { |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3070 | __ mov(object, Operand(esp, 2 * kPointerSize)); |
| 3071 | __ mov(function, Operand(esp, 1 * kPointerSize)); |
| 3072 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3073 | |
| 3074 | // Check that the left hand is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3075 | __ JumpIfSmi(object, ¬_js_object); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3076 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3077 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3078 | // If there is a call site cache don't look in the global cache, but do the |
| 3079 | // real lookup and update the call site cache. |
| 3080 | if (!HasCallSiteInlineCheck()) { |
| 3081 | // Look up the function and the map in the instanceof cache. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3082 | Label miss; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3083 | __ CompareRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3084 | __ j(not_equal, &miss, Label::kNear); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3085 | __ CompareRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
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 | __ LoadRoot(eax, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3088 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
| 3089 | __ bind(&miss); |
| 3090 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3091 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3092 | // Get the prototype of the function. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 3093 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow, true); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3094 | |
| 3095 | // Check that the function prototype is a JS object. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3096 | __ JumpIfSmi(prototype, &slow); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3097 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3098 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3099 | // Update the global instanceof or call site inlined cache with the current |
| 3100 | // map and function. The cached answer will be set when it is known below. |
| 3101 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3102 | __ StoreRoot(map, scratch, Heap::kInstanceofCacheMapRootIndex); |
| 3103 | __ StoreRoot(function, scratch, Heap::kInstanceofCacheFunctionRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3104 | } else { |
| 3105 | // The constants for the code patching are based on no push instructions |
| 3106 | // at the call site. |
| 3107 | ASSERT(HasArgsInRegisters()); |
| 3108 | // Get return address and delta to inlined map check. |
| 3109 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3110 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3111 | if (FLAG_debug_code) { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3112 | __ cmpb(Operand(scratch, 0), kCmpEdiOperandByte1); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3113 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp1); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3114 | __ cmpb(Operand(scratch, 1), kCmpEdiOperandByte2); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3115 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheCmp2); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3116 | } |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3117 | __ mov(scratch, Operand(scratch, kDeltaToCmpImmediate)); |
| 3118 | __ mov(Operand(scratch, 0), map); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3119 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3120 | |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3121 | // Loop through the prototype chain of the object looking for the function |
| 3122 | // prototype. |
| 3123 | __ mov(scratch, FieldOperand(map, Map::kPrototypeOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3124 | Label loop, is_instance, is_not_instance; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3125 | __ bind(&loop); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3126 | __ cmp(scratch, prototype); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3127 | __ j(equal, &is_instance, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3128 | Factory* factory = masm->isolate()->factory(); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3129 | __ cmp(scratch, Immediate(factory->null_value())); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3130 | __ j(equal, &is_not_instance, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3131 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
| 3132 | __ mov(scratch, FieldOperand(scratch, Map::kPrototypeOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3133 | __ jmp(&loop); |
| 3134 | |
| 3135 | __ bind(&is_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3136 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3137 | __ mov(eax, Immediate(0)); |
| 3138 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3139 | } else { |
| 3140 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3141 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3142 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3143 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3144 | if (FLAG_debug_code) { |
| 3145 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3146 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3147 | } |
| 3148 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 3149 | if (!ReturnTrueFalseObject()) { |
| 3150 | __ Set(eax, Immediate(0)); |
| 3151 | } |
| 3152 | } |
| 3153 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3154 | |
| 3155 | __ bind(&is_not_instance); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3156 | if (!HasCallSiteInlineCheck()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3157 | __ mov(eax, Immediate(Smi::FromInt(1))); |
| 3158 | __ StoreRoot(eax, scratch, Heap::kInstanceofCacheAnswerRootIndex); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3159 | } else { |
| 3160 | // Get return address and delta to inlined map check. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3161 | __ mov(eax, factory->false_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3162 | __ mov(scratch, Operand(esp, 0 * kPointerSize)); |
| 3163 | __ sub(scratch, Operand(esp, 1 * kPointerSize)); |
| 3164 | if (FLAG_debug_code) { |
| 3165 | __ cmpb(Operand(scratch, kDeltaToMov), kMovEaxImmediateByte); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3166 | __ Assert(equal, kInstanceofStubUnexpectedCallSiteCacheMov); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3167 | } |
| 3168 | __ mov(Operand(scratch, kDeltaToMovImmediate), eax); |
| 3169 | if (!ReturnTrueFalseObject()) { |
| 3170 | __ Set(eax, Immediate(Smi::FromInt(1))); |
| 3171 | } |
| 3172 | } |
| 3173 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3174 | |
| 3175 | Label object_not_null, object_not_null_or_smi; |
| 3176 | __ bind(¬_js_object); |
| 3177 | // Before null, smi and string value checks, check that the rhs is a function |
| 3178 | // 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] | 3179 | __ JumpIfSmi(function, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3180 | __ CmpObjectType(function, JS_FUNCTION_TYPE, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3181 | __ j(not_equal, &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3182 | |
| 3183 | // Null is not instance of anything. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3184 | __ cmp(object, factory->null_value()); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3185 | __ j(not_equal, &object_not_null, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3186 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3187 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3188 | |
| 3189 | __ bind(&object_not_null); |
| 3190 | // Smi values is not instance of anything. |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3191 | __ JumpIfNotSmi(object, &object_not_null_or_smi, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3192 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3193 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3194 | |
| 3195 | __ bind(&object_not_null_or_smi); |
| 3196 | // String values is not instance of anything. |
| 3197 | Condition is_string = masm->IsObjectStringType(object, scratch, scratch); |
ricow@chromium.org | 4668a2c | 2011-08-29 10:41:00 +0000 | [diff] [blame] | 3198 | __ j(NegateCondition(is_string), &slow, Label::kNear); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3199 | __ Set(eax, Immediate(Smi::FromInt(1))); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3200 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3201 | |
| 3202 | // Slow-case: Go through the JavaScript implementation. |
| 3203 | __ bind(&slow); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3204 | if (!ReturnTrueFalseObject()) { |
| 3205 | // Tail call the builtin which returns 0 or 1. |
| 3206 | if (HasArgsInRegisters()) { |
| 3207 | // Push arguments below return address. |
| 3208 | __ pop(scratch); |
| 3209 | __ push(object); |
| 3210 | __ push(function); |
| 3211 | __ push(scratch); |
| 3212 | } |
| 3213 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
| 3214 | } else { |
| 3215 | // Call the builtin and convert 0/1 to true/false. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3216 | { |
| 3217 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 3218 | __ push(object); |
| 3219 | __ push(function); |
| 3220 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
| 3221 | } |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3222 | Label true_value, done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3223 | __ test(eax, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3224 | __ j(zero, &true_value, Label::kNear); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3225 | __ mov(eax, factory->false_value()); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3226 | __ jmp(&done, Label::kNear); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3227 | __ bind(&true_value); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3228 | __ mov(eax, factory->true_value()); |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3229 | __ bind(&done); |
| 3230 | __ ret((HasArgsInRegisters() ? 0 : 2) * kPointerSize); |
ager@chromium.org | 5f0c45f | 2010-12-17 08:51:21 +0000 | [diff] [blame] | 3231 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | |
kmillikin@chromium.org | d2c22f0 | 2011-01-10 08:15:37 +0000 | [diff] [blame] | 3235 | Register InstanceofStub::left() { return eax; } |
| 3236 | |
| 3237 | |
| 3238 | Register InstanceofStub::right() { return edx; } |
| 3239 | |
| 3240 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3241 | // ------------------------------------------------------------------------- |
| 3242 | // StringCharCodeAtGenerator |
| 3243 | |
| 3244 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3245 | // If the receiver is a smi trigger the non-string case. |
| 3246 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3247 | __ JumpIfSmi(object_, receiver_not_string_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3248 | |
| 3249 | // Fetch the instance type of the receiver into result register. |
| 3250 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 3251 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 3252 | // If the receiver is not a string trigger the non-string case. |
| 3253 | __ test(result_, Immediate(kIsNotStringMask)); |
| 3254 | __ j(not_zero, receiver_not_string_); |
| 3255 | |
| 3256 | // If the index is non-smi trigger the non-smi case. |
| 3257 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3258 | __ JumpIfNotSmi(index_, &index_not_smi_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3259 | __ bind(&got_smi_index_); |
| 3260 | |
| 3261 | // Check for index out of range. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3262 | __ cmp(index_, FieldOperand(object_, String::kLengthOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3263 | __ j(above_equal, index_out_of_range_); |
| 3264 | |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3265 | __ SmiUntag(index_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3266 | |
| 3267 | Factory* factory = masm->isolate()->factory(); |
| 3268 | StringCharLoadGenerator::Generate( |
| 3269 | masm, factory, object_, index_, result_, &call_runtime_); |
| 3270 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3271 | __ SmiTag(result_); |
| 3272 | __ bind(&exit_); |
| 3273 | } |
| 3274 | |
| 3275 | |
| 3276 | void StringCharCodeAtGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3277 | MacroAssembler* masm, |
| 3278 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3279 | __ Abort(kUnexpectedFallthroughToCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3280 | |
| 3281 | // Index is not a smi. |
| 3282 | __ bind(&index_not_smi_); |
| 3283 | // 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] | 3284 | __ CheckMap(index_, |
| 3285 | masm->isolate()->factory()->heap_number_map(), |
| 3286 | index_not_number_, |
kmillikin@chromium.org | c53e10d | 2011-05-18 09:12:58 +0000 | [diff] [blame] | 3287 | DONT_DO_SMI_CHECK); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3288 | call_helper.BeforeCall(masm); |
| 3289 | __ push(object_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3290 | __ push(index_); // Consumed by runtime conversion function. |
| 3291 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 3292 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 3293 | } else { |
| 3294 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 3295 | // NumberToSmi discards numbers that are not exact integers. |
| 3296 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 3297 | } |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3298 | if (!index_.is(eax)) { |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3299 | // Save the conversion result before the pop instructions below |
| 3300 | // have a chance to overwrite it. |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3301 | __ mov(index_, eax); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3302 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3303 | __ pop(object_); |
| 3304 | // Reload the instance type. |
| 3305 | __ mov(result_, FieldOperand(object_, HeapObject::kMapOffset)); |
| 3306 | __ movzx_b(result_, FieldOperand(result_, Map::kInstanceTypeOffset)); |
| 3307 | call_helper.AfterCall(masm); |
| 3308 | // If index is still not a smi, it must be out of range. |
| 3309 | STATIC_ASSERT(kSmiTag == 0); |
danno@chromium.org | c612e02 | 2011-11-10 11:38:15 +0000 | [diff] [blame] | 3310 | __ JumpIfNotSmi(index_, index_out_of_range_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3311 | // Otherwise, return to the fast path. |
| 3312 | __ jmp(&got_smi_index_); |
| 3313 | |
| 3314 | // Call runtime. We get here when the receiver is a string and the |
| 3315 | // index is a number, but the code of getting the actual character |
| 3316 | // is too complex (e.g., when the string needs to be flattened). |
| 3317 | __ bind(&call_runtime_); |
| 3318 | call_helper.BeforeCall(masm); |
| 3319 | __ push(object_); |
erikcorry | 0ad885c | 2011-11-21 13:51:57 +0000 | [diff] [blame] | 3320 | __ SmiTag(index_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3321 | __ push(index_); |
| 3322 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 3323 | if (!result_.is(eax)) { |
| 3324 | __ mov(result_, eax); |
| 3325 | } |
| 3326 | call_helper.AfterCall(masm); |
| 3327 | __ jmp(&exit_); |
| 3328 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3329 | __ Abort(kUnexpectedFallthroughFromCharCodeAtSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | |
| 3333 | // ------------------------------------------------------------------------- |
| 3334 | // StringCharFromCodeGenerator |
| 3335 | |
| 3336 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 3337 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 3338 | STATIC_ASSERT(kSmiTag == 0); |
| 3339 | STATIC_ASSERT(kSmiShiftSize == 0); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3340 | ASSERT(IsPowerOf2(String::kMaxOneByteCharCode + 1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3341 | __ test(code_, |
| 3342 | Immediate(kSmiTagMask | |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 3343 | ((~String::kMaxOneByteCharCode) << kSmiTagSize))); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3344 | __ j(not_zero, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3345 | |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3346 | Factory* factory = masm->isolate()->factory(); |
| 3347 | __ Set(result_, Immediate(factory->single_character_string_cache())); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3348 | STATIC_ASSERT(kSmiTag == 0); |
| 3349 | STATIC_ASSERT(kSmiTagSize == 1); |
| 3350 | STATIC_ASSERT(kSmiShiftSize == 0); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3351 | // At this point code register contains smi tagged ASCII char code. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3352 | __ mov(result_, FieldOperand(result_, |
| 3353 | code_, times_half_pointer_size, |
| 3354 | FixedArray::kHeaderSize)); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3355 | __ cmp(result_, factory->undefined_value()); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 3356 | __ j(equal, &slow_case_); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3357 | __ bind(&exit_); |
| 3358 | } |
| 3359 | |
| 3360 | |
| 3361 | void StringCharFromCodeGenerator::GenerateSlow( |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 3362 | MacroAssembler* masm, |
| 3363 | const RuntimeCallHelper& call_helper) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3364 | __ Abort(kUnexpectedFallthroughToCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3365 | |
| 3366 | __ bind(&slow_case_); |
| 3367 | call_helper.BeforeCall(masm); |
| 3368 | __ push(code_); |
| 3369 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 3370 | if (!result_.is(eax)) { |
| 3371 | __ mov(result_, eax); |
| 3372 | } |
| 3373 | call_helper.AfterCall(masm); |
| 3374 | __ jmp(&exit_); |
| 3375 | |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3376 | __ Abort(kUnexpectedFallthroughFromCharFromCodeSlowCase); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
| 3379 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3380 | void StringAddStub::Generate(MacroAssembler* masm) { |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3381 | Label call_runtime, call_builtin; |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3382 | Builtins::JavaScript builtin_id = Builtins::ADD; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3383 | |
| 3384 | // Load the two arguments. |
| 3385 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 3386 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 3387 | |
| 3388 | // 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] | 3389 | // Otherwise, at least one of the arguments is definitely a string, |
| 3390 | // and we convert the one that is not known to be a string. |
| 3391 | if ((flags_ & STRING_ADD_CHECK_BOTH) == STRING_ADD_CHECK_BOTH) { |
| 3392 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT); |
| 3393 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3394 | __ JumpIfSmi(eax, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3395 | __ CmpObjectType(eax, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3396 | __ j(above_equal, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3397 | |
| 3398 | // First argument is a a string, test second. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3399 | __ JumpIfSmi(edx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3400 | __ CmpObjectType(edx, FIRST_NONSTRING_TYPE, ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3401 | __ j(above_equal, &call_runtime); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 3402 | } else if ((flags_ & STRING_ADD_CHECK_LEFT) == STRING_ADD_CHECK_LEFT) { |
| 3403 | ASSERT((flags_ & STRING_ADD_CHECK_RIGHT) == 0); |
| 3404 | GenerateConvertArgument(masm, 2 * kPointerSize, eax, ebx, ecx, edi, |
| 3405 | &call_builtin); |
| 3406 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 3407 | } else if ((flags_ & STRING_ADD_CHECK_RIGHT) == STRING_ADD_CHECK_RIGHT) { |
| 3408 | ASSERT((flags_ & STRING_ADD_CHECK_LEFT) == 0); |
| 3409 | GenerateConvertArgument(masm, 1 * kPointerSize, edx, ebx, ecx, edi, |
| 3410 | &call_builtin); |
| 3411 | builtin_id = Builtins::STRING_ADD_LEFT; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | // Both arguments are strings. |
| 3415 | // eax: first string |
| 3416 | // edx: second string |
| 3417 | // 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] | 3418 | Label second_not_zero_length, both_not_zero_length; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3419 | __ mov(ecx, FieldOperand(edx, String::kLengthOffset)); |
| 3420 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3421 | __ test(ecx, ecx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3422 | __ j(not_zero, &second_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3423 | // 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] | 3424 | Counters* counters = masm->isolate()->counters(); |
| 3425 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3426 | __ ret(2 * kPointerSize); |
| 3427 | __ bind(&second_not_zero_length); |
| 3428 | __ mov(ebx, FieldOperand(eax, String::kLengthOffset)); |
| 3429 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3430 | __ test(ebx, ebx); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3431 | __ j(not_zero, &both_not_zero_length, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3432 | // First string is empty, result is second string which is in edx. |
| 3433 | __ mov(eax, edx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3434 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3435 | __ ret(2 * kPointerSize); |
| 3436 | |
| 3437 | // Both strings are non-empty. |
| 3438 | // eax: first string |
| 3439 | // ebx: length of first string as a smi |
| 3440 | // ecx: length of second string as a smi |
| 3441 | // edx: second string |
| 3442 | // Look at the length of the result of adding the two strings. |
| 3443 | Label string_add_flat_result, longer_than_two; |
| 3444 | __ bind(&both_not_zero_length); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3445 | __ add(ebx, ecx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3446 | STATIC_ASSERT(Smi::kMaxValue == String::kMaxLength); |
| 3447 | // Handle exceptionally long strings in the runtime system. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3448 | __ j(overflow, &call_runtime); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3449 | // Use the string table when adding two one character strings, as it |
| 3450 | // helps later optimizations to return an internalized string here. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3451 | __ cmp(ebx, Immediate(Smi::FromInt(2))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3452 | __ j(not_equal, &longer_than_two); |
| 3453 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3454 | // Check that both strings are non-external ASCII strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3455 | __ JumpIfNotBothSequentialAsciiStrings(eax, edx, ebx, ecx, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3456 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3457 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3458 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 3459 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3460 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3461 | // 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] | 3462 | // just allocate a new one. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3463 | Label make_two_character_string, make_two_character_string_no_reload; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3464 | StringHelper::GenerateTwoCharacterStringTableProbe( |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3465 | masm, ebx, ecx, eax, edx, edi, |
| 3466 | &make_two_character_string_no_reload, &make_two_character_string); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3467 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3468 | __ ret(2 * kPointerSize); |
| 3469 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3470 | // Allocate a two character string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3471 | __ bind(&make_two_character_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3472 | // Reload the arguments. |
| 3473 | __ mov(eax, Operand(esp, 2 * kPointerSize)); // First argument. |
| 3474 | __ mov(edx, Operand(esp, 1 * kPointerSize)); // Second argument. |
| 3475 | // Get the two characters forming the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3476 | __ movzx_b(ebx, FieldOperand(eax, SeqOneByteString::kHeaderSize)); |
| 3477 | __ movzx_b(ecx, FieldOperand(edx, SeqOneByteString::kHeaderSize)); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3478 | __ bind(&make_two_character_string_no_reload); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3479 | __ IncrementCounter(counters->string_add_make_two_char(), 1); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3480 | __ AllocateAsciiString(eax, 2, edi, edx, &call_runtime); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3481 | // Pack both characters in ebx. |
| 3482 | __ shl(ecx, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3483 | __ or_(ebx, ecx); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3484 | // Set the characters in the new string. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3485 | __ mov_w(FieldOperand(eax, SeqOneByteString::kHeaderSize), ebx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3486 | __ IncrementCounter(counters->string_add_native(), 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3487 | __ ret(2 * kPointerSize); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3488 | |
| 3489 | __ bind(&longer_than_two); |
| 3490 | // Check if resulting string will be flat. |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3491 | __ cmp(ebx, Immediate(Smi::FromInt(ConsString::kMinLength))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3492 | __ j(below, &string_add_flat_result); |
| 3493 | |
| 3494 | // 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] | 3495 | // strings are ASCII the result is an ASCII cons string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3496 | Label non_ascii, allocated, ascii_data; |
| 3497 | __ mov(edi, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3498 | __ movzx_b(ecx, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 3499 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 3500 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3501 | __ and_(ecx, edi); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 3502 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 3503 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 3504 | __ test(ecx, Immediate(kStringEncodingMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3505 | __ j(zero, &non_ascii); |
| 3506 | __ bind(&ascii_data); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3507 | // Allocate an ASCII cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3508 | __ AllocateAsciiConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3509 | __ bind(&allocated); |
| 3510 | // Fill the fields of the cons string. |
svenpanne@chromium.org | c859c4f | 2012-10-15 11:51:39 +0000 | [diff] [blame] | 3511 | __ AssertSmi(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3512 | __ mov(FieldOperand(ecx, ConsString::kLengthOffset), ebx); |
| 3513 | __ mov(FieldOperand(ecx, ConsString::kHashFieldOffset), |
| 3514 | Immediate(String::kEmptyHashField)); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3515 | |
| 3516 | Label skip_write_barrier, after_writing; |
| 3517 | ExternalReference high_promotion_mode = ExternalReference:: |
| 3518 | new_space_high_promotion_mode_active_address(masm->isolate()); |
| 3519 | __ test(Operand::StaticVariable(high_promotion_mode), Immediate(1)); |
| 3520 | __ j(zero, &skip_write_barrier); |
| 3521 | |
| 3522 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 3523 | __ RecordWriteField(ecx, |
| 3524 | ConsString::kFirstOffset, |
| 3525 | eax, |
| 3526 | ebx, |
| 3527 | kDontSaveFPRegs); |
| 3528 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
| 3529 | __ RecordWriteField(ecx, |
| 3530 | ConsString::kSecondOffset, |
| 3531 | edx, |
| 3532 | ebx, |
| 3533 | kDontSaveFPRegs); |
| 3534 | __ jmp(&after_writing); |
| 3535 | |
| 3536 | __ bind(&skip_write_barrier); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3537 | __ mov(FieldOperand(ecx, ConsString::kFirstOffset), eax); |
| 3538 | __ mov(FieldOperand(ecx, ConsString::kSecondOffset), edx); |
ulan@chromium.org | 57ff881 | 2013-05-10 08:16:55 +0000 | [diff] [blame] | 3539 | |
| 3540 | __ bind(&after_writing); |
| 3541 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3542 | __ mov(eax, ecx); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3543 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3544 | __ ret(2 * kPointerSize); |
| 3545 | __ bind(&non_ascii); |
| 3546 | // 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] | 3547 | // to contain only one byte characters. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3548 | // ecx: first instance type AND second instance type. |
| 3549 | // edi: second instance type. |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3550 | __ test(ecx, Immediate(kOneByteDataHintMask)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3551 | __ j(not_zero, &ascii_data); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3552 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3553 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
| 3554 | __ xor_(edi, ecx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 3555 | STATIC_ASSERT(kOneByteStringTag != 0 && kOneByteDataHintTag != 0); |
| 3556 | __ and_(edi, kOneByteStringTag | kOneByteDataHintTag); |
| 3557 | __ cmp(edi, kOneByteStringTag | kOneByteDataHintTag); |
yangguo@chromium.org | 46a2a51 | 2013-01-18 16:29:40 +0000 | [diff] [blame] | 3558 | __ j(equal, &ascii_data); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3559 | // Allocate a two byte cons string. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3560 | __ AllocateTwoByteConsString(ecx, edi, no_reg, &call_runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3561 | __ jmp(&allocated); |
| 3562 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3563 | // We cannot encounter sliced strings or cons strings here since: |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3564 | STATIC_ASSERT(SlicedString::kMinLength >= ConsString::kMinLength); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3565 | // Handle creating a flat result from either external or sequential strings. |
| 3566 | // Locate the first characters' locations. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3567 | // eax: first string |
| 3568 | // ebx: length of resulting flat string as a smi |
| 3569 | // edx: second string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3570 | Label first_prepared, second_prepared; |
| 3571 | Label first_is_sequential, second_is_sequential; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3572 | __ bind(&string_add_flat_result); |
| 3573 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 3574 | __ movzx_b(ecx, FieldOperand(ecx, Map::kInstanceTypeOffset)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3575 | // ecx: instance type of first string |
| 3576 | STATIC_ASSERT(kSeqStringTag == 0); |
| 3577 | __ test_b(ecx, kStringRepresentationMask); |
| 3578 | __ j(zero, &first_is_sequential, Label::kNear); |
| 3579 | // Rule out short external string and load string resource. |
| 3580 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 3581 | __ test_b(ecx, kShortExternalStringMask); |
| 3582 | __ j(not_zero, &call_runtime); |
| 3583 | __ mov(eax, FieldOperand(eax, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3584 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3585 | __ jmp(&first_prepared, Label::kNear); |
| 3586 | __ bind(&first_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3587 | __ add(eax, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3588 | __ bind(&first_prepared); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3589 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3590 | __ mov(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 3591 | __ movzx_b(edi, FieldOperand(edi, Map::kInstanceTypeOffset)); |
| 3592 | // Check whether both strings have same encoding. |
| 3593 | // edi: instance type of second string |
| 3594 | __ xor_(ecx, edi); |
| 3595 | __ test_b(ecx, kStringEncodingMask); |
| 3596 | __ j(not_zero, &call_runtime); |
| 3597 | STATIC_ASSERT(kSeqStringTag == 0); |
| 3598 | __ test_b(edi, kStringRepresentationMask); |
| 3599 | __ j(zero, &second_is_sequential, Label::kNear); |
| 3600 | // Rule out short external string and load string resource. |
| 3601 | STATIC_ASSERT(kShortExternalStringTag != 0); |
| 3602 | __ test_b(edi, kShortExternalStringMask); |
| 3603 | __ j(not_zero, &call_runtime); |
| 3604 | __ mov(edx, FieldOperand(edx, ExternalString::kResourceDataOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3605 | STATIC_ASSERT(SeqOneByteString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3606 | __ jmp(&second_prepared, Label::kNear); |
| 3607 | __ bind(&second_is_sequential); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3608 | __ add(edx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3609 | __ bind(&second_prepared); |
| 3610 | |
| 3611 | // Push the addresses of both strings' first characters onto the stack. |
| 3612 | __ push(edx); |
| 3613 | __ push(eax); |
| 3614 | |
| 3615 | Label non_ascii_string_add_flat_result, call_runtime_drop_two; |
| 3616 | // edi: instance type of second string |
| 3617 | // First string and second string have the same encoding. |
| 3618 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 3619 | __ test_b(edi, kStringEncodingMask); |
| 3620 | __ j(zero, &non_ascii_string_add_flat_result); |
| 3621 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3622 | // Both strings are ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3623 | // ebx: length of resulting flat string as a smi |
| 3624 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3625 | __ AllocateAsciiString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3626 | // eax: result string |
| 3627 | __ mov(ecx, eax); |
| 3628 | // Locate first character of result. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3629 | __ add(ecx, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3630 | // Load first argument's length and first character location. Account for |
| 3631 | // values currently on the stack when fetching arguments from it. |
| 3632 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3633 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 3634 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3635 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3636 | // eax: result string |
| 3637 | // ecx: first character of result |
| 3638 | // edx: first char of first argument |
| 3639 | // edi: length of first argument |
| 3640 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3641 | // Load second argument's length and first character location. Account for |
| 3642 | // values currently on the stack when fetching arguments from it. |
| 3643 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3644 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 3645 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3646 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3647 | // eax: result string |
| 3648 | // ecx: next character of result |
| 3649 | // edx: first char of second argument |
| 3650 | // edi: length of second argument |
| 3651 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, true); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3652 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3653 | __ ret(2 * kPointerSize); |
| 3654 | |
| 3655 | // Handle creating a flat two byte result. |
| 3656 | // eax: first string - known to be two byte |
| 3657 | // ebx: length of resulting flat string as a smi |
| 3658 | // edx: second string |
| 3659 | __ bind(&non_ascii_string_add_flat_result); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3660 | // Both strings are two byte strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3661 | __ SmiUntag(ebx); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3662 | __ AllocateTwoByteString(eax, ebx, ecx, edx, edi, &call_runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3663 | // eax: result string |
| 3664 | __ mov(ecx, eax); |
| 3665 | // Locate first character of result. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3666 | __ add(ecx, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 3667 | // Load second argument's length and first character location. Account for |
| 3668 | // values currently on the stack when fetching arguments from it. |
| 3669 | __ mov(edx, Operand(esp, 4 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3670 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 3671 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3672 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3673 | // eax: result string |
| 3674 | // ecx: first character of result |
| 3675 | // edx: first char of first argument |
| 3676 | // edi: length of first argument |
| 3677 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3678 | // Load second argument's length and first character location. Account for |
| 3679 | // values currently on the stack when fetching arguments from it. |
| 3680 | __ mov(edx, Operand(esp, 2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3681 | __ mov(edi, FieldOperand(edx, String::kLengthOffset)); |
| 3682 | __ SmiUntag(edi); |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3683 | __ pop(edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3684 | // eax: result string |
| 3685 | // ecx: next character of result |
| 3686 | // edx: first char of second argument |
| 3687 | // edi: length of second argument |
| 3688 | StringHelper::GenerateCopyCharacters(masm, ecx, edx, edi, ebx, false); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 3689 | __ IncrementCounter(counters->string_add_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3690 | __ ret(2 * kPointerSize); |
| 3691 | |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3692 | // Recover stack pointer before jumping to runtime. |
| 3693 | __ bind(&call_runtime_drop_two); |
| 3694 | __ Drop(2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3695 | // Just jump to runtime to add the two strings. |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 3696 | __ bind(&call_runtime); |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 3697 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3698 | |
| 3699 | if (call_builtin.is_linked()) { |
| 3700 | __ bind(&call_builtin); |
bmeurer@chromium.org | e94b5ff | 2013-10-25 09:22:31 +0000 | [diff] [blame] | 3701 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3702 | } |
| 3703 | } |
| 3704 | |
| 3705 | |
jkummerow@chromium.org | 4e308cf | 2013-05-17 13:39:16 +0000 | [diff] [blame] | 3706 | void StringAddStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
| 3707 | __ push(eax); |
| 3708 | __ push(edx); |
| 3709 | } |
| 3710 | |
| 3711 | |
| 3712 | void StringAddStub::GenerateRegisterArgsPop(MacroAssembler* masm, |
| 3713 | Register temp) { |
| 3714 | __ pop(temp); |
| 3715 | __ pop(edx); |
| 3716 | __ pop(eax); |
| 3717 | __ push(temp); |
| 3718 | } |
| 3719 | |
| 3720 | |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3721 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 3722 | int stack_offset, |
| 3723 | Register arg, |
| 3724 | Register scratch1, |
| 3725 | Register scratch2, |
| 3726 | Register scratch3, |
| 3727 | Label* slow) { |
| 3728 | // First check if the argument is already a string. |
| 3729 | Label not_string, done; |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 3730 | __ JumpIfSmi(arg, ¬_string); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3731 | __ CmpObjectType(arg, FIRST_NONSTRING_TYPE, scratch1); |
| 3732 | __ j(below, &done); |
| 3733 | |
| 3734 | // Check the number to string cache. |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3735 | __ bind(¬_string); |
| 3736 | // Puts the cached result into scratch1. |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 3737 | __ LookupNumberStringCache(arg, scratch1, scratch2, scratch3, slow); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3738 | __ mov(arg, scratch1); |
| 3739 | __ mov(Operand(esp, stack_offset), arg); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3740 | __ bind(&done); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3741 | } |
| 3742 | |
| 3743 | |
| 3744 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 3745 | Register dest, |
| 3746 | Register src, |
| 3747 | Register count, |
| 3748 | Register scratch, |
| 3749 | bool ascii) { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3750 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3751 | __ bind(&loop); |
| 3752 | // This loop just copies one character at a time, as it is only used for very |
| 3753 | // short strings. |
| 3754 | if (ascii) { |
| 3755 | __ mov_b(scratch, Operand(src, 0)); |
| 3756 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3757 | __ add(src, Immediate(1)); |
| 3758 | __ add(dest, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3759 | } else { |
| 3760 | __ mov_w(scratch, Operand(src, 0)); |
| 3761 | __ mov_w(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3762 | __ add(src, Immediate(2)); |
| 3763 | __ add(dest, Immediate(2)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3764 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3765 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3766 | __ j(not_zero, &loop); |
| 3767 | } |
| 3768 | |
| 3769 | |
| 3770 | void StringHelper::GenerateCopyCharactersREP(MacroAssembler* masm, |
| 3771 | Register dest, |
| 3772 | Register src, |
| 3773 | Register count, |
| 3774 | Register scratch, |
| 3775 | bool ascii) { |
| 3776 | // Copy characters using rep movs of doublewords. |
| 3777 | // The destination is aligned on a 4 byte boundary because we are |
| 3778 | // copying to the beginning of a newly allocated string. |
| 3779 | ASSERT(dest.is(edi)); // rep movs destination |
| 3780 | ASSERT(src.is(esi)); // rep movs source |
| 3781 | ASSERT(count.is(ecx)); // rep movs count |
| 3782 | ASSERT(!scratch.is(dest)); |
| 3783 | ASSERT(!scratch.is(src)); |
| 3784 | ASSERT(!scratch.is(count)); |
| 3785 | |
| 3786 | // Nothing to do for zero characters. |
| 3787 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3788 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3789 | __ j(zero, &done); |
| 3790 | |
| 3791 | // Make count the number of bytes to copy. |
| 3792 | if (!ascii) { |
| 3793 | __ shl(count, 1); |
| 3794 | } |
| 3795 | |
| 3796 | // 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] | 3797 | Label last_bytes; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3798 | __ test(count, Immediate(~3)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3799 | __ j(zero, &last_bytes, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3800 | |
| 3801 | // Copy from edi to esi using rep movs instruction. |
| 3802 | __ mov(scratch, count); |
| 3803 | __ sar(count, 2); // Number of doublewords to copy. |
| 3804 | __ cld(); |
| 3805 | __ rep_movs(); |
| 3806 | |
| 3807 | // Find number of bytes left. |
| 3808 | __ mov(count, scratch); |
| 3809 | __ and_(count, 3); |
| 3810 | |
| 3811 | // Check if there are more bytes to copy. |
| 3812 | __ bind(&last_bytes); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3813 | __ test(count, count); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3814 | __ j(zero, &done); |
| 3815 | |
| 3816 | // Copy remaining characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3817 | Label loop; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3818 | __ bind(&loop); |
| 3819 | __ mov_b(scratch, Operand(src, 0)); |
| 3820 | __ mov_b(Operand(dest, 0), scratch); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3821 | __ add(src, Immediate(1)); |
| 3822 | __ add(dest, Immediate(1)); |
| 3823 | __ sub(count, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3824 | __ j(not_zero, &loop); |
| 3825 | |
| 3826 | __ bind(&done); |
| 3827 | } |
| 3828 | |
| 3829 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3830 | void StringHelper::GenerateTwoCharacterStringTableProbe(MacroAssembler* masm, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3831 | Register c1, |
| 3832 | Register c2, |
| 3833 | Register scratch1, |
| 3834 | Register scratch2, |
| 3835 | Register scratch3, |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3836 | Label* not_probed, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3837 | Label* not_found) { |
| 3838 | // Register scratch3 is the general scratch register in this function. |
| 3839 | Register scratch = scratch3; |
| 3840 | |
| 3841 | // 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] | 3842 | // 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] | 3843 | Label not_array_index; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3844 | __ mov(scratch, c1); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3845 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 3846 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 3847 | __ j(above, ¬_array_index, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3848 | __ mov(scratch, c2); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3849 | __ sub(scratch, Immediate(static_cast<int>('0'))); |
| 3850 | __ cmp(scratch, Immediate(static_cast<int>('9' - '0'))); |
kmillikin@chromium.org | 3cdd9e1 | 2010-09-06 11:39:48 +0000 | [diff] [blame] | 3851 | __ j(below_equal, not_probed); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3852 | |
| 3853 | __ bind(¬_array_index); |
| 3854 | // Calculate the two character string hash. |
| 3855 | Register hash = scratch1; |
| 3856 | GenerateHashInit(masm, hash, c1, scratch); |
| 3857 | GenerateHashAddCharacter(masm, hash, c2, scratch); |
| 3858 | GenerateHashGetHash(masm, hash, scratch); |
| 3859 | |
| 3860 | // Collect the two characters in a register. |
| 3861 | Register chars = c1; |
| 3862 | __ shl(c2, kBitsPerByte); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3863 | __ or_(chars, c2); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3864 | |
| 3865 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 3866 | // hash: hash of two character string. |
| 3867 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3868 | // Load the string table. |
| 3869 | Register string_table = c2; |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3870 | __ LoadRoot(string_table, Heap::kStringTableRootIndex); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3871 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3872 | // Calculate capacity mask from the string table capacity. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3873 | Register mask = scratch2; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3874 | __ mov(mask, FieldOperand(string_table, StringTable::kCapacityOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3875 | __ SmiUntag(mask); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3876 | __ sub(mask, Immediate(1)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3877 | |
| 3878 | // Registers |
| 3879 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 3880 | // hash: hash of two character string |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3881 | // string_table: string table |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3882 | // mask: capacity mask |
| 3883 | // scratch: - |
| 3884 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3885 | // Perform a number of probes in the string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3886 | static const int kProbes = 4; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3887 | Label found_in_string_table; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3888 | Label next_probe[kProbes], next_probe_pop_mask[kProbes]; |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3889 | Register candidate = scratch; // Scratch register contains candidate. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3890 | for (int i = 0; i < kProbes; i++) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3891 | // Calculate entry in string table. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3892 | __ mov(scratch, hash); |
| 3893 | if (i > 0) { |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3894 | __ add(scratch, Immediate(StringTable::GetProbeOffset(i))); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3895 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3896 | __ and_(scratch, mask); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3897 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3898 | // Load the entry from the string table. |
| 3899 | STATIC_ASSERT(StringTable::kEntrySize == 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3900 | __ mov(candidate, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3901 | FieldOperand(string_table, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3902 | scratch, |
| 3903 | times_pointer_size, |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3904 | StringTable::kElementsStartOffset)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3905 | |
| 3906 | // 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] | 3907 | Factory* factory = masm->isolate()->factory(); |
| 3908 | __ cmp(candidate, factory->undefined_value()); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3909 | __ j(equal, not_found); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3910 | __ cmp(candidate, factory->the_hole_value()); |
ricow@chromium.org | badaffc | 2011-03-17 12:15:27 +0000 | [diff] [blame] | 3911 | __ j(equal, &next_probe[i]); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3912 | |
| 3913 | // If length is not 2 the string is not a candidate. |
| 3914 | __ cmp(FieldOperand(candidate, String::kLengthOffset), |
| 3915 | Immediate(Smi::FromInt(2))); |
| 3916 | __ j(not_equal, &next_probe[i]); |
| 3917 | |
| 3918 | // As we are out of registers save the mask on the stack and use that |
| 3919 | // register as a temporary. |
| 3920 | __ push(mask); |
| 3921 | Register temp = mask; |
| 3922 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3923 | // Check that the candidate is a non-external ASCII string. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3924 | __ mov(temp, FieldOperand(candidate, HeapObject::kMapOffset)); |
| 3925 | __ movzx_b(temp, FieldOperand(temp, Map::kInstanceTypeOffset)); |
| 3926 | __ JumpIfInstanceTypeIsNotSequentialAscii( |
| 3927 | temp, temp, &next_probe_pop_mask[i]); |
| 3928 | |
| 3929 | // Check if the two characters match. |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 3930 | __ mov(temp, FieldOperand(candidate, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3931 | __ and_(temp, 0x0000ffff); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3932 | __ cmp(chars, temp); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3933 | __ j(equal, &found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3934 | __ bind(&next_probe_pop_mask[i]); |
| 3935 | __ pop(mask); |
| 3936 | __ bind(&next_probe[i]); |
| 3937 | } |
| 3938 | |
| 3939 | // No matching 2 character string found by probing. |
| 3940 | __ jmp(not_found); |
| 3941 | |
| 3942 | // Scratch register contains result when we fall through to here. |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3943 | Register result = candidate; |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 3944 | __ bind(&found_in_string_table); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3945 | __ pop(mask); // Pop saved mask from the stack. |
| 3946 | if (!result.is(eax)) { |
| 3947 | __ mov(eax, result); |
| 3948 | } |
| 3949 | } |
| 3950 | |
| 3951 | |
| 3952 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 3953 | Register hash, |
| 3954 | Register character, |
| 3955 | Register scratch) { |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3956 | // hash = (seed + character) + ((seed + character) << 10); |
| 3957 | if (Serializer::enabled()) { |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 3958 | __ LoadRoot(scratch, Heap::kHashSeedRootIndex); |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 3959 | __ SmiUntag(scratch); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3960 | __ add(scratch, character); |
| 3961 | __ mov(hash, scratch); |
| 3962 | __ shl(scratch, 10); |
| 3963 | __ add(hash, scratch); |
| 3964 | } else { |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 3965 | int32_t seed = masm->isolate()->heap()->HashSeed(); |
rossberg@chromium.org | fab1498 | 2012-01-05 15:02:15 +0000 | [diff] [blame] | 3966 | __ lea(scratch, Operand(character, seed)); |
| 3967 | __ shl(scratch, 10); |
| 3968 | __ lea(hash, Operand(scratch, character, times_1, seed)); |
| 3969 | } |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3970 | // hash ^= hash >> 6; |
| 3971 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3972 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3973 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | |
| 3977 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 3978 | Register hash, |
| 3979 | Register character, |
| 3980 | Register scratch) { |
| 3981 | // hash += character; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3982 | __ add(hash, character); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3983 | // hash += hash << 10; |
| 3984 | __ mov(scratch, hash); |
| 3985 | __ shl(scratch, 10); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3986 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3987 | // hash ^= hash >> 6; |
| 3988 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 3989 | __ shr(scratch, 6); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 3990 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 3991 | } |
| 3992 | |
| 3993 | |
| 3994 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 3995 | Register hash, |
| 3996 | Register scratch) { |
| 3997 | // hash += hash << 3; |
| 3998 | __ mov(scratch, hash); |
| 3999 | __ shl(scratch, 3); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4000 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4001 | // hash ^= hash >> 11; |
| 4002 | __ mov(scratch, hash); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 4003 | __ shr(scratch, 11); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4004 | __ xor_(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4005 | // hash += hash << 15; |
| 4006 | __ mov(scratch, hash); |
| 4007 | __ shl(scratch, 15); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4008 | __ add(hash, scratch); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4009 | |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4010 | __ and_(hash, String::kHashBitMask); |
danno@chromium.org | 2c45679 | 2011-11-11 12:00:53 +0000 | [diff] [blame] | 4011 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4012 | // if (hash == 0) hash = 27; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4013 | Label hash_not_zero; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4014 | __ j(not_zero, &hash_not_zero, Label::kNear); |
erik.corry@gmail.com | f2038fb | 2012-01-16 11:42:08 +0000 | [diff] [blame] | 4015 | __ mov(hash, Immediate(StringHasher::kZeroHash)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4016 | __ bind(&hash_not_zero); |
| 4017 | } |
| 4018 | |
| 4019 | |
| 4020 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 4021 | Label runtime; |
| 4022 | |
| 4023 | // Stack frame on entry. |
| 4024 | // esp[0]: return address |
| 4025 | // esp[4]: to |
| 4026 | // esp[8]: from |
| 4027 | // esp[12]: string |
| 4028 | |
| 4029 | // Make sure first argument is a string. |
| 4030 | __ mov(eax, Operand(esp, 3 * kPointerSize)); |
| 4031 | STATIC_ASSERT(kSmiTag == 0); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4032 | __ JumpIfSmi(eax, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4033 | Condition is_string = masm->IsObjectStringType(eax, ebx, ebx); |
| 4034 | __ j(NegateCondition(is_string), &runtime); |
| 4035 | |
| 4036 | // eax: string |
| 4037 | // ebx: instance type |
| 4038 | |
| 4039 | // Calculate length of sub string using the smi values. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4040 | __ mov(ecx, Operand(esp, 1 * kPointerSize)); // To index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4041 | __ JumpIfNotSmi(ecx, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4042 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // From index. |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4043 | __ JumpIfNotSmi(edx, &runtime); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4044 | __ sub(ecx, edx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4045 | __ cmp(ecx, FieldOperand(eax, String::kLengthOffset)); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4046 | Label not_original_string; |
erik.corry@gmail.com | ed49e96 | 2012-04-17 11:57:53 +0000 | [diff] [blame] | 4047 | // Shorter than original string's length: an actual substring. |
| 4048 | __ j(below, ¬_original_string, Label::kNear); |
| 4049 | // Longer than original string's length or negative: unsafe arguments. |
| 4050 | __ j(above, &runtime); |
| 4051 | // Return original string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4052 | Counters* counters = masm->isolate()->counters(); |
| 4053 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 4054 | __ ret(3 * kPointerSize); |
| 4055 | __ bind(¬_original_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4056 | |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 4057 | Label single_char; |
| 4058 | __ cmp(ecx, Immediate(Smi::FromInt(1))); |
| 4059 | __ j(equal, &single_char); |
| 4060 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4061 | // eax: string |
| 4062 | // ebx: instance type |
| 4063 | // ecx: sub string length (smi) |
| 4064 | // edx: from index (smi) |
| 4065 | // Deal with different string types: update the index if necessary |
| 4066 | // and put the underlying string into edi. |
| 4067 | Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 4068 | // If the string is not indirect, it can only be sequential or external. |
| 4069 | STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 4070 | STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 4071 | __ test(ebx, Immediate(kIsIndirectStringMask)); |
| 4072 | __ j(zero, &seq_or_external_string, Label::kNear); |
| 4073 | |
| 4074 | Factory* factory = masm->isolate()->factory(); |
| 4075 | __ test(ebx, Immediate(kSlicedNotConsMask)); |
| 4076 | __ j(not_zero, &sliced_string, Label::kNear); |
| 4077 | // Cons string. Check whether it is flat, then fetch first part. |
| 4078 | // Flat cons strings have an empty second part. |
| 4079 | __ cmp(FieldOperand(eax, ConsString::kSecondOffset), |
| 4080 | factory->empty_string()); |
| 4081 | __ j(not_equal, &runtime); |
| 4082 | __ mov(edi, FieldOperand(eax, ConsString::kFirstOffset)); |
| 4083 | // Update instance type. |
| 4084 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 4085 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4086 | __ jmp(&underlying_unpacked, Label::kNear); |
| 4087 | |
| 4088 | __ bind(&sliced_string); |
| 4089 | // Sliced string. Fetch parent and adjust start index by offset. |
| 4090 | __ add(edx, FieldOperand(eax, SlicedString::kOffsetOffset)); |
| 4091 | __ mov(edi, FieldOperand(eax, SlicedString::kParentOffset)); |
| 4092 | // Update instance type. |
| 4093 | __ mov(ebx, FieldOperand(edi, HeapObject::kMapOffset)); |
| 4094 | __ movzx_b(ebx, FieldOperand(ebx, Map::kInstanceTypeOffset)); |
| 4095 | __ jmp(&underlying_unpacked, Label::kNear); |
| 4096 | |
| 4097 | __ bind(&seq_or_external_string); |
| 4098 | // Sequential or external string. Just move string to the expected register. |
| 4099 | __ mov(edi, eax); |
| 4100 | |
| 4101 | __ bind(&underlying_unpacked); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4102 | |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4103 | if (FLAG_string_slices) { |
| 4104 | Label copy_routine; |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4105 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4106 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4107 | // edx: adjusted start index (smi) |
| 4108 | // ecx: length (smi) |
| 4109 | __ cmp(ecx, Immediate(Smi::FromInt(SlicedString::kMinLength))); |
| 4110 | // Short slice. Copy instead of slicing. |
| 4111 | __ j(less, ©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4112 | // Allocate new sliced string. At this point we do not reload the instance |
| 4113 | // type including the string encoding because we simply rely on the info |
| 4114 | // provided by the original string. It does not matter if the original |
| 4115 | // string's encoding is wrong because we always have to recheck encoding of |
| 4116 | // the newly created string's parent anyways due to externalized strings. |
| 4117 | Label two_byte_slice, set_slice_header; |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4118 | STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4119 | STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 4120 | __ test(ebx, Immediate(kStringEncodingMask)); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4121 | __ j(zero, &two_byte_slice, Label::kNear); |
| 4122 | __ AllocateAsciiSlicedString(eax, ebx, no_reg, &runtime); |
| 4123 | __ jmp(&set_slice_header, Label::kNear); |
| 4124 | __ bind(&two_byte_slice); |
fschneider@chromium.org | 1805e21 | 2011-09-05 10:49:12 +0000 | [diff] [blame] | 4125 | __ AllocateTwoByteSlicedString(eax, ebx, no_reg, &runtime); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4126 | __ bind(&set_slice_header); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4127 | __ mov(FieldOperand(eax, SlicedString::kLengthOffset), ecx); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4128 | __ mov(FieldOperand(eax, SlicedString::kHashFieldOffset), |
| 4129 | Immediate(String::kEmptyHashField)); |
erik.corry@gmail.com | bbceb57 | 2012-03-09 10:52:05 +0000 | [diff] [blame] | 4130 | __ mov(FieldOperand(eax, SlicedString::kParentOffset), edi); |
| 4131 | __ mov(FieldOperand(eax, SlicedString::kOffsetOffset), edx); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4132 | __ IncrementCounter(counters->sub_string_native(), 1); |
| 4133 | __ ret(3 * kPointerSize); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4134 | |
| 4135 | __ bind(©_routine); |
yangguo@chromium.org | 80c42ed | 2011-08-31 09:03:56 +0000 | [diff] [blame] | 4136 | } |
| 4137 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4138 | // edi: underlying subject string |
ricow@chromium.org | 7ad6522 | 2011-12-19 12:13:11 +0000 | [diff] [blame] | 4139 | // ebx: instance type of underlying subject string |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4140 | // edx: adjusted start index (smi) |
| 4141 | // ecx: length (smi) |
| 4142 | // The subject string can only be external or sequential string of either |
| 4143 | // encoding at this point. |
| 4144 | Label two_byte_sequential, runtime_drop_two, sequential_string; |
| 4145 | STATIC_ASSERT(kExternalStringTag != 0); |
| 4146 | STATIC_ASSERT(kSeqStringTag == 0); |
| 4147 | __ test_b(ebx, kExternalStringTag); |
| 4148 | __ j(zero, &sequential_string); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4149 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4150 | // Handle external string. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4151 | // Rule out short external strings. |
| 4152 | STATIC_CHECK(kShortExternalStringTag != 0); |
| 4153 | __ test_b(ebx, kShortExternalStringMask); |
| 4154 | __ j(not_zero, &runtime); |
| 4155 | __ mov(edi, FieldOperand(edi, ExternalString::kResourceDataOffset)); |
| 4156 | // 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] | 4157 | STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4158 | __ sub(edi, Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4159 | |
| 4160 | __ bind(&sequential_string); |
| 4161 | // Stash away (adjusted) index and (underlying) string. |
| 4162 | __ push(edx); |
| 4163 | __ push(edi); |
| 4164 | __ SmiUntag(ecx); |
mvstanton@chromium.org | e4ac3ef | 2012-11-12 14:53:34 +0000 | [diff] [blame] | 4165 | STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4166 | __ test_b(ebx, kStringEncodingMask); |
| 4167 | __ j(zero, &two_byte_sequential); |
| 4168 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4169 | // Sequential ASCII string. Allocate the result. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4170 | __ AllocateAsciiString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4171 | |
| 4172 | // eax: result string |
| 4173 | // ecx: result string length |
| 4174 | __ mov(edx, esi); // esi used by following code. |
| 4175 | // Locate first character of result. |
| 4176 | __ mov(edi, eax); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4177 | __ add(edi, Immediate(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4178 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4179 | __ pop(esi); |
| 4180 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4181 | __ SmiUntag(ebx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4182 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqOneByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4183 | |
| 4184 | // eax: result string |
| 4185 | // ecx: result length |
| 4186 | // edx: original value of esi |
| 4187 | // edi: first character of result |
| 4188 | // esi: character of sub string start |
| 4189 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, true); |
| 4190 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4191 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4192 | __ ret(3 * kPointerSize); |
| 4193 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4194 | __ bind(&two_byte_sequential); |
| 4195 | // Sequential two-byte string. Allocate the result. |
| 4196 | __ AllocateTwoByteString(eax, ecx, ebx, edx, edi, &runtime_drop_two); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4197 | |
| 4198 | // eax: result string |
| 4199 | // ecx: result string length |
| 4200 | __ mov(edx, esi); // esi used by following code. |
| 4201 | // Locate first character of result. |
| 4202 | __ mov(edi, eax); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4203 | __ add(edi, |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4204 | Immediate(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 4205 | // Load string argument and locate character of sub string start. |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4206 | __ pop(esi); |
| 4207 | __ pop(ebx); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4208 | // As from is a smi it is 2 times the value which matches the size of a two |
| 4209 | // byte character. |
| 4210 | STATIC_ASSERT(kSmiTag == 0); |
| 4211 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4212 | __ lea(esi, FieldOperand(esi, ebx, times_1, SeqTwoByteString::kHeaderSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4213 | |
| 4214 | // eax: result string |
| 4215 | // ecx: result length |
| 4216 | // edx: original value of esi |
| 4217 | // edi: first character of result |
| 4218 | // esi: character of sub string start |
| 4219 | StringHelper::GenerateCopyCharactersREP(masm, edi, esi, ecx, ebx, false); |
| 4220 | __ mov(esi, edx); // Restore esi. |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4221 | __ IncrementCounter(counters->sub_string_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4222 | __ ret(3 * kPointerSize); |
| 4223 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4224 | // Drop pushed values on the stack before tail call. |
| 4225 | __ bind(&runtime_drop_two); |
| 4226 | __ Drop(2); |
| 4227 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4228 | // Just jump to runtime to create the sub string. |
| 4229 | __ bind(&runtime); |
| 4230 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
ulan@chromium.org | 2e04b58 | 2013-02-21 14:06:02 +0000 | [diff] [blame] | 4231 | |
| 4232 | __ bind(&single_char); |
| 4233 | // eax: string |
| 4234 | // ebx: instance type |
| 4235 | // ecx: sub string length (smi) |
| 4236 | // edx: from index (smi) |
| 4237 | StringCharAtGenerator generator( |
| 4238 | eax, edx, ecx, eax, &runtime, &runtime, &runtime, STRING_INDEX_IS_NUMBER); |
| 4239 | generator.GenerateFast(masm); |
| 4240 | __ ret(3 * kPointerSize); |
| 4241 | generator.SkipSlow(masm, &runtime); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4242 | } |
| 4243 | |
| 4244 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4245 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 4246 | Register left, |
| 4247 | Register right, |
| 4248 | Register scratch1, |
| 4249 | Register scratch2) { |
| 4250 | Register length = scratch1; |
| 4251 | |
| 4252 | // Compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4253 | Label strings_not_equal, check_zero_length; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4254 | __ mov(length, FieldOperand(left, String::kLengthOffset)); |
| 4255 | __ cmp(length, FieldOperand(right, String::kLengthOffset)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4256 | __ j(equal, &check_zero_length, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4257 | __ bind(&strings_not_equal); |
| 4258 | __ Set(eax, Immediate(Smi::FromInt(NOT_EQUAL))); |
| 4259 | __ ret(0); |
| 4260 | |
| 4261 | // Check if the length is zero. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4262 | Label compare_chars; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4263 | __ bind(&check_zero_length); |
| 4264 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4265 | __ test(length, length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4266 | __ j(not_zero, &compare_chars, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4267 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4268 | __ ret(0); |
| 4269 | |
| 4270 | // Compare characters. |
| 4271 | __ bind(&compare_chars); |
| 4272 | GenerateAsciiCharsCompareLoop(masm, left, right, length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4273 | &strings_not_equal, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4274 | |
| 4275 | // Characters are equal. |
| 4276 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4277 | __ ret(0); |
| 4278 | } |
| 4279 | |
| 4280 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4281 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 4282 | Register left, |
| 4283 | Register right, |
| 4284 | Register scratch1, |
| 4285 | Register scratch2, |
| 4286 | Register scratch3) { |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4287 | Counters* counters = masm->isolate()->counters(); |
| 4288 | __ IncrementCounter(counters->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4289 | |
| 4290 | // Find minimum length. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4291 | Label left_shorter; |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4292 | __ mov(scratch1, FieldOperand(left, String::kLengthOffset)); |
| 4293 | __ mov(scratch3, scratch1); |
| 4294 | __ sub(scratch3, FieldOperand(right, String::kLengthOffset)); |
| 4295 | |
| 4296 | Register length_delta = scratch3; |
| 4297 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4298 | __ j(less_equal, &left_shorter, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4299 | // 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] | 4300 | __ sub(scratch1, length_delta); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4301 | __ bind(&left_shorter); |
| 4302 | |
| 4303 | Register min_length = scratch1; |
| 4304 | |
| 4305 | // If either length is zero, just compare lengths. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4306 | Label compare_lengths; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4307 | __ test(min_length, min_length); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4308 | __ j(zero, &compare_lengths, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4309 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4310 | // Compare characters. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4311 | Label result_not_equal; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4312 | GenerateAsciiCharsCompareLoop(masm, left, right, min_length, scratch2, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4313 | &result_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4314 | |
| 4315 | // Compare lengths - strings up to min-length are equal. |
| 4316 | __ bind(&compare_lengths); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4317 | __ test(length_delta, length_delta); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4318 | Label length_not_equal; |
| 4319 | __ j(not_zero, &length_not_equal, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4320 | |
| 4321 | // Result is EQUAL. |
| 4322 | STATIC_ASSERT(EQUAL == 0); |
| 4323 | STATIC_ASSERT(kSmiTag == 0); |
| 4324 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4325 | __ ret(0); |
| 4326 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4327 | Label result_greater; |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4328 | Label result_less; |
| 4329 | __ bind(&length_not_equal); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4330 | __ j(greater, &result_greater, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4331 | __ jmp(&result_less, Label::kNear); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4332 | __ bind(&result_not_equal); |
jkummerow@chromium.org | 59297c7 | 2013-01-09 16:32:23 +0000 | [diff] [blame] | 4333 | __ j(above, &result_greater, Label::kNear); |
| 4334 | __ bind(&result_less); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4335 | |
| 4336 | // Result is LESS. |
| 4337 | __ Set(eax, Immediate(Smi::FromInt(LESS))); |
| 4338 | __ ret(0); |
| 4339 | |
| 4340 | // Result is GREATER. |
| 4341 | __ bind(&result_greater); |
| 4342 | __ Set(eax, Immediate(Smi::FromInt(GREATER))); |
| 4343 | __ ret(0); |
| 4344 | } |
| 4345 | |
| 4346 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4347 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 4348 | MacroAssembler* masm, |
| 4349 | Register left, |
| 4350 | Register right, |
| 4351 | Register length, |
| 4352 | Register scratch, |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4353 | Label* chars_not_equal, |
| 4354 | Label::Distance chars_not_equal_near) { |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4355 | // Change index to run from -length to -1 by adding length to string |
| 4356 | // start. This means that loop ends when index reaches zero, which |
| 4357 | // doesn't need an additional compare. |
| 4358 | __ SmiUntag(length); |
| 4359 | __ lea(left, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4360 | FieldOperand(left, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4361 | __ lea(right, |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4362 | FieldOperand(right, length, times_1, SeqOneByteString::kHeaderSize)); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4363 | __ neg(length); |
| 4364 | Register index = length; // index = -length; |
| 4365 | |
| 4366 | // Compare loop. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4367 | Label loop; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4368 | __ bind(&loop); |
| 4369 | __ mov_b(scratch, Operand(left, index, times_1, 0)); |
| 4370 | __ cmpb(scratch, Operand(right, index, times_1, 0)); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4371 | __ j(not_equal, chars_not_equal, chars_not_equal_near); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4372 | __ inc(index); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4373 | __ j(not_zero, &loop); |
| 4374 | } |
| 4375 | |
| 4376 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4377 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 4378 | Label runtime; |
| 4379 | |
| 4380 | // Stack frame on entry. |
| 4381 | // esp[0]: return address |
| 4382 | // esp[4]: right string |
| 4383 | // esp[8]: left string |
| 4384 | |
| 4385 | __ mov(edx, Operand(esp, 2 * kPointerSize)); // left |
| 4386 | __ mov(eax, Operand(esp, 1 * kPointerSize)); // right |
| 4387 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4388 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4389 | __ cmp(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4390 | __ j(not_equal, ¬_same, Label::kNear); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4391 | STATIC_ASSERT(EQUAL == 0); |
| 4392 | STATIC_ASSERT(kSmiTag == 0); |
| 4393 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
fschneider@chromium.org | 7979bbb | 2011-03-28 10:47:03 +0000 | [diff] [blame] | 4394 | __ IncrementCounter(masm->isolate()->counters()->string_compare_native(), 1); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4395 | __ ret(2 * kPointerSize); |
| 4396 | |
| 4397 | __ bind(¬_same); |
| 4398 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4399 | // Check that both objects are sequential ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4400 | __ JumpIfNotBothSequentialAsciiStrings(edx, eax, ecx, ebx, &runtime); |
| 4401 | |
ulan@chromium.org | 2efb900 | 2012-01-19 15:36:35 +0000 | [diff] [blame] | 4402 | // Compare flat ASCII strings. |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4403 | // Drop arguments from the stack. |
| 4404 | __ pop(ecx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4405 | __ add(esp, Immediate(2 * kPointerSize)); |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 4406 | __ push(ecx); |
| 4407 | GenerateCompareFlatAsciiStrings(masm, edx, eax, ecx, ebx, edi); |
| 4408 | |
| 4409 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 4410 | // tagged as a small integer. |
| 4411 | __ bind(&runtime); |
| 4412 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 4413 | } |
| 4414 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4415 | |
machenbach@chromium.org | c8cbc43 | 2014-01-21 09:01:57 +0000 | [diff] [blame^] | 4416 | void ArrayPushStub::Generate(MacroAssembler* masm) { |
| 4417 | int argc = arguments_count(); |
| 4418 | |
| 4419 | if (argc == 0) { |
| 4420 | // Noop, return the length. |
| 4421 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 4422 | __ ret((argc + 1) * kPointerSize); |
| 4423 | return; |
| 4424 | } |
| 4425 | |
| 4426 | Isolate* isolate = masm->isolate(); |
| 4427 | |
| 4428 | if (argc != 1) { |
| 4429 | __ TailCallExternalReference( |
| 4430 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 4431 | return; |
| 4432 | } |
| 4433 | |
| 4434 | Label call_builtin, attempt_to_grow_elements, with_write_barrier; |
| 4435 | |
| 4436 | // Get the elements array of the object. |
| 4437 | __ mov(edi, FieldOperand(edx, JSArray::kElementsOffset)); |
| 4438 | |
| 4439 | if (IsFastSmiOrObjectElementsKind(elements_kind())) { |
| 4440 | // Check that the elements are in fast mode and writable. |
| 4441 | __ cmp(FieldOperand(edi, HeapObject::kMapOffset), |
| 4442 | isolate->factory()->fixed_array_map()); |
| 4443 | __ j(not_equal, &call_builtin); |
| 4444 | } |
| 4445 | |
| 4446 | // Get the array's length into eax and calculate new length. |
| 4447 | __ mov(eax, FieldOperand(edx, JSArray::kLengthOffset)); |
| 4448 | STATIC_ASSERT(kSmiTagSize == 1); |
| 4449 | STATIC_ASSERT(kSmiTag == 0); |
| 4450 | __ add(eax, Immediate(Smi::FromInt(argc))); |
| 4451 | |
| 4452 | // Get the elements' length into ecx. |
| 4453 | __ mov(ecx, FieldOperand(edi, FixedArray::kLengthOffset)); |
| 4454 | |
| 4455 | // Check if we could survive without allocation. |
| 4456 | __ cmp(eax, ecx); |
| 4457 | |
| 4458 | if (IsFastSmiOrObjectElementsKind(elements_kind())) { |
| 4459 | __ j(greater, &attempt_to_grow_elements); |
| 4460 | |
| 4461 | // Check if value is a smi. |
| 4462 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 4463 | __ JumpIfNotSmi(ecx, &with_write_barrier); |
| 4464 | |
| 4465 | // Store the value. |
| 4466 | __ mov(FieldOperand(edi, eax, times_half_pointer_size, |
| 4467 | FixedArray::kHeaderSize - argc * kPointerSize), |
| 4468 | ecx); |
| 4469 | } else { |
| 4470 | __ j(greater, &call_builtin); |
| 4471 | |
| 4472 | __ mov(ecx, Operand(esp, argc * kPointerSize)); |
| 4473 | __ StoreNumberToDoubleElements( |
| 4474 | ecx, edi, eax, ecx, xmm0, &call_builtin, true, argc * kDoubleSize); |
| 4475 | } |
| 4476 | |
| 4477 | // Save new length. |
| 4478 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 4479 | __ ret((argc + 1) * kPointerSize); |
| 4480 | |
| 4481 | if (IsFastDoubleElementsKind(elements_kind())) { |
| 4482 | __ bind(&call_builtin); |
| 4483 | __ TailCallExternalReference( |
| 4484 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 4485 | return; |
| 4486 | } |
| 4487 | |
| 4488 | __ bind(&with_write_barrier); |
| 4489 | |
| 4490 | if (IsFastSmiElementsKind(elements_kind())) { |
| 4491 | if (FLAG_trace_elements_transitions) __ jmp(&call_builtin); |
| 4492 | |
| 4493 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 4494 | isolate->factory()->heap_number_map()); |
| 4495 | __ j(equal, &call_builtin); |
| 4496 | |
| 4497 | ElementsKind target_kind = IsHoleyElementsKind(elements_kind()) |
| 4498 | ? FAST_HOLEY_ELEMENTS : FAST_ELEMENTS; |
| 4499 | __ mov(ebx, ContextOperand(esi, Context::GLOBAL_OBJECT_INDEX)); |
| 4500 | __ mov(ebx, FieldOperand(ebx, GlobalObject::kNativeContextOffset)); |
| 4501 | __ mov(ebx, ContextOperand(ebx, Context::JS_ARRAY_MAPS_INDEX)); |
| 4502 | const int header_size = FixedArrayBase::kHeaderSize; |
| 4503 | // Verify that the object can be transitioned in place. |
| 4504 | const int origin_offset = header_size + elements_kind() * kPointerSize; |
| 4505 | __ mov(edi, FieldOperand(ebx, origin_offset)); |
| 4506 | __ cmp(edi, FieldOperand(edx, HeapObject::kMapOffset)); |
| 4507 | __ j(not_equal, &call_builtin); |
| 4508 | |
| 4509 | const int target_offset = header_size + target_kind * kPointerSize; |
| 4510 | __ mov(ebx, FieldOperand(ebx, target_offset)); |
| 4511 | ElementsTransitionGenerator::GenerateMapChangeElementsTransition( |
| 4512 | masm, DONT_TRACK_ALLOCATION_SITE, NULL); |
| 4513 | // Restore edi used as a scratch register for the write barrier used while |
| 4514 | // setting the map. |
| 4515 | __ mov(edi, FieldOperand(edx, JSArray::kElementsOffset)); |
| 4516 | } |
| 4517 | |
| 4518 | // Save new length. |
| 4519 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 4520 | |
| 4521 | // Store the value. |
| 4522 | __ lea(edx, FieldOperand(edi, eax, times_half_pointer_size, |
| 4523 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 4524 | __ mov(Operand(edx, 0), ecx); |
| 4525 | |
| 4526 | __ RecordWrite(edi, edx, ecx, kDontSaveFPRegs, EMIT_REMEMBERED_SET, |
| 4527 | OMIT_SMI_CHECK); |
| 4528 | |
| 4529 | __ ret((argc + 1) * kPointerSize); |
| 4530 | |
| 4531 | __ bind(&attempt_to_grow_elements); |
| 4532 | if (!FLAG_inline_new) { |
| 4533 | __ bind(&call_builtin); |
| 4534 | __ TailCallExternalReference( |
| 4535 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 4536 | return; |
| 4537 | } |
| 4538 | |
| 4539 | __ mov(ebx, Operand(esp, argc * kPointerSize)); |
| 4540 | // Growing elements that are SMI-only requires special handling in case the |
| 4541 | // new element is non-Smi. For now, delegate to the builtin. |
| 4542 | if (IsFastSmiElementsKind(elements_kind())) { |
| 4543 | __ JumpIfNotSmi(ebx, &call_builtin); |
| 4544 | } |
| 4545 | |
| 4546 | // We could be lucky and the elements array could be at the top of new-space. |
| 4547 | // In this case we can just grow it in place by moving the allocation pointer |
| 4548 | // up. |
| 4549 | ExternalReference new_space_allocation_top = |
| 4550 | ExternalReference::new_space_allocation_top_address(isolate); |
| 4551 | ExternalReference new_space_allocation_limit = |
| 4552 | ExternalReference::new_space_allocation_limit_address(isolate); |
| 4553 | |
| 4554 | const int kAllocationDelta = 4; |
| 4555 | ASSERT(kAllocationDelta >= argc); |
| 4556 | // Load top. |
| 4557 | __ mov(ecx, Operand::StaticVariable(new_space_allocation_top)); |
| 4558 | |
| 4559 | // Check if it's the end of elements. |
| 4560 | __ lea(edx, FieldOperand(edi, eax, times_half_pointer_size, |
| 4561 | FixedArray::kHeaderSize - argc * kPointerSize)); |
| 4562 | __ cmp(edx, ecx); |
| 4563 | __ j(not_equal, &call_builtin); |
| 4564 | __ add(ecx, Immediate(kAllocationDelta * kPointerSize)); |
| 4565 | __ cmp(ecx, Operand::StaticVariable(new_space_allocation_limit)); |
| 4566 | __ j(above, &call_builtin); |
| 4567 | |
| 4568 | // We fit and could grow elements. |
| 4569 | __ mov(Operand::StaticVariable(new_space_allocation_top), ecx); |
| 4570 | |
| 4571 | // Push the argument... |
| 4572 | __ mov(Operand(edx, 0), ebx); |
| 4573 | // ... and fill the rest with holes. |
| 4574 | for (int i = 1; i < kAllocationDelta; i++) { |
| 4575 | __ mov(Operand(edx, i * kPointerSize), |
| 4576 | isolate->factory()->the_hole_value()); |
| 4577 | } |
| 4578 | |
| 4579 | if (IsFastObjectElementsKind(elements_kind())) { |
| 4580 | // We know the elements array is in new space so we don't need the |
| 4581 | // remembered set, but we just pushed a value onto it so we may have to tell |
| 4582 | // the incremental marker to rescan the object that we just grew. We don't |
| 4583 | // need to worry about the holes because they are in old space and already |
| 4584 | // marked black. |
| 4585 | __ RecordWrite(edi, edx, ebx, kDontSaveFPRegs, OMIT_REMEMBERED_SET); |
| 4586 | } |
| 4587 | |
| 4588 | // Restore receiver to edx as finish sequence assumes it's here. |
| 4589 | __ mov(edx, Operand(esp, (argc + 1) * kPointerSize)); |
| 4590 | |
| 4591 | // Increment element's and array's sizes. |
| 4592 | __ add(FieldOperand(edi, FixedArray::kLengthOffset), |
| 4593 | Immediate(Smi::FromInt(kAllocationDelta))); |
| 4594 | |
| 4595 | // NOTE: This only happen in new-space, where we don't care about the |
| 4596 | // black-byte-count on pages. Otherwise we should update that too if the |
| 4597 | // object is black. |
| 4598 | |
| 4599 | __ mov(FieldOperand(edx, JSArray::kLengthOffset), eax); |
| 4600 | __ ret((argc + 1) * kPointerSize); |
| 4601 | |
| 4602 | __ bind(&call_builtin); |
| 4603 | __ TailCallExternalReference( |
| 4604 | ExternalReference(Builtins::c_ArrayPush, isolate), argc + 1, 1); |
| 4605 | } |
| 4606 | |
| 4607 | |
ulan@chromium.org | 0f13e74 | 2014-01-03 15:51:11 +0000 | [diff] [blame] | 4608 | void BinaryOpICWithAllocationSiteStub::Generate(MacroAssembler* masm) { |
| 4609 | // ----------- S t a t e ------------- |
| 4610 | // -- edx : left |
| 4611 | // -- eax : right |
| 4612 | // -- esp[0] : return address |
| 4613 | // ----------------------------------- |
| 4614 | Isolate* isolate = masm->isolate(); |
| 4615 | |
| 4616 | // Load ecx with the allocation site. We stick an undefined dummy value here |
| 4617 | // and replace it with the real allocation site later when we instantiate this |
| 4618 | // stub in BinaryOpICWithAllocationSiteStub::GetCodeCopyFromTemplate(). |
| 4619 | __ mov(ecx, handle(isolate->heap()->undefined_value())); |
| 4620 | |
| 4621 | // Make sure that we actually patched the allocation site. |
| 4622 | if (FLAG_debug_code) { |
| 4623 | __ test(ecx, Immediate(kSmiTagMask)); |
| 4624 | __ Assert(not_equal, kExpectedAllocationSite); |
| 4625 | __ cmp(FieldOperand(ecx, HeapObject::kMapOffset), |
| 4626 | isolate->factory()->allocation_site_map()); |
| 4627 | __ Assert(equal, kExpectedAllocationSite); |
| 4628 | } |
| 4629 | |
| 4630 | // Tail call into the stub that handles binary operations with allocation |
| 4631 | // sites. |
| 4632 | BinaryOpWithAllocationSiteStub stub(state_); |
| 4633 | __ TailCallStub(&stub); |
| 4634 | } |
| 4635 | |
| 4636 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4637 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4638 | ASSERT(state_ == CompareIC::SMI); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4639 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4640 | __ mov(ecx, edx); |
| 4641 | __ or_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4642 | __ JumpIfNotSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4643 | |
| 4644 | if (GetCondition() == equal) { |
| 4645 | // 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] | 4646 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4647 | } else { |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4648 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4649 | __ sub(edx, eax); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4650 | __ j(no_overflow, &done, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4651 | // Correct sign of result in case of overflow. |
| 4652 | __ not_(edx); |
| 4653 | __ bind(&done); |
| 4654 | __ mov(eax, edx); |
| 4655 | } |
| 4656 | __ ret(0); |
| 4657 | |
| 4658 | __ bind(&miss); |
| 4659 | GenerateMiss(masm); |
| 4660 | } |
| 4661 | |
| 4662 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4663 | void ICCompareStub::GenerateNumbers(MacroAssembler* masm) { |
| 4664 | ASSERT(state_ == CompareIC::NUMBER); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4665 | |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4666 | Label generic_stub; |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4667 | Label unordered, maybe_undefined1, maybe_undefined2; |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4668 | Label miss; |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4669 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4670 | if (left_ == CompareIC::SMI) { |
| 4671 | __ JumpIfNotSmi(edx, &miss); |
| 4672 | } |
| 4673 | if (right_ == CompareIC::SMI) { |
| 4674 | __ JumpIfNotSmi(eax, &miss); |
| 4675 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4676 | |
| 4677 | // Inlining the double comparison and falling back to the general compare |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4678 | // stub if NaN is involved or SSE2 or CMOV is unsupported. |
kmillikin@chromium.org | c36ce6e | 2011-04-04 08:25:31 +0000 | [diff] [blame] | 4679 | if (CpuFeatures::IsSupported(SSE2) && CpuFeatures::IsSupported(CMOV)) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 4680 | CpuFeatureScope scope1(masm, SSE2); |
| 4681 | CpuFeatureScope scope2(masm, CMOV); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4682 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4683 | // Load left and right operand. |
| 4684 | Label done, left, left_smi, right_smi; |
| 4685 | __ JumpIfSmi(eax, &right_smi, Label::kNear); |
| 4686 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 4687 | masm->isolate()->factory()->heap_number_map()); |
| 4688 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4689 | __ movsd(xmm1, FieldOperand(eax, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4690 | __ jmp(&left, Label::kNear); |
| 4691 | __ bind(&right_smi); |
| 4692 | __ mov(ecx, eax); // Can't clobber eax because we can still jump away. |
| 4693 | __ SmiUntag(ecx); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4694 | __ Cvtsi2sd(xmm1, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4695 | |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4696 | __ bind(&left); |
| 4697 | __ JumpIfSmi(edx, &left_smi, Label::kNear); |
| 4698 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4699 | masm->isolate()->factory()->heap_number_map()); |
| 4700 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
bmeurer@chromium.org | 0fdb2a6 | 2013-10-21 07:19:36 +0000 | [diff] [blame] | 4701 | __ movsd(xmm0, FieldOperand(edx, HeapNumber::kValueOffset)); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4702 | __ jmp(&done); |
| 4703 | __ bind(&left_smi); |
| 4704 | __ mov(ecx, edx); // Can't clobber edx because we can still jump away. |
| 4705 | __ SmiUntag(ecx); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 4706 | __ Cvtsi2sd(xmm0, ecx); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4707 | |
| 4708 | __ bind(&done); |
| 4709 | // Compare operands. |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4710 | __ ucomisd(xmm0, xmm1); |
| 4711 | |
| 4712 | // Don't base result on EFLAGS when a NaN is involved. |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4713 | __ j(parity_even, &unordered, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4714 | |
| 4715 | // Return a result of -1, 0, or 1, based on EFLAGS. |
| 4716 | // Performing mov, because xor would destroy the flag register. |
| 4717 | __ mov(eax, 0); // equal |
| 4718 | __ mov(ecx, Immediate(Smi::FromInt(1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4719 | __ cmov(above, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4720 | __ mov(ecx, Immediate(Smi::FromInt(-1))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4721 | __ cmov(below, eax, ecx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4722 | __ ret(0); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4723 | } else { |
| 4724 | __ mov(ecx, edx); |
| 4725 | __ and_(ecx, eax); |
| 4726 | __ JumpIfSmi(ecx, &generic_stub, Label::kNear); |
| 4727 | |
| 4728 | __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| 4729 | masm->isolate()->factory()->heap_number_map()); |
| 4730 | __ j(not_equal, &maybe_undefined1, Label::kNear); |
| 4731 | __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| 4732 | masm->isolate()->factory()->heap_number_map()); |
| 4733 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4734 | } |
| 4735 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4736 | __ bind(&unordered); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4737 | __ bind(&generic_stub); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4738 | ICCompareStub stub(op_, CompareIC::GENERIC, CompareIC::GENERIC, |
| 4739 | CompareIC::GENERIC); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 4740 | __ jmp(stub.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4741 | |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4742 | __ bind(&maybe_undefined1); |
| 4743 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 4744 | __ cmp(eax, Immediate(masm->isolate()->factory()->undefined_value())); |
| 4745 | __ j(not_equal, &miss); |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4746 | __ JumpIfSmi(edx, &unordered); |
ulan@chromium.org | 9a21ec4 | 2012-03-06 08:42:24 +0000 | [diff] [blame] | 4747 | __ CmpObjectType(edx, HEAP_NUMBER_TYPE, ecx); |
| 4748 | __ j(not_equal, &maybe_undefined2, Label::kNear); |
| 4749 | __ jmp(&unordered); |
| 4750 | } |
| 4751 | |
| 4752 | __ bind(&maybe_undefined2); |
| 4753 | if (Token::IsOrderedRelationalCompareOp(op_)) { |
| 4754 | __ cmp(edx, Immediate(masm->isolate()->factory()->undefined_value())); |
| 4755 | __ j(equal, &unordered); |
| 4756 | } |
| 4757 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4758 | __ bind(&miss); |
| 4759 | GenerateMiss(masm); |
| 4760 | } |
| 4761 | |
| 4762 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4763 | void ICCompareStub::GenerateInternalizedStrings(MacroAssembler* masm) { |
| 4764 | ASSERT(state_ == CompareIC::INTERNALIZED_STRING); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4765 | ASSERT(GetCondition() == equal); |
| 4766 | |
| 4767 | // Registers containing left and right operands respectively. |
| 4768 | Register left = edx; |
| 4769 | Register right = eax; |
| 4770 | Register tmp1 = ecx; |
| 4771 | Register tmp2 = ebx; |
| 4772 | |
| 4773 | // Check that both operands are heap objects. |
| 4774 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4775 | __ mov(tmp1, left); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4776 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4777 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4778 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4779 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4780 | // Check that both operands are internalized strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4781 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4782 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4783 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4784 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4785 | STATIC_ASSERT(kInternalizedTag == 0 && kStringTag == 0); |
| 4786 | __ or_(tmp1, tmp2); |
| 4787 | __ test(tmp1, Immediate(kIsNotStringMask | kIsNotInternalizedMask)); |
| 4788 | __ j(not_zero, &miss, Label::kNear); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4789 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4790 | // Internalized strings are compared by identity. |
| 4791 | Label done; |
| 4792 | __ cmp(left, right); |
| 4793 | // Make sure eax is non-zero. At this point input operands are |
| 4794 | // guaranteed to be non-zero. |
| 4795 | ASSERT(right.is(eax)); |
| 4796 | __ j(not_equal, &done, Label::kNear); |
| 4797 | STATIC_ASSERT(EQUAL == 0); |
| 4798 | STATIC_ASSERT(kSmiTag == 0); |
| 4799 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4800 | __ bind(&done); |
| 4801 | __ ret(0); |
| 4802 | |
| 4803 | __ bind(&miss); |
| 4804 | GenerateMiss(masm); |
| 4805 | } |
| 4806 | |
| 4807 | |
| 4808 | void ICCompareStub::GenerateUniqueNames(MacroAssembler* masm) { |
| 4809 | ASSERT(state_ == CompareIC::UNIQUE_NAME); |
| 4810 | ASSERT(GetCondition() == equal); |
| 4811 | |
| 4812 | // Registers containing left and right operands respectively. |
| 4813 | Register left = edx; |
| 4814 | Register right = eax; |
| 4815 | Register tmp1 = ecx; |
| 4816 | Register tmp2 = ebx; |
| 4817 | |
| 4818 | // Check that both operands are heap objects. |
| 4819 | Label miss; |
| 4820 | __ mov(tmp1, left); |
| 4821 | STATIC_ASSERT(kSmiTag == 0); |
| 4822 | __ and_(tmp1, right); |
| 4823 | __ JumpIfSmi(tmp1, &miss, Label::kNear); |
| 4824 | |
| 4825 | // Check that both operands are unique names. This leaves the instance |
| 4826 | // types loaded in tmp1 and tmp2. |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4827 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4828 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4829 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4830 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 4831 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 4832 | __ JumpIfNotUniqueName(tmp1, &miss, Label::kNear); |
| 4833 | __ JumpIfNotUniqueName(tmp2, &miss, Label::kNear); |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4834 | |
| 4835 | // Unique names are compared by identity. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4836 | Label done; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4837 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4838 | // Make sure eax is non-zero. At this point input operands are |
| 4839 | // guaranteed to be non-zero. |
| 4840 | ASSERT(right.is(eax)); |
| 4841 | __ j(not_equal, &done, Label::kNear); |
| 4842 | STATIC_ASSERT(EQUAL == 0); |
| 4843 | STATIC_ASSERT(kSmiTag == 0); |
| 4844 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4845 | __ bind(&done); |
| 4846 | __ ret(0); |
| 4847 | |
| 4848 | __ bind(&miss); |
| 4849 | GenerateMiss(masm); |
| 4850 | } |
| 4851 | |
| 4852 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4853 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4854 | ASSERT(state_ == CompareIC::STRING); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4855 | Label miss; |
| 4856 | |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4857 | bool equality = Token::IsEqualityOp(op_); |
| 4858 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4859 | // Registers containing left and right operands respectively. |
| 4860 | Register left = edx; |
| 4861 | Register right = eax; |
| 4862 | Register tmp1 = ecx; |
| 4863 | Register tmp2 = ebx; |
| 4864 | Register tmp3 = edi; |
| 4865 | |
| 4866 | // Check that both operands are heap objects. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4867 | __ mov(tmp1, left); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4868 | STATIC_ASSERT(kSmiTag == 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4869 | __ and_(tmp1, right); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4870 | __ JumpIfSmi(tmp1, &miss); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4871 | |
| 4872 | // Check that both operands are strings. This leaves the instance |
| 4873 | // types loaded in tmp1 and tmp2. |
| 4874 | __ mov(tmp1, FieldOperand(left, HeapObject::kMapOffset)); |
| 4875 | __ mov(tmp2, FieldOperand(right, HeapObject::kMapOffset)); |
| 4876 | __ movzx_b(tmp1, FieldOperand(tmp1, Map::kInstanceTypeOffset)); |
| 4877 | __ movzx_b(tmp2, FieldOperand(tmp2, Map::kInstanceTypeOffset)); |
| 4878 | __ mov(tmp3, tmp1); |
| 4879 | STATIC_ASSERT(kNotStringTag != 0); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4880 | __ or_(tmp3, tmp2); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4881 | __ test(tmp3, Immediate(kIsNotStringMask)); |
| 4882 | __ j(not_zero, &miss); |
| 4883 | |
| 4884 | // Fast check for identical strings. |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4885 | Label not_same; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4886 | __ cmp(left, right); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4887 | __ j(not_equal, ¬_same, Label::kNear); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4888 | STATIC_ASSERT(EQUAL == 0); |
| 4889 | STATIC_ASSERT(kSmiTag == 0); |
| 4890 | __ Set(eax, Immediate(Smi::FromInt(EQUAL))); |
| 4891 | __ ret(0); |
| 4892 | |
| 4893 | // Handle not identical strings. |
| 4894 | __ bind(¬_same); |
| 4895 | |
yangguo@chromium.org | 4a9f655 | 2013-03-04 14:46:33 +0000 | [diff] [blame] | 4896 | // 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] | 4897 | // 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] | 4898 | // non-equality compare, we still need to determine the order. We |
| 4899 | // also know they are both strings. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4900 | if (equality) { |
| 4901 | Label do_compare; |
jkummerow@chromium.org | ba72ec8 | 2013-07-22 09:21:20 +0000 | [diff] [blame] | 4902 | STATIC_ASSERT(kInternalizedTag == 0); |
| 4903 | __ or_(tmp1, tmp2); |
| 4904 | __ test(tmp1, Immediate(kIsNotInternalizedMask)); |
| 4905 | __ j(not_zero, &do_compare, Label::kNear); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4906 | // Make sure eax is non-zero. At this point input operands are |
| 4907 | // guaranteed to be non-zero. |
| 4908 | ASSERT(right.is(eax)); |
| 4909 | __ ret(0); |
| 4910 | __ bind(&do_compare); |
| 4911 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4912 | |
| 4913 | // Check that both strings are sequential ASCII. |
| 4914 | Label runtime; |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4915 | __ JumpIfNotBothSequentialAsciiStrings(left, right, tmp1, tmp2, &runtime); |
| 4916 | |
| 4917 | // Compare flat ASCII strings. Returns when done. |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4918 | if (equality) { |
| 4919 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 4920 | masm, left, right, tmp1, tmp2); |
| 4921 | } else { |
| 4922 | StringCompareStub::GenerateCompareFlatAsciiStrings( |
| 4923 | masm, left, right, tmp1, tmp2, tmp3); |
| 4924 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4925 | |
| 4926 | // Handle more complex cases in runtime. |
| 4927 | __ bind(&runtime); |
| 4928 | __ pop(tmp1); // Return address. |
| 4929 | __ push(left); |
| 4930 | __ push(right); |
| 4931 | __ push(tmp1); |
svenpanne@chromium.org | 4efbdb1 | 2012-03-12 08:18:42 +0000 | [diff] [blame] | 4932 | if (equality) { |
| 4933 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 4934 | } else { |
| 4935 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 4936 | } |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 4937 | |
| 4938 | __ bind(&miss); |
| 4939 | GenerateMiss(masm); |
| 4940 | } |
| 4941 | |
| 4942 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4943 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
yangguo@chromium.org | fb37721 | 2012-11-16 14:43:43 +0000 | [diff] [blame] | 4944 | ASSERT(state_ == CompareIC::OBJECT); |
karlklose@chromium.org | 83a4728 | 2011-05-11 11:54:09 +0000 | [diff] [blame] | 4945 | Label miss; |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4946 | __ mov(ecx, edx); |
| 4947 | __ and_(ecx, eax); |
whesse@chromium.org | 7b26015 | 2011-06-20 15:33:18 +0000 | [diff] [blame] | 4948 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4949 | |
| 4950 | __ CmpObjectType(eax, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4951 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4952 | __ CmpObjectType(edx, JS_OBJECT_TYPE, ecx); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 4953 | __ j(not_equal, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4954 | |
| 4955 | ASSERT(GetCondition() == equal); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4956 | __ sub(eax, edx); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4957 | __ ret(0); |
| 4958 | |
| 4959 | __ bind(&miss); |
| 4960 | GenerateMiss(masm); |
| 4961 | } |
| 4962 | |
| 4963 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4964 | void ICCompareStub::GenerateKnownObjects(MacroAssembler* masm) { |
| 4965 | Label miss; |
| 4966 | __ mov(ecx, edx); |
| 4967 | __ and_(ecx, eax); |
| 4968 | __ JumpIfSmi(ecx, &miss, Label::kNear); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 4969 | |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4970 | __ mov(ecx, FieldOperand(eax, HeapObject::kMapOffset)); |
| 4971 | __ mov(ebx, FieldOperand(edx, HeapObject::kMapOffset)); |
| 4972 | __ cmp(ecx, known_map_); |
| 4973 | __ j(not_equal, &miss, Label::kNear); |
| 4974 | __ cmp(ebx, known_map_); |
| 4975 | __ j(not_equal, &miss, Label::kNear); |
| 4976 | |
| 4977 | __ sub(eax, edx); |
| 4978 | __ ret(0); |
| 4979 | |
| 4980 | __ bind(&miss); |
| 4981 | GenerateMiss(masm); |
| 4982 | } |
| 4983 | |
| 4984 | |
| 4985 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4986 | { |
| 4987 | // Call the runtime system in a fresh internal frame. |
| 4988 | ExternalReference miss = ExternalReference(IC_Utility(IC::kCompareIC_Miss), |
| 4989 | masm->isolate()); |
| 4990 | FrameScope scope(masm, StackFrame::INTERNAL); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4991 | __ push(edx); // Preserve edx and eax. |
| 4992 | __ push(eax); |
| 4993 | __ push(edx); // And also use them as the arguments. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 4994 | __ push(eax); |
| 4995 | __ push(Immediate(Smi::FromInt(op_))); |
| 4996 | __ CallExternalReference(miss, 3); |
ricow@chromium.org | 64e3a4b | 2011-12-13 08:07:27 +0000 | [diff] [blame] | 4997 | // Compute the entry point of the rewritten stub. |
| 4998 | __ lea(edi, FieldOperand(eax, Code::kHeaderSize)); |
| 4999 | __ pop(eax); |
| 5000 | __ pop(edx); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5001 | } |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5002 | |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5003 | // Do a tail call to the rewritten stub. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5004 | __ jmp(edi); |
kasperl@chromium.org | a555126 | 2010-12-07 12:49:48 +0000 | [diff] [blame] | 5005 | } |
| 5006 | |
| 5007 | |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5008 | // Helper function used to check that the dictionary doesn't contain |
| 5009 | // the property. This function may return false negatives, so miss_label |
| 5010 | // must always call a backup property check that is complete. |
| 5011 | // 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] | 5012 | // Name must be a unique name and receiver must be a heap object. |
| 5013 | void NameDictionaryLookupStub::GenerateNegativeLookup(MacroAssembler* masm, |
| 5014 | Label* miss, |
| 5015 | Label* done, |
| 5016 | Register properties, |
| 5017 | Handle<Name> name, |
| 5018 | Register r0) { |
| 5019 | ASSERT(name->IsUniqueName()); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5020 | |
| 5021 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 5022 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 5023 | // undefined value), it guarantees the hash table doesn't contain the |
| 5024 | // property. It's true even if some slots represent deleted properties |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5025 | // (their names are the hole value). |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5026 | for (int i = 0; i < kInlinedProbes; i++) { |
| 5027 | // Compute the masked index: (hash + i + i * i) & mask. |
| 5028 | Register index = r0; |
| 5029 | // Capacity is smi 2^n. |
| 5030 | __ mov(index, FieldOperand(properties, kCapacityOffset)); |
| 5031 | __ dec(index); |
| 5032 | __ and_(index, |
| 5033 | Immediate(Smi::FromInt(name->Hash() + |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5034 | NameDictionary::GetProbeOffset(i)))); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5035 | |
| 5036 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5037 | ASSERT(NameDictionary::kEntrySize == 3); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5038 | __ lea(index, Operand(index, index, times_2, 0)); // index *= 3. |
| 5039 | Register entity_name = r0; |
| 5040 | // Having undefined at this place means the name is not contained. |
| 5041 | ASSERT_EQ(kSmiTagSize, 1); |
| 5042 | __ mov(entity_name, Operand(properties, index, times_half_pointer_size, |
| 5043 | kElementsStartOffset - kHeapObjectTag)); |
| 5044 | __ cmp(entity_name, masm->isolate()->factory()->undefined_value()); |
| 5045 | __ j(equal, done); |
| 5046 | |
| 5047 | // Stop if found the property. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5048 | __ cmp(entity_name, Handle<Name>(name)); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5049 | __ j(equal, miss); |
| 5050 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5051 | Label good; |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5052 | // Check for the hole and skip. |
| 5053 | __ cmp(entity_name, masm->isolate()->factory()->the_hole_value()); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5054 | __ j(equal, &good, Label::kNear); |
ulan@chromium.org | 967e270 | 2012-02-28 09:49:15 +0000 | [diff] [blame] | 5055 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5056 | // Check if the entry name is not a unique name. |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5057 | __ mov(entity_name, FieldOperand(entity_name, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5058 | __ JumpIfNotUniqueName(FieldOperand(entity_name, Map::kInstanceTypeOffset), |
| 5059 | miss); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5060 | __ bind(&good); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5061 | } |
| 5062 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5063 | NameDictionaryLookupStub stub(properties, r0, r0, NEGATIVE_LOOKUP); |
erik.corry@gmail.com | 394dbcf | 2011-10-27 07:38:48 +0000 | [diff] [blame] | 5064 | __ push(Immediate(Handle<Object>(name))); |
| 5065 | __ push(Immediate(name->Hash())); |
| 5066 | __ CallStub(&stub); |
| 5067 | __ test(r0, r0); |
| 5068 | __ j(not_zero, miss); |
| 5069 | __ jmp(done); |
| 5070 | } |
| 5071 | |
| 5072 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5073 | // Probe the name dictionary in the |elements| register. Jump to the |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5074 | // |done| label if a property with the given name is found leaving the |
| 5075 | // index into the dictionary in |r0|. Jump to the |miss| label |
| 5076 | // otherwise. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5077 | void NameDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 5078 | Label* miss, |
| 5079 | Label* done, |
| 5080 | Register elements, |
| 5081 | Register name, |
| 5082 | Register r0, |
| 5083 | Register r1) { |
erik.corry@gmail.com | 6e28b56 | 2011-10-27 14:20:17 +0000 | [diff] [blame] | 5084 | ASSERT(!elements.is(r0)); |
| 5085 | ASSERT(!elements.is(r1)); |
| 5086 | ASSERT(!name.is(r0)); |
| 5087 | ASSERT(!name.is(r1)); |
| 5088 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5089 | __ AssertName(name); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5090 | |
| 5091 | __ mov(r1, FieldOperand(elements, kCapacityOffset)); |
| 5092 | __ shr(r1, kSmiTagSize); // convert smi to int |
| 5093 | __ dec(r1); |
| 5094 | |
| 5095 | // Generate an unrolled loop that performs a few probes before |
| 5096 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 5097 | // cover ~93% of loads from dictionaries. |
| 5098 | for (int i = 0; i < kInlinedProbes; i++) { |
| 5099 | // Compute the masked index: (hash + i + i * i) & mask. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5100 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 5101 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5102 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5103 | __ add(r0, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5104 | } |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5105 | __ and_(r0, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5106 | |
| 5107 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5108 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5109 | __ lea(r0, Operand(r0, r0, times_2, 0)); // r0 = r0 * 3 |
| 5110 | |
| 5111 | // Check if the key is identical to the name. |
| 5112 | __ cmp(name, Operand(elements, |
| 5113 | r0, |
| 5114 | times_4, |
| 5115 | kElementsStartOffset - kHeapObjectTag)); |
vegorov@chromium.org | 7304bca | 2011-05-16 12:14:13 +0000 | [diff] [blame] | 5116 | __ j(equal, done); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5117 | } |
| 5118 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5119 | NameDictionaryLookupStub stub(elements, r1, r0, POSITIVE_LOOKUP); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5120 | __ push(name); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5121 | __ mov(r0, FieldOperand(name, Name::kHashFieldOffset)); |
| 5122 | __ shr(r0, Name::kHashShift); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5123 | __ push(r0); |
| 5124 | __ CallStub(&stub); |
| 5125 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5126 | __ test(r1, r1); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5127 | __ j(zero, miss); |
| 5128 | __ jmp(done); |
| 5129 | } |
| 5130 | |
| 5131 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5132 | void NameDictionaryLookupStub::Generate(MacroAssembler* masm) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5133 | // This stub overrides SometimesSetsUpAFrame() to return false. That means |
| 5134 | // 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] | 5135 | // Stack frame on entry: |
| 5136 | // esp[0 * kPointerSize]: return address. |
| 5137 | // esp[1 * kPointerSize]: key's hash. |
| 5138 | // esp[2 * kPointerSize]: key. |
| 5139 | // Registers: |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5140 | // dictionary_: NameDictionary to probe. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5141 | // result_: used as scratch. |
| 5142 | // index_: will hold an index of entry if lookup is successful. |
| 5143 | // might alias with result_. |
| 5144 | // Returns: |
| 5145 | // result_ is zero if lookup failed, non zero otherwise. |
| 5146 | |
| 5147 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 5148 | |
| 5149 | Register scratch = result_; |
| 5150 | |
| 5151 | __ mov(scratch, FieldOperand(dictionary_, kCapacityOffset)); |
| 5152 | __ dec(scratch); |
| 5153 | __ SmiUntag(scratch); |
| 5154 | __ push(scratch); |
| 5155 | |
| 5156 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 5157 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 5158 | // undefined value), it guarantees the hash table doesn't contain the |
| 5159 | // property. It's true even if some slots represent deleted properties |
| 5160 | // (their names are the null value). |
| 5161 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 5162 | // Compute the masked index: (hash + i + i * i) & mask. |
| 5163 | __ mov(scratch, Operand(esp, 2 * kPointerSize)); |
| 5164 | if (i > 0) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5165 | __ add(scratch, Immediate(NameDictionary::GetProbeOffset(i))); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5166 | } |
| 5167 | __ and_(scratch, Operand(esp, 0)); |
| 5168 | |
| 5169 | // Scale the index by multiplying by the entry size. |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5170 | ASSERT(NameDictionary::kEntrySize == 3); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5171 | __ lea(index_, Operand(scratch, scratch, times_2, 0)); // index *= 3. |
| 5172 | |
| 5173 | // Having undefined at this place means the name is not contained. |
| 5174 | ASSERT_EQ(kSmiTagSize, 1); |
| 5175 | __ mov(scratch, Operand(dictionary_, |
| 5176 | index_, |
| 5177 | times_pointer_size, |
| 5178 | kElementsStartOffset - kHeapObjectTag)); |
| 5179 | __ cmp(scratch, masm->isolate()->factory()->undefined_value()); |
| 5180 | __ j(equal, ¬_in_dictionary); |
| 5181 | |
| 5182 | // Stop if found the property. |
| 5183 | __ cmp(scratch, Operand(esp, 3 * kPointerSize)); |
| 5184 | __ j(equal, &in_dictionary); |
| 5185 | |
| 5186 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5187 | // 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] | 5188 | // 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] | 5189 | // key we are looking for. |
| 5190 | |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5191 | // Check if the entry name is not a unique name. |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5192 | __ mov(scratch, FieldOperand(scratch, HeapObject::kMapOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5193 | __ JumpIfNotUniqueName(FieldOperand(scratch, Map::kInstanceTypeOffset), |
| 5194 | &maybe_in_dictionary); |
lrn@chromium.org | 1c09276 | 2011-05-09 09:42:16 +0000 | [diff] [blame] | 5195 | } |
| 5196 | } |
| 5197 | |
| 5198 | __ bind(&maybe_in_dictionary); |
| 5199 | // If we are doing negative lookup then probing failure should be |
| 5200 | // treated as a lookup success. For positive lookup probing failure |
| 5201 | // should be treated as lookup failure. |
| 5202 | if (mode_ == POSITIVE_LOOKUP) { |
| 5203 | __ mov(result_, Immediate(0)); |
| 5204 | __ Drop(1); |
| 5205 | __ ret(2 * kPointerSize); |
| 5206 | } |
| 5207 | |
| 5208 | __ bind(&in_dictionary); |
| 5209 | __ mov(result_, Immediate(1)); |
| 5210 | __ Drop(1); |
| 5211 | __ ret(2 * kPointerSize); |
| 5212 | |
| 5213 | __ bind(¬_in_dictionary); |
| 5214 | __ mov(result_, Immediate(0)); |
| 5215 | __ Drop(1); |
| 5216 | __ ret(2 * kPointerSize); |
| 5217 | } |
| 5218 | |
| 5219 | |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5220 | void StoreBufferOverflowStub::GenerateFixedRegStubsAheadOfTime( |
| 5221 | Isolate* isolate) { |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5222 | StoreBufferOverflowStub stub(kDontSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5223 | stub.GetCode(isolate); |
ulan@chromium.org | 750145a | 2013-03-07 15:14:13 +0000 | [diff] [blame] | 5224 | if (CpuFeatures::IsSafeForSnapshot(SSE2)) { |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5225 | StoreBufferOverflowStub stub2(kSaveFPRegs); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5226 | stub2.GetCode(isolate); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5227 | } |
| 5228 | } |
| 5229 | |
| 5230 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5231 | bool CodeStub::CanUseFPRegisters() { |
| 5232 | return CpuFeatures::IsSupported(SSE2); |
| 5233 | } |
| 5234 | |
| 5235 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5236 | // Takes the input in 3 registers: address_ value_ and object_. A pointer to |
| 5237 | // the value has just been written into the object, now this stub makes sure |
| 5238 | // we keep the GC informed. The word in the object where the value has been |
| 5239 | // written is in the address register. |
| 5240 | void RecordWriteStub::Generate(MacroAssembler* masm) { |
| 5241 | Label skip_to_incremental_noncompacting; |
| 5242 | Label skip_to_incremental_compacting; |
| 5243 | |
| 5244 | // The first two instructions are generated with labels so as to get the |
| 5245 | // offset fixed up correctly by the bind(Label*) call. We patch it back and |
| 5246 | // forth between a compare instructions (a nop in this position) and the |
| 5247 | // real branch when we start and stop incremental heap marking. |
| 5248 | __ jmp(&skip_to_incremental_noncompacting, Label::kNear); |
| 5249 | __ jmp(&skip_to_incremental_compacting, Label::kFar); |
| 5250 | |
| 5251 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 5252 | __ RememberedSetHelper(object_, |
| 5253 | address_, |
| 5254 | value_, |
| 5255 | save_fp_regs_mode_, |
| 5256 | MacroAssembler::kReturnAtEnd); |
| 5257 | } else { |
| 5258 | __ ret(0); |
| 5259 | } |
| 5260 | |
| 5261 | __ bind(&skip_to_incremental_noncompacting); |
| 5262 | GenerateIncremental(masm, INCREMENTAL); |
| 5263 | |
| 5264 | __ bind(&skip_to_incremental_compacting); |
| 5265 | GenerateIncremental(masm, INCREMENTAL_COMPACTION); |
| 5266 | |
| 5267 | // Initial mode of the stub is expected to be STORE_BUFFER_ONLY. |
| 5268 | // Will be checked in IncrementalMarking::ActivateGeneratedStub. |
| 5269 | masm->set_byte_at(0, kTwoByteNopInstruction); |
| 5270 | masm->set_byte_at(2, kFiveByteNopInstruction); |
| 5271 | } |
| 5272 | |
| 5273 | |
| 5274 | void RecordWriteStub::GenerateIncremental(MacroAssembler* masm, Mode mode) { |
| 5275 | regs_.Save(masm); |
| 5276 | |
| 5277 | if (remembered_set_action_ == EMIT_REMEMBERED_SET) { |
| 5278 | Label dont_need_remembered_set; |
| 5279 | |
| 5280 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 5281 | __ JumpIfNotInNewSpace(regs_.scratch0(), // Value. |
| 5282 | regs_.scratch0(), |
| 5283 | &dont_need_remembered_set); |
| 5284 | |
| 5285 | __ CheckPageFlag(regs_.object(), |
| 5286 | regs_.scratch0(), |
| 5287 | 1 << MemoryChunk::SCAN_ON_SCAVENGE, |
| 5288 | not_zero, |
| 5289 | &dont_need_remembered_set); |
| 5290 | |
| 5291 | // First notify the incremental marker if necessary, then update the |
| 5292 | // remembered set. |
| 5293 | CheckNeedsToInformIncrementalMarker( |
| 5294 | masm, |
| 5295 | kUpdateRememberedSetOnNoNeedToInformIncrementalMarker, |
| 5296 | mode); |
| 5297 | InformIncrementalMarker(masm, mode); |
| 5298 | regs_.Restore(masm); |
| 5299 | __ RememberedSetHelper(object_, |
| 5300 | address_, |
| 5301 | value_, |
| 5302 | save_fp_regs_mode_, |
| 5303 | MacroAssembler::kReturnAtEnd); |
| 5304 | |
| 5305 | __ bind(&dont_need_remembered_set); |
| 5306 | } |
| 5307 | |
| 5308 | CheckNeedsToInformIncrementalMarker( |
| 5309 | masm, |
| 5310 | kReturnOnNoNeedToInformIncrementalMarker, |
| 5311 | mode); |
| 5312 | InformIncrementalMarker(masm, mode); |
| 5313 | regs_.Restore(masm); |
| 5314 | __ ret(0); |
| 5315 | } |
| 5316 | |
| 5317 | |
| 5318 | void RecordWriteStub::InformIncrementalMarker(MacroAssembler* masm, Mode mode) { |
| 5319 | regs_.SaveCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 5320 | int argument_count = 3; |
| 5321 | __ PrepareCallCFunction(argument_count, regs_.scratch0()); |
| 5322 | __ mov(Operand(esp, 0 * kPointerSize), regs_.object()); |
ulan@chromium.org | 8e8d882 | 2012-11-23 14:36:46 +0000 | [diff] [blame] | 5323 | __ mov(Operand(esp, 1 * kPointerSize), regs_.address()); // Slot. |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5324 | __ mov(Operand(esp, 2 * kPointerSize), |
ulan@chromium.org | 32d7dba | 2013-04-24 10:59:06 +0000 | [diff] [blame] | 5325 | Immediate(ExternalReference::isolate_address(masm->isolate()))); |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5326 | |
| 5327 | AllowExternalCallThatCantCauseGC scope(masm); |
| 5328 | if (mode == INCREMENTAL_COMPACTION) { |
| 5329 | __ CallCFunction( |
| 5330 | ExternalReference::incremental_evacuation_record_write_function( |
| 5331 | masm->isolate()), |
| 5332 | argument_count); |
| 5333 | } else { |
| 5334 | ASSERT(mode == INCREMENTAL); |
| 5335 | __ CallCFunction( |
| 5336 | ExternalReference::incremental_marking_record_write_function( |
| 5337 | masm->isolate()), |
| 5338 | argument_count); |
| 5339 | } |
| 5340 | regs_.RestoreCallerSaveRegisters(masm, save_fp_regs_mode_); |
| 5341 | } |
| 5342 | |
| 5343 | |
| 5344 | void RecordWriteStub::CheckNeedsToInformIncrementalMarker( |
| 5345 | MacroAssembler* masm, |
| 5346 | OnNoNeedToInformIncrementalMarker on_no_need, |
| 5347 | Mode mode) { |
| 5348 | Label object_is_black, need_incremental, need_incremental_pop_object; |
| 5349 | |
verwaest@chromium.org | 33e09c8 | 2012-10-10 17:07:22 +0000 | [diff] [blame] | 5350 | __ mov(regs_.scratch0(), Immediate(~Page::kPageAlignmentMask)); |
| 5351 | __ and_(regs_.scratch0(), regs_.object()); |
| 5352 | __ mov(regs_.scratch1(), |
| 5353 | Operand(regs_.scratch0(), |
| 5354 | MemoryChunk::kWriteBarrierCounterOffset)); |
| 5355 | __ sub(regs_.scratch1(), Immediate(1)); |
| 5356 | __ mov(Operand(regs_.scratch0(), |
| 5357 | MemoryChunk::kWriteBarrierCounterOffset), |
| 5358 | regs_.scratch1()); |
| 5359 | __ j(negative, &need_incremental); |
| 5360 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 5361 | // Let's look at the color of the object: If it is not black we don't have |
| 5362 | // to inform the incremental marker. |
| 5363 | __ JumpIfBlack(regs_.object(), |
| 5364 | regs_.scratch0(), |
| 5365 | regs_.scratch1(), |
| 5366 | &object_is_black, |
| 5367 | Label::kNear); |
| 5368 | |
| 5369 | regs_.Restore(masm); |
| 5370 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 5371 | __ RememberedSetHelper(object_, |
| 5372 | address_, |
| 5373 | value_, |
| 5374 | save_fp_regs_mode_, |
| 5375 | MacroAssembler::kReturnAtEnd); |
| 5376 | } else { |
| 5377 | __ ret(0); |
| 5378 | } |
| 5379 | |
| 5380 | __ bind(&object_is_black); |
| 5381 | |
| 5382 | // Get the value from the slot. |
| 5383 | __ mov(regs_.scratch0(), Operand(regs_.address(), 0)); |
| 5384 | |
| 5385 | if (mode == INCREMENTAL_COMPACTION) { |
| 5386 | Label ensure_not_white; |
| 5387 | |
| 5388 | __ CheckPageFlag(regs_.scratch0(), // Contains value. |
| 5389 | regs_.scratch1(), // Scratch. |
| 5390 | MemoryChunk::kEvacuationCandidateMask, |
| 5391 | zero, |
| 5392 | &ensure_not_white, |
| 5393 | Label::kNear); |
| 5394 | |
| 5395 | __ CheckPageFlag(regs_.object(), |
| 5396 | regs_.scratch1(), // Scratch. |
| 5397 | MemoryChunk::kSkipEvacuationSlotsRecordingMask, |
| 5398 | not_zero, |
| 5399 | &ensure_not_white, |
| 5400 | Label::kNear); |
| 5401 | |
| 5402 | __ jmp(&need_incremental); |
| 5403 | |
| 5404 | __ bind(&ensure_not_white); |
| 5405 | } |
| 5406 | |
| 5407 | // We need an extra register for this, so we push the object register |
| 5408 | // temporarily. |
| 5409 | __ push(regs_.object()); |
| 5410 | __ EnsureNotWhite(regs_.scratch0(), // The value. |
| 5411 | regs_.scratch1(), // Scratch. |
| 5412 | regs_.object(), // Scratch. |
| 5413 | &need_incremental_pop_object, |
| 5414 | Label::kNear); |
| 5415 | __ pop(regs_.object()); |
| 5416 | |
| 5417 | regs_.Restore(masm); |
| 5418 | if (on_no_need == kUpdateRememberedSetOnNoNeedToInformIncrementalMarker) { |
| 5419 | __ RememberedSetHelper(object_, |
| 5420 | address_, |
| 5421 | value_, |
| 5422 | save_fp_regs_mode_, |
| 5423 | MacroAssembler::kReturnAtEnd); |
| 5424 | } else { |
| 5425 | __ ret(0); |
| 5426 | } |
| 5427 | |
| 5428 | __ bind(&need_incremental_pop_object); |
| 5429 | __ pop(regs_.object()); |
| 5430 | |
| 5431 | __ bind(&need_incremental); |
| 5432 | |
| 5433 | // Fall through when we need to inform the incremental marker. |
| 5434 | } |
| 5435 | |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5436 | |
| 5437 | void StoreArrayLiteralElementStub::Generate(MacroAssembler* masm) { |
| 5438 | // ----------- S t a t e ------------- |
| 5439 | // -- eax : element value to store |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5440 | // -- ecx : element index as smi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5441 | // -- esp[0] : return address |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 5442 | // -- esp[4] : array literal index in function |
| 5443 | // -- esp[8] : array literal |
| 5444 | // clobbers ebx, edx, edi |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5445 | // ----------------------------------- |
| 5446 | |
| 5447 | Label element_done; |
| 5448 | Label double_elements; |
| 5449 | Label smi_element; |
| 5450 | Label slow_elements; |
| 5451 | Label slow_elements_from_double; |
| 5452 | Label fast_elements; |
| 5453 | |
dslomov@chromium.org | b752d40 | 2013-06-18 11:54:54 +0000 | [diff] [blame] | 5454 | // Get array literal index, array literal and its map. |
| 5455 | __ mov(edx, Operand(esp, 1 * kPointerSize)); |
| 5456 | __ mov(ebx, Operand(esp, 2 * kPointerSize)); |
| 5457 | __ mov(edi, FieldOperand(ebx, JSObject::kMapOffset)); |
| 5458 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5459 | __ CheckFastElements(edi, &double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5460 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5461 | // Check for FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS elements |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5462 | __ JumpIfSmi(eax, &smi_element); |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5463 | __ CheckFastSmiElements(edi, &fast_elements, Label::kNear); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5464 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5465 | // Store into the array literal requires a elements transition. Call into |
| 5466 | // the runtime. |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5467 | |
| 5468 | __ bind(&slow_elements); |
| 5469 | __ pop(edi); // Pop return address and remember to put back later for tail |
| 5470 | // call. |
| 5471 | __ push(ebx); |
| 5472 | __ push(ecx); |
| 5473 | __ push(eax); |
| 5474 | __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
| 5475 | __ push(FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
| 5476 | __ push(edx); |
| 5477 | __ push(edi); // Return return address so that tail call returns to right |
| 5478 | // place. |
| 5479 | __ TailCallRuntime(Runtime::kStoreArrayLiteralElement, 5, 1); |
| 5480 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5481 | __ bind(&slow_elements_from_double); |
| 5482 | __ pop(edx); |
| 5483 | __ jmp(&slow_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5484 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5485 | // 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] | 5486 | __ bind(&fast_elements); |
| 5487 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 5488 | __ lea(ecx, FieldOperand(ebx, ecx, times_half_pointer_size, |
| 5489 | FixedArrayBase::kHeaderSize)); |
| 5490 | __ mov(Operand(ecx, 0), eax); |
| 5491 | // Update the write barrier for the array store. |
| 5492 | __ RecordWrite(ebx, ecx, eax, |
| 5493 | kDontSaveFPRegs, |
| 5494 | EMIT_REMEMBERED_SET, |
| 5495 | OMIT_SMI_CHECK); |
| 5496 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5497 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5498 | // Array literal has ElementsKind of FAST_*_SMI_ELEMENTS or FAST_*_ELEMENTS, |
| 5499 | // and value is Smi. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5500 | __ bind(&smi_element); |
| 5501 | __ mov(ebx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 5502 | __ mov(FieldOperand(ebx, ecx, times_half_pointer_size, |
| 5503 | FixedArrayBase::kHeaderSize), eax); |
| 5504 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5505 | |
svenpanne@chromium.org | 830d30c | 2012-05-29 13:20:14 +0000 | [diff] [blame] | 5506 | // Array literal has ElementsKind of FAST_*_DOUBLE_ELEMENTS. |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5507 | __ bind(&double_elements); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5508 | |
jkummerow@chromium.org | 04e4f1e | 2011-11-14 13:36:17 +0000 | [diff] [blame] | 5509 | __ push(edx); |
| 5510 | __ mov(edx, FieldOperand(ebx, JSObject::kElementsOffset)); |
| 5511 | __ StoreNumberToDoubleElements(eax, |
| 5512 | edx, |
| 5513 | ecx, |
| 5514 | edi, |
| 5515 | xmm0, |
| 5516 | &slow_elements_from_double, |
| 5517 | false); |
| 5518 | __ pop(edx); |
| 5519 | __ ret(0); |
jkummerow@chromium.org | c3b3712 | 2011-11-07 10:14:12 +0000 | [diff] [blame] | 5520 | } |
| 5521 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5522 | |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5523 | void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | e27d617 | 2013-04-17 11:51:44 +0000 | [diff] [blame] | 5524 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
hpayer@chromium.org | 8432c91 | 2013-02-28 15:55:26 +0000 | [diff] [blame] | 5525 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 5526 | int parameter_count_offset = |
| 5527 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 5528 | __ mov(ebx, MemOperand(ebp, parameter_count_offset)); |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5529 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 5530 | __ pop(ecx); |
mstarzinger@chromium.org | f705b50 | 2013-04-04 11:38:09 +0000 | [diff] [blame] | 5531 | int additional_offset = function_mode_ == JS_FUNCTION_STUB_MODE |
| 5532 | ? kPointerSize |
| 5533 | : 0; |
| 5534 | __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
mmassi@chromium.org | 2f0efde | 2013-02-06 14:12:58 +0000 | [diff] [blame] | 5535 | __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
mstarzinger@chromium.org | 068ea0a | 2013-01-30 09:39:44 +0000 | [diff] [blame] | 5536 | } |
| 5537 | |
| 5538 | |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5539 | void StubFailureTailCallTrampolineStub::Generate(MacroAssembler* masm) { |
| 5540 | CEntryStub ces(1, fp_registers_ ? kSaveFPRegs : kDontSaveFPRegs); |
| 5541 | __ call(ces.GetCode(masm->isolate()), RelocInfo::CODE_TARGET); |
| 5542 | __ mov(edi, eax); |
| 5543 | int parameter_count_offset = |
| 5544 | StubFailureTrampolineFrame::kCallerStackParameterCountFrameOffset; |
| 5545 | __ mov(eax, MemOperand(ebp, parameter_count_offset)); |
| 5546 | // The parameter count above includes the receiver for the arguments passed to |
| 5547 | // the deoptimization handler. Subtract the receiver for the parameter count |
| 5548 | // for the call. |
| 5549 | __ sub(eax, Immediate(1)); |
| 5550 | masm->LeaveFrame(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 5551 | ParameterCount argument_count(eax); |
machenbach@chromium.org | e31286d | 2014-01-15 10:29:52 +0000 | [diff] [blame] | 5552 | __ InvokeFunction(edi, argument_count, JUMP_FUNCTION, NullCallWrapper()); |
machenbach@chromium.org | ea46888 | 2013-11-18 08:53:19 +0000 | [diff] [blame] | 5553 | } |
| 5554 | |
| 5555 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5556 | void ProfileEntryHookStub::MaybeCallEntryHook(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5557 | if (masm->isolate()->function_entry_hook() != NULL) { |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5558 | ProfileEntryHookStub stub; |
| 5559 | masm->CallStub(&stub); |
| 5560 | } |
| 5561 | } |
| 5562 | |
| 5563 | |
| 5564 | void ProfileEntryHookStub::Generate(MacroAssembler* masm) { |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5565 | // Save volatile registers. |
| 5566 | const int kNumSavedRegisters = 3; |
| 5567 | __ push(eax); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5568 | __ push(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5569 | __ push(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5570 | |
| 5571 | // Calculate and push the original stack pointer. |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 5572 | __ lea(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5573 | __ push(eax); |
| 5574 | |
ulan@chromium.org | dfe5307 | 2013-06-06 14:14:51 +0000 | [diff] [blame] | 5575 | // Retrieve our return address and use it to calculate the calling |
| 5576 | // function's address. |
| 5577 | __ mov(eax, Operand(esp, (kNumSavedRegisters + 1) * kPointerSize)); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5578 | __ sub(eax, Immediate(Assembler::kCallInstructionLength)); |
| 5579 | __ push(eax); |
| 5580 | |
| 5581 | // Call the entry hook. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5582 | ASSERT(masm->isolate()->function_entry_hook() != NULL); |
| 5583 | __ call(FUNCTION_ADDR(masm->isolate()->function_entry_hook()), |
| 5584 | RelocInfo::RUNTIME_ENTRY); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5585 | __ add(esp, Immediate(2 * kPointerSize)); |
| 5586 | |
| 5587 | // Restore ecx. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5588 | __ pop(edx); |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5589 | __ pop(ecx); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5590 | __ pop(eax); |
| 5591 | |
verwaest@chromium.org | 753aee4 | 2012-07-17 16:15:42 +0000 | [diff] [blame] | 5592 | __ ret(0); |
| 5593 | } |
| 5594 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5595 | |
| 5596 | template<class T> |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5597 | static void CreateArrayDispatch(MacroAssembler* masm, |
| 5598 | AllocationSiteOverrideMode mode) { |
| 5599 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 5600 | T stub(GetInitialFastElementsKind(), |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5601 | mode); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5602 | __ TailCallStub(&stub); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5603 | } else if (mode == DONT_OVERRIDE) { |
| 5604 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 5605 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5606 | for (int i = 0; i <= last_index; ++i) { |
| 5607 | Label next; |
| 5608 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 5609 | __ cmp(edx, kind); |
| 5610 | __ j(not_equal, &next); |
| 5611 | T stub(kind); |
| 5612 | __ TailCallStub(&stub); |
| 5613 | __ bind(&next); |
| 5614 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5615 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5616 | // If we reached this point there is a problem. |
| 5617 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 5618 | } else { |
| 5619 | UNREACHABLE(); |
| 5620 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5621 | } |
| 5622 | |
| 5623 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5624 | static void CreateArrayDispatchOneArgument(MacroAssembler* masm, |
| 5625 | AllocationSiteOverrideMode mode) { |
| 5626 | // ebx - type info cell (if mode != DISABLE_ALLOCATION_SITES) |
| 5627 | // edx - kind (if mode != DISABLE_ALLOCATION_SITES) |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5628 | // eax - number of arguments |
| 5629 | // edi - constructor? |
| 5630 | // esp[0] - return address |
| 5631 | // esp[4] - last argument |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5632 | Label normal_sequence; |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5633 | if (mode == DONT_OVERRIDE) { |
| 5634 | ASSERT(FAST_SMI_ELEMENTS == 0); |
| 5635 | ASSERT(FAST_HOLEY_SMI_ELEMENTS == 1); |
| 5636 | ASSERT(FAST_ELEMENTS == 2); |
| 5637 | ASSERT(FAST_HOLEY_ELEMENTS == 3); |
| 5638 | ASSERT(FAST_DOUBLE_ELEMENTS == 4); |
| 5639 | ASSERT(FAST_HOLEY_DOUBLE_ELEMENTS == 5); |
| 5640 | |
| 5641 | // is the low bit set? If so, we are holey and that is good. |
| 5642 | __ test_b(edx, 1); |
| 5643 | __ j(not_zero, &normal_sequence); |
| 5644 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5645 | |
| 5646 | // look at the first argument |
| 5647 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 5648 | __ test(ecx, ecx); |
| 5649 | __ j(zero, &normal_sequence); |
| 5650 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5651 | if (mode == DISABLE_ALLOCATION_SITES) { |
| 5652 | ElementsKind initial = GetInitialFastElementsKind(); |
| 5653 | ElementsKind holey_initial = GetHoleyElementsKind(initial); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5654 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5655 | ArraySingleArgumentConstructorStub stub_holey(holey_initial, |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5656 | DISABLE_ALLOCATION_SITES); |
| 5657 | __ TailCallStub(&stub_holey); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5658 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5659 | __ bind(&normal_sequence); |
| 5660 | ArraySingleArgumentConstructorStub stub(initial, |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5661 | DISABLE_ALLOCATION_SITES); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5662 | __ TailCallStub(&stub); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5663 | } else if (mode == DONT_OVERRIDE) { |
| 5664 | // We are going to create a holey array, but our kind is non-holey. |
| 5665 | // Fix kind and retry. |
| 5666 | __ inc(edx); |
| 5667 | __ mov(ecx, FieldOperand(ebx, Cell::kValueOffset)); |
| 5668 | if (FLAG_debug_code) { |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5669 | Handle<Map> allocation_site_map = |
| 5670 | masm->isolate()->factory()->allocation_site_map(); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5671 | __ cmp(FieldOperand(ecx, 0), Immediate(allocation_site_map)); |
| 5672 | __ Assert(equal, kExpectedAllocationSiteInCell); |
| 5673 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5674 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5675 | // Save the resulting elements kind in type info. We can't just store r3 |
| 5676 | // in the AllocationSite::transition_info field because elements kind is |
| 5677 | // restricted to a portion of the field...upper bits need to be left alone. |
| 5678 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 5679 | __ add(FieldOperand(ecx, AllocationSite::kTransitionInfoOffset), |
| 5680 | Immediate(Smi::FromInt(kFastElementsKindPackedToHoley))); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5681 | |
| 5682 | __ bind(&normal_sequence); |
| 5683 | int last_index = GetSequenceIndexFromFastElementsKind( |
| 5684 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5685 | for (int i = 0; i <= last_index; ++i) { |
| 5686 | Label next; |
| 5687 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
| 5688 | __ cmp(edx, kind); |
| 5689 | __ j(not_equal, &next); |
| 5690 | ArraySingleArgumentConstructorStub stub(kind); |
| 5691 | __ TailCallStub(&stub); |
| 5692 | __ bind(&next); |
| 5693 | } |
| 5694 | |
| 5695 | // If we reached this point there is a problem. |
| 5696 | __ Abort(kUnexpectedElementsKindInArrayConstructor); |
| 5697 | } else { |
| 5698 | UNREACHABLE(); |
| 5699 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5700 | } |
| 5701 | |
| 5702 | |
| 5703 | template<class T> |
| 5704 | static void ArrayConstructorStubAheadOfTimeHelper(Isolate* isolate) { |
| 5705 | int to_index = GetSequenceIndexFromFastElementsKind( |
| 5706 | TERMINAL_FAST_ELEMENTS_KIND); |
| 5707 | for (int i = 0; i <= to_index; ++i) { |
| 5708 | ElementsKind kind = GetFastElementsKindFromSequenceIndex(i); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5709 | T stub(kind); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5710 | stub.GetCode(isolate); |
ulan@chromium.org | 9cbaabd | 2014-01-08 10:55:36 +0000 | [diff] [blame] | 5711 | if (AllocationSite::GetMode(kind) != DONT_TRACK_ALLOCATION_SITE) { |
machenbach@chromium.org | 0345396 | 2014-01-10 14:16:31 +0000 | [diff] [blame] | 5712 | T stub1(kind, DISABLE_ALLOCATION_SITES); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5713 | stub1.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5714 | } |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5715 | } |
| 5716 | } |
| 5717 | |
| 5718 | |
| 5719 | void ArrayConstructorStubBase::GenerateStubsAheadOfTime(Isolate* isolate) { |
| 5720 | ArrayConstructorStubAheadOfTimeHelper<ArrayNoArgumentConstructorStub>( |
| 5721 | isolate); |
| 5722 | ArrayConstructorStubAheadOfTimeHelper<ArraySingleArgumentConstructorStub>( |
| 5723 | isolate); |
| 5724 | ArrayConstructorStubAheadOfTimeHelper<ArrayNArgumentsConstructorStub>( |
| 5725 | isolate); |
| 5726 | } |
| 5727 | |
| 5728 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5729 | void InternalArrayConstructorStubBase::GenerateStubsAheadOfTime( |
| 5730 | Isolate* isolate) { |
| 5731 | ElementsKind kinds[2] = { FAST_ELEMENTS, FAST_HOLEY_ELEMENTS }; |
| 5732 | for (int i = 0; i < 2; i++) { |
| 5733 | // For internal arrays we only need a few things |
| 5734 | InternalArrayNoArgumentConstructorStub stubh1(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5735 | stubh1.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5736 | InternalArraySingleArgumentConstructorStub stubh2(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5737 | stubh2.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5738 | InternalArrayNArgumentsConstructorStub stubh3(kinds[i]); |
machenbach@chromium.org | 8a58f64 | 2013-12-02 10:46:30 +0000 | [diff] [blame] | 5739 | stubh3.GetCode(isolate); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5740 | } |
| 5741 | } |
| 5742 | |
| 5743 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5744 | void ArrayConstructorStub::GenerateDispatchToArrayStub( |
| 5745 | MacroAssembler* masm, |
| 5746 | AllocationSiteOverrideMode mode) { |
| 5747 | if (argument_count_ == ANY) { |
| 5748 | Label not_zero_case, not_one_case; |
| 5749 | __ test(eax, eax); |
| 5750 | __ j(not_zero, ¬_zero_case); |
| 5751 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 5752 | |
| 5753 | __ bind(¬_zero_case); |
| 5754 | __ cmp(eax, 1); |
| 5755 | __ j(greater, ¬_one_case); |
| 5756 | CreateArrayDispatchOneArgument(masm, mode); |
| 5757 | |
| 5758 | __ bind(¬_one_case); |
| 5759 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 5760 | } else if (argument_count_ == NONE) { |
| 5761 | CreateArrayDispatch<ArrayNoArgumentConstructorStub>(masm, mode); |
| 5762 | } else if (argument_count_ == ONE) { |
| 5763 | CreateArrayDispatchOneArgument(masm, mode); |
| 5764 | } else if (argument_count_ == MORE_THAN_ONE) { |
| 5765 | CreateArrayDispatch<ArrayNArgumentsConstructorStub>(masm, mode); |
| 5766 | } else { |
| 5767 | UNREACHABLE(); |
| 5768 | } |
| 5769 | } |
| 5770 | |
| 5771 | |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5772 | void ArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 5773 | // ----------- S t a t e ------------- |
| 5774 | // -- eax : argc (only if argument_count_ == ANY) |
| 5775 | // -- ebx : type info cell |
| 5776 | // -- edi : constructor |
| 5777 | // -- esp[0] : return address |
| 5778 | // -- esp[4] : last argument |
| 5779 | // ----------------------------------- |
| 5780 | Handle<Object> undefined_sentinel( |
| 5781 | masm->isolate()->heap()->undefined_value(), |
| 5782 | masm->isolate()); |
| 5783 | |
| 5784 | if (FLAG_debug_code) { |
| 5785 | // The array construct code is only set for the global and natives |
| 5786 | // builtin Array functions which always have maps. |
| 5787 | |
| 5788 | // Initial map for the builtin Array function should be a map. |
| 5789 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5790 | // Will both indicate a NULL and a Smi. |
| 5791 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5792 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5793 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5794 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5795 | |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5796 | // We should either have undefined in ebx or a valid cell |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5797 | Label okay_here; |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5798 | Handle<Map> cell_map = masm->isolate()->factory()->cell_map(); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5799 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 5800 | __ j(equal, &okay_here); |
danno@chromium.org | 4172848 | 2013-06-12 22:31:22 +0000 | [diff] [blame] | 5801 | __ cmp(FieldOperand(ebx, 0), Immediate(cell_map)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5802 | __ Assert(equal, kExpectedPropertyCellInRegisterEbx); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5803 | __ bind(&okay_here); |
| 5804 | } |
| 5805 | |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5806 | Label no_info; |
| 5807 | // If the type cell is undefined, or contains anything other than an |
| 5808 | // AllocationSite, call an array constructor that doesn't use AllocationSites. |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5809 | __ cmp(ebx, Immediate(undefined_sentinel)); |
| 5810 | __ j(equal, &no_info); |
| 5811 | __ mov(edx, FieldOperand(ebx, Cell::kValueOffset)); |
machenbach@chromium.org | 528ce02 | 2013-09-23 14:09:36 +0000 | [diff] [blame] | 5812 | __ cmp(FieldOperand(edx, 0), Immediate( |
| 5813 | masm->isolate()->factory()->allocation_site_map())); |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 5814 | __ j(not_equal, &no_info); |
| 5815 | |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5816 | // Only look at the lower 16 bits of the transition info. |
danno@chromium.org | bee5199 | 2013-07-10 14:57:15 +0000 | [diff] [blame] | 5817 | __ mov(edx, FieldOperand(edx, AllocationSite::kTransitionInfoOffset)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5818 | __ SmiUntag(edx); |
machenbach@chromium.org | b5be0a9 | 2013-11-15 10:32:41 +0000 | [diff] [blame] | 5819 | STATIC_ASSERT(AllocationSite::ElementsKindBits::kShift == 0); |
| 5820 | __ and_(edx, Immediate(AllocationSite::ElementsKindBits::kMask)); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5821 | GenerateDispatchToArrayStub(masm, DONT_OVERRIDE); |
| 5822 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5823 | __ bind(&no_info); |
dslomov@chromium.org | 4a35c5a | 2013-09-13 07:28:52 +0000 | [diff] [blame] | 5824 | GenerateDispatchToArrayStub(masm, DISABLE_ALLOCATION_SITES); |
danno@chromium.org | ca29dd8 | 2013-04-26 11:59:48 +0000 | [diff] [blame] | 5825 | } |
| 5826 | |
| 5827 | |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5828 | void InternalArrayConstructorStub::GenerateCase( |
| 5829 | MacroAssembler* masm, ElementsKind kind) { |
| 5830 | Label not_zero_case, not_one_case; |
| 5831 | Label normal_sequence; |
| 5832 | |
| 5833 | __ test(eax, eax); |
| 5834 | __ j(not_zero, ¬_zero_case); |
| 5835 | InternalArrayNoArgumentConstructorStub stub0(kind); |
| 5836 | __ TailCallStub(&stub0); |
| 5837 | |
| 5838 | __ bind(¬_zero_case); |
| 5839 | __ cmp(eax, 1); |
| 5840 | __ j(greater, ¬_one_case); |
| 5841 | |
| 5842 | if (IsFastPackedElementsKind(kind)) { |
| 5843 | // We might need to create a holey array |
| 5844 | // look at the first argument |
| 5845 | __ mov(ecx, Operand(esp, kPointerSize)); |
| 5846 | __ test(ecx, ecx); |
| 5847 | __ j(zero, &normal_sequence); |
| 5848 | |
| 5849 | InternalArraySingleArgumentConstructorStub |
| 5850 | stub1_holey(GetHoleyElementsKind(kind)); |
| 5851 | __ TailCallStub(&stub1_holey); |
| 5852 | } |
| 5853 | |
| 5854 | __ bind(&normal_sequence); |
| 5855 | InternalArraySingleArgumentConstructorStub stub1(kind); |
| 5856 | __ TailCallStub(&stub1); |
| 5857 | |
| 5858 | __ bind(¬_one_case); |
| 5859 | InternalArrayNArgumentsConstructorStub stubN(kind); |
| 5860 | __ TailCallStub(&stubN); |
| 5861 | } |
| 5862 | |
| 5863 | |
| 5864 | void InternalArrayConstructorStub::Generate(MacroAssembler* masm) { |
| 5865 | // ----------- S t a t e ------------- |
| 5866 | // -- eax : argc |
| 5867 | // -- ebx : type info cell |
| 5868 | // -- edi : constructor |
| 5869 | // -- esp[0] : return address |
| 5870 | // -- esp[4] : last argument |
| 5871 | // ----------------------------------- |
| 5872 | |
| 5873 | if (FLAG_debug_code) { |
| 5874 | // The array construct code is only set for the global and natives |
| 5875 | // builtin Array functions which always have maps. |
| 5876 | |
| 5877 | // Initial map for the builtin Array function should be a map. |
| 5878 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5879 | // Will both indicate a NULL and a Smi. |
| 5880 | __ test(ecx, Immediate(kSmiTagMask)); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5881 | __ Assert(not_zero, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5882 | __ CmpObjectType(ecx, MAP_TYPE, ecx); |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5883 | __ Assert(equal, kUnexpectedInitialMapForArrayFunction); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5884 | } |
| 5885 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5886 | // Figure out the right elements kind |
| 5887 | __ mov(ecx, FieldOperand(edi, JSFunction::kPrototypeOrInitialMapOffset)); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5888 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5889 | // Load the map's "bit field 2" into |result|. We only need the first byte, |
| 5890 | // but the following masking takes care of that anyway. |
| 5891 | __ mov(ecx, FieldOperand(ecx, Map::kBitField2Offset)); |
| 5892 | // Retrieve elements_kind from bit field 2. |
| 5893 | __ and_(ecx, Map::kElementsKindMask); |
| 5894 | __ shr(ecx, Map::kElementsKindShift); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5895 | |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5896 | if (FLAG_debug_code) { |
| 5897 | Label done; |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5898 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5899 | __ j(equal, &done); |
| 5900 | __ cmp(ecx, Immediate(FAST_HOLEY_ELEMENTS)); |
| 5901 | __ Assert(equal, |
danno@chromium.org | 5940060 | 2013-08-13 17:09:37 +0000 | [diff] [blame] | 5902 | kInvalidElementsKindForInternalArrayOrInternalPackedArray); |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5903 | __ bind(&done); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5904 | } |
mstarzinger@chromium.org | 1510d58 | 2013-06-28 14:00:48 +0000 | [diff] [blame] | 5905 | |
| 5906 | Label fast_elements_case; |
| 5907 | __ cmp(ecx, Immediate(FAST_ELEMENTS)); |
| 5908 | __ j(equal, &fast_elements_case); |
| 5909 | GenerateCase(masm, FAST_HOLEY_ELEMENTS); |
| 5910 | |
| 5911 | __ bind(&fast_elements_case); |
| 5912 | GenerateCase(masm, FAST_ELEMENTS); |
verwaest@chromium.org | d4be0f0 | 2013-06-05 13:39:03 +0000 | [diff] [blame] | 5913 | } |
| 5914 | |
| 5915 | |
ricow@chromium.org | 65fae84 | 2010-08-25 15:26:24 +0000 | [diff] [blame] | 5916 | #undef __ |
| 5917 | |
| 5918 | } } // namespace v8::internal |
| 5919 | |
| 5920 | #endif // V8_TARGET_ARCH_IA32 |