Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [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 | |
| 30 | #if defined(V8_TARGET_ARCH_ARM) |
| 31 | |
| 32 | #include "bootstrapper.h" |
| 33 | #include "code-stubs.h" |
| 34 | #include "regexp-macro-assembler.h" |
| 35 | |
| 36 | namespace v8 { |
| 37 | namespace internal { |
| 38 | |
| 39 | |
| 40 | #define __ ACCESS_MASM(masm) |
| 41 | |
| 42 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
| 43 | Label* slow, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 44 | Condition cond, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 45 | bool never_nan_nan); |
| 46 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 47 | Register lhs, |
| 48 | Register rhs, |
| 49 | Label* lhs_not_nan, |
| 50 | Label* slow, |
| 51 | bool strict); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 52 | static void EmitTwoNonNanDoubleComparison(MacroAssembler* masm, Condition cond); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 53 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 54 | Register lhs, |
| 55 | Register rhs); |
| 56 | |
| 57 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 58 | // Check if the operand is a heap number. |
| 59 | static void EmitCheckForHeapNumber(MacroAssembler* masm, Register operand, |
| 60 | Register scratch1, Register scratch2, |
| 61 | Label* not_a_heap_number) { |
| 62 | __ ldr(scratch1, FieldMemOperand(operand, HeapObject::kMapOffset)); |
| 63 | __ LoadRoot(scratch2, Heap::kHeapNumberMapRootIndex); |
| 64 | __ cmp(scratch1, scratch2); |
| 65 | __ b(ne, not_a_heap_number); |
| 66 | } |
| 67 | |
| 68 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 69 | void ToNumberStub::Generate(MacroAssembler* masm) { |
| 70 | // The ToNumber stub takes one argument in eax. |
| 71 | Label check_heap_number, call_builtin; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 72 | __ JumpIfNotSmi(r0, &check_heap_number); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 73 | __ Ret(); |
| 74 | |
| 75 | __ bind(&check_heap_number); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 76 | EmitCheckForHeapNumber(masm, r0, r1, ip, &call_builtin); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 77 | __ Ret(); |
| 78 | |
| 79 | __ bind(&call_builtin); |
| 80 | __ push(r0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 81 | __ InvokeBuiltin(Builtins::TO_NUMBER, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 85 | void FastNewClosureStub::Generate(MacroAssembler* masm) { |
| 86 | // Create a new closure from the given function info in new |
| 87 | // space. Set the context to the current context in cp. |
| 88 | Label gc; |
| 89 | |
| 90 | // Pop the function info from the stack. |
| 91 | __ pop(r3); |
| 92 | |
| 93 | // Attempt to allocate new JSFunction in new space. |
| 94 | __ AllocateInNewSpace(JSFunction::kSize, |
| 95 | r0, |
| 96 | r1, |
| 97 | r2, |
| 98 | &gc, |
| 99 | TAG_OBJECT); |
| 100 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 101 | int map_index = strict_mode_ == kStrictMode |
| 102 | ? Context::STRICT_MODE_FUNCTION_MAP_INDEX |
| 103 | : Context::FUNCTION_MAP_INDEX; |
| 104 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 105 | // Compute the function map in the current global context and set that |
| 106 | // as the map of the allocated object. |
| 107 | __ ldr(r2, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 108 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalContextOffset)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 109 | __ ldr(r2, MemOperand(r2, Context::SlotOffset(map_index))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 110 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 111 | |
| 112 | // Initialize the rest of the function. We don't have to update the |
| 113 | // write barrier because the allocated object is in new space. |
| 114 | __ LoadRoot(r1, Heap::kEmptyFixedArrayRootIndex); |
| 115 | __ LoadRoot(r2, Heap::kTheHoleValueRootIndex); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 116 | __ LoadRoot(r4, Heap::kUndefinedValueRootIndex); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 117 | __ str(r1, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 118 | __ str(r1, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 119 | __ str(r2, FieldMemOperand(r0, JSFunction::kPrototypeOrInitialMapOffset)); |
| 120 | __ str(r3, FieldMemOperand(r0, JSFunction::kSharedFunctionInfoOffset)); |
| 121 | __ str(cp, FieldMemOperand(r0, JSFunction::kContextOffset)); |
| 122 | __ str(r1, FieldMemOperand(r0, JSFunction::kLiteralsOffset)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 123 | __ str(r4, FieldMemOperand(r0, JSFunction::kNextFunctionLinkOffset)); |
| 124 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 125 | |
| 126 | // Initialize the code pointer in the function to be the one |
| 127 | // found in the shared function info object. |
| 128 | __ ldr(r3, FieldMemOperand(r3, SharedFunctionInfo::kCodeOffset)); |
| 129 | __ add(r3, r3, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 130 | __ str(r3, FieldMemOperand(r0, JSFunction::kCodeEntryOffset)); |
| 131 | |
| 132 | // Return result. The argument function info has been popped already. |
| 133 | __ Ret(); |
| 134 | |
| 135 | // Create a new closure through the slower runtime call. |
| 136 | __ bind(&gc); |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 137 | __ LoadRoot(r4, Heap::kFalseValueRootIndex); |
| 138 | __ Push(cp, r3, r4); |
| 139 | __ TailCallRuntime(Runtime::kNewClosure, 3, 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | |
| 143 | void FastNewContextStub::Generate(MacroAssembler* masm) { |
| 144 | // Try to allocate the context in new space. |
| 145 | Label gc; |
| 146 | int length = slots_ + Context::MIN_CONTEXT_SLOTS; |
| 147 | |
| 148 | // Attempt to allocate the context in new space. |
| 149 | __ AllocateInNewSpace(FixedArray::SizeFor(length), |
| 150 | r0, |
| 151 | r1, |
| 152 | r2, |
| 153 | &gc, |
| 154 | TAG_OBJECT); |
| 155 | |
| 156 | // Load the function from the stack. |
| 157 | __ ldr(r3, MemOperand(sp, 0)); |
| 158 | |
| 159 | // Setup the object header. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 160 | __ LoadRoot(r2, Heap::kFunctionContextMapRootIndex); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 161 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 162 | __ mov(r2, Operand(Smi::FromInt(length))); |
| 163 | __ str(r2, FieldMemOperand(r0, FixedArray::kLengthOffset)); |
| 164 | |
| 165 | // Setup the fixed slots. |
| 166 | __ mov(r1, Operand(Smi::FromInt(0))); |
| 167 | __ str(r3, MemOperand(r0, Context::SlotOffset(Context::CLOSURE_INDEX))); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 168 | __ str(cp, MemOperand(r0, Context::SlotOffset(Context::PREVIOUS_INDEX))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 169 | __ str(r1, MemOperand(r0, Context::SlotOffset(Context::EXTENSION_INDEX))); |
| 170 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 171 | // Copy the global object from the previous context. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 172 | __ ldr(r1, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 173 | __ str(r1, MemOperand(r0, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 174 | |
| 175 | // Initialize the rest of the slots to undefined. |
| 176 | __ LoadRoot(r1, Heap::kUndefinedValueRootIndex); |
| 177 | for (int i = Context::MIN_CONTEXT_SLOTS; i < length; i++) { |
| 178 | __ str(r1, MemOperand(r0, Context::SlotOffset(i))); |
| 179 | } |
| 180 | |
| 181 | // Remove the on-stack argument and return. |
| 182 | __ mov(cp, r0); |
| 183 | __ pop(); |
| 184 | __ Ret(); |
| 185 | |
| 186 | // Need to collect. Call into runtime system. |
| 187 | __ bind(&gc); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 188 | __ TailCallRuntime(Runtime::kNewFunctionContext, 1, 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | |
| 192 | void FastCloneShallowArrayStub::Generate(MacroAssembler* masm) { |
| 193 | // Stack layout on entry: |
| 194 | // |
| 195 | // [sp]: constant elements. |
| 196 | // [sp + kPointerSize]: literal index. |
| 197 | // [sp + (2 * kPointerSize)]: literals array. |
| 198 | |
| 199 | // All sizes here are multiples of kPointerSize. |
| 200 | int elements_size = (length_ > 0) ? FixedArray::SizeFor(length_) : 0; |
| 201 | int size = JSArray::kSize + elements_size; |
| 202 | |
| 203 | // Load boilerplate object into r3 and check if we need to create a |
| 204 | // boilerplate. |
| 205 | Label slow_case; |
| 206 | __ ldr(r3, MemOperand(sp, 2 * kPointerSize)); |
| 207 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); |
| 208 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 209 | __ ldr(r3, MemOperand(r3, r0, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 210 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 211 | __ cmp(r3, ip); |
| 212 | __ b(eq, &slow_case); |
| 213 | |
| 214 | if (FLAG_debug_code) { |
| 215 | const char* message; |
| 216 | Heap::RootListIndex expected_map_index; |
| 217 | if (mode_ == CLONE_ELEMENTS) { |
| 218 | message = "Expected (writable) fixed array"; |
| 219 | expected_map_index = Heap::kFixedArrayMapRootIndex; |
| 220 | } else { |
| 221 | ASSERT(mode_ == COPY_ON_WRITE_ELEMENTS); |
| 222 | message = "Expected copy-on-write fixed array"; |
| 223 | expected_map_index = Heap::kFixedCOWArrayMapRootIndex; |
| 224 | } |
| 225 | __ push(r3); |
| 226 | __ ldr(r3, FieldMemOperand(r3, JSArray::kElementsOffset)); |
| 227 | __ ldr(r3, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 228 | __ LoadRoot(ip, expected_map_index); |
| 229 | __ cmp(r3, ip); |
| 230 | __ Assert(eq, message); |
| 231 | __ pop(r3); |
| 232 | } |
| 233 | |
| 234 | // Allocate both the JS array and the elements array in one big |
| 235 | // allocation. This avoids multiple limit checks. |
| 236 | __ AllocateInNewSpace(size, |
| 237 | r0, |
| 238 | r1, |
| 239 | r2, |
| 240 | &slow_case, |
| 241 | TAG_OBJECT); |
| 242 | |
| 243 | // Copy the JS array part. |
| 244 | for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
| 245 | if ((i != JSArray::kElementsOffset) || (length_ == 0)) { |
| 246 | __ ldr(r1, FieldMemOperand(r3, i)); |
| 247 | __ str(r1, FieldMemOperand(r0, i)); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | if (length_ > 0) { |
| 252 | // Get hold of the elements array of the boilerplate and setup the |
| 253 | // elements pointer in the resulting object. |
| 254 | __ ldr(r3, FieldMemOperand(r3, JSArray::kElementsOffset)); |
| 255 | __ add(r2, r0, Operand(JSArray::kSize)); |
| 256 | __ str(r2, FieldMemOperand(r0, JSArray::kElementsOffset)); |
| 257 | |
| 258 | // Copy the elements array. |
| 259 | __ CopyFields(r2, r3, r1.bit(), elements_size / kPointerSize); |
| 260 | } |
| 261 | |
| 262 | // Return and remove the on-stack parameters. |
| 263 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 264 | __ Ret(); |
| 265 | |
| 266 | __ bind(&slow_case); |
| 267 | __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
| 268 | } |
| 269 | |
| 270 | |
| 271 | // Takes a Smi and converts to an IEEE 64 bit floating point value in two |
| 272 | // registers. The format is 1 sign bit, 11 exponent bits (biased 1023) and |
| 273 | // 52 fraction bits (20 in the first word, 32 in the second). Zeros is a |
| 274 | // scratch register. Destroys the source register. No GC occurs during this |
| 275 | // stub so you don't have to set up the frame. |
| 276 | class ConvertToDoubleStub : public CodeStub { |
| 277 | public: |
| 278 | ConvertToDoubleStub(Register result_reg_1, |
| 279 | Register result_reg_2, |
| 280 | Register source_reg, |
| 281 | Register scratch_reg) |
| 282 | : result1_(result_reg_1), |
| 283 | result2_(result_reg_2), |
| 284 | source_(source_reg), |
| 285 | zeros_(scratch_reg) { } |
| 286 | |
| 287 | private: |
| 288 | Register result1_; |
| 289 | Register result2_; |
| 290 | Register source_; |
| 291 | Register zeros_; |
| 292 | |
| 293 | // Minor key encoding in 16 bits. |
| 294 | class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
| 295 | class OpBits: public BitField<Token::Value, 2, 14> {}; |
| 296 | |
| 297 | Major MajorKey() { return ConvertToDouble; } |
| 298 | int MinorKey() { |
| 299 | // Encode the parameters in a unique 16 bit value. |
| 300 | return result1_.code() + |
| 301 | (result2_.code() << 4) + |
| 302 | (source_.code() << 8) + |
| 303 | (zeros_.code() << 12); |
| 304 | } |
| 305 | |
| 306 | void Generate(MacroAssembler* masm); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 307 | }; |
| 308 | |
| 309 | |
| 310 | void ConvertToDoubleStub::Generate(MacroAssembler* masm) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 311 | Register exponent = result1_; |
| 312 | Register mantissa = result2_; |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 313 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 314 | Label not_special; |
| 315 | // Convert from Smi to integer. |
| 316 | __ mov(source_, Operand(source_, ASR, kSmiTagSize)); |
| 317 | // Move sign bit from source to destination. This works because the sign bit |
| 318 | // in the exponent word of the double has the same position and polarity as |
| 319 | // the 2's complement sign bit in a Smi. |
| 320 | STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
| 321 | __ and_(exponent, source_, Operand(HeapNumber::kSignMask), SetCC); |
| 322 | // Subtract from 0 if source was negative. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 323 | __ rsb(source_, source_, Operand(0, RelocInfo::NONE), LeaveCC, ne); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 324 | |
| 325 | // We have -1, 0 or 1, which we treat specially. Register source_ contains |
| 326 | // absolute value: it is either equal to 1 (special case of -1 and 1), |
| 327 | // greater than 1 (not a special case) or less than 1 (special case of 0). |
| 328 | __ cmp(source_, Operand(1)); |
| 329 | __ b(gt, ¬_special); |
| 330 | |
| 331 | // For 1 or -1 we need to or in the 0 exponent (biased to 1023). |
| 332 | static const uint32_t exponent_word_for_1 = |
| 333 | HeapNumber::kExponentBias << HeapNumber::kExponentShift; |
| 334 | __ orr(exponent, exponent, Operand(exponent_word_for_1), LeaveCC, eq); |
| 335 | // 1, 0 and -1 all have 0 for the second word. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 336 | __ mov(mantissa, Operand(0, RelocInfo::NONE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 337 | __ Ret(); |
| 338 | |
| 339 | __ bind(¬_special); |
| 340 | // Count leading zeros. Uses mantissa for a scratch register on pre-ARM5. |
| 341 | // Gets the wrong answer for 0, but we already checked for that case above. |
| 342 | __ CountLeadingZeros(zeros_, source_, mantissa); |
| 343 | // Compute exponent and or it into the exponent register. |
| 344 | // We use mantissa as a scratch register here. Use a fudge factor to |
| 345 | // divide the constant 31 + HeapNumber::kExponentBias, 0x41d, into two parts |
| 346 | // that fit in the ARM's constant field. |
| 347 | int fudge = 0x400; |
| 348 | __ rsb(mantissa, zeros_, Operand(31 + HeapNumber::kExponentBias - fudge)); |
| 349 | __ add(mantissa, mantissa, Operand(fudge)); |
| 350 | __ orr(exponent, |
| 351 | exponent, |
| 352 | Operand(mantissa, LSL, HeapNumber::kExponentShift)); |
| 353 | // Shift up the source chopping the top bit off. |
| 354 | __ add(zeros_, zeros_, Operand(1)); |
| 355 | // This wouldn't work for 1.0 or -1.0 as the shift would be 32 which means 0. |
| 356 | __ mov(source_, Operand(source_, LSL, zeros_)); |
| 357 | // Compute lower part of fraction (last 12 bits). |
| 358 | __ mov(mantissa, Operand(source_, LSL, HeapNumber::kMantissaBitsInTopWord)); |
| 359 | // And the top (top 20 bits). |
| 360 | __ orr(exponent, |
| 361 | exponent, |
| 362 | Operand(source_, LSR, 32 - HeapNumber::kMantissaBitsInTopWord)); |
| 363 | __ Ret(); |
| 364 | } |
| 365 | |
| 366 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 367 | void FloatingPointHelper::LoadSmis(MacroAssembler* masm, |
| 368 | FloatingPointHelper::Destination destination, |
| 369 | Register scratch1, |
| 370 | Register scratch2) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 371 | if (CpuFeatures::IsSupported(VFP3)) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 372 | CpuFeatures::Scope scope(VFP3); |
| 373 | __ mov(scratch1, Operand(r0, ASR, kSmiTagSize)); |
| 374 | __ vmov(d7.high(), scratch1); |
| 375 | __ vcvt_f64_s32(d7, d7.high()); |
| 376 | __ mov(scratch1, Operand(r1, ASR, kSmiTagSize)); |
| 377 | __ vmov(d6.high(), scratch1); |
| 378 | __ vcvt_f64_s32(d6, d6.high()); |
| 379 | if (destination == kCoreRegisters) { |
| 380 | __ vmov(r2, r3, d7); |
| 381 | __ vmov(r0, r1, d6); |
| 382 | } |
| 383 | } else { |
| 384 | ASSERT(destination == kCoreRegisters); |
| 385 | // Write Smi from r0 to r3 and r2 in double format. |
| 386 | __ mov(scratch1, Operand(r0)); |
| 387 | ConvertToDoubleStub stub1(r3, r2, scratch1, scratch2); |
| 388 | __ push(lr); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 389 | __ Call(stub1.GetCode()); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 390 | // Write Smi from r1 to r1 and r0 in double format. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 391 | __ mov(scratch1, Operand(r1)); |
| 392 | ConvertToDoubleStub stub2(r1, r0, scratch1, scratch2); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 393 | __ Call(stub2.GetCode()); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 394 | __ pop(lr); |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | |
| 399 | void FloatingPointHelper::LoadOperands( |
| 400 | MacroAssembler* masm, |
| 401 | FloatingPointHelper::Destination destination, |
| 402 | Register heap_number_map, |
| 403 | Register scratch1, |
| 404 | Register scratch2, |
| 405 | Label* slow) { |
| 406 | |
| 407 | // Load right operand (r0) to d6 or r2/r3. |
| 408 | LoadNumber(masm, destination, |
| 409 | r0, d7, r2, r3, heap_number_map, scratch1, scratch2, slow); |
| 410 | |
| 411 | // Load left operand (r1) to d7 or r0/r1. |
| 412 | LoadNumber(masm, destination, |
| 413 | r1, d6, r0, r1, heap_number_map, scratch1, scratch2, slow); |
| 414 | } |
| 415 | |
| 416 | |
| 417 | void FloatingPointHelper::LoadNumber(MacroAssembler* masm, |
| 418 | Destination destination, |
| 419 | Register object, |
| 420 | DwVfpRegister dst, |
| 421 | Register dst1, |
| 422 | Register dst2, |
| 423 | Register heap_number_map, |
| 424 | Register scratch1, |
| 425 | Register scratch2, |
| 426 | Label* not_number) { |
| 427 | if (FLAG_debug_code) { |
| 428 | __ AbortIfNotRootValue(heap_number_map, |
| 429 | Heap::kHeapNumberMapRootIndex, |
| 430 | "HeapNumberMap register clobbered."); |
| 431 | } |
| 432 | |
| 433 | Label is_smi, done; |
| 434 | |
| 435 | __ JumpIfSmi(object, &is_smi); |
| 436 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_number); |
| 437 | |
| 438 | // Handle loading a double from a heap number. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 439 | if (CpuFeatures::IsSupported(VFP3) && |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 440 | destination == kVFPRegisters) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 441 | CpuFeatures::Scope scope(VFP3); |
| 442 | // Load the double from tagged HeapNumber to double register. |
| 443 | __ sub(scratch1, object, Operand(kHeapObjectTag)); |
| 444 | __ vldr(dst, scratch1, HeapNumber::kValueOffset); |
| 445 | } else { |
| 446 | ASSERT(destination == kCoreRegisters); |
| 447 | // Load the double from heap number to dst1 and dst2 in double format. |
| 448 | __ Ldrd(dst1, dst2, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 449 | } |
| 450 | __ jmp(&done); |
| 451 | |
| 452 | // Handle loading a double from a smi. |
| 453 | __ bind(&is_smi); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 454 | if (CpuFeatures::IsSupported(VFP3)) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 455 | CpuFeatures::Scope scope(VFP3); |
| 456 | // Convert smi to double using VFP instructions. |
| 457 | __ SmiUntag(scratch1, object); |
| 458 | __ vmov(dst.high(), scratch1); |
| 459 | __ vcvt_f64_s32(dst, dst.high()); |
| 460 | if (destination == kCoreRegisters) { |
| 461 | // Load the converted smi to dst1 and dst2 in double format. |
| 462 | __ vmov(dst1, dst2, dst); |
| 463 | } |
| 464 | } else { |
| 465 | ASSERT(destination == kCoreRegisters); |
| 466 | // Write smi to dst1 and dst2 double format. |
| 467 | __ mov(scratch1, Operand(object)); |
| 468 | ConvertToDoubleStub stub(dst2, dst1, scratch1, scratch2); |
| 469 | __ push(lr); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 470 | __ Call(stub.GetCode()); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 471 | __ pop(lr); |
| 472 | } |
| 473 | |
| 474 | __ bind(&done); |
| 475 | } |
| 476 | |
| 477 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 478 | void FloatingPointHelper::ConvertNumberToInt32(MacroAssembler* masm, |
| 479 | Register object, |
| 480 | Register dst, |
| 481 | Register heap_number_map, |
| 482 | Register scratch1, |
| 483 | Register scratch2, |
| 484 | Register scratch3, |
| 485 | DwVfpRegister double_scratch, |
| 486 | Label* not_number) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 487 | if (FLAG_debug_code) { |
| 488 | __ AbortIfNotRootValue(heap_number_map, |
| 489 | Heap::kHeapNumberMapRootIndex, |
| 490 | "HeapNumberMap register clobbered."); |
| 491 | } |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 492 | Label is_smi; |
| 493 | Label done; |
| 494 | Label not_in_int32_range; |
| 495 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 496 | __ JumpIfSmi(object, &is_smi); |
| 497 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kMapOffset)); |
| 498 | __ cmp(scratch1, heap_number_map); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 499 | __ b(ne, not_number); |
| 500 | __ ConvertToInt32(object, |
| 501 | dst, |
| 502 | scratch1, |
| 503 | scratch2, |
| 504 | double_scratch, |
| 505 | ¬_in_int32_range); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 506 | __ jmp(&done); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 507 | |
| 508 | __ bind(¬_in_int32_range); |
| 509 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 510 | __ ldr(scratch2, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
| 511 | |
| 512 | __ EmitOutOfInt32RangeTruncate(dst, |
| 513 | scratch1, |
| 514 | scratch2, |
| 515 | scratch3); |
| 516 | __ jmp(&done); |
| 517 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 518 | __ bind(&is_smi); |
| 519 | __ SmiUntag(dst, object); |
| 520 | __ bind(&done); |
| 521 | } |
| 522 | |
| 523 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 524 | void FloatingPointHelper::ConvertIntToDouble(MacroAssembler* masm, |
| 525 | Register int_scratch, |
| 526 | Destination destination, |
| 527 | DwVfpRegister double_dst, |
| 528 | Register dst1, |
| 529 | Register dst2, |
| 530 | Register scratch2, |
| 531 | SwVfpRegister single_scratch) { |
| 532 | ASSERT(!int_scratch.is(scratch2)); |
| 533 | ASSERT(!int_scratch.is(dst1)); |
| 534 | ASSERT(!int_scratch.is(dst2)); |
| 535 | |
| 536 | Label done; |
| 537 | |
| 538 | if (CpuFeatures::IsSupported(VFP3)) { |
| 539 | CpuFeatures::Scope scope(VFP3); |
| 540 | __ vmov(single_scratch, int_scratch); |
| 541 | __ vcvt_f64_s32(double_dst, single_scratch); |
| 542 | if (destination == kCoreRegisters) { |
| 543 | __ vmov(dst1, dst2, double_dst); |
| 544 | } |
| 545 | } else { |
| 546 | Label fewer_than_20_useful_bits; |
| 547 | // Expected output: |
| 548 | // | dst2 | dst1 | |
| 549 | // | s | exp | mantissa | |
| 550 | |
| 551 | // Check for zero. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 552 | __ cmp(int_scratch, Operand::Zero()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 553 | __ mov(dst2, int_scratch); |
| 554 | __ mov(dst1, int_scratch); |
| 555 | __ b(eq, &done); |
| 556 | |
| 557 | // Preload the sign of the value. |
| 558 | __ and_(dst2, int_scratch, Operand(HeapNumber::kSignMask), SetCC); |
| 559 | // Get the absolute value of the object (as an unsigned integer). |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 560 | __ rsb(int_scratch, int_scratch, Operand::Zero(), SetCC, mi); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 561 | |
| 562 | // Get mantisssa[51:20]. |
| 563 | |
| 564 | // Get the position of the first set bit. |
| 565 | __ CountLeadingZeros(dst1, int_scratch, scratch2); |
| 566 | __ rsb(dst1, dst1, Operand(31)); |
| 567 | |
| 568 | // Set the exponent. |
| 569 | __ add(scratch2, dst1, Operand(HeapNumber::kExponentBias)); |
| 570 | __ Bfi(dst2, scratch2, scratch2, |
| 571 | HeapNumber::kExponentShift, HeapNumber::kExponentBits); |
| 572 | |
| 573 | // Clear the first non null bit. |
| 574 | __ mov(scratch2, Operand(1)); |
| 575 | __ bic(int_scratch, int_scratch, Operand(scratch2, LSL, dst1)); |
| 576 | |
| 577 | __ cmp(dst1, Operand(HeapNumber::kMantissaBitsInTopWord)); |
| 578 | // Get the number of bits to set in the lower part of the mantissa. |
| 579 | __ sub(scratch2, dst1, Operand(HeapNumber::kMantissaBitsInTopWord), SetCC); |
| 580 | __ b(mi, &fewer_than_20_useful_bits); |
| 581 | // Set the higher 20 bits of the mantissa. |
| 582 | __ orr(dst2, dst2, Operand(int_scratch, LSR, scratch2)); |
| 583 | __ rsb(scratch2, scratch2, Operand(32)); |
| 584 | __ mov(dst1, Operand(int_scratch, LSL, scratch2)); |
| 585 | __ b(&done); |
| 586 | |
| 587 | __ bind(&fewer_than_20_useful_bits); |
| 588 | __ rsb(scratch2, dst1, Operand(HeapNumber::kMantissaBitsInTopWord)); |
| 589 | __ mov(scratch2, Operand(int_scratch, LSL, scratch2)); |
| 590 | __ orr(dst2, dst2, scratch2); |
| 591 | // Set dst1 to 0. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 592 | __ mov(dst1, Operand::Zero()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 593 | } |
| 594 | __ bind(&done); |
| 595 | } |
| 596 | |
| 597 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 598 | void FloatingPointHelper::LoadNumberAsInt32Double(MacroAssembler* masm, |
| 599 | Register object, |
| 600 | Destination destination, |
| 601 | DwVfpRegister double_dst, |
| 602 | Register dst1, |
| 603 | Register dst2, |
| 604 | Register heap_number_map, |
| 605 | Register scratch1, |
| 606 | Register scratch2, |
| 607 | SwVfpRegister single_scratch, |
| 608 | Label* not_int32) { |
| 609 | ASSERT(!scratch1.is(object) && !scratch2.is(object)); |
| 610 | ASSERT(!scratch1.is(scratch2)); |
| 611 | ASSERT(!heap_number_map.is(object) && |
| 612 | !heap_number_map.is(scratch1) && |
| 613 | !heap_number_map.is(scratch2)); |
| 614 | |
| 615 | Label done, obj_is_not_smi; |
| 616 | |
| 617 | __ JumpIfNotSmi(object, &obj_is_not_smi); |
| 618 | __ SmiUntag(scratch1, object); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 619 | ConvertIntToDouble(masm, scratch1, destination, double_dst, dst1, dst2, |
| 620 | scratch2, single_scratch); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 621 | __ b(&done); |
| 622 | |
| 623 | __ bind(&obj_is_not_smi); |
| 624 | if (FLAG_debug_code) { |
| 625 | __ AbortIfNotRootValue(heap_number_map, |
| 626 | Heap::kHeapNumberMapRootIndex, |
| 627 | "HeapNumberMap register clobbered."); |
| 628 | } |
| 629 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_int32); |
| 630 | |
| 631 | // Load the number. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 632 | if (CpuFeatures::IsSupported(VFP3)) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 633 | CpuFeatures::Scope scope(VFP3); |
| 634 | // Load the double value. |
| 635 | __ sub(scratch1, object, Operand(kHeapObjectTag)); |
| 636 | __ vldr(double_dst, scratch1, HeapNumber::kValueOffset); |
| 637 | |
| 638 | __ EmitVFPTruncate(kRoundToZero, |
| 639 | single_scratch, |
| 640 | double_dst, |
| 641 | scratch1, |
| 642 | scratch2, |
| 643 | kCheckForInexactConversion); |
| 644 | |
| 645 | // Jump to not_int32 if the operation did not succeed. |
| 646 | __ b(ne, not_int32); |
| 647 | |
| 648 | if (destination == kCoreRegisters) { |
| 649 | __ vmov(dst1, dst2, double_dst); |
| 650 | } |
| 651 | |
| 652 | } else { |
| 653 | ASSERT(!scratch1.is(object) && !scratch2.is(object)); |
| 654 | // Load the double value in the destination registers.. |
| 655 | __ Ldrd(dst1, dst2, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 656 | |
| 657 | // Check for 0 and -0. |
| 658 | __ bic(scratch1, dst1, Operand(HeapNumber::kSignMask)); |
| 659 | __ orr(scratch1, scratch1, Operand(dst2)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 660 | __ cmp(scratch1, Operand::Zero()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 661 | __ b(eq, &done); |
| 662 | |
| 663 | // Check that the value can be exactly represented by a 32-bit integer. |
| 664 | // Jump to not_int32 if that's not the case. |
| 665 | DoubleIs32BitInteger(masm, dst1, dst2, scratch1, scratch2, not_int32); |
| 666 | |
| 667 | // dst1 and dst2 were trashed. Reload the double value. |
| 668 | __ Ldrd(dst1, dst2, FieldMemOperand(object, HeapNumber::kValueOffset)); |
| 669 | } |
| 670 | |
| 671 | __ bind(&done); |
| 672 | } |
| 673 | |
| 674 | |
| 675 | void FloatingPointHelper::LoadNumberAsInt32(MacroAssembler* masm, |
| 676 | Register object, |
| 677 | Register dst, |
| 678 | Register heap_number_map, |
| 679 | Register scratch1, |
| 680 | Register scratch2, |
| 681 | Register scratch3, |
| 682 | DwVfpRegister double_scratch, |
| 683 | Label* not_int32) { |
| 684 | ASSERT(!dst.is(object)); |
| 685 | ASSERT(!scratch1.is(object) && !scratch2.is(object) && !scratch3.is(object)); |
| 686 | ASSERT(!scratch1.is(scratch2) && |
| 687 | !scratch1.is(scratch3) && |
| 688 | !scratch2.is(scratch3)); |
| 689 | |
| 690 | Label done; |
| 691 | |
| 692 | // Untag the object into the destination register. |
| 693 | __ SmiUntag(dst, object); |
| 694 | // Just return if the object is a smi. |
| 695 | __ JumpIfSmi(object, &done); |
| 696 | |
| 697 | if (FLAG_debug_code) { |
| 698 | __ AbortIfNotRootValue(heap_number_map, |
| 699 | Heap::kHeapNumberMapRootIndex, |
| 700 | "HeapNumberMap register clobbered."); |
| 701 | } |
| 702 | __ JumpIfNotHeapNumber(object, heap_number_map, scratch1, not_int32); |
| 703 | |
| 704 | // Object is a heap number. |
| 705 | // Convert the floating point value to a 32-bit integer. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 706 | if (CpuFeatures::IsSupported(VFP3)) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 707 | CpuFeatures::Scope scope(VFP3); |
| 708 | SwVfpRegister single_scratch = double_scratch.low(); |
| 709 | // Load the double value. |
| 710 | __ sub(scratch1, object, Operand(kHeapObjectTag)); |
| 711 | __ vldr(double_scratch, scratch1, HeapNumber::kValueOffset); |
| 712 | |
| 713 | __ EmitVFPTruncate(kRoundToZero, |
| 714 | single_scratch, |
| 715 | double_scratch, |
| 716 | scratch1, |
| 717 | scratch2, |
| 718 | kCheckForInexactConversion); |
| 719 | |
| 720 | // Jump to not_int32 if the operation did not succeed. |
| 721 | __ b(ne, not_int32); |
| 722 | // Get the result in the destination register. |
| 723 | __ vmov(dst, single_scratch); |
| 724 | |
| 725 | } else { |
| 726 | // Load the double value in the destination registers. |
| 727 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 728 | __ ldr(scratch2, FieldMemOperand(object, HeapNumber::kMantissaOffset)); |
| 729 | |
| 730 | // Check for 0 and -0. |
| 731 | __ bic(dst, scratch1, Operand(HeapNumber::kSignMask)); |
| 732 | __ orr(dst, scratch2, Operand(dst)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 733 | __ cmp(dst, Operand::Zero()); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 734 | __ b(eq, &done); |
| 735 | |
| 736 | DoubleIs32BitInteger(masm, scratch1, scratch2, dst, scratch3, not_int32); |
| 737 | |
| 738 | // Registers state after DoubleIs32BitInteger. |
| 739 | // dst: mantissa[51:20]. |
| 740 | // scratch2: 1 |
| 741 | |
| 742 | // Shift back the higher bits of the mantissa. |
| 743 | __ mov(dst, Operand(dst, LSR, scratch3)); |
| 744 | // Set the implicit first bit. |
| 745 | __ rsb(scratch3, scratch3, Operand(32)); |
| 746 | __ orr(dst, dst, Operand(scratch2, LSL, scratch3)); |
| 747 | // Set the sign. |
| 748 | __ ldr(scratch1, FieldMemOperand(object, HeapNumber::kExponentOffset)); |
| 749 | __ tst(scratch1, Operand(HeapNumber::kSignMask)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 750 | __ rsb(dst, dst, Operand::Zero(), LeaveCC, mi); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | __ bind(&done); |
| 754 | } |
| 755 | |
| 756 | |
| 757 | void FloatingPointHelper::DoubleIs32BitInteger(MacroAssembler* masm, |
| 758 | Register src1, |
| 759 | Register src2, |
| 760 | Register dst, |
| 761 | Register scratch, |
| 762 | Label* not_int32) { |
| 763 | // Get exponent alone in scratch. |
| 764 | __ Ubfx(scratch, |
| 765 | src1, |
| 766 | HeapNumber::kExponentShift, |
| 767 | HeapNumber::kExponentBits); |
| 768 | |
| 769 | // Substract the bias from the exponent. |
| 770 | __ sub(scratch, scratch, Operand(HeapNumber::kExponentBias), SetCC); |
| 771 | |
| 772 | // src1: higher (exponent) part of the double value. |
| 773 | // src2: lower (mantissa) part of the double value. |
| 774 | // scratch: unbiased exponent. |
| 775 | |
| 776 | // Fast cases. Check for obvious non 32-bit integer values. |
| 777 | // Negative exponent cannot yield 32-bit integers. |
| 778 | __ b(mi, not_int32); |
| 779 | // Exponent greater than 31 cannot yield 32-bit integers. |
| 780 | // Also, a positive value with an exponent equal to 31 is outside of the |
| 781 | // signed 32-bit integer range. |
| 782 | // Another way to put it is that if (exponent - signbit) > 30 then the |
| 783 | // number cannot be represented as an int32. |
| 784 | Register tmp = dst; |
| 785 | __ sub(tmp, scratch, Operand(src1, LSR, 31)); |
| 786 | __ cmp(tmp, Operand(30)); |
| 787 | __ b(gt, not_int32); |
| 788 | // - Bits [21:0] in the mantissa are not null. |
| 789 | __ tst(src2, Operand(0x3fffff)); |
| 790 | __ b(ne, not_int32); |
| 791 | |
| 792 | // Otherwise the exponent needs to be big enough to shift left all the |
| 793 | // non zero bits left. So we need the (30 - exponent) last bits of the |
| 794 | // 31 higher bits of the mantissa to be null. |
| 795 | // Because bits [21:0] are null, we can check instead that the |
| 796 | // (32 - exponent) last bits of the 32 higher bits of the mantisssa are null. |
| 797 | |
| 798 | // Get the 32 higher bits of the mantissa in dst. |
| 799 | __ Ubfx(dst, |
| 800 | src2, |
| 801 | HeapNumber::kMantissaBitsInTopWord, |
| 802 | 32 - HeapNumber::kMantissaBitsInTopWord); |
| 803 | __ orr(dst, |
| 804 | dst, |
| 805 | Operand(src1, LSL, HeapNumber::kNonMantissaBitsInTopWord)); |
| 806 | |
| 807 | // Create the mask and test the lower bits (of the higher bits). |
| 808 | __ rsb(scratch, scratch, Operand(32)); |
| 809 | __ mov(src2, Operand(1)); |
| 810 | __ mov(src1, Operand(src2, LSL, scratch)); |
| 811 | __ sub(src1, src1, Operand(1)); |
| 812 | __ tst(dst, src1); |
| 813 | __ b(ne, not_int32); |
| 814 | } |
| 815 | |
| 816 | |
| 817 | void FloatingPointHelper::CallCCodeForDoubleOperation( |
| 818 | MacroAssembler* masm, |
| 819 | Token::Value op, |
| 820 | Register heap_number_result, |
| 821 | Register scratch) { |
| 822 | // Using core registers: |
| 823 | // r0: Left value (least significant part of mantissa). |
| 824 | // r1: Left value (sign, exponent, top of mantissa). |
| 825 | // r2: Right value (least significant part of mantissa). |
| 826 | // r3: Right value (sign, exponent, top of mantissa). |
| 827 | |
| 828 | // Assert that heap_number_result is callee-saved. |
| 829 | // We currently always use r5 to pass it. |
| 830 | ASSERT(heap_number_result.is(r5)); |
| 831 | |
| 832 | // Push the current return address before the C call. Return will be |
| 833 | // through pop(pc) below. |
| 834 | __ push(lr); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 835 | __ PrepareCallCFunction(0, 2, scratch); |
| 836 | if (masm->use_eabi_hardfloat()) { |
| 837 | CpuFeatures::Scope scope(VFP3); |
| 838 | __ vmov(d0, r0, r1); |
| 839 | __ vmov(d1, r2, r3); |
| 840 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 841 | // Call C routine that may not cause GC or other trouble. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 842 | __ CallCFunction(ExternalReference::double_fp_operation(op, masm->isolate()), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 843 | 0, 2); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 844 | // Store answer in the overwritable heap number. Double returned in |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 845 | // registers r0 and r1 or in d0. |
| 846 | if (masm->use_eabi_hardfloat()) { |
| 847 | CpuFeatures::Scope scope(VFP3); |
| 848 | __ vstr(d0, |
| 849 | FieldMemOperand(heap_number_result, HeapNumber::kValueOffset)); |
| 850 | } else { |
| 851 | __ Strd(r0, r1, FieldMemOperand(heap_number_result, |
| 852 | HeapNumber::kValueOffset)); |
| 853 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 854 | // Place heap_number_result in r0 and return to the pushed return address. |
| 855 | __ mov(r0, Operand(heap_number_result)); |
| 856 | __ pop(pc); |
| 857 | } |
| 858 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 859 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 860 | // See comment for class. |
| 861 | void WriteInt32ToHeapNumberStub::Generate(MacroAssembler* masm) { |
| 862 | Label max_negative_int; |
| 863 | // the_int_ has the answer which is a signed int32 but not a Smi. |
| 864 | // We test for the special value that has a different exponent. This test |
| 865 | // has the neat side effect of setting the flags according to the sign. |
| 866 | STATIC_ASSERT(HeapNumber::kSignMask == 0x80000000u); |
| 867 | __ cmp(the_int_, Operand(0x80000000u)); |
| 868 | __ b(eq, &max_negative_int); |
| 869 | // Set up the correct exponent in scratch_. All non-Smi int32s have the same. |
| 870 | // A non-Smi integer is 1.xxx * 2^30 so the exponent is 30 (biased). |
| 871 | uint32_t non_smi_exponent = |
| 872 | (HeapNumber::kExponentBias + 30) << HeapNumber::kExponentShift; |
| 873 | __ mov(scratch_, Operand(non_smi_exponent)); |
| 874 | // Set the sign bit in scratch_ if the value was negative. |
| 875 | __ orr(scratch_, scratch_, Operand(HeapNumber::kSignMask), LeaveCC, cs); |
| 876 | // Subtract from 0 if the value was negative. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 877 | __ rsb(the_int_, the_int_, Operand(0, RelocInfo::NONE), LeaveCC, cs); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 878 | // We should be masking the implict first digit of the mantissa away here, |
| 879 | // but it just ends up combining harmlessly with the last digit of the |
| 880 | // exponent that happens to be 1. The sign bit is 0 so we shift 10 to get |
| 881 | // the most significant 1 to hit the last bit of the 12 bit sign and exponent. |
| 882 | ASSERT(((1 << HeapNumber::kExponentShift) & non_smi_exponent) != 0); |
| 883 | const int shift_distance = HeapNumber::kNonMantissaBitsInTopWord - 2; |
| 884 | __ orr(scratch_, scratch_, Operand(the_int_, LSR, shift_distance)); |
| 885 | __ str(scratch_, FieldMemOperand(the_heap_number_, |
| 886 | HeapNumber::kExponentOffset)); |
| 887 | __ mov(scratch_, Operand(the_int_, LSL, 32 - shift_distance)); |
| 888 | __ str(scratch_, FieldMemOperand(the_heap_number_, |
| 889 | HeapNumber::kMantissaOffset)); |
| 890 | __ Ret(); |
| 891 | |
| 892 | __ bind(&max_negative_int); |
| 893 | // The max negative int32 is stored as a positive number in the mantissa of |
| 894 | // a double because it uses a sign bit instead of using two's complement. |
| 895 | // The actual mantissa bits stored are all 0 because the implicit most |
| 896 | // significant 1 bit is not stored. |
| 897 | non_smi_exponent += 1 << HeapNumber::kExponentShift; |
| 898 | __ mov(ip, Operand(HeapNumber::kSignMask | non_smi_exponent)); |
| 899 | __ str(ip, FieldMemOperand(the_heap_number_, HeapNumber::kExponentOffset)); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 900 | __ mov(ip, Operand(0, RelocInfo::NONE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 901 | __ str(ip, FieldMemOperand(the_heap_number_, HeapNumber::kMantissaOffset)); |
| 902 | __ Ret(); |
| 903 | } |
| 904 | |
| 905 | |
| 906 | // Handle the case where the lhs and rhs are the same object. |
| 907 | // Equality is almost reflexive (everything but NaN), so this is a test |
| 908 | // for "identity and not NaN". |
| 909 | static void EmitIdenticalObjectComparison(MacroAssembler* masm, |
| 910 | Label* slow, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 911 | Condition cond, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 912 | bool never_nan_nan) { |
| 913 | Label not_identical; |
| 914 | Label heap_number, return_equal; |
| 915 | __ cmp(r0, r1); |
| 916 | __ b(ne, ¬_identical); |
| 917 | |
| 918 | // The two objects are identical. If we know that one of them isn't NaN then |
| 919 | // we now know they test equal. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 920 | if (cond != eq || !never_nan_nan) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 921 | // Test for NaN. Sadly, we can't just compare to FACTORY->nan_value(), |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 922 | // so we do the second best thing - test it ourselves. |
| 923 | // They are both equal and they are not both Smis so both of them are not |
| 924 | // Smis. If it's not a heap number, then return equal. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 925 | if (cond == lt || cond == gt) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 926 | __ CompareObjectType(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 927 | __ b(ge, slow); |
| 928 | } else { |
| 929 | __ CompareObjectType(r0, r4, r4, HEAP_NUMBER_TYPE); |
| 930 | __ b(eq, &heap_number); |
| 931 | // Comparing JS objects with <=, >= is complicated. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 932 | if (cond != eq) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 933 | __ cmp(r4, Operand(FIRST_SPEC_OBJECT_TYPE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 934 | __ b(ge, slow); |
| 935 | // Normally here we fall through to return_equal, but undefined is |
| 936 | // special: (undefined == undefined) == true, but |
| 937 | // (undefined <= undefined) == false! See ECMAScript 11.8.5. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 938 | if (cond == le || cond == ge) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 939 | __ cmp(r4, Operand(ODDBALL_TYPE)); |
| 940 | __ b(ne, &return_equal); |
| 941 | __ LoadRoot(r2, Heap::kUndefinedValueRootIndex); |
| 942 | __ cmp(r0, r2); |
| 943 | __ b(ne, &return_equal); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 944 | if (cond == le) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 945 | // undefined <= undefined should fail. |
| 946 | __ mov(r0, Operand(GREATER)); |
| 947 | } else { |
| 948 | // undefined >= undefined should fail. |
| 949 | __ mov(r0, Operand(LESS)); |
| 950 | } |
| 951 | __ Ret(); |
| 952 | } |
| 953 | } |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | __ bind(&return_equal); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 958 | if (cond == lt) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 959 | __ mov(r0, Operand(GREATER)); // Things aren't less than themselves. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 960 | } else if (cond == gt) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 961 | __ mov(r0, Operand(LESS)); // Things aren't greater than themselves. |
| 962 | } else { |
| 963 | __ mov(r0, Operand(EQUAL)); // Things are <=, >=, ==, === themselves. |
| 964 | } |
| 965 | __ Ret(); |
| 966 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 967 | if (cond != eq || !never_nan_nan) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 968 | // For less and greater we don't have to check for NaN since the result of |
| 969 | // x < x is false regardless. For the others here is some code to check |
| 970 | // for NaN. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 971 | if (cond != lt && cond != gt) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 972 | __ bind(&heap_number); |
| 973 | // It is a heap number, so return non-equal if it's NaN and equal if it's |
| 974 | // not NaN. |
| 975 | |
| 976 | // The representation of NaN values has all exponent bits (52..62) set, |
| 977 | // and not all mantissa bits (0..51) clear. |
| 978 | // Read top bits of double representation (second word of value). |
| 979 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 980 | // Test that exponent bits are all set. |
| 981 | __ Sbfx(r3, r2, HeapNumber::kExponentShift, HeapNumber::kExponentBits); |
| 982 | // NaNs have all-one exponents so they sign extend to -1. |
| 983 | __ cmp(r3, Operand(-1)); |
| 984 | __ b(ne, &return_equal); |
| 985 | |
| 986 | // Shift out flag and all exponent bits, retaining only mantissa. |
| 987 | __ mov(r2, Operand(r2, LSL, HeapNumber::kNonMantissaBitsInTopWord)); |
| 988 | // Or with all low-bits of mantissa. |
| 989 | __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset)); |
| 990 | __ orr(r0, r3, Operand(r2), SetCC); |
| 991 | // For equal we already have the right value in r0: Return zero (equal) |
| 992 | // if all bits in mantissa are zero (it's an Infinity) and non-zero if |
| 993 | // not (it's a NaN). For <= and >= we need to load r0 with the failing |
| 994 | // value if it's a NaN. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 995 | if (cond != eq) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 996 | // All-zero means Infinity means equal. |
| 997 | __ Ret(eq); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 998 | if (cond == le) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 999 | __ mov(r0, Operand(GREATER)); // NaN <= NaN should fail. |
| 1000 | } else { |
| 1001 | __ mov(r0, Operand(LESS)); // NaN >= NaN should fail. |
| 1002 | } |
| 1003 | } |
| 1004 | __ Ret(); |
| 1005 | } |
| 1006 | // No fall through here. |
| 1007 | } |
| 1008 | |
| 1009 | __ bind(¬_identical); |
| 1010 | } |
| 1011 | |
| 1012 | |
| 1013 | // See comment at call site. |
| 1014 | static void EmitSmiNonsmiComparison(MacroAssembler* masm, |
| 1015 | Register lhs, |
| 1016 | Register rhs, |
| 1017 | Label* lhs_not_nan, |
| 1018 | Label* slow, |
| 1019 | bool strict) { |
| 1020 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1021 | (lhs.is(r1) && rhs.is(r0))); |
| 1022 | |
| 1023 | Label rhs_is_smi; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1024 | __ JumpIfSmi(rhs, &rhs_is_smi); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1025 | |
| 1026 | // Lhs is a Smi. Check whether the rhs is a heap number. |
| 1027 | __ CompareObjectType(rhs, r4, r4, HEAP_NUMBER_TYPE); |
| 1028 | if (strict) { |
| 1029 | // If rhs is not a number and lhs is a Smi then strict equality cannot |
| 1030 | // succeed. Return non-equal |
| 1031 | // If rhs is r0 then there is already a non zero value in it. |
| 1032 | if (!rhs.is(r0)) { |
| 1033 | __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne); |
| 1034 | } |
| 1035 | __ Ret(ne); |
| 1036 | } else { |
| 1037 | // Smi compared non-strictly with a non-Smi non-heap-number. Call |
| 1038 | // the runtime. |
| 1039 | __ b(ne, slow); |
| 1040 | } |
| 1041 | |
| 1042 | // Lhs is a smi, rhs is a number. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1043 | if (CpuFeatures::IsSupported(VFP3)) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1044 | // Convert lhs to a double in d7. |
| 1045 | CpuFeatures::Scope scope(VFP3); |
| 1046 | __ SmiToDoubleVFPRegister(lhs, d7, r7, s15); |
| 1047 | // Load the double from rhs, tagged HeapNumber r0, to d6. |
| 1048 | __ sub(r7, rhs, Operand(kHeapObjectTag)); |
| 1049 | __ vldr(d6, r7, HeapNumber::kValueOffset); |
| 1050 | } else { |
| 1051 | __ push(lr); |
| 1052 | // Convert lhs to a double in r2, r3. |
| 1053 | __ mov(r7, Operand(lhs)); |
| 1054 | ConvertToDoubleStub stub1(r3, r2, r7, r6); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1055 | __ Call(stub1.GetCode()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1056 | // Load rhs to a double in r0, r1. |
| 1057 | __ Ldrd(r0, r1, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1058 | __ pop(lr); |
| 1059 | } |
| 1060 | |
| 1061 | // We now have both loaded as doubles but we can skip the lhs nan check |
| 1062 | // since it's a smi. |
| 1063 | __ jmp(lhs_not_nan); |
| 1064 | |
| 1065 | __ bind(&rhs_is_smi); |
| 1066 | // Rhs is a smi. Check whether the non-smi lhs is a heap number. |
| 1067 | __ CompareObjectType(lhs, r4, r4, HEAP_NUMBER_TYPE); |
| 1068 | if (strict) { |
| 1069 | // If lhs is not a number and rhs is a smi then strict equality cannot |
| 1070 | // succeed. Return non-equal. |
| 1071 | // If lhs is r0 then there is already a non zero value in it. |
| 1072 | if (!lhs.is(r0)) { |
| 1073 | __ mov(r0, Operand(NOT_EQUAL), LeaveCC, ne); |
| 1074 | } |
| 1075 | __ Ret(ne); |
| 1076 | } else { |
| 1077 | // Smi compared non-strictly with a non-smi non-heap-number. Call |
| 1078 | // the runtime. |
| 1079 | __ b(ne, slow); |
| 1080 | } |
| 1081 | |
| 1082 | // Rhs is a smi, lhs is a heap number. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1083 | if (CpuFeatures::IsSupported(VFP3)) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1084 | CpuFeatures::Scope scope(VFP3); |
| 1085 | // Load the double from lhs, tagged HeapNumber r1, to d7. |
| 1086 | __ sub(r7, lhs, Operand(kHeapObjectTag)); |
| 1087 | __ vldr(d7, r7, HeapNumber::kValueOffset); |
| 1088 | // Convert rhs to a double in d6 . |
| 1089 | __ SmiToDoubleVFPRegister(rhs, d6, r7, s13); |
| 1090 | } else { |
| 1091 | __ push(lr); |
| 1092 | // Load lhs to a double in r2, r3. |
| 1093 | __ Ldrd(r2, r3, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 1094 | // Convert rhs to a double in r0, r1. |
| 1095 | __ mov(r7, Operand(rhs)); |
| 1096 | ConvertToDoubleStub stub2(r1, r0, r7, r6); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1097 | __ Call(stub2.GetCode()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1098 | __ pop(lr); |
| 1099 | } |
| 1100 | // Fall through to both_loaded_as_doubles. |
| 1101 | } |
| 1102 | |
| 1103 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1104 | void EmitNanCheck(MacroAssembler* masm, Label* lhs_not_nan, Condition cond) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1105 | bool exp_first = (HeapNumber::kExponentOffset == HeapNumber::kValueOffset); |
| 1106 | Register rhs_exponent = exp_first ? r0 : r1; |
| 1107 | Register lhs_exponent = exp_first ? r2 : r3; |
| 1108 | Register rhs_mantissa = exp_first ? r1 : r0; |
| 1109 | Register lhs_mantissa = exp_first ? r3 : r2; |
| 1110 | Label one_is_nan, neither_is_nan; |
| 1111 | |
| 1112 | __ Sbfx(r4, |
| 1113 | lhs_exponent, |
| 1114 | HeapNumber::kExponentShift, |
| 1115 | HeapNumber::kExponentBits); |
| 1116 | // NaNs have all-one exponents so they sign extend to -1. |
| 1117 | __ cmp(r4, Operand(-1)); |
| 1118 | __ b(ne, lhs_not_nan); |
| 1119 | __ mov(r4, |
| 1120 | Operand(lhs_exponent, LSL, HeapNumber::kNonMantissaBitsInTopWord), |
| 1121 | SetCC); |
| 1122 | __ b(ne, &one_is_nan); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1123 | __ cmp(lhs_mantissa, Operand(0, RelocInfo::NONE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1124 | __ b(ne, &one_is_nan); |
| 1125 | |
| 1126 | __ bind(lhs_not_nan); |
| 1127 | __ Sbfx(r4, |
| 1128 | rhs_exponent, |
| 1129 | HeapNumber::kExponentShift, |
| 1130 | HeapNumber::kExponentBits); |
| 1131 | // NaNs have all-one exponents so they sign extend to -1. |
| 1132 | __ cmp(r4, Operand(-1)); |
| 1133 | __ b(ne, &neither_is_nan); |
| 1134 | __ mov(r4, |
| 1135 | Operand(rhs_exponent, LSL, HeapNumber::kNonMantissaBitsInTopWord), |
| 1136 | SetCC); |
| 1137 | __ b(ne, &one_is_nan); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 1138 | __ cmp(rhs_mantissa, Operand(0, RelocInfo::NONE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1139 | __ b(eq, &neither_is_nan); |
| 1140 | |
| 1141 | __ bind(&one_is_nan); |
| 1142 | // NaN comparisons always fail. |
| 1143 | // Load whatever we need in r0 to make the comparison fail. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1144 | if (cond == lt || cond == le) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1145 | __ mov(r0, Operand(GREATER)); |
| 1146 | } else { |
| 1147 | __ mov(r0, Operand(LESS)); |
| 1148 | } |
| 1149 | __ Ret(); |
| 1150 | |
| 1151 | __ bind(&neither_is_nan); |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | // See comment at call site. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1156 | static void EmitTwoNonNanDoubleComparison(MacroAssembler* masm, |
| 1157 | Condition cond) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1158 | bool exp_first = (HeapNumber::kExponentOffset == HeapNumber::kValueOffset); |
| 1159 | Register rhs_exponent = exp_first ? r0 : r1; |
| 1160 | Register lhs_exponent = exp_first ? r2 : r3; |
| 1161 | Register rhs_mantissa = exp_first ? r1 : r0; |
| 1162 | Register lhs_mantissa = exp_first ? r3 : r2; |
| 1163 | |
| 1164 | // r0, r1, r2, r3 have the two doubles. Neither is a NaN. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1165 | if (cond == eq) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1166 | // Doubles are not equal unless they have the same bit pattern. |
| 1167 | // Exception: 0 and -0. |
| 1168 | __ cmp(rhs_mantissa, Operand(lhs_mantissa)); |
| 1169 | __ orr(r0, rhs_mantissa, Operand(lhs_mantissa), LeaveCC, ne); |
| 1170 | // Return non-zero if the numbers are unequal. |
| 1171 | __ Ret(ne); |
| 1172 | |
| 1173 | __ sub(r0, rhs_exponent, Operand(lhs_exponent), SetCC); |
| 1174 | // If exponents are equal then return 0. |
| 1175 | __ Ret(eq); |
| 1176 | |
| 1177 | // Exponents are unequal. The only way we can return that the numbers |
| 1178 | // are equal is if one is -0 and the other is 0. We already dealt |
| 1179 | // with the case where both are -0 or both are 0. |
| 1180 | // We start by seeing if the mantissas (that are equal) or the bottom |
| 1181 | // 31 bits of the rhs exponent are non-zero. If so we return not |
| 1182 | // equal. |
| 1183 | __ orr(r4, lhs_mantissa, Operand(lhs_exponent, LSL, kSmiTagSize), SetCC); |
| 1184 | __ mov(r0, Operand(r4), LeaveCC, ne); |
| 1185 | __ Ret(ne); |
| 1186 | // Now they are equal if and only if the lhs exponent is zero in its |
| 1187 | // low 31 bits. |
| 1188 | __ mov(r0, Operand(rhs_exponent, LSL, kSmiTagSize)); |
| 1189 | __ Ret(); |
| 1190 | } else { |
| 1191 | // Call a native function to do a comparison between two non-NaNs. |
| 1192 | // Call C routine that may not cause GC or other trouble. |
| 1193 | __ push(lr); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1194 | __ PrepareCallCFunction(0, 2, r5); |
| 1195 | if (masm->use_eabi_hardfloat()) { |
| 1196 | CpuFeatures::Scope scope(VFP3); |
| 1197 | __ vmov(d0, r0, r1); |
| 1198 | __ vmov(d1, r2, r3); |
| 1199 | } |
| 1200 | __ CallCFunction(ExternalReference::compare_doubles(masm->isolate()), |
| 1201 | 0, 2); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1202 | __ pop(pc); // Return. |
| 1203 | } |
| 1204 | } |
| 1205 | |
| 1206 | |
| 1207 | // See comment at call site. |
| 1208 | static void EmitStrictTwoHeapObjectCompare(MacroAssembler* masm, |
| 1209 | Register lhs, |
| 1210 | Register rhs) { |
| 1211 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1212 | (lhs.is(r1) && rhs.is(r0))); |
| 1213 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1214 | // If either operand is a JS object or an oddball value, then they are |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1215 | // not equal since their pointers are different. |
| 1216 | // There is no test for undetectability in strict equality. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1217 | STATIC_ASSERT(LAST_TYPE == LAST_CALLABLE_SPEC_OBJECT_TYPE); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1218 | Label first_non_object; |
| 1219 | // Get the type of the first operand into r2 and compare it with |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1220 | // FIRST_SPEC_OBJECT_TYPE. |
| 1221 | __ CompareObjectType(rhs, r2, r2, FIRST_SPEC_OBJECT_TYPE); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1222 | __ b(lt, &first_non_object); |
| 1223 | |
| 1224 | // Return non-zero (r0 is not zero) |
| 1225 | Label return_not_equal; |
| 1226 | __ bind(&return_not_equal); |
| 1227 | __ Ret(); |
| 1228 | |
| 1229 | __ bind(&first_non_object); |
| 1230 | // Check for oddballs: true, false, null, undefined. |
| 1231 | __ cmp(r2, Operand(ODDBALL_TYPE)); |
| 1232 | __ b(eq, &return_not_equal); |
| 1233 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1234 | __ CompareObjectType(lhs, r3, r3, FIRST_SPEC_OBJECT_TYPE); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1235 | __ b(ge, &return_not_equal); |
| 1236 | |
| 1237 | // Check for oddballs: true, false, null, undefined. |
| 1238 | __ cmp(r3, Operand(ODDBALL_TYPE)); |
| 1239 | __ b(eq, &return_not_equal); |
| 1240 | |
| 1241 | // Now that we have the types we might as well check for symbol-symbol. |
| 1242 | // Ensure that no non-strings have the symbol bit set. |
| 1243 | STATIC_ASSERT(LAST_TYPE < kNotStringTag + kIsSymbolMask); |
| 1244 | STATIC_ASSERT(kSymbolTag != 0); |
| 1245 | __ and_(r2, r2, Operand(r3)); |
| 1246 | __ tst(r2, Operand(kIsSymbolMask)); |
| 1247 | __ b(ne, &return_not_equal); |
| 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | // See comment at call site. |
| 1252 | static void EmitCheckForTwoHeapNumbers(MacroAssembler* masm, |
| 1253 | Register lhs, |
| 1254 | Register rhs, |
| 1255 | Label* both_loaded_as_doubles, |
| 1256 | Label* not_heap_numbers, |
| 1257 | Label* slow) { |
| 1258 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1259 | (lhs.is(r1) && rhs.is(r0))); |
| 1260 | |
| 1261 | __ CompareObjectType(rhs, r3, r2, HEAP_NUMBER_TYPE); |
| 1262 | __ b(ne, not_heap_numbers); |
| 1263 | __ ldr(r2, FieldMemOperand(lhs, HeapObject::kMapOffset)); |
| 1264 | __ cmp(r2, r3); |
| 1265 | __ b(ne, slow); // First was a heap number, second wasn't. Go slow case. |
| 1266 | |
| 1267 | // Both are heap numbers. Load them up then jump to the code we have |
| 1268 | // for that. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1269 | if (CpuFeatures::IsSupported(VFP3)) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1270 | CpuFeatures::Scope scope(VFP3); |
| 1271 | __ sub(r7, rhs, Operand(kHeapObjectTag)); |
| 1272 | __ vldr(d6, r7, HeapNumber::kValueOffset); |
| 1273 | __ sub(r7, lhs, Operand(kHeapObjectTag)); |
| 1274 | __ vldr(d7, r7, HeapNumber::kValueOffset); |
| 1275 | } else { |
| 1276 | __ Ldrd(r2, r3, FieldMemOperand(lhs, HeapNumber::kValueOffset)); |
| 1277 | __ Ldrd(r0, r1, FieldMemOperand(rhs, HeapNumber::kValueOffset)); |
| 1278 | } |
| 1279 | __ jmp(both_loaded_as_doubles); |
| 1280 | } |
| 1281 | |
| 1282 | |
| 1283 | // Fast negative check for symbol-to-symbol equality. |
| 1284 | static void EmitCheckForSymbolsOrObjects(MacroAssembler* masm, |
| 1285 | Register lhs, |
| 1286 | Register rhs, |
| 1287 | Label* possible_strings, |
| 1288 | Label* not_both_strings) { |
| 1289 | ASSERT((lhs.is(r0) && rhs.is(r1)) || |
| 1290 | (lhs.is(r1) && rhs.is(r0))); |
| 1291 | |
| 1292 | // r2 is object type of rhs. |
| 1293 | // Ensure that no non-strings have the symbol bit set. |
| 1294 | Label object_test; |
| 1295 | STATIC_ASSERT(kSymbolTag != 0); |
| 1296 | __ tst(r2, Operand(kIsNotStringMask)); |
| 1297 | __ b(ne, &object_test); |
| 1298 | __ tst(r2, Operand(kIsSymbolMask)); |
| 1299 | __ b(eq, possible_strings); |
| 1300 | __ CompareObjectType(lhs, r3, r3, FIRST_NONSTRING_TYPE); |
| 1301 | __ b(ge, not_both_strings); |
| 1302 | __ tst(r3, Operand(kIsSymbolMask)); |
| 1303 | __ b(eq, possible_strings); |
| 1304 | |
| 1305 | // Both are symbols. We already checked they weren't the same pointer |
| 1306 | // so they are not equal. |
| 1307 | __ mov(r0, Operand(NOT_EQUAL)); |
| 1308 | __ Ret(); |
| 1309 | |
| 1310 | __ bind(&object_test); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1311 | __ cmp(r2, Operand(FIRST_SPEC_OBJECT_TYPE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1312 | __ b(lt, not_both_strings); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1313 | __ CompareObjectType(lhs, r2, r3, FIRST_SPEC_OBJECT_TYPE); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1314 | __ b(lt, not_both_strings); |
| 1315 | // If both objects are undetectable, they are equal. Otherwise, they |
| 1316 | // are not equal, since they are different objects and an object is not |
| 1317 | // equal to undefined. |
| 1318 | __ ldr(r3, FieldMemOperand(rhs, HeapObject::kMapOffset)); |
| 1319 | __ ldrb(r2, FieldMemOperand(r2, Map::kBitFieldOffset)); |
| 1320 | __ ldrb(r3, FieldMemOperand(r3, Map::kBitFieldOffset)); |
| 1321 | __ and_(r0, r2, Operand(r3)); |
| 1322 | __ and_(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 1323 | __ eor(r0, r0, Operand(1 << Map::kIsUndetectable)); |
| 1324 | __ Ret(); |
| 1325 | } |
| 1326 | |
| 1327 | |
| 1328 | void NumberToStringStub::GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 1329 | Register object, |
| 1330 | Register result, |
| 1331 | Register scratch1, |
| 1332 | Register scratch2, |
| 1333 | Register scratch3, |
| 1334 | bool object_is_smi, |
| 1335 | Label* not_found) { |
| 1336 | // Use of registers. Register result is used as a temporary. |
| 1337 | Register number_string_cache = result; |
| 1338 | Register mask = scratch3; |
| 1339 | |
| 1340 | // Load the number string cache. |
| 1341 | __ LoadRoot(number_string_cache, Heap::kNumberStringCacheRootIndex); |
| 1342 | |
| 1343 | // Make the hash mask from the length of the number string cache. It |
| 1344 | // contains two elements (number and string) for each cache entry. |
| 1345 | __ ldr(mask, FieldMemOperand(number_string_cache, FixedArray::kLengthOffset)); |
| 1346 | // Divide length by two (length is a smi). |
| 1347 | __ mov(mask, Operand(mask, ASR, kSmiTagSize + 1)); |
| 1348 | __ sub(mask, mask, Operand(1)); // Make mask. |
| 1349 | |
| 1350 | // Calculate the entry in the number string cache. The hash value in the |
| 1351 | // number string cache for smis is just the smi value, and the hash for |
| 1352 | // doubles is the xor of the upper and lower words. See |
| 1353 | // Heap::GetNumberStringCache. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1354 | Isolate* isolate = masm->isolate(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1355 | Label is_smi; |
| 1356 | Label load_result_from_cache; |
| 1357 | if (!object_is_smi) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1358 | __ JumpIfSmi(object, &is_smi); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1359 | if (CpuFeatures::IsSupported(VFP3)) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1360 | CpuFeatures::Scope scope(VFP3); |
| 1361 | __ CheckMap(object, |
| 1362 | scratch1, |
| 1363 | Heap::kHeapNumberMapRootIndex, |
| 1364 | not_found, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1365 | DONT_DO_SMI_CHECK); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1366 | |
| 1367 | STATIC_ASSERT(8 == kDoubleSize); |
| 1368 | __ add(scratch1, |
| 1369 | object, |
| 1370 | Operand(HeapNumber::kValueOffset - kHeapObjectTag)); |
| 1371 | __ ldm(ia, scratch1, scratch1.bit() | scratch2.bit()); |
| 1372 | __ eor(scratch1, scratch1, Operand(scratch2)); |
| 1373 | __ and_(scratch1, scratch1, Operand(mask)); |
| 1374 | |
| 1375 | // Calculate address of entry in string cache: each entry consists |
| 1376 | // of two pointer sized fields. |
| 1377 | __ add(scratch1, |
| 1378 | number_string_cache, |
| 1379 | Operand(scratch1, LSL, kPointerSizeLog2 + 1)); |
| 1380 | |
| 1381 | Register probe = mask; |
| 1382 | __ ldr(probe, |
| 1383 | FieldMemOperand(scratch1, FixedArray::kHeaderSize)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1384 | __ JumpIfSmi(probe, not_found); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1385 | __ sub(scratch2, object, Operand(kHeapObjectTag)); |
| 1386 | __ vldr(d0, scratch2, HeapNumber::kValueOffset); |
| 1387 | __ sub(probe, probe, Operand(kHeapObjectTag)); |
| 1388 | __ vldr(d1, probe, HeapNumber::kValueOffset); |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1389 | __ VFPCompareAndSetFlags(d0, d1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1390 | __ b(ne, not_found); // The cache did not contain this value. |
| 1391 | __ b(&load_result_from_cache); |
| 1392 | } else { |
| 1393 | __ b(not_found); |
| 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | __ bind(&is_smi); |
| 1398 | Register scratch = scratch1; |
| 1399 | __ and_(scratch, mask, Operand(object, ASR, 1)); |
| 1400 | // Calculate address of entry in string cache: each entry consists |
| 1401 | // of two pointer sized fields. |
| 1402 | __ add(scratch, |
| 1403 | number_string_cache, |
| 1404 | Operand(scratch, LSL, kPointerSizeLog2 + 1)); |
| 1405 | |
| 1406 | // Check if the entry is the smi we are looking for. |
| 1407 | Register probe = mask; |
| 1408 | __ ldr(probe, FieldMemOperand(scratch, FixedArray::kHeaderSize)); |
| 1409 | __ cmp(object, probe); |
| 1410 | __ b(ne, not_found); |
| 1411 | |
| 1412 | // Get the result from the cache. |
| 1413 | __ bind(&load_result_from_cache); |
| 1414 | __ ldr(result, |
| 1415 | FieldMemOperand(scratch, FixedArray::kHeaderSize + kPointerSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1416 | __ IncrementCounter(isolate->counters()->number_to_string_native(), |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1417 | 1, |
| 1418 | scratch1, |
| 1419 | scratch2); |
| 1420 | } |
| 1421 | |
| 1422 | |
| 1423 | void NumberToStringStub::Generate(MacroAssembler* masm) { |
| 1424 | Label runtime; |
| 1425 | |
| 1426 | __ ldr(r1, MemOperand(sp, 0)); |
| 1427 | |
| 1428 | // Generate code to lookup number in the number string cache. |
| 1429 | GenerateLookupNumberStringCache(masm, r1, r0, r2, r3, r4, false, &runtime); |
| 1430 | __ add(sp, sp, Operand(1 * kPointerSize)); |
| 1431 | __ Ret(); |
| 1432 | |
| 1433 | __ bind(&runtime); |
| 1434 | // Handle number to string in the runtime system if not found in the cache. |
| 1435 | __ TailCallRuntime(Runtime::kNumberToStringSkipCache, 1, 1); |
| 1436 | } |
| 1437 | |
| 1438 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1439 | // On entry lhs_ and rhs_ are the values to be compared. |
| 1440 | // On exit r0 is 0, positive or negative to indicate the result of |
| 1441 | // the comparison. |
| 1442 | void CompareStub::Generate(MacroAssembler* masm) { |
| 1443 | ASSERT((lhs_.is(r0) && rhs_.is(r1)) || |
| 1444 | (lhs_.is(r1) && rhs_.is(r0))); |
| 1445 | |
| 1446 | Label slow; // Call builtin. |
| 1447 | Label not_smis, both_loaded_as_doubles, lhs_not_nan; |
| 1448 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1449 | if (include_smi_compare_) { |
| 1450 | Label not_two_smis, smi_done; |
| 1451 | __ orr(r2, r1, r0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1452 | __ JumpIfNotSmi(r2, ¬_two_smis); |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 1453 | __ mov(r1, Operand(r1, ASR, 1)); |
| 1454 | __ sub(r0, r1, Operand(r0, ASR, 1)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1455 | __ Ret(); |
| 1456 | __ bind(¬_two_smis); |
| 1457 | } else if (FLAG_debug_code) { |
| 1458 | __ orr(r2, r1, r0); |
| 1459 | __ tst(r2, Operand(kSmiTagMask)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 1460 | __ Assert(ne, "CompareStub: unexpected smi operands."); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 1461 | } |
| 1462 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1463 | // NOTICE! This code is only reached after a smi-fast-case check, so |
| 1464 | // it is certain that at least one operand isn't a smi. |
| 1465 | |
| 1466 | // Handle the case where the objects are identical. Either returns the answer |
| 1467 | // or goes to slow. Only falls through if the objects were not identical. |
| 1468 | EmitIdenticalObjectComparison(masm, &slow, cc_, never_nan_nan_); |
| 1469 | |
| 1470 | // If either is a Smi (we know that not both are), then they can only |
| 1471 | // be strictly equal if the other is a HeapNumber. |
| 1472 | STATIC_ASSERT(kSmiTag == 0); |
| 1473 | ASSERT_EQ(0, Smi::FromInt(0)); |
| 1474 | __ and_(r2, lhs_, Operand(rhs_)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1475 | __ JumpIfNotSmi(r2, ¬_smis); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1476 | // One operand is a smi. EmitSmiNonsmiComparison generates code that can: |
| 1477 | // 1) Return the answer. |
| 1478 | // 2) Go to slow. |
| 1479 | // 3) Fall through to both_loaded_as_doubles. |
| 1480 | // 4) Jump to lhs_not_nan. |
| 1481 | // In cases 3 and 4 we have found out we were dealing with a number-number |
| 1482 | // comparison. If VFP3 is supported the double values of the numbers have |
| 1483 | // been loaded into d7 and d6. Otherwise, the double values have been loaded |
| 1484 | // into r0, r1, r2, and r3. |
| 1485 | EmitSmiNonsmiComparison(masm, lhs_, rhs_, &lhs_not_nan, &slow, strict_); |
| 1486 | |
| 1487 | __ bind(&both_loaded_as_doubles); |
| 1488 | // The arguments have been converted to doubles and stored in d6 and d7, if |
| 1489 | // VFP3 is supported, or in r0, r1, r2, and r3. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1490 | Isolate* isolate = masm->isolate(); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 1491 | if (CpuFeatures::IsSupported(VFP3)) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1492 | __ bind(&lhs_not_nan); |
| 1493 | CpuFeatures::Scope scope(VFP3); |
| 1494 | Label no_nan; |
| 1495 | // ARMv7 VFP3 instructions to implement double precision comparison. |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 1496 | __ VFPCompareAndSetFlags(d7, d6); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1497 | Label nan; |
| 1498 | __ b(vs, &nan); |
| 1499 | __ mov(r0, Operand(EQUAL), LeaveCC, eq); |
| 1500 | __ mov(r0, Operand(LESS), LeaveCC, lt); |
| 1501 | __ mov(r0, Operand(GREATER), LeaveCC, gt); |
| 1502 | __ Ret(); |
| 1503 | |
| 1504 | __ bind(&nan); |
| 1505 | // If one of the sides was a NaN then the v flag is set. Load r0 with |
| 1506 | // whatever it takes to make the comparison fail, since comparisons with NaN |
| 1507 | // always fail. |
| 1508 | if (cc_ == lt || cc_ == le) { |
| 1509 | __ mov(r0, Operand(GREATER)); |
| 1510 | } else { |
| 1511 | __ mov(r0, Operand(LESS)); |
| 1512 | } |
| 1513 | __ Ret(); |
| 1514 | } else { |
| 1515 | // Checks for NaN in the doubles we have loaded. Can return the answer or |
| 1516 | // fall through if neither is a NaN. Also binds lhs_not_nan. |
| 1517 | EmitNanCheck(masm, &lhs_not_nan, cc_); |
| 1518 | // Compares two doubles in r0, r1, r2, r3 that are not NaNs. Returns the |
| 1519 | // answer. Never falls through. |
| 1520 | EmitTwoNonNanDoubleComparison(masm, cc_); |
| 1521 | } |
| 1522 | |
| 1523 | __ bind(¬_smis); |
| 1524 | // At this point we know we are dealing with two different objects, |
| 1525 | // and neither of them is a Smi. The objects are in rhs_ and lhs_. |
| 1526 | if (strict_) { |
| 1527 | // This returns non-equal for some object types, or falls through if it |
| 1528 | // was not lucky. |
| 1529 | EmitStrictTwoHeapObjectCompare(masm, lhs_, rhs_); |
| 1530 | } |
| 1531 | |
| 1532 | Label check_for_symbols; |
| 1533 | Label flat_string_check; |
| 1534 | // Check for heap-number-heap-number comparison. Can jump to slow case, |
| 1535 | // or load both doubles into r0, r1, r2, r3 and jump to the code that handles |
| 1536 | // that case. If the inputs are not doubles then jumps to check_for_symbols. |
| 1537 | // In this case r2 will contain the type of rhs_. Never falls through. |
| 1538 | EmitCheckForTwoHeapNumbers(masm, |
| 1539 | lhs_, |
| 1540 | rhs_, |
| 1541 | &both_loaded_as_doubles, |
| 1542 | &check_for_symbols, |
| 1543 | &flat_string_check); |
| 1544 | |
| 1545 | __ bind(&check_for_symbols); |
| 1546 | // In the strict case the EmitStrictTwoHeapObjectCompare already took care of |
| 1547 | // symbols. |
| 1548 | if (cc_ == eq && !strict_) { |
| 1549 | // Returns an answer for two symbols or two detectable objects. |
| 1550 | // Otherwise jumps to string case or not both strings case. |
| 1551 | // Assumes that r2 is the type of rhs_ on entry. |
| 1552 | EmitCheckForSymbolsOrObjects(masm, lhs_, rhs_, &flat_string_check, &slow); |
| 1553 | } |
| 1554 | |
| 1555 | // Check for both being sequential ASCII strings, and inline if that is the |
| 1556 | // case. |
| 1557 | __ bind(&flat_string_check); |
| 1558 | |
| 1559 | __ JumpIfNonSmisNotBothSequentialAsciiStrings(lhs_, rhs_, r2, r3, &slow); |
| 1560 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 1561 | __ IncrementCounter(isolate->counters()->string_compare_native(), 1, r2, r3); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1562 | if (cc_ == eq) { |
| 1563 | StringCompareStub::GenerateFlatAsciiStringEquals(masm, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1564 | lhs_, |
| 1565 | rhs_, |
| 1566 | r2, |
| 1567 | r3, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1568 | r4); |
| 1569 | } else { |
| 1570 | StringCompareStub::GenerateCompareFlatAsciiStrings(masm, |
| 1571 | lhs_, |
| 1572 | rhs_, |
| 1573 | r2, |
| 1574 | r3, |
| 1575 | r4, |
| 1576 | r5); |
| 1577 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1578 | // Never falls through to here. |
| 1579 | |
| 1580 | __ bind(&slow); |
| 1581 | |
| 1582 | __ Push(lhs_, rhs_); |
| 1583 | // Figure out which native to call and setup the arguments. |
| 1584 | Builtins::JavaScript native; |
| 1585 | if (cc_ == eq) { |
| 1586 | native = strict_ ? Builtins::STRICT_EQUALS : Builtins::EQUALS; |
| 1587 | } else { |
| 1588 | native = Builtins::COMPARE; |
| 1589 | int ncr; // NaN compare result |
| 1590 | if (cc_ == lt || cc_ == le) { |
| 1591 | ncr = GREATER; |
| 1592 | } else { |
| 1593 | ASSERT(cc_ == gt || cc_ == ge); // remaining cases |
| 1594 | ncr = LESS; |
| 1595 | } |
| 1596 | __ mov(r0, Operand(Smi::FromInt(ncr))); |
| 1597 | __ push(r0); |
| 1598 | } |
| 1599 | |
| 1600 | // Call the native; it returns -1 (less), 0 (equal), or 1 (greater) |
| 1601 | // tagged as a small integer. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1602 | __ InvokeBuiltin(native, JUMP_FUNCTION); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1606 | // The stub expects its argument in the tos_ register and returns its result in |
| 1607 | // it, too: zero for false, and a non-zero value for true. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1608 | void ToBooleanStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1609 | // This stub uses VFP3 instructions. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1610 | CpuFeatures::Scope scope(VFP3); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 1611 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1612 | Label patch; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1613 | const Register map = r9.is(tos_) ? r7 : r9; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1614 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1615 | // undefined -> false. |
| 1616 | CheckOddball(masm, UNDEFINED, Heap::kUndefinedValueRootIndex, false); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1617 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1618 | // Boolean -> its value. |
| 1619 | CheckOddball(masm, BOOLEAN, Heap::kFalseValueRootIndex, false); |
| 1620 | CheckOddball(masm, BOOLEAN, Heap::kTrueValueRootIndex, true); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1621 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1622 | // 'null' -> false. |
| 1623 | CheckOddball(masm, NULL_TYPE, Heap::kNullValueRootIndex, false); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1624 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1625 | if (types_.Contains(SMI)) { |
| 1626 | // Smis: 0 -> false, all other -> true |
| 1627 | __ tst(tos_, Operand(kSmiTagMask)); |
| 1628 | // tos_ contains the correct return value already |
| 1629 | __ Ret(eq); |
| 1630 | } else if (types_.NeedsMap()) { |
| 1631 | // If we need a map later and have a Smi -> patch. |
| 1632 | __ JumpIfSmi(tos_, &patch); |
| 1633 | } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 1634 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1635 | if (types_.NeedsMap()) { |
| 1636 | __ ldr(map, FieldMemOperand(tos_, HeapObject::kMapOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1637 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1638 | if (types_.CanBeUndetectable()) { |
| 1639 | __ ldrb(ip, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 1640 | __ tst(ip, Operand(1 << Map::kIsUndetectable)); |
| 1641 | // Undetectable -> false. |
| 1642 | __ mov(tos_, Operand(0, RelocInfo::NONE), LeaveCC, ne); |
| 1643 | __ Ret(ne); |
| 1644 | } |
| 1645 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1646 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1647 | if (types_.Contains(SPEC_OBJECT)) { |
| 1648 | // Spec object -> true. |
| 1649 | __ CompareInstanceType(map, ip, FIRST_SPEC_OBJECT_TYPE); |
| 1650 | // tos_ contains the correct non-zero return value already. |
| 1651 | __ Ret(ge); |
| 1652 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1653 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1654 | if (types_.Contains(STRING)) { |
| 1655 | // String value -> false iff empty. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1656 | __ CompareInstanceType(map, ip, FIRST_NONSTRING_TYPE); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1657 | __ ldr(tos_, FieldMemOperand(tos_, String::kLengthOffset), lt); |
| 1658 | __ Ret(lt); // the string length is OK as the return value |
| 1659 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1660 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1661 | if (types_.Contains(HEAP_NUMBER)) { |
| 1662 | // Heap number -> false iff +0, -0, or NaN. |
| 1663 | Label not_heap_number; |
| 1664 | __ CompareRoot(map, Heap::kHeapNumberMapRootIndex); |
| 1665 | __ b(ne, ¬_heap_number); |
| 1666 | __ vldr(d1, FieldMemOperand(tos_, HeapNumber::kValueOffset)); |
| 1667 | __ VFPCompareAndSetFlags(d1, 0.0); |
| 1668 | // "tos_" is a register, and contains a non zero value by default. |
| 1669 | // Hence we only need to overwrite "tos_" with zero to return false for |
| 1670 | // FP_ZERO or FP_NAN cases. Otherwise, by default it returns true. |
| 1671 | __ mov(tos_, Operand(0, RelocInfo::NONE), LeaveCC, eq); // for FP_ZERO |
| 1672 | __ mov(tos_, Operand(0, RelocInfo::NONE), LeaveCC, vs); // for FP_NAN |
| 1673 | __ Ret(); |
| 1674 | __ bind(¬_heap_number); |
| 1675 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1676 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 1677 | __ bind(&patch); |
| 1678 | GenerateTypeTransition(masm); |
| 1679 | } |
| 1680 | |
| 1681 | |
| 1682 | void ToBooleanStub::CheckOddball(MacroAssembler* masm, |
| 1683 | Type type, |
| 1684 | Heap::RootListIndex value, |
| 1685 | bool result) { |
| 1686 | if (types_.Contains(type)) { |
| 1687 | // If we see an expected oddball, return its ToBoolean value tos_. |
| 1688 | __ LoadRoot(ip, value); |
| 1689 | __ cmp(tos_, ip); |
| 1690 | // The value of a root is never NULL, so we can avoid loading a non-null |
| 1691 | // value into tos_ when we want to return 'true'. |
| 1692 | if (!result) { |
| 1693 | __ mov(tos_, Operand(0, RelocInfo::NONE), LeaveCC, eq); |
| 1694 | } |
| 1695 | __ Ret(eq); |
| 1696 | } |
| 1697 | } |
| 1698 | |
| 1699 | |
| 1700 | void ToBooleanStub::GenerateTypeTransition(MacroAssembler* masm) { |
| 1701 | if (!tos_.is(r3)) { |
| 1702 | __ mov(r3, Operand(tos_)); |
| 1703 | } |
| 1704 | __ mov(r2, Operand(Smi::FromInt(tos_.code()))); |
| 1705 | __ mov(r1, Operand(Smi::FromInt(types_.ToByte()))); |
| 1706 | __ Push(r3, r2, r1); |
| 1707 | // Patch the caller to an appropriate specialized stub and return the |
| 1708 | // operation result to the caller of the stub. |
| 1709 | __ TailCallExternalReference( |
| 1710 | ExternalReference(IC_Utility(IC::kToBoolean_Patch), masm->isolate()), |
| 1711 | 3, |
| 1712 | 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1716 | void UnaryOpStub::PrintName(StringStream* stream) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1717 | const char* op_name = Token::Name(op_); |
| 1718 | const char* overwrite_name = NULL; // Make g++ happy. |
| 1719 | switch (mode_) { |
| 1720 | case UNARY_NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 1721 | case UNARY_OVERWRITE: overwrite_name = "Overwrite"; break; |
| 1722 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1723 | stream->Add("UnaryOpStub_%s_%s_%s", |
| 1724 | op_name, |
| 1725 | overwrite_name, |
| 1726 | UnaryOpIC::GetName(operand_type_)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | |
| 1730 | // TODO(svenpanne): Use virtual functions instead of switch. |
| 1731 | void UnaryOpStub::Generate(MacroAssembler* masm) { |
| 1732 | switch (operand_type_) { |
| 1733 | case UnaryOpIC::UNINITIALIZED: |
| 1734 | GenerateTypeTransition(masm); |
| 1735 | break; |
| 1736 | case UnaryOpIC::SMI: |
| 1737 | GenerateSmiStub(masm); |
| 1738 | break; |
| 1739 | case UnaryOpIC::HEAP_NUMBER: |
| 1740 | GenerateHeapNumberStub(masm); |
| 1741 | break; |
| 1742 | case UnaryOpIC::GENERIC: |
| 1743 | GenerateGenericStub(masm); |
| 1744 | break; |
| 1745 | } |
| 1746 | } |
| 1747 | |
| 1748 | |
| 1749 | void UnaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1750 | __ mov(r3, Operand(r0)); // the operand |
| 1751 | __ mov(r2, Operand(Smi::FromInt(op_))); |
| 1752 | __ mov(r1, Operand(Smi::FromInt(mode_))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1753 | __ mov(r0, Operand(Smi::FromInt(operand_type_))); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1754 | __ Push(r3, r2, r1, r0); |
| 1755 | |
| 1756 | __ TailCallExternalReference( |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1757 | ExternalReference(IC_Utility(IC::kUnaryOp_Patch), masm->isolate()), 4, 1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | |
| 1761 | // TODO(svenpanne): Use virtual functions instead of switch. |
| 1762 | void UnaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
| 1763 | switch (op_) { |
| 1764 | case Token::SUB: |
| 1765 | GenerateSmiStubSub(masm); |
| 1766 | break; |
| 1767 | case Token::BIT_NOT: |
| 1768 | GenerateSmiStubBitNot(masm); |
| 1769 | break; |
| 1770 | default: |
| 1771 | UNREACHABLE(); |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | |
| 1776 | void UnaryOpStub::GenerateSmiStubSub(MacroAssembler* masm) { |
| 1777 | Label non_smi, slow; |
| 1778 | GenerateSmiCodeSub(masm, &non_smi, &slow); |
| 1779 | __ bind(&non_smi); |
| 1780 | __ bind(&slow); |
| 1781 | GenerateTypeTransition(masm); |
| 1782 | } |
| 1783 | |
| 1784 | |
| 1785 | void UnaryOpStub::GenerateSmiStubBitNot(MacroAssembler* masm) { |
| 1786 | Label non_smi; |
| 1787 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 1788 | __ bind(&non_smi); |
| 1789 | GenerateTypeTransition(masm); |
| 1790 | } |
| 1791 | |
| 1792 | |
| 1793 | void UnaryOpStub::GenerateSmiCodeSub(MacroAssembler* masm, |
| 1794 | Label* non_smi, |
| 1795 | Label* slow) { |
| 1796 | __ JumpIfNotSmi(r0, non_smi); |
| 1797 | |
| 1798 | // The result of negating zero or the smallest negative smi is not a smi. |
| 1799 | __ bic(ip, r0, Operand(0x80000000), SetCC); |
| 1800 | __ b(eq, slow); |
| 1801 | |
| 1802 | // Return '0 - value'. |
| 1803 | __ rsb(r0, r0, Operand(0, RelocInfo::NONE)); |
| 1804 | __ Ret(); |
| 1805 | } |
| 1806 | |
| 1807 | |
| 1808 | void UnaryOpStub::GenerateSmiCodeBitNot(MacroAssembler* masm, |
| 1809 | Label* non_smi) { |
| 1810 | __ JumpIfNotSmi(r0, non_smi); |
| 1811 | |
| 1812 | // Flip bits and revert inverted smi-tag. |
| 1813 | __ mvn(r0, Operand(r0)); |
| 1814 | __ bic(r0, r0, Operand(kSmiTagMask)); |
| 1815 | __ Ret(); |
| 1816 | } |
| 1817 | |
| 1818 | |
| 1819 | // TODO(svenpanne): Use virtual functions instead of switch. |
| 1820 | void UnaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
| 1821 | switch (op_) { |
| 1822 | case Token::SUB: |
| 1823 | GenerateHeapNumberStubSub(masm); |
| 1824 | break; |
| 1825 | case Token::BIT_NOT: |
| 1826 | GenerateHeapNumberStubBitNot(masm); |
| 1827 | break; |
| 1828 | default: |
| 1829 | UNREACHABLE(); |
| 1830 | } |
| 1831 | } |
| 1832 | |
| 1833 | |
| 1834 | void UnaryOpStub::GenerateHeapNumberStubSub(MacroAssembler* masm) { |
| 1835 | Label non_smi, slow, call_builtin; |
| 1836 | GenerateSmiCodeSub(masm, &non_smi, &call_builtin); |
| 1837 | __ bind(&non_smi); |
| 1838 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1839 | __ bind(&slow); |
| 1840 | GenerateTypeTransition(masm); |
| 1841 | __ bind(&call_builtin); |
| 1842 | GenerateGenericCodeFallback(masm); |
| 1843 | } |
| 1844 | |
| 1845 | |
| 1846 | void UnaryOpStub::GenerateHeapNumberStubBitNot(MacroAssembler* masm) { |
| 1847 | Label non_smi, slow; |
| 1848 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 1849 | __ bind(&non_smi); |
| 1850 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1851 | __ bind(&slow); |
| 1852 | GenerateTypeTransition(masm); |
| 1853 | } |
| 1854 | |
| 1855 | void UnaryOpStub::GenerateHeapNumberCodeSub(MacroAssembler* masm, |
| 1856 | Label* slow) { |
| 1857 | EmitCheckForHeapNumber(masm, r0, r1, r6, slow); |
| 1858 | // r0 is a heap number. Get a new heap number in r1. |
| 1859 | if (mode_ == UNARY_OVERWRITE) { |
| 1860 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 1861 | __ eor(r2, r2, Operand(HeapNumber::kSignMask)); // Flip sign. |
| 1862 | __ str(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 1863 | } else { |
| 1864 | Label slow_allocate_heapnumber, heapnumber_allocated; |
| 1865 | __ AllocateHeapNumber(r1, r2, r3, r6, &slow_allocate_heapnumber); |
| 1866 | __ jmp(&heapnumber_allocated); |
| 1867 | |
| 1868 | __ bind(&slow_allocate_heapnumber); |
| 1869 | __ EnterInternalFrame(); |
| 1870 | __ push(r0); |
| 1871 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1872 | __ mov(r1, Operand(r0)); |
| 1873 | __ pop(r0); |
| 1874 | __ LeaveInternalFrame(); |
| 1875 | |
| 1876 | __ bind(&heapnumber_allocated); |
| 1877 | __ ldr(r3, FieldMemOperand(r0, HeapNumber::kMantissaOffset)); |
| 1878 | __ ldr(r2, FieldMemOperand(r0, HeapNumber::kExponentOffset)); |
| 1879 | __ str(r3, FieldMemOperand(r1, HeapNumber::kMantissaOffset)); |
| 1880 | __ eor(r2, r2, Operand(HeapNumber::kSignMask)); // Flip sign. |
| 1881 | __ str(r2, FieldMemOperand(r1, HeapNumber::kExponentOffset)); |
| 1882 | __ mov(r0, Operand(r1)); |
| 1883 | } |
| 1884 | __ Ret(); |
| 1885 | } |
| 1886 | |
| 1887 | |
| 1888 | void UnaryOpStub::GenerateHeapNumberCodeBitNot( |
| 1889 | MacroAssembler* masm, Label* slow) { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1890 | Label impossible; |
| 1891 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1892 | EmitCheckForHeapNumber(masm, r0, r1, r6, slow); |
| 1893 | // Convert the heap number is r0 to an untagged integer in r1. |
| 1894 | __ ConvertToInt32(r0, r1, r2, r3, d0, slow); |
| 1895 | |
| 1896 | // Do the bitwise operation and check if the result fits in a smi. |
| 1897 | Label try_float; |
| 1898 | __ mvn(r1, Operand(r1)); |
| 1899 | __ add(r2, r1, Operand(0x40000000), SetCC); |
| 1900 | __ b(mi, &try_float); |
| 1901 | |
| 1902 | // Tag the result as a smi and we're done. |
| 1903 | __ mov(r0, Operand(r1, LSL, kSmiTagSize)); |
| 1904 | __ Ret(); |
| 1905 | |
| 1906 | // Try to store the result in a heap number. |
| 1907 | __ bind(&try_float); |
| 1908 | if (mode_ == UNARY_NO_OVERWRITE) { |
| 1909 | Label slow_allocate_heapnumber, heapnumber_allocated; |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1910 | // Allocate a new heap number without zapping r0, which we need if it fails. |
| 1911 | __ AllocateHeapNumber(r2, r3, r4, r6, &slow_allocate_heapnumber); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1912 | __ jmp(&heapnumber_allocated); |
| 1913 | |
| 1914 | __ bind(&slow_allocate_heapnumber); |
| 1915 | __ EnterInternalFrame(); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1916 | __ push(r0); // Push the heap number, not the untagged int32. |
| 1917 | __ CallRuntime(Runtime::kNumberAlloc, 0); |
| 1918 | __ mov(r2, r0); // Move the new heap number into r2. |
| 1919 | // Get the heap number into r0, now that the new heap number is in r2. |
| 1920 | __ pop(r0); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1921 | __ LeaveInternalFrame(); |
| 1922 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1923 | // Convert the heap number in r0 to an untagged integer in r1. |
| 1924 | // This can't go slow-case because it's the same number we already |
| 1925 | // converted once again. |
| 1926 | __ ConvertToInt32(r0, r1, r3, r4, d0, &impossible); |
| 1927 | __ mvn(r1, Operand(r1)); |
| 1928 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1929 | __ bind(&heapnumber_allocated); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1930 | __ mov(r0, r2); // Move newly allocated heap number to r0. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1931 | } |
| 1932 | |
| 1933 | if (CpuFeatures::IsSupported(VFP3)) { |
| 1934 | // Convert the int32 in r1 to the heap number in r0. r2 is corrupted. |
| 1935 | CpuFeatures::Scope scope(VFP3); |
| 1936 | __ vmov(s0, r1); |
| 1937 | __ vcvt_f64_s32(d0, s0); |
| 1938 | __ sub(r2, r0, Operand(kHeapObjectTag)); |
| 1939 | __ vstr(d0, r2, HeapNumber::kValueOffset); |
| 1940 | __ Ret(); |
| 1941 | } else { |
| 1942 | // WriteInt32ToHeapNumberStub does not trigger GC, so we do not |
| 1943 | // have to set up a frame. |
| 1944 | WriteInt32ToHeapNumberStub stub(r1, r0, r2); |
| 1945 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 1946 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 1947 | |
| 1948 | __ bind(&impossible); |
| 1949 | if (FLAG_debug_code) { |
| 1950 | __ stop("Incorrect assumption in bit-not stub"); |
| 1951 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | |
| 1955 | // TODO(svenpanne): Use virtual functions instead of switch. |
| 1956 | void UnaryOpStub::GenerateGenericStub(MacroAssembler* masm) { |
| 1957 | switch (op_) { |
| 1958 | case Token::SUB: |
| 1959 | GenerateGenericStubSub(masm); |
| 1960 | break; |
| 1961 | case Token::BIT_NOT: |
| 1962 | GenerateGenericStubBitNot(masm); |
| 1963 | break; |
| 1964 | default: |
| 1965 | UNREACHABLE(); |
| 1966 | } |
| 1967 | } |
| 1968 | |
| 1969 | |
| 1970 | void UnaryOpStub::GenerateGenericStubSub(MacroAssembler* masm) { |
| 1971 | Label non_smi, slow; |
| 1972 | GenerateSmiCodeSub(masm, &non_smi, &slow); |
| 1973 | __ bind(&non_smi); |
| 1974 | GenerateHeapNumberCodeSub(masm, &slow); |
| 1975 | __ bind(&slow); |
| 1976 | GenerateGenericCodeFallback(masm); |
| 1977 | } |
| 1978 | |
| 1979 | |
| 1980 | void UnaryOpStub::GenerateGenericStubBitNot(MacroAssembler* masm) { |
| 1981 | Label non_smi, slow; |
| 1982 | GenerateSmiCodeBitNot(masm, &non_smi); |
| 1983 | __ bind(&non_smi); |
| 1984 | GenerateHeapNumberCodeBitNot(masm, &slow); |
| 1985 | __ bind(&slow); |
| 1986 | GenerateGenericCodeFallback(masm); |
| 1987 | } |
| 1988 | |
| 1989 | |
| 1990 | void UnaryOpStub::GenerateGenericCodeFallback(MacroAssembler* masm) { |
| 1991 | // Handle the slow case by jumping to the JavaScript builtin. |
| 1992 | __ push(r0); |
| 1993 | switch (op_) { |
| 1994 | case Token::SUB: |
| 1995 | __ InvokeBuiltin(Builtins::UNARY_MINUS, JUMP_FUNCTION); |
| 1996 | break; |
| 1997 | case Token::BIT_NOT: |
| 1998 | __ InvokeBuiltin(Builtins::BIT_NOT, JUMP_FUNCTION); |
| 1999 | break; |
| 2000 | default: |
| 2001 | UNREACHABLE(); |
| 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2006 | void BinaryOpStub::GenerateTypeTransition(MacroAssembler* masm) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2007 | Label get_result; |
| 2008 | |
| 2009 | __ Push(r1, r0); |
| 2010 | |
| 2011 | __ mov(r2, Operand(Smi::FromInt(MinorKey()))); |
| 2012 | __ mov(r1, Operand(Smi::FromInt(op_))); |
| 2013 | __ mov(r0, Operand(Smi::FromInt(operands_type_))); |
| 2014 | __ Push(r2, r1, r0); |
| 2015 | |
| 2016 | __ TailCallExternalReference( |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2017 | ExternalReference(IC_Utility(IC::kBinaryOp_Patch), |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2018 | masm->isolate()), |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2019 | 5, |
| 2020 | 1); |
| 2021 | } |
| 2022 | |
| 2023 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2024 | void BinaryOpStub::GenerateTypeTransitionWithSavedArgs( |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2025 | MacroAssembler* masm) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2026 | UNIMPLEMENTED(); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2027 | } |
| 2028 | |
| 2029 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2030 | void BinaryOpStub::Generate(MacroAssembler* masm) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2031 | switch (operands_type_) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2032 | case BinaryOpIC::UNINITIALIZED: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2033 | GenerateTypeTransition(masm); |
| 2034 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2035 | case BinaryOpIC::SMI: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2036 | GenerateSmiStub(masm); |
| 2037 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2038 | case BinaryOpIC::INT32: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2039 | GenerateInt32Stub(masm); |
| 2040 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2041 | case BinaryOpIC::HEAP_NUMBER: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2042 | GenerateHeapNumberStub(masm); |
| 2043 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2044 | case BinaryOpIC::ODDBALL: |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2045 | GenerateOddballStub(masm); |
| 2046 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2047 | case BinaryOpIC::BOTH_STRING: |
| 2048 | GenerateBothStringStub(masm); |
| 2049 | break; |
| 2050 | case BinaryOpIC::STRING: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2051 | GenerateStringStub(masm); |
| 2052 | break; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2053 | case BinaryOpIC::GENERIC: |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2054 | GenerateGeneric(masm); |
| 2055 | break; |
| 2056 | default: |
| 2057 | UNREACHABLE(); |
| 2058 | } |
| 2059 | } |
| 2060 | |
| 2061 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2062 | void BinaryOpStub::PrintName(StringStream* stream) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2063 | const char* op_name = Token::Name(op_); |
| 2064 | const char* overwrite_name; |
| 2065 | switch (mode_) { |
| 2066 | case NO_OVERWRITE: overwrite_name = "Alloc"; break; |
| 2067 | case OVERWRITE_RIGHT: overwrite_name = "OverwriteRight"; break; |
| 2068 | case OVERWRITE_LEFT: overwrite_name = "OverwriteLeft"; break; |
| 2069 | default: overwrite_name = "UnknownOverwrite"; break; |
| 2070 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2071 | stream->Add("BinaryOpStub_%s_%s_%s", |
| 2072 | op_name, |
| 2073 | overwrite_name, |
| 2074 | BinaryOpIC::GetName(operands_type_)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2078 | void BinaryOpStub::GenerateSmiSmiOperation(MacroAssembler* masm) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2079 | Register left = r1; |
| 2080 | Register right = r0; |
| 2081 | Register scratch1 = r7; |
| 2082 | Register scratch2 = r9; |
| 2083 | |
| 2084 | ASSERT(right.is(r0)); |
| 2085 | STATIC_ASSERT(kSmiTag == 0); |
| 2086 | |
| 2087 | Label not_smi_result; |
| 2088 | switch (op_) { |
| 2089 | case Token::ADD: |
| 2090 | __ add(right, left, Operand(right), SetCC); // Add optimistically. |
| 2091 | __ Ret(vc); |
| 2092 | __ sub(right, right, Operand(left)); // Revert optimistic add. |
| 2093 | break; |
| 2094 | case Token::SUB: |
| 2095 | __ sub(right, left, Operand(right), SetCC); // Subtract optimistically. |
| 2096 | __ Ret(vc); |
| 2097 | __ sub(right, left, Operand(right)); // Revert optimistic subtract. |
| 2098 | break; |
| 2099 | case Token::MUL: |
| 2100 | // Remove tag from one of the operands. This way the multiplication result |
| 2101 | // will be a smi if it fits the smi range. |
| 2102 | __ SmiUntag(ip, right); |
| 2103 | // Do multiplication |
| 2104 | // scratch1 = lower 32 bits of ip * left. |
| 2105 | // scratch2 = higher 32 bits of ip * left. |
| 2106 | __ smull(scratch1, scratch2, left, ip); |
| 2107 | // Check for overflowing the smi range - no overflow if higher 33 bits of |
| 2108 | // the result are identical. |
| 2109 | __ mov(ip, Operand(scratch1, ASR, 31)); |
| 2110 | __ cmp(ip, Operand(scratch2)); |
| 2111 | __ b(ne, ¬_smi_result); |
| 2112 | // Go slow on zero result to handle -0. |
| 2113 | __ tst(scratch1, Operand(scratch1)); |
| 2114 | __ mov(right, Operand(scratch1), LeaveCC, ne); |
| 2115 | __ Ret(ne); |
| 2116 | // We need -0 if we were multiplying a negative number with 0 to get 0. |
| 2117 | // We know one of them was zero. |
| 2118 | __ add(scratch2, right, Operand(left), SetCC); |
| 2119 | __ mov(right, Operand(Smi::FromInt(0)), LeaveCC, pl); |
| 2120 | __ Ret(pl); // Return smi 0 if the non-zero one was positive. |
| 2121 | // We fall through here if we multiplied a negative number with 0, because |
| 2122 | // that would mean we should produce -0. |
| 2123 | break; |
| 2124 | case Token::DIV: |
| 2125 | // Check for power of two on the right hand side. |
| 2126 | __ JumpIfNotPowerOfTwoOrZero(right, scratch1, ¬_smi_result); |
| 2127 | // Check for positive and no remainder (scratch1 contains right - 1). |
| 2128 | __ orr(scratch2, scratch1, Operand(0x80000000u)); |
| 2129 | __ tst(left, scratch2); |
| 2130 | __ b(ne, ¬_smi_result); |
| 2131 | |
| 2132 | // Perform division by shifting. |
| 2133 | __ CountLeadingZeros(scratch1, scratch1, scratch2); |
| 2134 | __ rsb(scratch1, scratch1, Operand(31)); |
| 2135 | __ mov(right, Operand(left, LSR, scratch1)); |
| 2136 | __ Ret(); |
| 2137 | break; |
| 2138 | case Token::MOD: |
| 2139 | // Check for two positive smis. |
| 2140 | __ orr(scratch1, left, Operand(right)); |
| 2141 | __ tst(scratch1, Operand(0x80000000u | kSmiTagMask)); |
| 2142 | __ b(ne, ¬_smi_result); |
| 2143 | |
| 2144 | // Check for power of two on the right hand side. |
| 2145 | __ JumpIfNotPowerOfTwoOrZero(right, scratch1, ¬_smi_result); |
| 2146 | |
| 2147 | // Perform modulus by masking. |
| 2148 | __ and_(right, left, Operand(scratch1)); |
| 2149 | __ Ret(); |
| 2150 | break; |
| 2151 | case Token::BIT_OR: |
| 2152 | __ orr(right, left, Operand(right)); |
| 2153 | __ Ret(); |
| 2154 | break; |
| 2155 | case Token::BIT_AND: |
| 2156 | __ and_(right, left, Operand(right)); |
| 2157 | __ Ret(); |
| 2158 | break; |
| 2159 | case Token::BIT_XOR: |
| 2160 | __ eor(right, left, Operand(right)); |
| 2161 | __ Ret(); |
| 2162 | break; |
| 2163 | case Token::SAR: |
| 2164 | // Remove tags from right operand. |
| 2165 | __ GetLeastBitsFromSmi(scratch1, right, 5); |
| 2166 | __ mov(right, Operand(left, ASR, scratch1)); |
| 2167 | // Smi tag result. |
| 2168 | __ bic(right, right, Operand(kSmiTagMask)); |
| 2169 | __ Ret(); |
| 2170 | break; |
| 2171 | case Token::SHR: |
| 2172 | // Remove tags from operands. We can't do this on a 31 bit number |
| 2173 | // because then the 0s get shifted into bit 30 instead of bit 31. |
| 2174 | __ SmiUntag(scratch1, left); |
| 2175 | __ GetLeastBitsFromSmi(scratch2, right, 5); |
| 2176 | __ mov(scratch1, Operand(scratch1, LSR, scratch2)); |
| 2177 | // Unsigned shift is not allowed to produce a negative number, so |
| 2178 | // check the sign bit and the sign bit after Smi tagging. |
| 2179 | __ tst(scratch1, Operand(0xc0000000)); |
| 2180 | __ b(ne, ¬_smi_result); |
| 2181 | // Smi tag result. |
| 2182 | __ SmiTag(right, scratch1); |
| 2183 | __ Ret(); |
| 2184 | break; |
| 2185 | case Token::SHL: |
| 2186 | // Remove tags from operands. |
| 2187 | __ SmiUntag(scratch1, left); |
| 2188 | __ GetLeastBitsFromSmi(scratch2, right, 5); |
| 2189 | __ mov(scratch1, Operand(scratch1, LSL, scratch2)); |
| 2190 | // Check that the signed result fits in a Smi. |
| 2191 | __ add(scratch2, scratch1, Operand(0x40000000), SetCC); |
| 2192 | __ b(mi, ¬_smi_result); |
| 2193 | __ SmiTag(right, scratch1); |
| 2194 | __ Ret(); |
| 2195 | break; |
| 2196 | default: |
| 2197 | UNREACHABLE(); |
| 2198 | } |
| 2199 | __ bind(¬_smi_result); |
| 2200 | } |
| 2201 | |
| 2202 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2203 | void BinaryOpStub::GenerateFPOperation(MacroAssembler* masm, |
| 2204 | bool smi_operands, |
| 2205 | Label* not_numbers, |
| 2206 | Label* gc_required) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2207 | Register left = r1; |
| 2208 | Register right = r0; |
| 2209 | Register scratch1 = r7; |
| 2210 | Register scratch2 = r9; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2211 | Register scratch3 = r4; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2212 | |
| 2213 | ASSERT(smi_operands || (not_numbers != NULL)); |
| 2214 | if (smi_operands && FLAG_debug_code) { |
| 2215 | __ AbortIfNotSmi(left); |
| 2216 | __ AbortIfNotSmi(right); |
| 2217 | } |
| 2218 | |
| 2219 | Register heap_number_map = r6; |
| 2220 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2221 | |
| 2222 | switch (op_) { |
| 2223 | case Token::ADD: |
| 2224 | case Token::SUB: |
| 2225 | case Token::MUL: |
| 2226 | case Token::DIV: |
| 2227 | case Token::MOD: { |
| 2228 | // Load left and right operands into d6 and d7 or r0/r1 and r2/r3 |
| 2229 | // depending on whether VFP3 is available or not. |
| 2230 | FloatingPointHelper::Destination destination = |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2231 | CpuFeatures::IsSupported(VFP3) && |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2232 | op_ != Token::MOD ? |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2233 | FloatingPointHelper::kVFPRegisters : |
| 2234 | FloatingPointHelper::kCoreRegisters; |
| 2235 | |
| 2236 | // Allocate new heap number for result. |
| 2237 | Register result = r5; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2238 | GenerateHeapResultAllocation( |
| 2239 | masm, result, heap_number_map, scratch1, scratch2, gc_required); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2240 | |
| 2241 | // Load the operands. |
| 2242 | if (smi_operands) { |
| 2243 | FloatingPointHelper::LoadSmis(masm, destination, scratch1, scratch2); |
| 2244 | } else { |
| 2245 | FloatingPointHelper::LoadOperands(masm, |
| 2246 | destination, |
| 2247 | heap_number_map, |
| 2248 | scratch1, |
| 2249 | scratch2, |
| 2250 | not_numbers); |
| 2251 | } |
| 2252 | |
| 2253 | // Calculate the result. |
| 2254 | if (destination == FloatingPointHelper::kVFPRegisters) { |
| 2255 | // Using VFP registers: |
| 2256 | // d6: Left value |
| 2257 | // d7: Right value |
| 2258 | CpuFeatures::Scope scope(VFP3); |
| 2259 | switch (op_) { |
| 2260 | case Token::ADD: |
| 2261 | __ vadd(d5, d6, d7); |
| 2262 | break; |
| 2263 | case Token::SUB: |
| 2264 | __ vsub(d5, d6, d7); |
| 2265 | break; |
| 2266 | case Token::MUL: |
| 2267 | __ vmul(d5, d6, d7); |
| 2268 | break; |
| 2269 | case Token::DIV: |
| 2270 | __ vdiv(d5, d6, d7); |
| 2271 | break; |
| 2272 | default: |
| 2273 | UNREACHABLE(); |
| 2274 | } |
| 2275 | |
| 2276 | __ sub(r0, result, Operand(kHeapObjectTag)); |
| 2277 | __ vstr(d5, r0, HeapNumber::kValueOffset); |
| 2278 | __ add(r0, r0, Operand(kHeapObjectTag)); |
| 2279 | __ Ret(); |
| 2280 | } else { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2281 | // Call the C function to handle the double operation. |
| 2282 | FloatingPointHelper::CallCCodeForDoubleOperation(masm, |
| 2283 | op_, |
| 2284 | result, |
| 2285 | scratch1); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2286 | if (FLAG_debug_code) { |
| 2287 | __ stop("Unreachable code."); |
| 2288 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2289 | } |
| 2290 | break; |
| 2291 | } |
| 2292 | case Token::BIT_OR: |
| 2293 | case Token::BIT_XOR: |
| 2294 | case Token::BIT_AND: |
| 2295 | case Token::SAR: |
| 2296 | case Token::SHR: |
| 2297 | case Token::SHL: { |
| 2298 | if (smi_operands) { |
| 2299 | __ SmiUntag(r3, left); |
| 2300 | __ SmiUntag(r2, right); |
| 2301 | } else { |
| 2302 | // Convert operands to 32-bit integers. Right in r2 and left in r3. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2303 | FloatingPointHelper::ConvertNumberToInt32(masm, |
| 2304 | left, |
| 2305 | r3, |
| 2306 | heap_number_map, |
| 2307 | scratch1, |
| 2308 | scratch2, |
| 2309 | scratch3, |
| 2310 | d0, |
| 2311 | not_numbers); |
| 2312 | FloatingPointHelper::ConvertNumberToInt32(masm, |
| 2313 | right, |
| 2314 | r2, |
| 2315 | heap_number_map, |
| 2316 | scratch1, |
| 2317 | scratch2, |
| 2318 | scratch3, |
| 2319 | d0, |
| 2320 | not_numbers); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2321 | } |
| 2322 | |
| 2323 | Label result_not_a_smi; |
| 2324 | switch (op_) { |
| 2325 | case Token::BIT_OR: |
| 2326 | __ orr(r2, r3, Operand(r2)); |
| 2327 | break; |
| 2328 | case Token::BIT_XOR: |
| 2329 | __ eor(r2, r3, Operand(r2)); |
| 2330 | break; |
| 2331 | case Token::BIT_AND: |
| 2332 | __ and_(r2, r3, Operand(r2)); |
| 2333 | break; |
| 2334 | case Token::SAR: |
| 2335 | // Use only the 5 least significant bits of the shift count. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2336 | __ GetLeastBitsFromInt32(r2, r2, 5); |
| 2337 | __ mov(r2, Operand(r3, ASR, r2)); |
| 2338 | break; |
| 2339 | case Token::SHR: |
| 2340 | // Use only the 5 least significant bits of the shift count. |
| 2341 | __ GetLeastBitsFromInt32(r2, r2, 5); |
| 2342 | __ mov(r2, Operand(r3, LSR, r2), SetCC); |
| 2343 | // SHR is special because it is required to produce a positive answer. |
| 2344 | // The code below for writing into heap numbers isn't capable of |
| 2345 | // writing the register as an unsigned int so we go to slow case if we |
| 2346 | // hit this case. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2347 | if (CpuFeatures::IsSupported(VFP3)) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2348 | __ b(mi, &result_not_a_smi); |
| 2349 | } else { |
| 2350 | __ b(mi, not_numbers); |
| 2351 | } |
| 2352 | break; |
| 2353 | case Token::SHL: |
| 2354 | // Use only the 5 least significant bits of the shift count. |
| 2355 | __ GetLeastBitsFromInt32(r2, r2, 5); |
| 2356 | __ mov(r2, Operand(r3, LSL, r2)); |
| 2357 | break; |
| 2358 | default: |
| 2359 | UNREACHABLE(); |
| 2360 | } |
| 2361 | |
| 2362 | // Check that the *signed* result fits in a smi. |
| 2363 | __ add(r3, r2, Operand(0x40000000), SetCC); |
| 2364 | __ b(mi, &result_not_a_smi); |
| 2365 | __ SmiTag(r0, r2); |
| 2366 | __ Ret(); |
| 2367 | |
| 2368 | // Allocate new heap number for result. |
| 2369 | __ bind(&result_not_a_smi); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2370 | Register result = r5; |
| 2371 | if (smi_operands) { |
| 2372 | __ AllocateHeapNumber( |
| 2373 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 2374 | } else { |
| 2375 | GenerateHeapResultAllocation( |
| 2376 | masm, result, heap_number_map, scratch1, scratch2, gc_required); |
| 2377 | } |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2378 | |
| 2379 | // r2: Answer as signed int32. |
| 2380 | // r5: Heap number to write answer into. |
| 2381 | |
| 2382 | // Nothing can go wrong now, so move the heap number to r0, which is the |
| 2383 | // result. |
| 2384 | __ mov(r0, Operand(r5)); |
| 2385 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2386 | if (CpuFeatures::IsSupported(VFP3)) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2387 | // Convert the int32 in r2 to the heap number in r0. r3 is corrupted. As |
| 2388 | // mentioned above SHR needs to always produce a positive result. |
| 2389 | CpuFeatures::Scope scope(VFP3); |
| 2390 | __ vmov(s0, r2); |
| 2391 | if (op_ == Token::SHR) { |
| 2392 | __ vcvt_f64_u32(d0, s0); |
| 2393 | } else { |
| 2394 | __ vcvt_f64_s32(d0, s0); |
| 2395 | } |
| 2396 | __ sub(r3, r0, Operand(kHeapObjectTag)); |
| 2397 | __ vstr(d0, r3, HeapNumber::kValueOffset); |
| 2398 | __ Ret(); |
| 2399 | } else { |
| 2400 | // Tail call that writes the int32 in r2 to the heap number in r0, using |
| 2401 | // r3 as scratch. r0 is preserved and returned. |
| 2402 | WriteInt32ToHeapNumberStub stub(r2, r0, r3); |
| 2403 | __ TailCallStub(&stub); |
| 2404 | } |
| 2405 | break; |
| 2406 | } |
| 2407 | default: |
| 2408 | UNREACHABLE(); |
| 2409 | } |
| 2410 | } |
| 2411 | |
| 2412 | |
| 2413 | // Generate the smi code. If the operation on smis are successful this return is |
| 2414 | // generated. If the result is not a smi and heap number allocation is not |
| 2415 | // requested the code falls through. If number allocation is requested but a |
| 2416 | // heap number cannot be allocated the code jumps to the lable gc_required. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2417 | void BinaryOpStub::GenerateSmiCode( |
| 2418 | MacroAssembler* masm, |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2419 | Label* use_runtime, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2420 | Label* gc_required, |
| 2421 | SmiCodeGenerateHeapNumberResults allow_heapnumber_results) { |
| 2422 | Label not_smis; |
| 2423 | |
| 2424 | Register left = r1; |
| 2425 | Register right = r0; |
| 2426 | Register scratch1 = r7; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2427 | |
| 2428 | // Perform combined smi check on both operands. |
| 2429 | __ orr(scratch1, left, Operand(right)); |
| 2430 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2431 | __ JumpIfNotSmi(scratch1, ¬_smis); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2432 | |
| 2433 | // If the smi-smi operation results in a smi return is generated. |
| 2434 | GenerateSmiSmiOperation(masm); |
| 2435 | |
| 2436 | // If heap number results are possible generate the result in an allocated |
| 2437 | // heap number. |
| 2438 | if (allow_heapnumber_results == ALLOW_HEAPNUMBER_RESULTS) { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2439 | GenerateFPOperation(masm, true, use_runtime, gc_required); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2440 | } |
| 2441 | __ bind(¬_smis); |
| 2442 | } |
| 2443 | |
| 2444 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2445 | void BinaryOpStub::GenerateSmiStub(MacroAssembler* masm) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2446 | Label not_smis, call_runtime; |
| 2447 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2448 | if (result_type_ == BinaryOpIC::UNINITIALIZED || |
| 2449 | result_type_ == BinaryOpIC::SMI) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2450 | // Only allow smi results. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2451 | GenerateSmiCode(masm, &call_runtime, NULL, NO_HEAPNUMBER_RESULTS); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2452 | } else { |
| 2453 | // Allow heap number result and don't make a transition if a heap number |
| 2454 | // cannot be allocated. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2455 | GenerateSmiCode(masm, |
| 2456 | &call_runtime, |
| 2457 | &call_runtime, |
| 2458 | ALLOW_HEAPNUMBER_RESULTS); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2459 | } |
| 2460 | |
| 2461 | // Code falls through if the result is not returned as either a smi or heap |
| 2462 | // number. |
| 2463 | GenerateTypeTransition(masm); |
| 2464 | |
| 2465 | __ bind(&call_runtime); |
| 2466 | GenerateCallRuntime(masm); |
| 2467 | } |
| 2468 | |
| 2469 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2470 | void BinaryOpStub::GenerateStringStub(MacroAssembler* masm) { |
| 2471 | ASSERT(operands_type_ == BinaryOpIC::STRING); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2472 | ASSERT(op_ == Token::ADD); |
| 2473 | // Try to add arguments as strings, otherwise, transition to the generic |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2474 | // BinaryOpIC type. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2475 | GenerateAddStrings(masm); |
| 2476 | GenerateTypeTransition(masm); |
| 2477 | } |
| 2478 | |
| 2479 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2480 | void BinaryOpStub::GenerateBothStringStub(MacroAssembler* masm) { |
| 2481 | Label call_runtime; |
| 2482 | ASSERT(operands_type_ == BinaryOpIC::BOTH_STRING); |
| 2483 | ASSERT(op_ == Token::ADD); |
| 2484 | // If both arguments are strings, call the string add stub. |
| 2485 | // Otherwise, do a transition. |
| 2486 | |
| 2487 | // Registers containing left and right operands respectively. |
| 2488 | Register left = r1; |
| 2489 | Register right = r0; |
| 2490 | |
| 2491 | // Test if left operand is a string. |
| 2492 | __ JumpIfSmi(left, &call_runtime); |
| 2493 | __ CompareObjectType(left, r2, r2, FIRST_NONSTRING_TYPE); |
| 2494 | __ b(ge, &call_runtime); |
| 2495 | |
| 2496 | // Test if right operand is a string. |
| 2497 | __ JumpIfSmi(right, &call_runtime); |
| 2498 | __ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE); |
| 2499 | __ b(ge, &call_runtime); |
| 2500 | |
| 2501 | StringAddStub string_add_stub(NO_STRING_CHECK_IN_STUB); |
| 2502 | GenerateRegisterArgsPush(masm); |
| 2503 | __ TailCallStub(&string_add_stub); |
| 2504 | |
| 2505 | __ bind(&call_runtime); |
| 2506 | GenerateTypeTransition(masm); |
| 2507 | } |
| 2508 | |
| 2509 | |
| 2510 | void BinaryOpStub::GenerateInt32Stub(MacroAssembler* masm) { |
| 2511 | ASSERT(operands_type_ == BinaryOpIC::INT32); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2512 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2513 | Register left = r1; |
| 2514 | Register right = r0; |
| 2515 | Register scratch1 = r7; |
| 2516 | Register scratch2 = r9; |
| 2517 | DwVfpRegister double_scratch = d0; |
| 2518 | SwVfpRegister single_scratch = s3; |
| 2519 | |
| 2520 | Register heap_number_result = no_reg; |
| 2521 | Register heap_number_map = r6; |
| 2522 | __ LoadRoot(heap_number_map, Heap::kHeapNumberMapRootIndex); |
| 2523 | |
| 2524 | Label call_runtime; |
| 2525 | // Labels for type transition, used for wrong input or output types. |
| 2526 | // Both label are currently actually bound to the same position. We use two |
| 2527 | // different label to differentiate the cause leading to type transition. |
| 2528 | Label transition; |
| 2529 | |
| 2530 | // Smi-smi fast case. |
| 2531 | Label skip; |
| 2532 | __ orr(scratch1, left, right); |
| 2533 | __ JumpIfNotSmi(scratch1, &skip); |
| 2534 | GenerateSmiSmiOperation(masm); |
| 2535 | // Fall through if the result is not a smi. |
| 2536 | __ bind(&skip); |
| 2537 | |
| 2538 | switch (op_) { |
| 2539 | case Token::ADD: |
| 2540 | case Token::SUB: |
| 2541 | case Token::MUL: |
| 2542 | case Token::DIV: |
| 2543 | case Token::MOD: { |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2544 | // Load both operands and check that they are 32-bit integer. |
| 2545 | // Jump to type transition if they are not. The registers r0 and r1 (right |
| 2546 | // and left) are preserved for the runtime call. |
| 2547 | FloatingPointHelper::Destination destination = |
| 2548 | (CpuFeatures::IsSupported(VFP3) && op_ != Token::MOD) |
| 2549 | ? FloatingPointHelper::kVFPRegisters |
| 2550 | : FloatingPointHelper::kCoreRegisters; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2551 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2552 | FloatingPointHelper::LoadNumberAsInt32Double(masm, |
| 2553 | right, |
| 2554 | destination, |
| 2555 | d7, |
| 2556 | r2, |
| 2557 | r3, |
| 2558 | heap_number_map, |
| 2559 | scratch1, |
| 2560 | scratch2, |
| 2561 | s0, |
| 2562 | &transition); |
| 2563 | FloatingPointHelper::LoadNumberAsInt32Double(masm, |
| 2564 | left, |
| 2565 | destination, |
| 2566 | d6, |
| 2567 | r4, |
| 2568 | r5, |
| 2569 | heap_number_map, |
| 2570 | scratch1, |
| 2571 | scratch2, |
| 2572 | s0, |
| 2573 | &transition); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2574 | |
| 2575 | if (destination == FloatingPointHelper::kVFPRegisters) { |
| 2576 | CpuFeatures::Scope scope(VFP3); |
| 2577 | Label return_heap_number; |
| 2578 | switch (op_) { |
| 2579 | case Token::ADD: |
| 2580 | __ vadd(d5, d6, d7); |
| 2581 | break; |
| 2582 | case Token::SUB: |
| 2583 | __ vsub(d5, d6, d7); |
| 2584 | break; |
| 2585 | case Token::MUL: |
| 2586 | __ vmul(d5, d6, d7); |
| 2587 | break; |
| 2588 | case Token::DIV: |
| 2589 | __ vdiv(d5, d6, d7); |
| 2590 | break; |
| 2591 | default: |
| 2592 | UNREACHABLE(); |
| 2593 | } |
| 2594 | |
| 2595 | if (op_ != Token::DIV) { |
| 2596 | // These operations produce an integer result. |
| 2597 | // Try to return a smi if we can. |
| 2598 | // Otherwise return a heap number if allowed, or jump to type |
| 2599 | // transition. |
| 2600 | |
| 2601 | __ EmitVFPTruncate(kRoundToZero, |
| 2602 | single_scratch, |
| 2603 | d5, |
| 2604 | scratch1, |
| 2605 | scratch2); |
| 2606 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2607 | if (result_type_ <= BinaryOpIC::INT32) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2608 | // If the ne condition is set, result does |
| 2609 | // not fit in a 32-bit integer. |
| 2610 | __ b(ne, &transition); |
| 2611 | } |
| 2612 | |
| 2613 | // Check if the result fits in a smi. |
| 2614 | __ vmov(scratch1, single_scratch); |
| 2615 | __ add(scratch2, scratch1, Operand(0x40000000), SetCC); |
| 2616 | // If not try to return a heap number. |
| 2617 | __ b(mi, &return_heap_number); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2618 | // Check for minus zero. Return heap number for minus zero. |
| 2619 | Label not_zero; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 2620 | __ cmp(scratch1, Operand::Zero()); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2621 | __ b(ne, ¬_zero); |
| 2622 | __ vmov(scratch2, d5.high()); |
| 2623 | __ tst(scratch2, Operand(HeapNumber::kSignMask)); |
| 2624 | __ b(ne, &return_heap_number); |
| 2625 | __ bind(¬_zero); |
| 2626 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2627 | // Tag the result and return. |
| 2628 | __ SmiTag(r0, scratch1); |
| 2629 | __ Ret(); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2630 | } else { |
| 2631 | // DIV just falls through to allocating a heap number. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2632 | } |
| 2633 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2634 | __ bind(&return_heap_number); |
| 2635 | // Return a heap number, or fall through to type transition or runtime |
| 2636 | // call if we can't. |
| 2637 | if (result_type_ >= ((op_ == Token::DIV) ? BinaryOpIC::HEAP_NUMBER |
| 2638 | : BinaryOpIC::INT32)) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2639 | // We are using vfp registers so r5 is available. |
| 2640 | heap_number_result = r5; |
| 2641 | GenerateHeapResultAllocation(masm, |
| 2642 | heap_number_result, |
| 2643 | heap_number_map, |
| 2644 | scratch1, |
| 2645 | scratch2, |
| 2646 | &call_runtime); |
| 2647 | __ sub(r0, heap_number_result, Operand(kHeapObjectTag)); |
| 2648 | __ vstr(d5, r0, HeapNumber::kValueOffset); |
| 2649 | __ mov(r0, heap_number_result); |
| 2650 | __ Ret(); |
| 2651 | } |
| 2652 | |
| 2653 | // A DIV operation expecting an integer result falls through |
| 2654 | // to type transition. |
| 2655 | |
| 2656 | } else { |
| 2657 | // We preserved r0 and r1 to be able to call runtime. |
| 2658 | // Save the left value on the stack. |
| 2659 | __ Push(r5, r4); |
| 2660 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 2661 | Label pop_and_call_runtime; |
| 2662 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2663 | // Allocate a heap number to store the result. |
| 2664 | heap_number_result = r5; |
| 2665 | GenerateHeapResultAllocation(masm, |
| 2666 | heap_number_result, |
| 2667 | heap_number_map, |
| 2668 | scratch1, |
| 2669 | scratch2, |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 2670 | &pop_and_call_runtime); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2671 | |
| 2672 | // Load the left value from the value saved on the stack. |
| 2673 | __ Pop(r1, r0); |
| 2674 | |
| 2675 | // Call the C function to handle the double operation. |
| 2676 | FloatingPointHelper::CallCCodeForDoubleOperation( |
| 2677 | masm, op_, heap_number_result, scratch1); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2678 | if (FLAG_debug_code) { |
| 2679 | __ stop("Unreachable code."); |
| 2680 | } |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 2681 | |
| 2682 | __ bind(&pop_and_call_runtime); |
| 2683 | __ Drop(2); |
| 2684 | __ b(&call_runtime); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | break; |
| 2688 | } |
| 2689 | |
| 2690 | case Token::BIT_OR: |
| 2691 | case Token::BIT_XOR: |
| 2692 | case Token::BIT_AND: |
| 2693 | case Token::SAR: |
| 2694 | case Token::SHR: |
| 2695 | case Token::SHL: { |
| 2696 | Label return_heap_number; |
| 2697 | Register scratch3 = r5; |
| 2698 | // Convert operands to 32-bit integers. Right in r2 and left in r3. The |
| 2699 | // registers r0 and r1 (right and left) are preserved for the runtime |
| 2700 | // call. |
| 2701 | FloatingPointHelper::LoadNumberAsInt32(masm, |
| 2702 | left, |
| 2703 | r3, |
| 2704 | heap_number_map, |
| 2705 | scratch1, |
| 2706 | scratch2, |
| 2707 | scratch3, |
| 2708 | d0, |
| 2709 | &transition); |
| 2710 | FloatingPointHelper::LoadNumberAsInt32(masm, |
| 2711 | right, |
| 2712 | r2, |
| 2713 | heap_number_map, |
| 2714 | scratch1, |
| 2715 | scratch2, |
| 2716 | scratch3, |
| 2717 | d0, |
| 2718 | &transition); |
| 2719 | |
| 2720 | // The ECMA-262 standard specifies that, for shift operations, only the |
| 2721 | // 5 least significant bits of the shift value should be used. |
| 2722 | switch (op_) { |
| 2723 | case Token::BIT_OR: |
| 2724 | __ orr(r2, r3, Operand(r2)); |
| 2725 | break; |
| 2726 | case Token::BIT_XOR: |
| 2727 | __ eor(r2, r3, Operand(r2)); |
| 2728 | break; |
| 2729 | case Token::BIT_AND: |
| 2730 | __ and_(r2, r3, Operand(r2)); |
| 2731 | break; |
| 2732 | case Token::SAR: |
| 2733 | __ and_(r2, r2, Operand(0x1f)); |
| 2734 | __ mov(r2, Operand(r3, ASR, r2)); |
| 2735 | break; |
| 2736 | case Token::SHR: |
| 2737 | __ and_(r2, r2, Operand(0x1f)); |
| 2738 | __ mov(r2, Operand(r3, LSR, r2), SetCC); |
| 2739 | // SHR is special because it is required to produce a positive answer. |
| 2740 | // We only get a negative result if the shift value (r2) is 0. |
| 2741 | // This result cannot be respresented as a signed 32-bit integer, try |
| 2742 | // to return a heap number if we can. |
| 2743 | // The non vfp3 code does not support this special case, so jump to |
| 2744 | // runtime if we don't support it. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2745 | if (CpuFeatures::IsSupported(VFP3)) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2746 | __ b(mi, (result_type_ <= BinaryOpIC::INT32) |
| 2747 | ? &transition |
| 2748 | : &return_heap_number); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2749 | } else { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2750 | __ b(mi, (result_type_ <= BinaryOpIC::INT32) |
| 2751 | ? &transition |
| 2752 | : &call_runtime); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2753 | } |
| 2754 | break; |
| 2755 | case Token::SHL: |
| 2756 | __ and_(r2, r2, Operand(0x1f)); |
| 2757 | __ mov(r2, Operand(r3, LSL, r2)); |
| 2758 | break; |
| 2759 | default: |
| 2760 | UNREACHABLE(); |
| 2761 | } |
| 2762 | |
| 2763 | // Check if the result fits in a smi. |
| 2764 | __ add(scratch1, r2, Operand(0x40000000), SetCC); |
| 2765 | // If not try to return a heap number. (We know the result is an int32.) |
| 2766 | __ b(mi, &return_heap_number); |
| 2767 | // Tag the result and return. |
| 2768 | __ SmiTag(r0, r2); |
| 2769 | __ Ret(); |
| 2770 | |
| 2771 | __ bind(&return_heap_number); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2772 | heap_number_result = r5; |
| 2773 | GenerateHeapResultAllocation(masm, |
| 2774 | heap_number_result, |
| 2775 | heap_number_map, |
| 2776 | scratch1, |
| 2777 | scratch2, |
| 2778 | &call_runtime); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2779 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2780 | if (CpuFeatures::IsSupported(VFP3)) { |
| 2781 | CpuFeatures::Scope scope(VFP3); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2782 | if (op_ != Token::SHR) { |
| 2783 | // Convert the result to a floating point value. |
| 2784 | __ vmov(double_scratch.low(), r2); |
| 2785 | __ vcvt_f64_s32(double_scratch, double_scratch.low()); |
| 2786 | } else { |
| 2787 | // The result must be interpreted as an unsigned 32-bit integer. |
| 2788 | __ vmov(double_scratch.low(), r2); |
| 2789 | __ vcvt_f64_u32(double_scratch, double_scratch.low()); |
| 2790 | } |
| 2791 | |
| 2792 | // Store the result. |
| 2793 | __ sub(r0, heap_number_result, Operand(kHeapObjectTag)); |
| 2794 | __ vstr(double_scratch, r0, HeapNumber::kValueOffset); |
| 2795 | __ mov(r0, heap_number_result); |
| 2796 | __ Ret(); |
| 2797 | } else { |
| 2798 | // Tail call that writes the int32 in r2 to the heap number in r0, using |
| 2799 | // r3 as scratch. r0 is preserved and returned. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2800 | __ mov(r0, r5); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2801 | WriteInt32ToHeapNumberStub stub(r2, r0, r3); |
| 2802 | __ TailCallStub(&stub); |
| 2803 | } |
| 2804 | |
| 2805 | break; |
| 2806 | } |
| 2807 | |
| 2808 | default: |
| 2809 | UNREACHABLE(); |
| 2810 | } |
| 2811 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 2812 | // We never expect DIV to yield an integer result, so we always generate |
| 2813 | // type transition code for DIV operations expecting an integer result: the |
| 2814 | // code will fall through to this type transition. |
| 2815 | if (transition.is_linked() || |
| 2816 | ((op_ == Token::DIV) && (result_type_ <= BinaryOpIC::INT32))) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2817 | __ bind(&transition); |
| 2818 | GenerateTypeTransition(masm); |
| 2819 | } |
| 2820 | |
| 2821 | __ bind(&call_runtime); |
| 2822 | GenerateCallRuntime(masm); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2826 | void BinaryOpStub::GenerateOddballStub(MacroAssembler* masm) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2827 | Label call_runtime; |
| 2828 | |
| 2829 | if (op_ == Token::ADD) { |
| 2830 | // Handle string addition here, because it is the only operation |
| 2831 | // that does not do a ToNumber conversion on the operands. |
| 2832 | GenerateAddStrings(masm); |
| 2833 | } |
| 2834 | |
| 2835 | // Convert oddball arguments to numbers. |
| 2836 | Label check, done; |
| 2837 | __ CompareRoot(r1, Heap::kUndefinedValueRootIndex); |
| 2838 | __ b(ne, &check); |
| 2839 | if (Token::IsBitOp(op_)) { |
| 2840 | __ mov(r1, Operand(Smi::FromInt(0))); |
| 2841 | } else { |
| 2842 | __ LoadRoot(r1, Heap::kNanValueRootIndex); |
| 2843 | } |
| 2844 | __ jmp(&done); |
| 2845 | __ bind(&check); |
| 2846 | __ CompareRoot(r0, Heap::kUndefinedValueRootIndex); |
| 2847 | __ b(ne, &done); |
| 2848 | if (Token::IsBitOp(op_)) { |
| 2849 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 2850 | } else { |
| 2851 | __ LoadRoot(r0, Heap::kNanValueRootIndex); |
| 2852 | } |
| 2853 | __ bind(&done); |
| 2854 | |
| 2855 | GenerateHeapNumberStub(masm); |
| 2856 | } |
| 2857 | |
| 2858 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2859 | void BinaryOpStub::GenerateHeapNumberStub(MacroAssembler* masm) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 2860 | Label call_runtime; |
| 2861 | GenerateFPOperation(masm, false, &call_runtime, &call_runtime); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2862 | |
| 2863 | __ bind(&call_runtime); |
| 2864 | GenerateCallRuntime(masm); |
| 2865 | } |
| 2866 | |
| 2867 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2868 | void BinaryOpStub::GenerateGeneric(MacroAssembler* masm) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2869 | Label call_runtime, call_string_add_or_runtime; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2870 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 2871 | GenerateSmiCode(masm, &call_runtime, &call_runtime, ALLOW_HEAPNUMBER_RESULTS); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2872 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2873 | GenerateFPOperation(masm, false, &call_string_add_or_runtime, &call_runtime); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2874 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2875 | __ bind(&call_string_add_or_runtime); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2876 | if (op_ == Token::ADD) { |
| 2877 | GenerateAddStrings(masm); |
| 2878 | } |
| 2879 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2880 | __ bind(&call_runtime); |
| 2881 | GenerateCallRuntime(masm); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2882 | } |
| 2883 | |
| 2884 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2885 | void BinaryOpStub::GenerateAddStrings(MacroAssembler* masm) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2886 | ASSERT(op_ == Token::ADD); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2887 | Label left_not_string, call_runtime; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2888 | |
| 2889 | Register left = r1; |
| 2890 | Register right = r0; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2891 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2892 | // Check if left argument is a string. |
| 2893 | __ JumpIfSmi(left, &left_not_string); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2894 | __ CompareObjectType(left, r2, r2, FIRST_NONSTRING_TYPE); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2895 | __ b(ge, &left_not_string); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2896 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2897 | StringAddStub string_add_left_stub(NO_STRING_CHECK_LEFT_IN_STUB); |
| 2898 | GenerateRegisterArgsPush(masm); |
| 2899 | __ TailCallStub(&string_add_left_stub); |
| 2900 | |
| 2901 | // Left operand is not a string, test right. |
| 2902 | __ bind(&left_not_string); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2903 | __ JumpIfSmi(right, &call_runtime); |
| 2904 | __ CompareObjectType(right, r2, r2, FIRST_NONSTRING_TYPE); |
| 2905 | __ b(ge, &call_runtime); |
| 2906 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2907 | StringAddStub string_add_right_stub(NO_STRING_CHECK_RIGHT_IN_STUB); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2908 | GenerateRegisterArgsPush(masm); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2909 | __ TailCallStub(&string_add_right_stub); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2910 | |
| 2911 | // At least one argument is not a string. |
| 2912 | __ bind(&call_runtime); |
| 2913 | } |
| 2914 | |
| 2915 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2916 | void BinaryOpStub::GenerateCallRuntime(MacroAssembler* masm) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2917 | GenerateRegisterArgsPush(masm); |
| 2918 | switch (op_) { |
| 2919 | case Token::ADD: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2920 | __ InvokeBuiltin(Builtins::ADD, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2921 | break; |
| 2922 | case Token::SUB: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2923 | __ InvokeBuiltin(Builtins::SUB, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2924 | break; |
| 2925 | case Token::MUL: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2926 | __ InvokeBuiltin(Builtins::MUL, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2927 | break; |
| 2928 | case Token::DIV: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2929 | __ InvokeBuiltin(Builtins::DIV, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2930 | break; |
| 2931 | case Token::MOD: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2932 | __ InvokeBuiltin(Builtins::MOD, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2933 | break; |
| 2934 | case Token::BIT_OR: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2935 | __ InvokeBuiltin(Builtins::BIT_OR, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2936 | break; |
| 2937 | case Token::BIT_AND: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2938 | __ InvokeBuiltin(Builtins::BIT_AND, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2939 | break; |
| 2940 | case Token::BIT_XOR: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2941 | __ InvokeBuiltin(Builtins::BIT_XOR, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2942 | break; |
| 2943 | case Token::SAR: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2944 | __ InvokeBuiltin(Builtins::SAR, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2945 | break; |
| 2946 | case Token::SHR: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2947 | __ InvokeBuiltin(Builtins::SHR, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2948 | break; |
| 2949 | case Token::SHL: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2950 | __ InvokeBuiltin(Builtins::SHL, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2951 | break; |
| 2952 | default: |
| 2953 | UNREACHABLE(); |
| 2954 | } |
| 2955 | } |
| 2956 | |
| 2957 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2958 | void BinaryOpStub::GenerateHeapResultAllocation(MacroAssembler* masm, |
| 2959 | Register result, |
| 2960 | Register heap_number_map, |
| 2961 | Register scratch1, |
| 2962 | Register scratch2, |
| 2963 | Label* gc_required) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2964 | // Code below will scratch result if allocation fails. To keep both arguments |
| 2965 | // intact for the runtime call result cannot be one of these. |
| 2966 | ASSERT(!result.is(r0) && !result.is(r1)); |
| 2967 | |
| 2968 | if (mode_ == OVERWRITE_LEFT || mode_ == OVERWRITE_RIGHT) { |
| 2969 | Label skip_allocation, allocated; |
| 2970 | Register overwritable_operand = mode_ == OVERWRITE_LEFT ? r1 : r0; |
| 2971 | // If the overwritable operand is already an object, we skip the |
| 2972 | // allocation of a heap number. |
| 2973 | __ JumpIfNotSmi(overwritable_operand, &skip_allocation); |
| 2974 | // Allocate a heap number for the result. |
| 2975 | __ AllocateHeapNumber( |
| 2976 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 2977 | __ b(&allocated); |
| 2978 | __ bind(&skip_allocation); |
| 2979 | // Use object holding the overwritable operand for result. |
| 2980 | __ mov(result, Operand(overwritable_operand)); |
| 2981 | __ bind(&allocated); |
| 2982 | } else { |
| 2983 | ASSERT(mode_ == NO_OVERWRITE); |
| 2984 | __ AllocateHeapNumber( |
| 2985 | result, scratch1, scratch2, heap_number_map, gc_required); |
| 2986 | } |
| 2987 | } |
| 2988 | |
| 2989 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 2990 | void BinaryOpStub::GenerateRegisterArgsPush(MacroAssembler* masm) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 2991 | __ Push(r1, r0); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 2992 | } |
| 2993 | |
| 2994 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 2995 | void TranscendentalCacheStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 2996 | // Untagged case: double input in d2, double result goes |
| 2997 | // into d2. |
| 2998 | // Tagged case: tagged input on top of stack and in r0, |
| 2999 | // tagged result (heap number) goes into r0. |
| 3000 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3001 | Label input_not_smi; |
| 3002 | Label loaded; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3003 | Label calculate; |
| 3004 | Label invalid_cache; |
| 3005 | const Register scratch0 = r9; |
| 3006 | const Register scratch1 = r7; |
| 3007 | const Register cache_entry = r0; |
| 3008 | const bool tagged = (argument_type_ == TAGGED); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3009 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3010 | if (CpuFeatures::IsSupported(VFP3)) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3011 | CpuFeatures::Scope scope(VFP3); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3012 | if (tagged) { |
| 3013 | // Argument is a number and is on stack and in r0. |
| 3014 | // Load argument and check if it is a smi. |
| 3015 | __ JumpIfNotSmi(r0, &input_not_smi); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3016 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3017 | // Input is a smi. Convert to double and load the low and high words |
| 3018 | // of the double into r2, r3. |
| 3019 | __ IntegerToDoubleConversionWithVFP3(r0, r3, r2); |
| 3020 | __ b(&loaded); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3021 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3022 | __ bind(&input_not_smi); |
| 3023 | // Check if input is a HeapNumber. |
| 3024 | __ CheckMap(r0, |
| 3025 | r1, |
| 3026 | Heap::kHeapNumberMapRootIndex, |
| 3027 | &calculate, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3028 | DONT_DO_SMI_CHECK); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3029 | // Input is a HeapNumber. Load it to a double register and store the |
| 3030 | // low and high words into r2, r3. |
| 3031 | __ vldr(d0, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
| 3032 | __ vmov(r2, r3, d0); |
| 3033 | } else { |
| 3034 | // Input is untagged double in d2. Output goes to d2. |
| 3035 | __ vmov(r2, r3, d2); |
| 3036 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3037 | __ bind(&loaded); |
| 3038 | // r2 = low 32 bits of double value |
| 3039 | // r3 = high 32 bits of double value |
| 3040 | // Compute hash (the shifts are arithmetic): |
| 3041 | // h = (low ^ high); h ^= h >> 16; h ^= h >> 8; h = h & (cacheSize - 1); |
| 3042 | __ eor(r1, r2, Operand(r3)); |
| 3043 | __ eor(r1, r1, Operand(r1, ASR, 16)); |
| 3044 | __ eor(r1, r1, Operand(r1, ASR, 8)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3045 | ASSERT(IsPowerOf2(TranscendentalCache::SubCache::kCacheSize)); |
| 3046 | __ And(r1, r1, Operand(TranscendentalCache::SubCache::kCacheSize - 1)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3047 | |
| 3048 | // r2 = low 32 bits of double value. |
| 3049 | // r3 = high 32 bits of double value. |
| 3050 | // r1 = TranscendentalCache::hash(double value). |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3051 | Isolate* isolate = masm->isolate(); |
| 3052 | ExternalReference cache_array = |
| 3053 | ExternalReference::transcendental_cache_array_address(isolate); |
| 3054 | __ mov(cache_entry, Operand(cache_array)); |
| 3055 | // cache_entry points to cache array. |
| 3056 | int cache_array_index |
| 3057 | = type_ * sizeof(isolate->transcendental_cache()->caches_[0]); |
| 3058 | __ ldr(cache_entry, MemOperand(cache_entry, cache_array_index)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3059 | // r0 points to the cache for the type type_. |
| 3060 | // If NULL, the cache hasn't been initialized yet, so go through runtime. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3061 | __ cmp(cache_entry, Operand(0, RelocInfo::NONE)); |
| 3062 | __ b(eq, &invalid_cache); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3063 | |
| 3064 | #ifdef DEBUG |
| 3065 | // Check that the layout of cache elements match expectations. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3066 | { TranscendentalCache::SubCache::Element test_elem[2]; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3067 | char* elem_start = reinterpret_cast<char*>(&test_elem[0]); |
| 3068 | char* elem2_start = reinterpret_cast<char*>(&test_elem[1]); |
| 3069 | char* elem_in0 = reinterpret_cast<char*>(&(test_elem[0].in[0])); |
| 3070 | char* elem_in1 = reinterpret_cast<char*>(&(test_elem[0].in[1])); |
| 3071 | char* elem_out = reinterpret_cast<char*>(&(test_elem[0].output)); |
| 3072 | CHECK_EQ(12, elem2_start - elem_start); // Two uint_32's and a pointer. |
| 3073 | CHECK_EQ(0, elem_in0 - elem_start); |
| 3074 | CHECK_EQ(kIntSize, elem_in1 - elem_start); |
| 3075 | CHECK_EQ(2 * kIntSize, elem_out - elem_start); |
| 3076 | } |
| 3077 | #endif |
| 3078 | |
| 3079 | // Find the address of the r1'st entry in the cache, i.e., &r0[r1*12]. |
| 3080 | __ add(r1, r1, Operand(r1, LSL, 1)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3081 | __ add(cache_entry, cache_entry, Operand(r1, LSL, 2)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3082 | // Check if cache matches: Double value is stored in uint32_t[2] array. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3083 | __ ldm(ia, cache_entry, r4.bit() | r5.bit() | r6.bit()); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3084 | __ cmp(r2, r4); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3085 | __ b(ne, &calculate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3086 | __ cmp(r3, r5); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3087 | __ b(ne, &calculate); |
| 3088 | // Cache hit. Load result, cleanup and return. |
| 3089 | if (tagged) { |
| 3090 | // Pop input value from stack and load result into r0. |
| 3091 | __ pop(); |
| 3092 | __ mov(r0, Operand(r6)); |
| 3093 | } else { |
| 3094 | // Load result into d2. |
| 3095 | __ vldr(d2, FieldMemOperand(r6, HeapNumber::kValueOffset)); |
| 3096 | } |
| 3097 | __ Ret(); |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3098 | } // if (CpuFeatures::IsSupported(VFP3)) |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3099 | |
| 3100 | __ bind(&calculate); |
| 3101 | if (tagged) { |
| 3102 | __ bind(&invalid_cache); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3103 | ExternalReference runtime_function = |
| 3104 | ExternalReference(RuntimeFunction(), masm->isolate()); |
| 3105 | __ TailCallExternalReference(runtime_function, 1, 1); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3106 | } else { |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3107 | if (!CpuFeatures::IsSupported(VFP3)) UNREACHABLE(); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3108 | CpuFeatures::Scope scope(VFP3); |
| 3109 | |
| 3110 | Label no_update; |
| 3111 | Label skip_cache; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3112 | |
| 3113 | // Call C function to calculate the result and update the cache. |
| 3114 | // Register r0 holds precalculated cache entry address; preserve |
| 3115 | // it on the stack and pop it into register cache_entry after the |
| 3116 | // call. |
| 3117 | __ push(cache_entry); |
| 3118 | GenerateCallCFunction(masm, scratch0); |
| 3119 | __ GetCFunctionDoubleResult(d2); |
| 3120 | |
| 3121 | // Try to update the cache. If we cannot allocate a |
| 3122 | // heap number, we return the result without updating. |
| 3123 | __ pop(cache_entry); |
| 3124 | __ LoadRoot(r5, Heap::kHeapNumberMapRootIndex); |
| 3125 | __ AllocateHeapNumber(r6, scratch0, scratch1, r5, &no_update); |
| 3126 | __ vstr(d2, FieldMemOperand(r6, HeapNumber::kValueOffset)); |
| 3127 | __ stm(ia, cache_entry, r2.bit() | r3.bit() | r6.bit()); |
| 3128 | __ Ret(); |
| 3129 | |
| 3130 | __ bind(&invalid_cache); |
| 3131 | // The cache is invalid. Call runtime which will recreate the |
| 3132 | // cache. |
| 3133 | __ LoadRoot(r5, Heap::kHeapNumberMapRootIndex); |
| 3134 | __ AllocateHeapNumber(r0, scratch0, scratch1, r5, &skip_cache); |
| 3135 | __ vstr(d2, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
| 3136 | __ EnterInternalFrame(); |
| 3137 | __ push(r0); |
| 3138 | __ CallRuntime(RuntimeFunction(), 1); |
| 3139 | __ LeaveInternalFrame(); |
| 3140 | __ vldr(d2, FieldMemOperand(r0, HeapNumber::kValueOffset)); |
| 3141 | __ Ret(); |
| 3142 | |
| 3143 | __ bind(&skip_cache); |
| 3144 | // Call C function to calculate the result and answer directly |
| 3145 | // without updating the cache. |
| 3146 | GenerateCallCFunction(masm, scratch0); |
| 3147 | __ GetCFunctionDoubleResult(d2); |
| 3148 | __ bind(&no_update); |
| 3149 | |
| 3150 | // We return the value in d2 without adding it to the cache, but |
| 3151 | // we cause a scavenging GC so that future allocations will succeed. |
| 3152 | __ EnterInternalFrame(); |
| 3153 | |
| 3154 | // Allocate an aligned object larger than a HeapNumber. |
| 3155 | ASSERT(4 * kPointerSize >= HeapNumber::kSize); |
| 3156 | __ mov(scratch0, Operand(4 * kPointerSize)); |
| 3157 | __ push(scratch0); |
| 3158 | __ CallRuntimeSaveDoubles(Runtime::kAllocateInNewSpace); |
| 3159 | __ LeaveInternalFrame(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3160 | __ Ret(); |
| 3161 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3162 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3163 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3164 | |
| 3165 | void TranscendentalCacheStub::GenerateCallCFunction(MacroAssembler* masm, |
| 3166 | Register scratch) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3167 | Isolate* isolate = masm->isolate(); |
| 3168 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3169 | __ push(lr); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3170 | __ PrepareCallCFunction(0, 1, scratch); |
| 3171 | if (masm->use_eabi_hardfloat()) { |
| 3172 | __ vmov(d0, d2); |
| 3173 | } else { |
| 3174 | __ vmov(r0, r1, d2); |
| 3175 | } |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3176 | switch (type_) { |
| 3177 | case TranscendentalCache::SIN: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3178 | __ CallCFunction(ExternalReference::math_sin_double_function(isolate), |
| 3179 | 0, 1); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3180 | break; |
| 3181 | case TranscendentalCache::COS: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3182 | __ CallCFunction(ExternalReference::math_cos_double_function(isolate), |
| 3183 | 0, 1); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3184 | break; |
| 3185 | case TranscendentalCache::LOG: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3186 | __ CallCFunction(ExternalReference::math_log_double_function(isolate), |
| 3187 | 0, 1); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3188 | break; |
| 3189 | default: |
| 3190 | UNIMPLEMENTED(); |
| 3191 | break; |
| 3192 | } |
| 3193 | __ pop(lr); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | |
| 3197 | Runtime::FunctionId TranscendentalCacheStub::RuntimeFunction() { |
| 3198 | switch (type_) { |
| 3199 | // Add more cases when necessary. |
| 3200 | case TranscendentalCache::SIN: return Runtime::kMath_sin; |
| 3201 | case TranscendentalCache::COS: return Runtime::kMath_cos; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3202 | case TranscendentalCache::LOG: return Runtime::kMath_log; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3203 | default: |
| 3204 | UNIMPLEMENTED(); |
| 3205 | return Runtime::kAbort; |
| 3206 | } |
| 3207 | } |
| 3208 | |
| 3209 | |
| 3210 | void StackCheckStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame] | 3211 | __ TailCallRuntime(Runtime::kStackGuard, 0, 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3215 | void MathPowStub::Generate(MacroAssembler* masm) { |
| 3216 | Label call_runtime; |
| 3217 | |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 3218 | if (CpuFeatures::IsSupported(VFP3)) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3219 | CpuFeatures::Scope scope(VFP3); |
| 3220 | |
| 3221 | Label base_not_smi; |
| 3222 | Label exponent_not_smi; |
| 3223 | Label convert_exponent; |
| 3224 | |
| 3225 | const Register base = r0; |
| 3226 | const Register exponent = r1; |
| 3227 | const Register heapnumbermap = r5; |
| 3228 | const Register heapnumber = r6; |
| 3229 | const DoubleRegister double_base = d0; |
| 3230 | const DoubleRegister double_exponent = d1; |
| 3231 | const DoubleRegister double_result = d2; |
| 3232 | const SwVfpRegister single_scratch = s0; |
| 3233 | const Register scratch = r9; |
| 3234 | const Register scratch2 = r7; |
| 3235 | |
| 3236 | __ LoadRoot(heapnumbermap, Heap::kHeapNumberMapRootIndex); |
| 3237 | __ ldr(base, MemOperand(sp, 1 * kPointerSize)); |
| 3238 | __ ldr(exponent, MemOperand(sp, 0 * kPointerSize)); |
| 3239 | |
| 3240 | // Convert base to double value and store it in d0. |
| 3241 | __ JumpIfNotSmi(base, &base_not_smi); |
| 3242 | // Base is a Smi. Untag and convert it. |
| 3243 | __ SmiUntag(base); |
| 3244 | __ vmov(single_scratch, base); |
| 3245 | __ vcvt_f64_s32(double_base, single_scratch); |
| 3246 | __ b(&convert_exponent); |
| 3247 | |
| 3248 | __ bind(&base_not_smi); |
| 3249 | __ ldr(scratch, FieldMemOperand(base, JSObject::kMapOffset)); |
| 3250 | __ cmp(scratch, heapnumbermap); |
| 3251 | __ b(ne, &call_runtime); |
| 3252 | // Base is a heapnumber. Load it into double register. |
| 3253 | __ vldr(double_base, FieldMemOperand(base, HeapNumber::kValueOffset)); |
| 3254 | |
| 3255 | __ bind(&convert_exponent); |
| 3256 | __ JumpIfNotSmi(exponent, &exponent_not_smi); |
| 3257 | __ SmiUntag(exponent); |
| 3258 | |
| 3259 | // The base is in a double register and the exponent is |
| 3260 | // an untagged smi. Allocate a heap number and call a |
| 3261 | // C function for integer exponents. The register containing |
| 3262 | // the heap number is callee-saved. |
| 3263 | __ AllocateHeapNumber(heapnumber, |
| 3264 | scratch, |
| 3265 | scratch2, |
| 3266 | heapnumbermap, |
| 3267 | &call_runtime); |
| 3268 | __ push(lr); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3269 | __ PrepareCallCFunction(1, 1, scratch); |
| 3270 | __ SetCallCDoubleArguments(double_base, exponent); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3271 | __ CallCFunction( |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3272 | ExternalReference::power_double_int_function(masm->isolate()), |
| 3273 | 1, 1); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3274 | __ pop(lr); |
| 3275 | __ GetCFunctionDoubleResult(double_result); |
| 3276 | __ vstr(double_result, |
| 3277 | FieldMemOperand(heapnumber, HeapNumber::kValueOffset)); |
| 3278 | __ mov(r0, heapnumber); |
| 3279 | __ Ret(2 * kPointerSize); |
| 3280 | |
| 3281 | __ bind(&exponent_not_smi); |
| 3282 | __ ldr(scratch, FieldMemOperand(exponent, JSObject::kMapOffset)); |
| 3283 | __ cmp(scratch, heapnumbermap); |
| 3284 | __ b(ne, &call_runtime); |
| 3285 | // Exponent is a heapnumber. Load it into double register. |
| 3286 | __ vldr(double_exponent, |
| 3287 | FieldMemOperand(exponent, HeapNumber::kValueOffset)); |
| 3288 | |
| 3289 | // The base and the exponent are in double registers. |
| 3290 | // Allocate a heap number and call a C function for |
| 3291 | // double exponents. The register containing |
| 3292 | // the heap number is callee-saved. |
| 3293 | __ AllocateHeapNumber(heapnumber, |
| 3294 | scratch, |
| 3295 | scratch2, |
| 3296 | heapnumbermap, |
| 3297 | &call_runtime); |
| 3298 | __ push(lr); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3299 | __ PrepareCallCFunction(0, 2, scratch); |
| 3300 | __ SetCallCDoubleArguments(double_base, double_exponent); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3301 | __ CallCFunction( |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3302 | ExternalReference::power_double_double_function(masm->isolate()), |
| 3303 | 0, 2); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3304 | __ pop(lr); |
| 3305 | __ GetCFunctionDoubleResult(double_result); |
| 3306 | __ vstr(double_result, |
| 3307 | FieldMemOperand(heapnumber, HeapNumber::kValueOffset)); |
| 3308 | __ mov(r0, heapnumber); |
| 3309 | __ Ret(2 * kPointerSize); |
| 3310 | } |
| 3311 | |
| 3312 | __ bind(&call_runtime); |
| 3313 | __ TailCallRuntime(Runtime::kMath_pow_cfunction, 2, 1); |
| 3314 | } |
| 3315 | |
| 3316 | |
| 3317 | bool CEntryStub::NeedsImmovableCode() { |
| 3318 | return true; |
| 3319 | } |
| 3320 | |
| 3321 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3322 | void CEntryStub::GenerateThrowTOS(MacroAssembler* masm) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3323 | __ Throw(r0); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3324 | } |
| 3325 | |
| 3326 | |
| 3327 | void CEntryStub::GenerateThrowUncatchable(MacroAssembler* masm, |
| 3328 | UncatchableExceptionType type) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3329 | __ ThrowUncatchable(type, r0); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | |
| 3333 | void CEntryStub::GenerateCore(MacroAssembler* masm, |
| 3334 | Label* throw_normal_exception, |
| 3335 | Label* throw_termination_exception, |
| 3336 | Label* throw_out_of_memory_exception, |
| 3337 | bool do_gc, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3338 | bool always_allocate) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3339 | // r0: result parameter for PerformGC, if any |
| 3340 | // r4: number of arguments including receiver (C callee-saved) |
| 3341 | // r5: pointer to builtin function (C callee-saved) |
| 3342 | // r6: pointer to the first argument (C callee-saved) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3343 | Isolate* isolate = masm->isolate(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3344 | |
| 3345 | if (do_gc) { |
| 3346 | // Passing r0. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3347 | __ PrepareCallCFunction(1, 0, r1); |
| 3348 | __ CallCFunction(ExternalReference::perform_gc_function(isolate), |
| 3349 | 1, 0); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | ExternalReference scope_depth = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3353 | ExternalReference::heap_always_allocate_scope_depth(isolate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3354 | if (always_allocate) { |
| 3355 | __ mov(r0, Operand(scope_depth)); |
| 3356 | __ ldr(r1, MemOperand(r0)); |
| 3357 | __ add(r1, r1, Operand(1)); |
| 3358 | __ str(r1, MemOperand(r0)); |
| 3359 | } |
| 3360 | |
| 3361 | // Call C built-in. |
| 3362 | // r0 = argc, r1 = argv |
| 3363 | __ mov(r0, Operand(r4)); |
| 3364 | __ mov(r1, Operand(r6)); |
| 3365 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3366 | #if defined(V8_HOST_ARCH_ARM) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3367 | int frame_alignment = MacroAssembler::ActivationFrameAlignment(); |
| 3368 | int frame_alignment_mask = frame_alignment - 1; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3369 | if (FLAG_debug_code) { |
| 3370 | if (frame_alignment > kPointerSize) { |
| 3371 | Label alignment_as_expected; |
| 3372 | ASSERT(IsPowerOf2(frame_alignment)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3373 | __ tst(sp, Operand(frame_alignment_mask)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3374 | __ b(eq, &alignment_as_expected); |
| 3375 | // Don't use Check here, as it will call Runtime_Abort re-entering here. |
| 3376 | __ stop("Unexpected alignment"); |
| 3377 | __ bind(&alignment_as_expected); |
| 3378 | } |
| 3379 | } |
| 3380 | #endif |
| 3381 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3382 | __ mov(r2, Operand(ExternalReference::isolate_address())); |
| 3383 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3384 | // To let the GC traverse the return address of the exit frames, we need to |
| 3385 | // know where the return address is. The CEntryStub is unmovable, so |
| 3386 | // we can store the address on the stack to be able to find it again and |
| 3387 | // we never have to restore it, because it will not change. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3388 | // Compute the return address in lr to return to after the jump below. Pc is |
| 3389 | // already at '+ 8' from the current instruction but return is after three |
| 3390 | // instructions so add another 4 to pc to get the return address. |
| 3391 | masm->add(lr, pc, Operand(4)); |
| 3392 | __ str(lr, MemOperand(sp, 0)); |
| 3393 | masm->Jump(r5); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3394 | |
| 3395 | if (always_allocate) { |
| 3396 | // It's okay to clobber r2 and r3 here. Don't mess with r0 and r1 |
| 3397 | // though (contain the result). |
| 3398 | __ mov(r2, Operand(scope_depth)); |
| 3399 | __ ldr(r3, MemOperand(r2)); |
| 3400 | __ sub(r3, r3, Operand(1)); |
| 3401 | __ str(r3, MemOperand(r2)); |
| 3402 | } |
| 3403 | |
| 3404 | // check for failure result |
| 3405 | Label failure_returned; |
| 3406 | STATIC_ASSERT(((kFailureTag + 1) & kFailureTagMask) == 0); |
| 3407 | // Lower 2 bits of r2 are 0 iff r0 has failure tag. |
| 3408 | __ add(r2, r0, Operand(1)); |
| 3409 | __ tst(r2, Operand(kFailureTagMask)); |
| 3410 | __ b(eq, &failure_returned); |
| 3411 | |
| 3412 | // Exit C frame and return. |
| 3413 | // r0:r1: result |
| 3414 | // sp: stack pointer |
| 3415 | // fp: frame pointer |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3416 | // Callee-saved register r4 still holds argc. |
| 3417 | __ LeaveExitFrame(save_doubles_, r4); |
| 3418 | __ mov(pc, lr); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3419 | |
| 3420 | // check if we should retry or throw exception |
| 3421 | Label retry; |
| 3422 | __ bind(&failure_returned); |
| 3423 | STATIC_ASSERT(Failure::RETRY_AFTER_GC == 0); |
| 3424 | __ tst(r0, Operand(((1 << kFailureTypeTagSize) - 1) << kFailureTagSize)); |
| 3425 | __ b(eq, &retry); |
| 3426 | |
| 3427 | // Special handling of out of memory exceptions. |
| 3428 | Failure* out_of_memory = Failure::OutOfMemoryException(); |
| 3429 | __ cmp(r0, Operand(reinterpret_cast<int32_t>(out_of_memory))); |
| 3430 | __ b(eq, throw_out_of_memory_exception); |
| 3431 | |
| 3432 | // Retrieve the pending exception and clear the variable. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3433 | __ mov(ip, Operand(ExternalReference::the_hole_value_location(isolate))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3434 | __ ldr(r3, MemOperand(ip)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3435 | __ mov(ip, Operand(ExternalReference(Isolate::k_pending_exception_address, |
| 3436 | isolate))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3437 | __ ldr(r0, MemOperand(ip)); |
| 3438 | __ str(r3, MemOperand(ip)); |
| 3439 | |
| 3440 | // Special handling of termination exceptions which are uncatchable |
| 3441 | // by javascript code. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3442 | __ cmp(r0, Operand(isolate->factory()->termination_exception())); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3443 | __ b(eq, throw_termination_exception); |
| 3444 | |
| 3445 | // Handle normal exception. |
| 3446 | __ jmp(throw_normal_exception); |
| 3447 | |
| 3448 | __ bind(&retry); // pass last failure (r0) as parameter (r0) when retrying |
| 3449 | } |
| 3450 | |
| 3451 | |
| 3452 | void CEntryStub::Generate(MacroAssembler* masm) { |
| 3453 | // Called from JavaScript; parameters are on stack as if calling JS function |
| 3454 | // r0: number of arguments including receiver |
| 3455 | // r1: pointer to builtin function |
| 3456 | // fp: frame pointer (restored after C call) |
| 3457 | // sp: stack pointer (restored as callee's sp after C call) |
| 3458 | // cp: current context (C callee-saved) |
| 3459 | |
| 3460 | // Result returned in r0 or r0+r1 by default. |
| 3461 | |
| 3462 | // NOTE: Invocations of builtins may return failure objects |
| 3463 | // instead of a proper result. The builtin entry handles |
| 3464 | // this by performing a garbage collection and retrying the |
| 3465 | // builtin once. |
| 3466 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3467 | // Compute the argv pointer in a callee-saved register. |
| 3468 | __ add(r6, sp, Operand(r0, LSL, kPointerSizeLog2)); |
| 3469 | __ sub(r6, r6, Operand(kPointerSize)); |
| 3470 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3471 | // Enter the exit frame that transitions from JavaScript to C++. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3472 | __ EnterExitFrame(save_doubles_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3473 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3474 | // Setup argc and the builtin function in callee-saved registers. |
| 3475 | __ mov(r4, Operand(r0)); |
| 3476 | __ mov(r5, Operand(r1)); |
| 3477 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3478 | // r4: number of arguments (C callee-saved) |
| 3479 | // r5: pointer to builtin function (C callee-saved) |
| 3480 | // r6: pointer to first argument (C callee-saved) |
| 3481 | |
| 3482 | Label throw_normal_exception; |
| 3483 | Label throw_termination_exception; |
| 3484 | Label throw_out_of_memory_exception; |
| 3485 | |
| 3486 | // Call into the runtime system. |
| 3487 | GenerateCore(masm, |
| 3488 | &throw_normal_exception, |
| 3489 | &throw_termination_exception, |
| 3490 | &throw_out_of_memory_exception, |
| 3491 | false, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3492 | false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3493 | |
| 3494 | // Do space-specific GC and retry runtime call. |
| 3495 | GenerateCore(masm, |
| 3496 | &throw_normal_exception, |
| 3497 | &throw_termination_exception, |
| 3498 | &throw_out_of_memory_exception, |
| 3499 | true, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3500 | false); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3501 | |
| 3502 | // Do full GC and retry runtime call one final time. |
| 3503 | Failure* failure = Failure::InternalError(); |
| 3504 | __ mov(r0, Operand(reinterpret_cast<int32_t>(failure))); |
| 3505 | GenerateCore(masm, |
| 3506 | &throw_normal_exception, |
| 3507 | &throw_termination_exception, |
| 3508 | &throw_out_of_memory_exception, |
| 3509 | true, |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3510 | true); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3511 | |
| 3512 | __ bind(&throw_out_of_memory_exception); |
| 3513 | GenerateThrowUncatchable(masm, OUT_OF_MEMORY); |
| 3514 | |
| 3515 | __ bind(&throw_termination_exception); |
| 3516 | GenerateThrowUncatchable(masm, TERMINATION); |
| 3517 | |
| 3518 | __ bind(&throw_normal_exception); |
| 3519 | GenerateThrowTOS(masm); |
| 3520 | } |
| 3521 | |
| 3522 | |
| 3523 | void JSEntryStub::GenerateBody(MacroAssembler* masm, bool is_construct) { |
| 3524 | // r0: code entry |
| 3525 | // r1: function |
| 3526 | // r2: receiver |
| 3527 | // r3: argc |
| 3528 | // [sp+0]: argv |
| 3529 | |
| 3530 | Label invoke, exit; |
| 3531 | |
| 3532 | // Called from C, so do not pop argc and args on exit (preserve sp) |
| 3533 | // No need to save register-passed args |
| 3534 | // Save callee-saved registers (incl. cp and fp), sp, and lr |
| 3535 | __ stm(db_w, sp, kCalleeSaved | lr.bit()); |
| 3536 | |
Ben Murdoch | 7d3e7fc | 2011-07-12 16:37:06 +0100 | [diff] [blame] | 3537 | if (CpuFeatures::IsSupported(VFP3)) { |
| 3538 | CpuFeatures::Scope scope(VFP3); |
| 3539 | // Save callee-saved vfp registers. |
| 3540 | __ vstm(db_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3541 | // Set up the reserved register for 0.0. |
| 3542 | __ vmov(kDoubleRegZero, 0.0); |
Ben Murdoch | 7d3e7fc | 2011-07-12 16:37:06 +0100 | [diff] [blame] | 3543 | } |
| 3544 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3545 | // Get address of argv, see stm above. |
| 3546 | // r0: code entry |
| 3547 | // r1: function |
| 3548 | // r2: receiver |
| 3549 | // r3: argc |
Ben Murdoch | 7d3e7fc | 2011-07-12 16:37:06 +0100 | [diff] [blame] | 3550 | |
| 3551 | // Setup argv in r4. |
| 3552 | int offset_to_argv = (kNumCalleeSaved + 1) * kPointerSize; |
| 3553 | if (CpuFeatures::IsSupported(VFP3)) { |
| 3554 | offset_to_argv += kNumDoubleCalleeSaved * kDoubleSize; |
| 3555 | } |
| 3556 | __ ldr(r4, MemOperand(sp, offset_to_argv)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3557 | |
| 3558 | // Push a frame with special values setup to mark it as an entry frame. |
| 3559 | // r0: code entry |
| 3560 | // r1: function |
| 3561 | // r2: receiver |
| 3562 | // r3: argc |
| 3563 | // r4: argv |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3564 | Isolate* isolate = masm->isolate(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3565 | __ mov(r8, Operand(-1)); // Push a bad frame pointer to fail if it is used. |
| 3566 | int marker = is_construct ? StackFrame::ENTRY_CONSTRUCT : StackFrame::ENTRY; |
| 3567 | __ mov(r7, Operand(Smi::FromInt(marker))); |
| 3568 | __ mov(r6, Operand(Smi::FromInt(marker))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3569 | __ mov(r5, |
| 3570 | Operand(ExternalReference(Isolate::k_c_entry_fp_address, isolate))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3571 | __ ldr(r5, MemOperand(r5)); |
| 3572 | __ Push(r8, r7, r6, r5); |
| 3573 | |
| 3574 | // Setup frame pointer for the frame to be pushed. |
| 3575 | __ add(fp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| 3576 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3577 | // If this is the outermost JS call, set js_entry_sp value. |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 3578 | Label non_outermost_js; |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3579 | ExternalReference js_entry_sp(Isolate::k_js_entry_sp_address, isolate); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3580 | __ mov(r5, Operand(ExternalReference(js_entry_sp))); |
| 3581 | __ ldr(r6, MemOperand(r5)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3582 | __ cmp(r6, Operand::Zero()); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 3583 | __ b(ne, &non_outermost_js); |
| 3584 | __ str(fp, MemOperand(r5)); |
| 3585 | __ mov(ip, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 3586 | Label cont; |
| 3587 | __ b(&cont); |
| 3588 | __ bind(&non_outermost_js); |
| 3589 | __ mov(ip, Operand(Smi::FromInt(StackFrame::INNER_JSENTRY_FRAME))); |
| 3590 | __ bind(&cont); |
| 3591 | __ push(ip); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3592 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3593 | // Call a faked try-block that does the invoke. |
| 3594 | __ bl(&invoke); |
| 3595 | |
| 3596 | // Caught exception: Store result (exception) in the pending |
| 3597 | // exception field in the JSEnv and return a failure sentinel. |
| 3598 | // Coming in here the fp will be invalid because the PushTryHandler below |
| 3599 | // sets it to 0 to signal the existence of the JSEntry frame. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3600 | __ mov(ip, Operand(ExternalReference(Isolate::k_pending_exception_address, |
| 3601 | isolate))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3602 | __ str(r0, MemOperand(ip)); |
| 3603 | __ mov(r0, Operand(reinterpret_cast<int32_t>(Failure::Exception()))); |
| 3604 | __ b(&exit); |
| 3605 | |
| 3606 | // Invoke: Link this frame into the handler chain. |
| 3607 | __ bind(&invoke); |
| 3608 | // Must preserve r0-r4, r5-r7 are available. |
| 3609 | __ PushTryHandler(IN_JS_ENTRY, JS_ENTRY_HANDLER); |
| 3610 | // If an exception not caught by another handler occurs, this handler |
| 3611 | // returns control to the code after the bl(&invoke) above, which |
| 3612 | // restores all kCalleeSaved registers (including cp and fp) to their |
| 3613 | // saved values before returning a failure to C. |
| 3614 | |
| 3615 | // Clear any pending exceptions. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3616 | __ mov(ip, Operand(ExternalReference::the_hole_value_location(isolate))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3617 | __ ldr(r5, MemOperand(ip)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3618 | __ mov(ip, Operand(ExternalReference(Isolate::k_pending_exception_address, |
| 3619 | isolate))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3620 | __ str(r5, MemOperand(ip)); |
| 3621 | |
| 3622 | // Invoke the function by calling through JS entry trampoline builtin. |
| 3623 | // Notice that we cannot store a reference to the trampoline code directly in |
| 3624 | // this stub, because runtime stubs are not traversed when doing GC. |
| 3625 | |
| 3626 | // Expected registers by Builtins::JSEntryTrampoline |
| 3627 | // r0: code entry |
| 3628 | // r1: function |
| 3629 | // r2: receiver |
| 3630 | // r3: argc |
| 3631 | // r4: argv |
| 3632 | if (is_construct) { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3633 | ExternalReference construct_entry(Builtins::kJSConstructEntryTrampoline, |
| 3634 | isolate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3635 | __ mov(ip, Operand(construct_entry)); |
| 3636 | } else { |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3637 | ExternalReference entry(Builtins::kJSEntryTrampoline, isolate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3638 | __ mov(ip, Operand(entry)); |
| 3639 | } |
| 3640 | __ ldr(ip, MemOperand(ip)); // deref address |
| 3641 | |
| 3642 | // Branch and link to JSEntryTrampoline. We don't use the double underscore |
| 3643 | // macro for the add instruction because we don't want the coverage tool |
| 3644 | // inserting instructions here after we read the pc. |
| 3645 | __ mov(lr, Operand(pc)); |
| 3646 | masm->add(pc, ip, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 3647 | |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 3648 | // Unlink this frame from the handler chain. |
| 3649 | __ PopTryHandler(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3650 | |
| 3651 | __ bind(&exit); // r0 holds result |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 3652 | // Check if the current stack frame is marked as the outermost JS frame. |
| 3653 | Label non_outermost_js_2; |
| 3654 | __ pop(r5); |
| 3655 | __ cmp(r5, Operand(Smi::FromInt(StackFrame::OUTERMOST_JSENTRY_FRAME))); |
| 3656 | __ b(ne, &non_outermost_js_2); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3657 | __ mov(r6, Operand::Zero()); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 3658 | __ mov(r5, Operand(ExternalReference(js_entry_sp))); |
| 3659 | __ str(r6, MemOperand(r5)); |
| 3660 | __ bind(&non_outermost_js_2); |
Steve Block | 053d10c | 2011-06-13 19:13:29 +0100 | [diff] [blame] | 3661 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3662 | // Restore the top frame descriptors from the stack. |
| 3663 | __ pop(r3); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 3664 | __ mov(ip, |
| 3665 | Operand(ExternalReference(Isolate::k_c_entry_fp_address, isolate))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3666 | __ str(r3, MemOperand(ip)); |
| 3667 | |
| 3668 | // Reset the stack to the callee saved registers. |
| 3669 | __ add(sp, sp, Operand(-EntryFrameConstants::kCallerFPOffset)); |
| 3670 | |
| 3671 | // Restore callee-saved registers and return. |
| 3672 | #ifdef DEBUG |
| 3673 | if (FLAG_debug_code) { |
| 3674 | __ mov(lr, Operand(pc)); |
| 3675 | } |
| 3676 | #endif |
Ben Murdoch | 7d3e7fc | 2011-07-12 16:37:06 +0100 | [diff] [blame] | 3677 | |
| 3678 | if (CpuFeatures::IsSupported(VFP3)) { |
| 3679 | CpuFeatures::Scope scope(VFP3); |
| 3680 | // Restore callee-saved vfp registers. |
| 3681 | __ vldm(ia_w, sp, kFirstCalleeSavedDoubleReg, kLastCalleeSavedDoubleReg); |
| 3682 | } |
| 3683 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3684 | __ ldm(ia_w, sp, kCalleeSaved | pc.bit()); |
| 3685 | } |
| 3686 | |
| 3687 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3688 | // Uses registers r0 to r4. |
| 3689 | // Expected input (depending on whether args are in registers or on the stack): |
| 3690 | // * object: r0 or at sp + 1 * kPointerSize. |
| 3691 | // * function: r1 or at sp. |
| 3692 | // |
| 3693 | // An inlined call site may have been generated before calling this stub. |
| 3694 | // In this case the offset to the inline site to patch is passed on the stack, |
| 3695 | // in the safepoint slot for register r4. |
| 3696 | // (See LCodeGen::DoInstanceOfKnownGlobal) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3697 | void InstanceofStub::Generate(MacroAssembler* masm) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3698 | // Call site inlining and patching implies arguments in registers. |
| 3699 | ASSERT(HasArgsInRegisters() || !HasCallSiteInlineCheck()); |
| 3700 | // ReturnTrueFalse is only implemented for inlined call sites. |
| 3701 | ASSERT(!ReturnTrueFalseObject() || HasCallSiteInlineCheck()); |
| 3702 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3703 | // Fixed register usage throughout the stub: |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 3704 | const Register object = r0; // Object (lhs). |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3705 | Register map = r3; // Map of the object. |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 3706 | const Register function = r1; // Function (rhs). |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3707 | const Register prototype = r4; // Prototype of the function. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3708 | const Register inline_site = r9; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3709 | const Register scratch = r2; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3710 | |
| 3711 | const int32_t kDeltaToLoadBoolResult = 3 * kPointerSize; |
| 3712 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3713 | Label slow, loop, is_instance, is_not_instance, not_js_object; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3714 | |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3715 | if (!HasArgsInRegisters()) { |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 3716 | __ ldr(object, MemOperand(sp, 1 * kPointerSize)); |
| 3717 | __ ldr(function, MemOperand(sp, 0)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3718 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3719 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3720 | // Check that the left hand is a JS object and load map. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3721 | __ JumpIfSmi(object, ¬_js_object); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 3722 | __ IsObjectJSObjectType(object, map, scratch, ¬_js_object); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3723 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3724 | // If there is a call site cache don't look in the global cache, but do the |
| 3725 | // real lookup and update the call site cache. |
| 3726 | if (!HasCallSiteInlineCheck()) { |
| 3727 | Label miss; |
| 3728 | __ LoadRoot(ip, Heap::kInstanceofCacheFunctionRootIndex); |
| 3729 | __ cmp(function, ip); |
| 3730 | __ b(ne, &miss); |
| 3731 | __ LoadRoot(ip, Heap::kInstanceofCacheMapRootIndex); |
| 3732 | __ cmp(map, ip); |
| 3733 | __ b(ne, &miss); |
| 3734 | __ LoadRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
| 3735 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3736 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3737 | __ bind(&miss); |
| 3738 | } |
| 3739 | |
| 3740 | // Get the prototype of the function. |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 3741 | __ TryGetFunctionPrototype(function, prototype, scratch, &slow); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3742 | |
| 3743 | // Check that the function prototype is a JS object. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3744 | __ JumpIfSmi(prototype, &slow); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3745 | __ IsObjectJSObjectType(prototype, scratch, scratch, &slow); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3746 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3747 | // Update the global instanceof or call site inlined cache with the current |
| 3748 | // map and function. The cached answer will be set when it is known below. |
| 3749 | if (!HasCallSiteInlineCheck()) { |
| 3750 | __ StoreRoot(function, Heap::kInstanceofCacheFunctionRootIndex); |
| 3751 | __ StoreRoot(map, Heap::kInstanceofCacheMapRootIndex); |
| 3752 | } else { |
| 3753 | ASSERT(HasArgsInRegisters()); |
| 3754 | // Patch the (relocated) inlined map check. |
| 3755 | |
| 3756 | // The offset was stored in r4 safepoint slot. |
| 3757 | // (See LCodeGen::DoDeferredLInstanceOfKnownGlobal) |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 3758 | __ LoadFromSafepointRegisterSlot(scratch, r4); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3759 | __ sub(inline_site, lr, scratch); |
| 3760 | // Get the map location in scratch and patch it. |
| 3761 | __ GetRelocatedValueLocation(inline_site, scratch); |
| 3762 | __ str(map, MemOperand(scratch)); |
| 3763 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3764 | |
| 3765 | // Register mapping: r3 is object map and r4 is function prototype. |
| 3766 | // Get prototype of object into r2. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3767 | __ ldr(scratch, FieldMemOperand(map, Map::kPrototypeOffset)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3768 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3769 | // We don't need map any more. Use it as a scratch register. |
| 3770 | Register scratch2 = map; |
| 3771 | map = no_reg; |
| 3772 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3773 | // Loop through the prototype chain looking for the function prototype. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3774 | __ LoadRoot(scratch2, Heap::kNullValueRootIndex); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3775 | __ bind(&loop); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3776 | __ cmp(scratch, Operand(prototype)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3777 | __ b(eq, &is_instance); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3778 | __ cmp(scratch, scratch2); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3779 | __ b(eq, &is_not_instance); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3780 | __ ldr(scratch, FieldMemOperand(scratch, HeapObject::kMapOffset)); |
| 3781 | __ ldr(scratch, FieldMemOperand(scratch, Map::kPrototypeOffset)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3782 | __ jmp(&loop); |
| 3783 | |
| 3784 | __ bind(&is_instance); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3785 | if (!HasCallSiteInlineCheck()) { |
| 3786 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 3787 | __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
| 3788 | } else { |
| 3789 | // Patch the call site to return true. |
| 3790 | __ LoadRoot(r0, Heap::kTrueValueRootIndex); |
| 3791 | __ add(inline_site, inline_site, Operand(kDeltaToLoadBoolResult)); |
| 3792 | // Get the boolean result location in scratch and patch it. |
| 3793 | __ GetRelocatedValueLocation(inline_site, scratch); |
| 3794 | __ str(r0, MemOperand(scratch)); |
| 3795 | |
| 3796 | if (!ReturnTrueFalseObject()) { |
| 3797 | __ mov(r0, Operand(Smi::FromInt(0))); |
| 3798 | } |
| 3799 | } |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3800 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3801 | |
| 3802 | __ bind(&is_not_instance); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3803 | if (!HasCallSiteInlineCheck()) { |
| 3804 | __ mov(r0, Operand(Smi::FromInt(1))); |
| 3805 | __ StoreRoot(r0, Heap::kInstanceofCacheAnswerRootIndex); |
| 3806 | } else { |
| 3807 | // Patch the call site to return false. |
| 3808 | __ LoadRoot(r0, Heap::kFalseValueRootIndex); |
| 3809 | __ add(inline_site, inline_site, Operand(kDeltaToLoadBoolResult)); |
| 3810 | // Get the boolean result location in scratch and patch it. |
| 3811 | __ GetRelocatedValueLocation(inline_site, scratch); |
| 3812 | __ str(r0, MemOperand(scratch)); |
| 3813 | |
| 3814 | if (!ReturnTrueFalseObject()) { |
| 3815 | __ mov(r0, Operand(Smi::FromInt(1))); |
| 3816 | } |
| 3817 | } |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3818 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3819 | |
| 3820 | Label object_not_null, object_not_null_or_smi; |
| 3821 | __ bind(¬_js_object); |
| 3822 | // Before null, smi and string value checks, check that the rhs is a function |
| 3823 | // as for a non-function rhs an exception needs to be thrown. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3824 | __ JumpIfSmi(function, &slow); |
| 3825 | __ CompareObjectType(function, scratch2, scratch, JS_FUNCTION_TYPE); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3826 | __ b(ne, &slow); |
| 3827 | |
| 3828 | // Null is not instance of anything. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3829 | __ cmp(scratch, Operand(masm->isolate()->factory()->null_value())); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3830 | __ b(ne, &object_not_null); |
| 3831 | __ mov(r0, Operand(Smi::FromInt(1))); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3832 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3833 | |
| 3834 | __ bind(&object_not_null); |
| 3835 | // Smi values are not instances of anything. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3836 | __ JumpIfNotSmi(object, &object_not_null_or_smi); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3837 | __ mov(r0, Operand(Smi::FromInt(1))); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3838 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 3839 | |
| 3840 | __ bind(&object_not_null_or_smi); |
| 3841 | // String values are not instances of anything. |
| 3842 | __ IsObjectJSStringType(object, scratch, &slow); |
| 3843 | __ mov(r0, Operand(Smi::FromInt(1))); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3844 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3845 | |
| 3846 | // Slow-case. Tail call builtin. |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3847 | __ bind(&slow); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3848 | if (!ReturnTrueFalseObject()) { |
| 3849 | if (HasArgsInRegisters()) { |
| 3850 | __ Push(r0, r1); |
| 3851 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3852 | __ InvokeBuiltin(Builtins::INSTANCE_OF, JUMP_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3853 | } else { |
| 3854 | __ EnterInternalFrame(); |
| 3855 | __ Push(r0, r1); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 3856 | __ InvokeBuiltin(Builtins::INSTANCE_OF, CALL_FUNCTION); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3857 | __ LeaveInternalFrame(); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3858 | __ cmp(r0, Operand::Zero()); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3859 | __ LoadRoot(r0, Heap::kTrueValueRootIndex, eq); |
| 3860 | __ LoadRoot(r0, Heap::kFalseValueRootIndex, ne); |
| 3861 | __ Ret(HasArgsInRegisters() ? 0 : 2); |
| 3862 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3863 | } |
| 3864 | |
| 3865 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3866 | Register InstanceofStub::left() { return r0; } |
| 3867 | |
| 3868 | |
| 3869 | Register InstanceofStub::right() { return r1; } |
| 3870 | |
| 3871 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3872 | void ArgumentsAccessStub::GenerateReadElement(MacroAssembler* masm) { |
| 3873 | // The displacement is the offset of the last parameter (if any) |
| 3874 | // relative to the frame pointer. |
| 3875 | static const int kDisplacement = |
| 3876 | StandardFrameConstants::kCallerSPOffset - kPointerSize; |
| 3877 | |
| 3878 | // Check that the key is a smi. |
| 3879 | Label slow; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 3880 | __ JumpIfNotSmi(r1, &slow); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3881 | |
| 3882 | // Check if the calling frame is an arguments adaptor frame. |
| 3883 | Label adaptor; |
| 3884 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3885 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 3886 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3887 | __ b(eq, &adaptor); |
| 3888 | |
| 3889 | // Check index against formal parameters count limit passed in |
| 3890 | // through register r0. Use unsigned comparison to get negative |
| 3891 | // check for free. |
| 3892 | __ cmp(r1, r0); |
Ben Murdoch | 086aeea | 2011-05-13 15:57:08 +0100 | [diff] [blame] | 3893 | __ b(hs, &slow); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3894 | |
| 3895 | // Read the argument from the stack and return it. |
| 3896 | __ sub(r3, r0, r1); |
| 3897 | __ add(r3, fp, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 3898 | __ ldr(r0, MemOperand(r3, kDisplacement)); |
| 3899 | __ Jump(lr); |
| 3900 | |
| 3901 | // Arguments adaptor case: Check index against actual arguments |
| 3902 | // limit found in the arguments adaptor frame. Use unsigned |
| 3903 | // comparison to get negative check for free. |
| 3904 | __ bind(&adaptor); |
| 3905 | __ ldr(r0, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3906 | __ cmp(r1, r0); |
| 3907 | __ b(cs, &slow); |
| 3908 | |
| 3909 | // Read the argument from the adaptor frame and return it. |
| 3910 | __ sub(r3, r0, r1); |
| 3911 | __ add(r3, r2, Operand(r3, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 3912 | __ ldr(r0, MemOperand(r3, kDisplacement)); |
| 3913 | __ Jump(lr); |
| 3914 | |
| 3915 | // Slow-case: Handle non-smi or out-of-bounds access to arguments |
| 3916 | // by calling the runtime system. |
| 3917 | __ bind(&slow); |
| 3918 | __ push(r1); |
| 3919 | __ TailCallRuntime(Runtime::kGetArgumentsProperty, 1, 1); |
| 3920 | } |
| 3921 | |
| 3922 | |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3923 | void ArgumentsAccessStub::GenerateNewNonStrictSlow(MacroAssembler* masm) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 3924 | // sp[0] : number of parameters |
| 3925 | // sp[4] : receiver displacement |
| 3926 | // sp[8] : function |
| 3927 | |
| 3928 | // Check if the calling frame is an arguments adaptor frame. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3929 | Label runtime; |
| 3930 | __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3931 | __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset)); |
| 3932 | __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3933 | __ b(ne, &runtime); |
| 3934 | |
| 3935 | // Patch the arguments.length and the parameters pointer in the current frame. |
| 3936 | __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3937 | __ str(r2, MemOperand(sp, 0 * kPointerSize)); |
| 3938 | __ add(r3, r3, Operand(r2, LSL, 1)); |
| 3939 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 3940 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 3941 | |
| 3942 | __ bind(&runtime); |
| 3943 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 3944 | } |
| 3945 | |
| 3946 | |
| 3947 | void ArgumentsAccessStub::GenerateNewNonStrictFast(MacroAssembler* masm) { |
| 3948 | // Stack layout: |
| 3949 | // sp[0] : number of parameters (tagged) |
| 3950 | // sp[4] : address of receiver argument |
| 3951 | // sp[8] : function |
| 3952 | // Registers used over whole function: |
| 3953 | // r6 : allocated object (tagged) |
| 3954 | // r9 : mapped parameter count (tagged) |
| 3955 | |
| 3956 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
| 3957 | // r1 = parameter count (tagged) |
| 3958 | |
| 3959 | // Check if the calling frame is an arguments adaptor frame. |
| 3960 | Label runtime; |
| 3961 | Label adaptor_frame, try_allocate; |
| 3962 | __ ldr(r3, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 3963 | __ ldr(r2, MemOperand(r3, StandardFrameConstants::kContextOffset)); |
| 3964 | __ cmp(r2, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 3965 | __ b(eq, &adaptor_frame); |
| 3966 | |
| 3967 | // No adaptor, parameter count = argument count. |
| 3968 | __ mov(r2, r1); |
| 3969 | __ b(&try_allocate); |
| 3970 | |
| 3971 | // We have an adaptor frame. Patch the parameters pointer. |
| 3972 | __ bind(&adaptor_frame); |
| 3973 | __ ldr(r2, MemOperand(r3, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 3974 | __ add(r3, r3, Operand(r2, LSL, 1)); |
| 3975 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 3976 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 3977 | |
| 3978 | // r1 = parameter count (tagged) |
| 3979 | // r2 = argument count (tagged) |
| 3980 | // Compute the mapped parameter count = min(r1, r2) in r1. |
| 3981 | __ cmp(r1, Operand(r2)); |
| 3982 | __ mov(r1, Operand(r2), LeaveCC, gt); |
| 3983 | |
| 3984 | __ bind(&try_allocate); |
| 3985 | |
| 3986 | // Compute the sizes of backing store, parameter map, and arguments object. |
| 3987 | // 1. Parameter map, has 2 extra words containing context and backing store. |
| 3988 | const int kParameterMapHeaderSize = |
| 3989 | FixedArray::kHeaderSize + 2 * kPointerSize; |
| 3990 | // If there are no mapped parameters, we do not need the parameter_map. |
| 3991 | __ cmp(r1, Operand(Smi::FromInt(0))); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 3992 | __ mov(r9, Operand::Zero(), LeaveCC, eq); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 3993 | __ mov(r9, Operand(r1, LSL, 1), LeaveCC, ne); |
| 3994 | __ add(r9, r9, Operand(kParameterMapHeaderSize), LeaveCC, ne); |
| 3995 | |
| 3996 | // 2. Backing store. |
| 3997 | __ add(r9, r9, Operand(r2, LSL, 1)); |
| 3998 | __ add(r9, r9, Operand(FixedArray::kHeaderSize)); |
| 3999 | |
| 4000 | // 3. Arguments object. |
| 4001 | __ add(r9, r9, Operand(Heap::kArgumentsObjectSize)); |
| 4002 | |
| 4003 | // Do the allocation of all three objects in one go. |
| 4004 | __ AllocateInNewSpace(r9, r0, r3, r4, &runtime, TAG_OBJECT); |
| 4005 | |
| 4006 | // r0 = address of new object(s) (tagged) |
| 4007 | // r2 = argument count (tagged) |
| 4008 | // Get the arguments boilerplate from the current (global) context into r4. |
| 4009 | const int kNormalOffset = |
| 4010 | Context::SlotOffset(Context::ARGUMENTS_BOILERPLATE_INDEX); |
| 4011 | const int kAliasedOffset = |
| 4012 | Context::SlotOffset(Context::ALIASED_ARGUMENTS_BOILERPLATE_INDEX); |
| 4013 | |
| 4014 | __ ldr(r4, MemOperand(r8, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 4015 | __ ldr(r4, FieldMemOperand(r4, GlobalObject::kGlobalContextOffset)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4016 | __ cmp(r1, Operand::Zero()); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4017 | __ ldr(r4, MemOperand(r4, kNormalOffset), eq); |
| 4018 | __ ldr(r4, MemOperand(r4, kAliasedOffset), ne); |
| 4019 | |
| 4020 | // r0 = address of new object (tagged) |
| 4021 | // r1 = mapped parameter count (tagged) |
| 4022 | // r2 = argument count (tagged) |
| 4023 | // r4 = address of boilerplate object (tagged) |
| 4024 | // Copy the JS object part. |
| 4025 | for (int i = 0; i < JSObject::kHeaderSize; i += kPointerSize) { |
| 4026 | __ ldr(r3, FieldMemOperand(r4, i)); |
| 4027 | __ str(r3, FieldMemOperand(r0, i)); |
| 4028 | } |
| 4029 | |
| 4030 | // Setup the callee in-object property. |
| 4031 | STATIC_ASSERT(Heap::kArgumentsCalleeIndex == 1); |
| 4032 | __ ldr(r3, MemOperand(sp, 2 * kPointerSize)); |
| 4033 | const int kCalleeOffset = JSObject::kHeaderSize + |
| 4034 | Heap::kArgumentsCalleeIndex * kPointerSize; |
| 4035 | __ str(r3, FieldMemOperand(r0, kCalleeOffset)); |
| 4036 | |
| 4037 | // Use the length (smi tagged) and set that as an in-object property too. |
| 4038 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
| 4039 | const int kLengthOffset = JSObject::kHeaderSize + |
| 4040 | Heap::kArgumentsLengthIndex * kPointerSize; |
| 4041 | __ str(r2, FieldMemOperand(r0, kLengthOffset)); |
| 4042 | |
| 4043 | // Setup the elements pointer in the allocated arguments object. |
| 4044 | // If we allocated a parameter map, r4 will point there, otherwise |
| 4045 | // it will point to the backing store. |
| 4046 | __ add(r4, r0, Operand(Heap::kArgumentsObjectSize)); |
| 4047 | __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 4048 | |
| 4049 | // r0 = address of new object (tagged) |
| 4050 | // r1 = mapped parameter count (tagged) |
| 4051 | // r2 = argument count (tagged) |
| 4052 | // r4 = address of parameter map or backing store (tagged) |
| 4053 | // Initialize parameter map. If there are no mapped arguments, we're done. |
| 4054 | Label skip_parameter_map; |
| 4055 | __ cmp(r1, Operand(Smi::FromInt(0))); |
| 4056 | // Move backing store address to r3, because it is |
| 4057 | // expected there when filling in the unmapped arguments. |
| 4058 | __ mov(r3, r4, LeaveCC, eq); |
| 4059 | __ b(eq, &skip_parameter_map); |
| 4060 | |
| 4061 | __ LoadRoot(r6, Heap::kNonStrictArgumentsElementsMapRootIndex); |
| 4062 | __ str(r6, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| 4063 | __ add(r6, r1, Operand(Smi::FromInt(2))); |
| 4064 | __ str(r6, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
| 4065 | __ str(r8, FieldMemOperand(r4, FixedArray::kHeaderSize + 0 * kPointerSize)); |
| 4066 | __ add(r6, r4, Operand(r1, LSL, 1)); |
| 4067 | __ add(r6, r6, Operand(kParameterMapHeaderSize)); |
| 4068 | __ str(r6, FieldMemOperand(r4, FixedArray::kHeaderSize + 1 * kPointerSize)); |
| 4069 | |
| 4070 | // Copy the parameter slots and the holes in the arguments. |
| 4071 | // We need to fill in mapped_parameter_count slots. They index the context, |
| 4072 | // where parameters are stored in reverse order, at |
| 4073 | // MIN_CONTEXT_SLOTS .. MIN_CONTEXT_SLOTS+parameter_count-1 |
| 4074 | // The mapped parameter thus need to get indices |
| 4075 | // MIN_CONTEXT_SLOTS+parameter_count-1 .. |
| 4076 | // MIN_CONTEXT_SLOTS+parameter_count-mapped_parameter_count |
| 4077 | // We loop from right to left. |
| 4078 | Label parameters_loop, parameters_test; |
| 4079 | __ mov(r6, r1); |
| 4080 | __ ldr(r9, MemOperand(sp, 0 * kPointerSize)); |
| 4081 | __ add(r9, r9, Operand(Smi::FromInt(Context::MIN_CONTEXT_SLOTS))); |
| 4082 | __ sub(r9, r9, Operand(r1)); |
| 4083 | __ LoadRoot(r7, Heap::kTheHoleValueRootIndex); |
| 4084 | __ add(r3, r4, Operand(r6, LSL, 1)); |
| 4085 | __ add(r3, r3, Operand(kParameterMapHeaderSize)); |
| 4086 | |
| 4087 | // r6 = loop variable (tagged) |
| 4088 | // r1 = mapping index (tagged) |
| 4089 | // r3 = address of backing store (tagged) |
| 4090 | // r4 = address of parameter map (tagged) |
| 4091 | // r5 = temporary scratch (a.o., for address calculation) |
| 4092 | // r7 = the hole value |
| 4093 | __ jmp(¶meters_test); |
| 4094 | |
| 4095 | __ bind(¶meters_loop); |
| 4096 | __ sub(r6, r6, Operand(Smi::FromInt(1))); |
| 4097 | __ mov(r5, Operand(r6, LSL, 1)); |
| 4098 | __ add(r5, r5, Operand(kParameterMapHeaderSize - kHeapObjectTag)); |
| 4099 | __ str(r9, MemOperand(r4, r5)); |
| 4100 | __ sub(r5, r5, Operand(kParameterMapHeaderSize - FixedArray::kHeaderSize)); |
| 4101 | __ str(r7, MemOperand(r3, r5)); |
| 4102 | __ add(r9, r9, Operand(Smi::FromInt(1))); |
| 4103 | __ bind(¶meters_test); |
| 4104 | __ cmp(r6, Operand(Smi::FromInt(0))); |
| 4105 | __ b(ne, ¶meters_loop); |
| 4106 | |
| 4107 | __ bind(&skip_parameter_map); |
| 4108 | // r2 = argument count (tagged) |
| 4109 | // r3 = address of backing store (tagged) |
| 4110 | // r5 = scratch |
| 4111 | // Copy arguments header and remaining slots (if there are any). |
| 4112 | __ LoadRoot(r5, Heap::kFixedArrayMapRootIndex); |
| 4113 | __ str(r5, FieldMemOperand(r3, FixedArray::kMapOffset)); |
| 4114 | __ str(r2, FieldMemOperand(r3, FixedArray::kLengthOffset)); |
| 4115 | |
| 4116 | Label arguments_loop, arguments_test; |
| 4117 | __ mov(r9, r1); |
| 4118 | __ ldr(r4, MemOperand(sp, 1 * kPointerSize)); |
| 4119 | __ sub(r4, r4, Operand(r9, LSL, 1)); |
| 4120 | __ jmp(&arguments_test); |
| 4121 | |
| 4122 | __ bind(&arguments_loop); |
| 4123 | __ sub(r4, r4, Operand(kPointerSize)); |
| 4124 | __ ldr(r6, MemOperand(r4, 0)); |
| 4125 | __ add(r5, r3, Operand(r9, LSL, 1)); |
| 4126 | __ str(r6, FieldMemOperand(r5, FixedArray::kHeaderSize)); |
| 4127 | __ add(r9, r9, Operand(Smi::FromInt(1))); |
| 4128 | |
| 4129 | __ bind(&arguments_test); |
| 4130 | __ cmp(r9, Operand(r2)); |
| 4131 | __ b(lt, &arguments_loop); |
| 4132 | |
| 4133 | // Return and remove the on-stack parameters. |
| 4134 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 4135 | __ Ret(); |
| 4136 | |
| 4137 | // Do the runtime call to allocate the arguments object. |
| 4138 | // r2 = argument count (taggged) |
| 4139 | __ bind(&runtime); |
| 4140 | __ str(r2, MemOperand(sp, 0 * kPointerSize)); // Patch argument count. |
| 4141 | __ TailCallRuntime(Runtime::kNewArgumentsFast, 3, 1); |
| 4142 | } |
| 4143 | |
| 4144 | |
| 4145 | void ArgumentsAccessStub::GenerateNewStrict(MacroAssembler* masm) { |
| 4146 | // sp[0] : number of parameters |
| 4147 | // sp[4] : receiver displacement |
| 4148 | // sp[8] : function |
| 4149 | // Check if the calling frame is an arguments adaptor frame. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4150 | Label adaptor_frame, try_allocate, runtime; |
| 4151 | __ ldr(r2, MemOperand(fp, StandardFrameConstants::kCallerFPOffset)); |
| 4152 | __ ldr(r3, MemOperand(r2, StandardFrameConstants::kContextOffset)); |
| 4153 | __ cmp(r3, Operand(Smi::FromInt(StackFrame::ARGUMENTS_ADAPTOR))); |
| 4154 | __ b(eq, &adaptor_frame); |
| 4155 | |
| 4156 | // Get the length from the frame. |
| 4157 | __ ldr(r1, MemOperand(sp, 0)); |
| 4158 | __ b(&try_allocate); |
| 4159 | |
| 4160 | // Patch the arguments.length and the parameters pointer. |
| 4161 | __ bind(&adaptor_frame); |
| 4162 | __ ldr(r1, MemOperand(r2, ArgumentsAdaptorFrameConstants::kLengthOffset)); |
| 4163 | __ str(r1, MemOperand(sp, 0)); |
| 4164 | __ add(r3, r2, Operand(r1, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4165 | __ add(r3, r3, Operand(StandardFrameConstants::kCallerSPOffset)); |
| 4166 | __ str(r3, MemOperand(sp, 1 * kPointerSize)); |
| 4167 | |
| 4168 | // Try the new space allocation. Start out with computing the size |
| 4169 | // of the arguments object and the elements array in words. |
| 4170 | Label add_arguments_object; |
| 4171 | __ bind(&try_allocate); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 4172 | __ cmp(r1, Operand(0, RelocInfo::NONE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4173 | __ b(eq, &add_arguments_object); |
| 4174 | __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
| 4175 | __ add(r1, r1, Operand(FixedArray::kHeaderSize / kPointerSize)); |
| 4176 | __ bind(&add_arguments_object); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4177 | __ add(r1, r1, Operand(Heap::kArgumentsObjectSizeStrict / kPointerSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4178 | |
| 4179 | // Do the allocation of both objects in one go. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4180 | __ AllocateInNewSpace(r1, |
| 4181 | r0, |
| 4182 | r2, |
| 4183 | r3, |
| 4184 | &runtime, |
| 4185 | static_cast<AllocationFlags>(TAG_OBJECT | |
| 4186 | SIZE_IN_WORDS)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4187 | |
| 4188 | // Get the arguments boilerplate from the current (global) context. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4189 | __ ldr(r4, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 4190 | __ ldr(r4, FieldMemOperand(r4, GlobalObject::kGlobalContextOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4191 | __ ldr(r4, MemOperand(r4, Context::SlotOffset( |
| 4192 | Context::STRICT_MODE_ARGUMENTS_BOILERPLATE_INDEX))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4193 | |
| 4194 | // Copy the JS object part. |
| 4195 | __ CopyFields(r0, r4, r3.bit(), JSObject::kHeaderSize / kPointerSize); |
| 4196 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4197 | // Get the length (smi tagged) and set that as an in-object property too. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4198 | STATIC_ASSERT(Heap::kArgumentsLengthIndex == 0); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4199 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4200 | __ str(r1, FieldMemOperand(r0, JSObject::kHeaderSize + |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4201 | Heap::kArgumentsLengthIndex * kPointerSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4202 | |
| 4203 | // If there are no actual arguments, we're done. |
| 4204 | Label done; |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 4205 | __ cmp(r1, Operand(0, RelocInfo::NONE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4206 | __ b(eq, &done); |
| 4207 | |
| 4208 | // Get the parameters pointer from the stack. |
| 4209 | __ ldr(r2, MemOperand(sp, 1 * kPointerSize)); |
| 4210 | |
| 4211 | // Setup the elements pointer in the allocated arguments object and |
| 4212 | // initialize the header in the elements fixed array. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4213 | __ add(r4, r0, Operand(Heap::kArgumentsObjectSizeStrict)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4214 | __ str(r4, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 4215 | __ LoadRoot(r3, Heap::kFixedArrayMapRootIndex); |
| 4216 | __ str(r3, FieldMemOperand(r4, FixedArray::kMapOffset)); |
| 4217 | __ str(r1, FieldMemOperand(r4, FixedArray::kLengthOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4218 | // Untag the length for the loop. |
| 4219 | __ mov(r1, Operand(r1, LSR, kSmiTagSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4220 | |
| 4221 | // Copy the fixed array slots. |
| 4222 | Label loop; |
| 4223 | // Setup r4 to point to the first array slot. |
| 4224 | __ add(r4, r4, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4225 | __ bind(&loop); |
| 4226 | // Pre-decrement r2 with kPointerSize on each iteration. |
| 4227 | // Pre-decrement in order to skip receiver. |
| 4228 | __ ldr(r3, MemOperand(r2, kPointerSize, NegPreIndex)); |
| 4229 | // Post-increment r4 with kPointerSize on each iteration. |
| 4230 | __ str(r3, MemOperand(r4, kPointerSize, PostIndex)); |
| 4231 | __ sub(r1, r1, Operand(1)); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 4232 | __ cmp(r1, Operand(0, RelocInfo::NONE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4233 | __ b(ne, &loop); |
| 4234 | |
| 4235 | // Return and remove the on-stack parameters. |
| 4236 | __ bind(&done); |
| 4237 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 4238 | __ Ret(); |
| 4239 | |
| 4240 | // Do the runtime call to allocate the arguments object. |
| 4241 | __ bind(&runtime); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4242 | __ TailCallRuntime(Runtime::kNewStrictArgumentsFast, 3, 1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4243 | } |
| 4244 | |
| 4245 | |
| 4246 | void RegExpExecStub::Generate(MacroAssembler* masm) { |
| 4247 | // Just jump directly to runtime if native RegExp is not selected at compile |
| 4248 | // time or if regexp entry in generated code is turned off runtime switch or |
| 4249 | // at compilation. |
| 4250 | #ifdef V8_INTERPRETED_REGEXP |
| 4251 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4252 | #else // V8_INTERPRETED_REGEXP |
| 4253 | if (!FLAG_regexp_entry_native) { |
| 4254 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4255 | return; |
| 4256 | } |
| 4257 | |
| 4258 | // Stack frame on entry. |
| 4259 | // sp[0]: last_match_info (expected JSArray) |
| 4260 | // sp[4]: previous index |
| 4261 | // sp[8]: subject string |
| 4262 | // sp[12]: JSRegExp object |
| 4263 | |
| 4264 | static const int kLastMatchInfoOffset = 0 * kPointerSize; |
| 4265 | static const int kPreviousIndexOffset = 1 * kPointerSize; |
| 4266 | static const int kSubjectOffset = 2 * kPointerSize; |
| 4267 | static const int kJSRegExpOffset = 3 * kPointerSize; |
| 4268 | |
| 4269 | Label runtime, invoke_regexp; |
| 4270 | |
| 4271 | // Allocation of registers for this function. These are in callee save |
| 4272 | // registers and will be preserved by the call to the native RegExp code, as |
| 4273 | // this code is called using the normal C calling convention. When calling |
| 4274 | // directly from generated code the native RegExp code will not do a GC and |
| 4275 | // therefore the content of these registers are safe to use after the call. |
| 4276 | Register subject = r4; |
| 4277 | Register regexp_data = r5; |
| 4278 | Register last_match_info_elements = r6; |
| 4279 | |
| 4280 | // Ensure that a RegExp stack is allocated. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4281 | Isolate* isolate = masm->isolate(); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4282 | ExternalReference address_of_regexp_stack_memory_address = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4283 | ExternalReference::address_of_regexp_stack_memory_address(isolate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4284 | ExternalReference address_of_regexp_stack_memory_size = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4285 | ExternalReference::address_of_regexp_stack_memory_size(isolate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4286 | __ mov(r0, Operand(address_of_regexp_stack_memory_size)); |
| 4287 | __ ldr(r0, MemOperand(r0, 0)); |
| 4288 | __ tst(r0, Operand(r0)); |
| 4289 | __ b(eq, &runtime); |
| 4290 | |
| 4291 | // Check that the first argument is a JSRegExp object. |
| 4292 | __ ldr(r0, MemOperand(sp, kJSRegExpOffset)); |
| 4293 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4294 | __ JumpIfSmi(r0, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4295 | __ CompareObjectType(r0, r1, r1, JS_REGEXP_TYPE); |
| 4296 | __ b(ne, &runtime); |
| 4297 | |
| 4298 | // Check that the RegExp has been compiled (data contains a fixed array). |
| 4299 | __ ldr(regexp_data, FieldMemOperand(r0, JSRegExp::kDataOffset)); |
| 4300 | if (FLAG_debug_code) { |
| 4301 | __ tst(regexp_data, Operand(kSmiTagMask)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4302 | __ Check(ne, "Unexpected type for RegExp data, FixedArray expected"); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4303 | __ CompareObjectType(regexp_data, r0, r0, FIXED_ARRAY_TYPE); |
| 4304 | __ Check(eq, "Unexpected type for RegExp data, FixedArray expected"); |
| 4305 | } |
| 4306 | |
| 4307 | // regexp_data: RegExp data (FixedArray) |
| 4308 | // Check the type of the RegExp. Only continue if type is JSRegExp::IRREGEXP. |
| 4309 | __ ldr(r0, FieldMemOperand(regexp_data, JSRegExp::kDataTagOffset)); |
| 4310 | __ cmp(r0, Operand(Smi::FromInt(JSRegExp::IRREGEXP))); |
| 4311 | __ b(ne, &runtime); |
| 4312 | |
| 4313 | // regexp_data: RegExp data (FixedArray) |
| 4314 | // Check that the number of captures fit in the static offsets vector buffer. |
| 4315 | __ ldr(r2, |
| 4316 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4317 | // Calculate number of capture registers (number_of_captures + 1) * 2. This |
| 4318 | // uses the asumption that smis are 2 * their untagged value. |
| 4319 | STATIC_ASSERT(kSmiTag == 0); |
| 4320 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 4321 | __ add(r2, r2, Operand(2)); // r2 was a smi. |
| 4322 | // Check that the static offsets vector buffer is large enough. |
| 4323 | __ cmp(r2, Operand(OffsetsVector::kStaticOffsetsVectorSize)); |
| 4324 | __ b(hi, &runtime); |
| 4325 | |
| 4326 | // r2: Number of capture registers |
| 4327 | // regexp_data: RegExp data (FixedArray) |
| 4328 | // Check that the second argument is a string. |
| 4329 | __ ldr(subject, MemOperand(sp, kSubjectOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4330 | __ JumpIfSmi(subject, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4331 | Condition is_string = masm->IsObjectStringType(subject, r0); |
| 4332 | __ b(NegateCondition(is_string), &runtime); |
| 4333 | // Get the length of the string to r3. |
| 4334 | __ ldr(r3, FieldMemOperand(subject, String::kLengthOffset)); |
| 4335 | |
| 4336 | // r2: Number of capture registers |
| 4337 | // r3: Length of subject string as a smi |
| 4338 | // subject: Subject string |
| 4339 | // regexp_data: RegExp data (FixedArray) |
| 4340 | // Check that the third argument is a positive smi less than the subject |
| 4341 | // string length. A negative value will be greater (unsigned comparison). |
| 4342 | __ ldr(r0, MemOperand(sp, kPreviousIndexOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4343 | __ JumpIfNotSmi(r0, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4344 | __ cmp(r3, Operand(r0)); |
| 4345 | __ b(ls, &runtime); |
| 4346 | |
| 4347 | // r2: Number of capture registers |
| 4348 | // subject: Subject string |
| 4349 | // regexp_data: RegExp data (FixedArray) |
| 4350 | // Check that the fourth object is a JSArray object. |
| 4351 | __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4352 | __ JumpIfSmi(r0, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4353 | __ CompareObjectType(r0, r1, r1, JS_ARRAY_TYPE); |
| 4354 | __ b(ne, &runtime); |
| 4355 | // Check that the JSArray is in fast case. |
| 4356 | __ ldr(last_match_info_elements, |
| 4357 | FieldMemOperand(r0, JSArray::kElementsOffset)); |
| 4358 | __ ldr(r0, FieldMemOperand(last_match_info_elements, HeapObject::kMapOffset)); |
| 4359 | __ LoadRoot(ip, Heap::kFixedArrayMapRootIndex); |
| 4360 | __ cmp(r0, ip); |
| 4361 | __ b(ne, &runtime); |
| 4362 | // Check that the last match info has space for the capture registers and the |
| 4363 | // additional information. |
| 4364 | __ ldr(r0, |
| 4365 | FieldMemOperand(last_match_info_elements, FixedArray::kLengthOffset)); |
| 4366 | __ add(r2, r2, Operand(RegExpImpl::kLastMatchOverhead)); |
| 4367 | __ cmp(r2, Operand(r0, ASR, kSmiTagSize)); |
| 4368 | __ b(gt, &runtime); |
| 4369 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4370 | // Reset offset for possibly sliced string. |
| 4371 | __ mov(r9, Operand(0)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4372 | // subject: Subject string |
| 4373 | // regexp_data: RegExp data (FixedArray) |
| 4374 | // Check the representation and encoding of the subject string. |
| 4375 | Label seq_string; |
| 4376 | __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 4377 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
| 4378 | // First check for flat string. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4379 | __ and_(r1, r0, Operand(kIsNotStringMask | kStringRepresentationMask), SetCC); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4380 | STATIC_ASSERT((kStringTag | kSeqStringTag) == 0); |
| 4381 | __ b(eq, &seq_string); |
| 4382 | |
| 4383 | // subject: Subject string |
| 4384 | // regexp_data: RegExp data (FixedArray) |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4385 | // Check for flat cons string or sliced string. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4386 | // A flat cons string is a cons string where the second part is the empty |
| 4387 | // string. In that case the subject string is just the first part of the cons |
| 4388 | // string. Also in this case the first part of the cons string is known to be |
| 4389 | // a sequential string or an external string. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4390 | // In the case of a sliced string its offset has to be taken into account. |
| 4391 | Label cons_string, check_encoding; |
| 4392 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 4393 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
| 4394 | __ cmp(r1, Operand(kExternalStringTag)); |
| 4395 | __ b(lt, &cons_string); |
| 4396 | __ b(eq, &runtime); |
| 4397 | |
| 4398 | // String is sliced. |
| 4399 | __ ldr(r9, FieldMemOperand(subject, SlicedString::kOffsetOffset)); |
| 4400 | __ mov(r9, Operand(r9, ASR, kSmiTagSize)); |
| 4401 | __ ldr(subject, FieldMemOperand(subject, SlicedString::kParentOffset)); |
| 4402 | // r9: offset of sliced string, smi-tagged. |
| 4403 | __ jmp(&check_encoding); |
| 4404 | // String is a cons string, check whether it is flat. |
| 4405 | __ bind(&cons_string); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4406 | __ ldr(r0, FieldMemOperand(subject, ConsString::kSecondOffset)); |
| 4407 | __ LoadRoot(r1, Heap::kEmptyStringRootIndex); |
| 4408 | __ cmp(r0, r1); |
| 4409 | __ b(ne, &runtime); |
| 4410 | __ ldr(subject, FieldMemOperand(subject, ConsString::kFirstOffset)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4411 | // Is first part of cons or parent of slice a flat string? |
| 4412 | __ bind(&check_encoding); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4413 | __ ldr(r0, FieldMemOperand(subject, HeapObject::kMapOffset)); |
| 4414 | __ ldrb(r0, FieldMemOperand(r0, Map::kInstanceTypeOffset)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4415 | STATIC_ASSERT(kSeqStringTag == 0); |
| 4416 | __ tst(r0, Operand(kStringRepresentationMask)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4417 | __ b(ne, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4418 | __ bind(&seq_string); |
| 4419 | // subject: Subject string |
| 4420 | // regexp_data: RegExp data (FixedArray) |
| 4421 | // r0: Instance type of subject string |
| 4422 | STATIC_ASSERT(4 == kAsciiStringTag); |
| 4423 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 4424 | // Find the code object based on the assumptions above. |
| 4425 | __ and_(r0, r0, Operand(kStringEncodingMask)); |
| 4426 | __ mov(r3, Operand(r0, ASR, 2), SetCC); |
| 4427 | __ ldr(r7, FieldMemOperand(regexp_data, JSRegExp::kDataAsciiCodeOffset), ne); |
| 4428 | __ ldr(r7, FieldMemOperand(regexp_data, JSRegExp::kDataUC16CodeOffset), eq); |
| 4429 | |
| 4430 | // Check that the irregexp code has been generated for the actual string |
| 4431 | // encoding. If it has, the field contains a code object otherwise it contains |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4432 | // a smi (code flushing support). |
| 4433 | __ JumpIfSmi(r7, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4434 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4435 | // r3: encoding of subject string (1 if ASCII, 0 if two_byte); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4436 | // r7: code |
| 4437 | // subject: Subject string |
| 4438 | // regexp_data: RegExp data (FixedArray) |
| 4439 | // Load used arguments before starting to push arguments for call to native |
| 4440 | // RegExp code to avoid handling changing stack height. |
| 4441 | __ ldr(r1, MemOperand(sp, kPreviousIndexOffset)); |
| 4442 | __ mov(r1, Operand(r1, ASR, kSmiTagSize)); |
| 4443 | |
| 4444 | // r1: previous index |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4445 | // r3: encoding of subject string (1 if ASCII, 0 if two_byte); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4446 | // r7: code |
| 4447 | // subject: Subject string |
| 4448 | // regexp_data: RegExp data (FixedArray) |
| 4449 | // All checks done. Now push arguments for native regexp code. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4450 | __ IncrementCounter(isolate->counters()->regexp_entry_native(), 1, r0, r2); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4451 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4452 | // Isolates: note we add an additional parameter here (isolate pointer). |
| 4453 | static const int kRegExpExecuteArguments = 8; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4454 | static const int kParameterRegisters = 4; |
| 4455 | __ EnterExitFrame(false, kRegExpExecuteArguments - kParameterRegisters); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4456 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4457 | // Stack pointer now points to cell where return address is to be written. |
| 4458 | // Arguments are before that on the stack or in registers. |
| 4459 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4460 | // Argument 8 (sp[16]): Pass current isolate address. |
| 4461 | __ mov(r0, Operand(ExternalReference::isolate_address())); |
| 4462 | __ str(r0, MemOperand(sp, 4 * kPointerSize)); |
| 4463 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4464 | // Argument 7 (sp[12]): Indicate that this is a direct call from JavaScript. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4465 | __ mov(r0, Operand(1)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4466 | __ str(r0, MemOperand(sp, 3 * kPointerSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4467 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4468 | // Argument 6 (sp[8]): Start (high end) of backtracking stack memory area. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4469 | __ mov(r0, Operand(address_of_regexp_stack_memory_address)); |
| 4470 | __ ldr(r0, MemOperand(r0, 0)); |
| 4471 | __ mov(r2, Operand(address_of_regexp_stack_memory_size)); |
| 4472 | __ ldr(r2, MemOperand(r2, 0)); |
| 4473 | __ add(r0, r0, Operand(r2)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4474 | __ str(r0, MemOperand(sp, 2 * kPointerSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4475 | |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4476 | // Argument 5 (sp[4]): static offsets vector buffer. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4477 | __ mov(r0, |
| 4478 | Operand(ExternalReference::address_of_static_offsets_vector(isolate))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4479 | __ str(r0, MemOperand(sp, 1 * kPointerSize)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4480 | |
| 4481 | // For arguments 4 and 3 get string length, calculate start of string data and |
| 4482 | // calculate the shift of the index (0 for ASCII and 1 for two byte). |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4483 | STATIC_ASSERT(SeqAsciiString::kHeaderSize == SeqTwoByteString::kHeaderSize); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4484 | __ add(r8, subject, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4485 | __ eor(r3, r3, Operand(1)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4486 | // Load the length from the original subject string from the previous stack |
| 4487 | // frame. Therefore we have to use fp, which points exactly to two pointer |
| 4488 | // sizes below the previous sp. (Because creating a new stack frame pushes |
| 4489 | // the previous fp onto the stack and moves up sp by 2 * kPointerSize.) |
| 4490 | __ ldr(r0, MemOperand(fp, kSubjectOffset + 2 * kPointerSize)); |
| 4491 | // If slice offset is not 0, load the length from the original sliced string. |
| 4492 | // Argument 4, r3: End of string data |
| 4493 | // Argument 3, r2: Start of string data |
| 4494 | // Prepare start and end index of the input. |
| 4495 | __ add(r9, r8, Operand(r9, LSL, r3)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4496 | __ add(r2, r9, Operand(r1, LSL, r3)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4497 | |
| 4498 | __ ldr(r8, FieldMemOperand(r0, String::kLengthOffset)); |
| 4499 | __ mov(r8, Operand(r8, ASR, kSmiTagSize)); |
| 4500 | __ add(r3, r9, Operand(r8, LSL, r3)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4501 | |
| 4502 | // Argument 2 (r1): Previous index. |
| 4503 | // Already there |
| 4504 | |
| 4505 | // Argument 1 (r0): Subject string. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4506 | // Already there |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4507 | |
| 4508 | // Locate the code entry and call it. |
| 4509 | __ add(r7, r7, Operand(Code::kHeaderSize - kHeapObjectTag)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4510 | DirectCEntryStub stub; |
| 4511 | stub.GenerateCall(masm, r7); |
| 4512 | |
| 4513 | __ LeaveExitFrame(false, no_reg); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4514 | |
| 4515 | // r0: result |
| 4516 | // subject: subject string (callee saved) |
| 4517 | // regexp_data: RegExp data (callee saved) |
| 4518 | // last_match_info_elements: Last match info elements (callee saved) |
| 4519 | |
| 4520 | // Check the result. |
| 4521 | Label success; |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4522 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4523 | __ cmp(subject, Operand(NativeRegExpMacroAssembler::SUCCESS)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4524 | __ b(eq, &success); |
| 4525 | Label failure; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4526 | __ cmp(subject, Operand(NativeRegExpMacroAssembler::FAILURE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4527 | __ b(eq, &failure); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4528 | __ cmp(subject, Operand(NativeRegExpMacroAssembler::EXCEPTION)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4529 | // If not exception it can only be retry. Handle that in the runtime system. |
| 4530 | __ b(ne, &runtime); |
| 4531 | // Result must now be exception. If there is no pending exception already a |
| 4532 | // stack overflow (on the backtrack stack) was detected in RegExp code but |
| 4533 | // haven't created the exception yet. Handle that in the runtime system. |
| 4534 | // TODO(592): Rerunning the RegExp to get the stack overflow exception. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4535 | __ mov(r1, Operand(ExternalReference::the_hole_value_location(isolate))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4536 | __ ldr(r1, MemOperand(r1, 0)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4537 | __ mov(r2, Operand(ExternalReference(Isolate::k_pending_exception_address, |
| 4538 | isolate))); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4539 | __ ldr(r0, MemOperand(r2, 0)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4540 | __ cmp(subject, r1); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4541 | __ b(eq, &runtime); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4542 | |
| 4543 | __ str(r1, MemOperand(r2, 0)); // Clear pending exception. |
| 4544 | |
| 4545 | // Check if the exception is a termination. If so, throw as uncatchable. |
| 4546 | __ LoadRoot(ip, Heap::kTerminationExceptionRootIndex); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4547 | __ cmp(subject, ip); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4548 | Label termination_exception; |
| 4549 | __ b(eq, &termination_exception); |
| 4550 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4551 | __ Throw(subject); // Expects thrown value in r0. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 4552 | |
| 4553 | __ bind(&termination_exception); |
| 4554 | __ ThrowUncatchable(TERMINATION, r0); // Expects thrown value in r0. |
| 4555 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4556 | __ bind(&failure); |
| 4557 | // For failure and exception return null. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4558 | __ mov(r0, Operand(masm->isolate()->factory()->null_value())); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4559 | __ add(sp, sp, Operand(4 * kPointerSize)); |
| 4560 | __ Ret(); |
| 4561 | |
| 4562 | // Process the result from the native regexp code. |
| 4563 | __ bind(&success); |
| 4564 | __ ldr(r1, |
| 4565 | FieldMemOperand(regexp_data, JSRegExp::kIrregexpCaptureCountOffset)); |
| 4566 | // Calculate number of capture registers (number_of_captures + 1) * 2. |
| 4567 | STATIC_ASSERT(kSmiTag == 0); |
| 4568 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 4569 | __ add(r1, r1, Operand(2)); // r1 was a smi. |
| 4570 | |
| 4571 | // r1: number of capture registers |
| 4572 | // r4: subject string |
| 4573 | // Store the capture count. |
| 4574 | __ mov(r2, Operand(r1, LSL, kSmiTagSize + kSmiShiftSize)); // To smi. |
| 4575 | __ str(r2, FieldMemOperand(last_match_info_elements, |
| 4576 | RegExpImpl::kLastCaptureCountOffset)); |
| 4577 | // Store last subject and last input. |
| 4578 | __ mov(r3, last_match_info_elements); // Moved up to reduce latency. |
| 4579 | __ str(subject, |
| 4580 | FieldMemOperand(last_match_info_elements, |
| 4581 | RegExpImpl::kLastSubjectOffset)); |
| 4582 | __ RecordWrite(r3, Operand(RegExpImpl::kLastSubjectOffset), r2, r7); |
| 4583 | __ str(subject, |
| 4584 | FieldMemOperand(last_match_info_elements, |
| 4585 | RegExpImpl::kLastInputOffset)); |
| 4586 | __ mov(r3, last_match_info_elements); |
| 4587 | __ RecordWrite(r3, Operand(RegExpImpl::kLastInputOffset), r2, r7); |
| 4588 | |
| 4589 | // Get the static offsets vector filled by the native regexp code. |
| 4590 | ExternalReference address_of_static_offsets_vector = |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4591 | ExternalReference::address_of_static_offsets_vector(isolate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4592 | __ mov(r2, Operand(address_of_static_offsets_vector)); |
| 4593 | |
| 4594 | // r1: number of capture registers |
| 4595 | // r2: offsets vector |
| 4596 | Label next_capture, done; |
| 4597 | // Capture register counter starts from number of capture registers and |
| 4598 | // counts down until wraping after zero. |
| 4599 | __ add(r0, |
| 4600 | last_match_info_elements, |
| 4601 | Operand(RegExpImpl::kFirstCaptureOffset - kHeapObjectTag)); |
| 4602 | __ bind(&next_capture); |
| 4603 | __ sub(r1, r1, Operand(1), SetCC); |
| 4604 | __ b(mi, &done); |
| 4605 | // Read the value from the static offsets vector buffer. |
| 4606 | __ ldr(r3, MemOperand(r2, kPointerSize, PostIndex)); |
| 4607 | // Store the smi value in the last match info. |
| 4608 | __ mov(r3, Operand(r3, LSL, kSmiTagSize)); |
| 4609 | __ str(r3, MemOperand(r0, kPointerSize, PostIndex)); |
| 4610 | __ jmp(&next_capture); |
| 4611 | __ bind(&done); |
| 4612 | |
| 4613 | // Return last match info. |
| 4614 | __ ldr(r0, MemOperand(sp, kLastMatchInfoOffset)); |
| 4615 | __ add(sp, sp, Operand(4 * kPointerSize)); |
| 4616 | __ Ret(); |
| 4617 | |
| 4618 | // Do the runtime call to execute the regexp. |
| 4619 | __ bind(&runtime); |
| 4620 | __ TailCallRuntime(Runtime::kRegExpExec, 4, 1); |
| 4621 | #endif // V8_INTERPRETED_REGEXP |
| 4622 | } |
| 4623 | |
| 4624 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4625 | void RegExpConstructResultStub::Generate(MacroAssembler* masm) { |
| 4626 | const int kMaxInlineLength = 100; |
| 4627 | Label slowcase; |
| 4628 | Label done; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4629 | Factory* factory = masm->isolate()->factory(); |
| 4630 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4631 | __ ldr(r1, MemOperand(sp, kPointerSize * 2)); |
| 4632 | STATIC_ASSERT(kSmiTag == 0); |
| 4633 | STATIC_ASSERT(kSmiTagSize == 1); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4634 | __ JumpIfNotSmi(r1, &slowcase); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4635 | __ cmp(r1, Operand(Smi::FromInt(kMaxInlineLength))); |
| 4636 | __ b(hi, &slowcase); |
| 4637 | // Smi-tagging is equivalent to multiplying by 2. |
| 4638 | // Allocate RegExpResult followed by FixedArray with size in ebx. |
| 4639 | // JSArray: [Map][empty properties][Elements][Length-smi][index][input] |
| 4640 | // Elements: [Map][Length][..elements..] |
| 4641 | // Size of JSArray with two in-object properties and the header of a |
| 4642 | // FixedArray. |
| 4643 | int objects_size = |
| 4644 | (JSRegExpResult::kSize + FixedArray::kHeaderSize) / kPointerSize; |
| 4645 | __ mov(r5, Operand(r1, LSR, kSmiTagSize + kSmiShiftSize)); |
| 4646 | __ add(r2, r5, Operand(objects_size)); |
| 4647 | __ AllocateInNewSpace( |
| 4648 | r2, // In: Size, in words. |
| 4649 | r0, // Out: Start of allocation (tagged). |
| 4650 | r3, // Scratch register. |
| 4651 | r4, // Scratch register. |
| 4652 | &slowcase, |
| 4653 | static_cast<AllocationFlags>(TAG_OBJECT | SIZE_IN_WORDS)); |
| 4654 | // r0: Start of allocated area, object-tagged. |
| 4655 | // r1: Number of elements in array, as smi. |
| 4656 | // r5: Number of elements, untagged. |
| 4657 | |
| 4658 | // Set JSArray map to global.regexp_result_map(). |
| 4659 | // Set empty properties FixedArray. |
| 4660 | // Set elements to point to FixedArray allocated right after the JSArray. |
| 4661 | // Interleave operations for better latency. |
| 4662 | __ ldr(r2, ContextOperand(cp, Context::GLOBAL_INDEX)); |
| 4663 | __ add(r3, r0, Operand(JSRegExpResult::kSize)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4664 | __ mov(r4, Operand(factory->empty_fixed_array())); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4665 | __ ldr(r2, FieldMemOperand(r2, GlobalObject::kGlobalContextOffset)); |
| 4666 | __ str(r3, FieldMemOperand(r0, JSObject::kElementsOffset)); |
| 4667 | __ ldr(r2, ContextOperand(r2, Context::REGEXP_RESULT_MAP_INDEX)); |
| 4668 | __ str(r4, FieldMemOperand(r0, JSObject::kPropertiesOffset)); |
| 4669 | __ str(r2, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 4670 | |
| 4671 | // Set input, index and length fields from arguments. |
| 4672 | __ ldr(r1, MemOperand(sp, kPointerSize * 0)); |
| 4673 | __ str(r1, FieldMemOperand(r0, JSRegExpResult::kInputOffset)); |
| 4674 | __ ldr(r1, MemOperand(sp, kPointerSize * 1)); |
| 4675 | __ str(r1, FieldMemOperand(r0, JSRegExpResult::kIndexOffset)); |
| 4676 | __ ldr(r1, MemOperand(sp, kPointerSize * 2)); |
| 4677 | __ str(r1, FieldMemOperand(r0, JSArray::kLengthOffset)); |
| 4678 | |
| 4679 | // Fill out the elements FixedArray. |
| 4680 | // r0: JSArray, tagged. |
| 4681 | // r3: FixedArray, tagged. |
| 4682 | // r5: Number of elements in array, untagged. |
| 4683 | |
| 4684 | // Set map. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4685 | __ mov(r2, Operand(factory->fixed_array_map())); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4686 | __ str(r2, FieldMemOperand(r3, HeapObject::kMapOffset)); |
| 4687 | // Set FixedArray length. |
| 4688 | __ mov(r6, Operand(r5, LSL, kSmiTagSize)); |
| 4689 | __ str(r6, FieldMemOperand(r3, FixedArray::kLengthOffset)); |
| 4690 | // Fill contents of fixed-array with the-hole. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4691 | __ mov(r2, Operand(factory->the_hole_value())); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 4692 | __ add(r3, r3, Operand(FixedArray::kHeaderSize - kHeapObjectTag)); |
| 4693 | // Fill fixed array elements with hole. |
| 4694 | // r0: JSArray, tagged. |
| 4695 | // r2: the hole. |
| 4696 | // r3: Start of elements in FixedArray. |
| 4697 | // r5: Number of elements to fill. |
| 4698 | Label loop; |
| 4699 | __ tst(r5, Operand(r5)); |
| 4700 | __ bind(&loop); |
| 4701 | __ b(le, &done); // Jump if r1 is negative or zero. |
| 4702 | __ sub(r5, r5, Operand(1), SetCC); |
| 4703 | __ str(r2, MemOperand(r3, r5, LSL, kPointerSizeLog2)); |
| 4704 | __ jmp(&loop); |
| 4705 | |
| 4706 | __ bind(&done); |
| 4707 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 4708 | __ Ret(); |
| 4709 | |
| 4710 | __ bind(&slowcase); |
| 4711 | __ TailCallRuntime(Runtime::kRegExpConstructResult, 3, 1); |
| 4712 | } |
| 4713 | |
| 4714 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4715 | void CallFunctionStub::Generate(MacroAssembler* masm) { |
| 4716 | Label slow; |
| 4717 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4718 | // The receiver might implicitly be the global object. This is |
| 4719 | // indicated by passing the hole as the receiver to the call |
| 4720 | // function stub. |
| 4721 | if (ReceiverMightBeImplicit()) { |
| 4722 | Label call; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4723 | // Get the receiver from the stack. |
| 4724 | // function, receiver [, arguments] |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4725 | __ ldr(r4, MemOperand(sp, argc_ * kPointerSize)); |
| 4726 | // Call as function is indicated with the hole. |
| 4727 | __ CompareRoot(r4, Heap::kTheHoleValueRootIndex); |
| 4728 | __ b(ne, &call); |
| 4729 | // Patch the receiver on the stack with the global receiver object. |
| 4730 | __ ldr(r1, MemOperand(cp, Context::SlotOffset(Context::GLOBAL_INDEX))); |
| 4731 | __ ldr(r1, FieldMemOperand(r1, GlobalObject::kGlobalReceiverOffset)); |
| 4732 | __ str(r1, MemOperand(sp, argc_ * kPointerSize)); |
| 4733 | __ bind(&call); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4734 | } |
| 4735 | |
| 4736 | // Get the function to call from the stack. |
| 4737 | // function, receiver [, arguments] |
| 4738 | __ ldr(r1, MemOperand(sp, (argc_ + 1) * kPointerSize)); |
| 4739 | |
| 4740 | // Check that the function is really a JavaScript function. |
| 4741 | // r1: pushed function (to be verified) |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4742 | __ JumpIfSmi(r1, &slow); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4743 | // Get the map of the function object. |
| 4744 | __ CompareObjectType(r1, r2, r2, JS_FUNCTION_TYPE); |
| 4745 | __ b(ne, &slow); |
| 4746 | |
| 4747 | // Fast-case: Invoke the function now. |
| 4748 | // r1: pushed function |
| 4749 | ParameterCount actual(argc_); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4750 | |
| 4751 | if (ReceiverMightBeImplicit()) { |
| 4752 | Label call_as_function; |
| 4753 | __ CompareRoot(r4, Heap::kTheHoleValueRootIndex); |
| 4754 | __ b(eq, &call_as_function); |
| 4755 | __ InvokeFunction(r1, |
| 4756 | actual, |
| 4757 | JUMP_FUNCTION, |
| 4758 | NullCallWrapper(), |
| 4759 | CALL_AS_METHOD); |
| 4760 | __ bind(&call_as_function); |
| 4761 | } |
| 4762 | __ InvokeFunction(r1, |
| 4763 | actual, |
| 4764 | JUMP_FUNCTION, |
| 4765 | NullCallWrapper(), |
| 4766 | CALL_AS_FUNCTION); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4767 | |
| 4768 | // Slow-case: Non-function called. |
| 4769 | __ bind(&slow); |
| 4770 | // CALL_NON_FUNCTION expects the non-function callee as receiver (instead |
| 4771 | // of the original receiver from the call site). |
| 4772 | __ str(r1, MemOperand(sp, argc_ * kPointerSize)); |
| 4773 | __ mov(r0, Operand(argc_)); // Setup the number of arguments. |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 4774 | __ mov(r2, Operand(0, RelocInfo::NONE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4775 | __ GetBuiltinEntry(r3, Builtins::CALL_NON_FUNCTION); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4776 | __ SetCallKind(r5, CALL_AS_METHOD); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4777 | __ Jump(masm->isolate()->builtins()->ArgumentsAdaptorTrampoline(), |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4778 | RelocInfo::CODE_TARGET); |
| 4779 | } |
| 4780 | |
| 4781 | |
| 4782 | // Unfortunately you have to run without snapshots to see most of these |
| 4783 | // names in the profile since most compare stubs end up in the snapshot. |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4784 | void CompareStub::PrintName(StringStream* stream) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4785 | ASSERT((lhs_.is(r0) && rhs_.is(r1)) || |
| 4786 | (lhs_.is(r1) && rhs_.is(r0))); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4787 | const char* cc_name; |
| 4788 | switch (cc_) { |
| 4789 | case lt: cc_name = "LT"; break; |
| 4790 | case gt: cc_name = "GT"; break; |
| 4791 | case le: cc_name = "LE"; break; |
| 4792 | case ge: cc_name = "GE"; break; |
| 4793 | case eq: cc_name = "EQ"; break; |
| 4794 | case ne: cc_name = "NE"; break; |
| 4795 | default: cc_name = "UnknownCondition"; break; |
| 4796 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 4797 | bool is_equality = cc_ == eq || cc_ == ne; |
| 4798 | stream->Add("CompareStub_%s", cc_name); |
| 4799 | stream->Add(lhs_.is(r0) ? "_r0" : "_r1"); |
| 4800 | stream->Add(rhs_.is(r0) ? "_r0" : "_r1"); |
| 4801 | if (strict_ && is_equality) stream->Add("_STRICT"); |
| 4802 | if (never_nan_nan_ && is_equality) stream->Add("_NO_NAN"); |
| 4803 | if (!include_number_compare_) stream->Add("_NO_NUMBER"); |
| 4804 | if (!include_smi_compare_) stream->Add("_NO_SMI"); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4805 | } |
| 4806 | |
| 4807 | |
| 4808 | int CompareStub::MinorKey() { |
| 4809 | // Encode the three parameters in a unique 16 bit value. To avoid duplicate |
| 4810 | // stubs the never NaN NaN condition is only taken into account if the |
| 4811 | // condition is equals. |
| 4812 | ASSERT((static_cast<unsigned>(cc_) >> 28) < (1 << 12)); |
| 4813 | ASSERT((lhs_.is(r0) && rhs_.is(r1)) || |
| 4814 | (lhs_.is(r1) && rhs_.is(r0))); |
| 4815 | return ConditionField::encode(static_cast<unsigned>(cc_) >> 28) |
| 4816 | | RegisterField::encode(lhs_.is(r0)) |
| 4817 | | StrictField::encode(strict_) |
| 4818 | | NeverNanNanField::encode(cc_ == eq ? never_nan_nan_ : false) |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 4819 | | IncludeNumberCompareField::encode(include_number_compare_) |
| 4820 | | IncludeSmiCompareField::encode(include_smi_compare_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4821 | } |
| 4822 | |
| 4823 | |
| 4824 | // StringCharCodeAtGenerator |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4825 | void StringCharCodeAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 4826 | Label flat_string; |
| 4827 | Label ascii_string; |
| 4828 | Label got_char_code; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4829 | Label sliced_string; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4830 | |
| 4831 | // If the receiver is a smi trigger the non-string case. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4832 | __ JumpIfSmi(object_, receiver_not_string_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4833 | |
| 4834 | // Fetch the instance type of the receiver into result register. |
| 4835 | __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 4836 | __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 4837 | // If the receiver is not a string trigger the non-string case. |
| 4838 | __ tst(result_, Operand(kIsNotStringMask)); |
| 4839 | __ b(ne, receiver_not_string_); |
| 4840 | |
| 4841 | // If the index is non-smi trigger the non-smi case. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4842 | __ JumpIfNotSmi(index_, &index_not_smi_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4843 | |
| 4844 | // Put smi-tagged index into scratch register. |
| 4845 | __ mov(scratch_, index_); |
| 4846 | __ bind(&got_smi_index_); |
| 4847 | |
| 4848 | // Check for index out of range. |
| 4849 | __ ldr(ip, FieldMemOperand(object_, String::kLengthOffset)); |
| 4850 | __ cmp(ip, Operand(scratch_)); |
| 4851 | __ b(ls, index_out_of_range_); |
| 4852 | |
| 4853 | // We need special handling for non-flat strings. |
| 4854 | STATIC_ASSERT(kSeqStringTag == 0); |
| 4855 | __ tst(result_, Operand(kStringRepresentationMask)); |
| 4856 | __ b(eq, &flat_string); |
| 4857 | |
| 4858 | // Handle non-flat strings. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4859 | __ and_(result_, result_, Operand(kStringRepresentationMask)); |
| 4860 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 4861 | STATIC_ASSERT(kSlicedStringTag > kExternalStringTag); |
| 4862 | __ cmp(result_, Operand(kExternalStringTag)); |
| 4863 | __ b(gt, &sliced_string); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4864 | __ b(eq, &call_runtime_); |
| 4865 | |
| 4866 | // ConsString. |
| 4867 | // Check whether the right hand side is the empty string (i.e. if |
| 4868 | // this is really a flat string in a cons string). If that is not |
| 4869 | // the case we would rather go to the runtime system now to flatten |
| 4870 | // the string. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4871 | Label assure_seq_string; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4872 | __ ldr(result_, FieldMemOperand(object_, ConsString::kSecondOffset)); |
| 4873 | __ LoadRoot(ip, Heap::kEmptyStringRootIndex); |
| 4874 | __ cmp(result_, Operand(ip)); |
| 4875 | __ b(ne, &call_runtime_); |
| 4876 | // Get the first of the two strings and load its instance type. |
| 4877 | __ ldr(object_, FieldMemOperand(object_, ConsString::kFirstOffset)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4878 | __ jmp(&assure_seq_string); |
| 4879 | |
| 4880 | // SlicedString, unpack and add offset. |
| 4881 | __ bind(&sliced_string); |
| 4882 | __ ldr(result_, FieldMemOperand(object_, SlicedString::kOffsetOffset)); |
| 4883 | __ add(scratch_, scratch_, result_); |
| 4884 | __ ldr(object_, FieldMemOperand(object_, SlicedString::kParentOffset)); |
| 4885 | |
| 4886 | // Assure that we are dealing with a sequential string. Go to runtime if not. |
| 4887 | __ bind(&assure_seq_string); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4888 | __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 4889 | __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 4890 | // Check that parent is not an external string. Go to runtime otherwise. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4891 | STATIC_ASSERT(kSeqStringTag == 0); |
| 4892 | __ tst(result_, Operand(kStringRepresentationMask)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4893 | __ b(ne, &call_runtime_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4894 | |
| 4895 | // Check for 1-byte or 2-byte string. |
| 4896 | __ bind(&flat_string); |
| 4897 | STATIC_ASSERT(kAsciiStringTag != 0); |
| 4898 | __ tst(result_, Operand(kStringEncodingMask)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4899 | __ b(ne, &ascii_string); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4900 | |
| 4901 | // 2-byte string. |
| 4902 | // Load the 2-byte character code into the result register. We can |
| 4903 | // add without shifting since the smi tag size is the log2 of the |
| 4904 | // number of bytes in a two-byte character. |
| 4905 | STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize == 1 && kSmiShiftSize == 0); |
| 4906 | __ add(scratch_, object_, Operand(scratch_)); |
| 4907 | __ ldrh(result_, FieldMemOperand(scratch_, SeqTwoByteString::kHeaderSize)); |
| 4908 | __ jmp(&got_char_code); |
| 4909 | |
| 4910 | // ASCII string. |
| 4911 | // Load the byte into the result register. |
| 4912 | __ bind(&ascii_string); |
| 4913 | __ add(scratch_, object_, Operand(scratch_, LSR, kSmiTagSize)); |
| 4914 | __ ldrb(result_, FieldMemOperand(scratch_, SeqAsciiString::kHeaderSize)); |
| 4915 | |
| 4916 | __ bind(&got_char_code); |
| 4917 | __ mov(result_, Operand(result_, LSL, kSmiTagSize)); |
| 4918 | __ bind(&exit_); |
| 4919 | } |
| 4920 | |
| 4921 | |
| 4922 | void StringCharCodeAtGenerator::GenerateSlow( |
| 4923 | MacroAssembler* masm, const RuntimeCallHelper& call_helper) { |
| 4924 | __ Abort("Unexpected fallthrough to CharCodeAt slow case"); |
| 4925 | |
| 4926 | // Index is not a smi. |
| 4927 | __ bind(&index_not_smi_); |
| 4928 | // If index is a heap number, try converting it to an integer. |
| 4929 | __ CheckMap(index_, |
| 4930 | scratch_, |
| 4931 | Heap::kHeapNumberMapRootIndex, |
| 4932 | index_not_number_, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 4933 | DONT_DO_SMI_CHECK); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4934 | call_helper.BeforeCall(masm); |
| 4935 | __ Push(object_, index_); |
| 4936 | __ push(index_); // Consumed by runtime conversion function. |
| 4937 | if (index_flags_ == STRING_INDEX_IS_NUMBER) { |
| 4938 | __ CallRuntime(Runtime::kNumberToIntegerMapMinusZero, 1); |
| 4939 | } else { |
| 4940 | ASSERT(index_flags_ == STRING_INDEX_IS_ARRAY_INDEX); |
| 4941 | // NumberToSmi discards numbers that are not exact integers. |
| 4942 | __ CallRuntime(Runtime::kNumberToSmi, 1); |
| 4943 | } |
| 4944 | // Save the conversion result before the pop instructions below |
| 4945 | // have a chance to overwrite it. |
| 4946 | __ Move(scratch_, r0); |
| 4947 | __ pop(index_); |
| 4948 | __ pop(object_); |
| 4949 | // Reload the instance type. |
| 4950 | __ ldr(result_, FieldMemOperand(object_, HeapObject::kMapOffset)); |
| 4951 | __ ldrb(result_, FieldMemOperand(result_, Map::kInstanceTypeOffset)); |
| 4952 | call_helper.AfterCall(masm); |
| 4953 | // If index is still not a smi, it must be out of range. |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4954 | __ JumpIfNotSmi(scratch_, index_out_of_range_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4955 | // Otherwise, return to the fast path. |
| 4956 | __ jmp(&got_smi_index_); |
| 4957 | |
| 4958 | // Call runtime. We get here when the receiver is a string and the |
| 4959 | // index is a number, but the code of getting the actual character |
| 4960 | // is too complex (e.g., when the string needs to be flattened). |
| 4961 | __ bind(&call_runtime_); |
| 4962 | call_helper.BeforeCall(masm); |
| 4963 | __ Push(object_, index_); |
| 4964 | __ CallRuntime(Runtime::kStringCharCodeAt, 2); |
| 4965 | __ Move(result_, r0); |
| 4966 | call_helper.AfterCall(masm); |
| 4967 | __ jmp(&exit_); |
| 4968 | |
| 4969 | __ Abort("Unexpected fallthrough from CharCodeAt slow case"); |
| 4970 | } |
| 4971 | |
| 4972 | |
| 4973 | // ------------------------------------------------------------------------- |
| 4974 | // StringCharFromCodeGenerator |
| 4975 | |
| 4976 | void StringCharFromCodeGenerator::GenerateFast(MacroAssembler* masm) { |
| 4977 | // Fast case of Heap::LookupSingleCharacterStringFromCode. |
| 4978 | STATIC_ASSERT(kSmiTag == 0); |
| 4979 | STATIC_ASSERT(kSmiShiftSize == 0); |
| 4980 | ASSERT(IsPowerOf2(String::kMaxAsciiCharCode + 1)); |
| 4981 | __ tst(code_, |
| 4982 | Operand(kSmiTagMask | |
| 4983 | ((~String::kMaxAsciiCharCode) << kSmiTagSize))); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 4984 | __ b(ne, &slow_case_); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4985 | |
| 4986 | __ LoadRoot(result_, Heap::kSingleCharacterStringCacheRootIndex); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 4987 | // At this point code register contains smi tagged ASCII char code. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 4988 | STATIC_ASSERT(kSmiTag == 0); |
| 4989 | __ add(result_, result_, Operand(code_, LSL, kPointerSizeLog2 - kSmiTagSize)); |
| 4990 | __ ldr(result_, FieldMemOperand(result_, FixedArray::kHeaderSize)); |
| 4991 | __ LoadRoot(ip, Heap::kUndefinedValueRootIndex); |
| 4992 | __ cmp(result_, Operand(ip)); |
| 4993 | __ b(eq, &slow_case_); |
| 4994 | __ bind(&exit_); |
| 4995 | } |
| 4996 | |
| 4997 | |
| 4998 | void StringCharFromCodeGenerator::GenerateSlow( |
| 4999 | MacroAssembler* masm, const RuntimeCallHelper& call_helper) { |
| 5000 | __ Abort("Unexpected fallthrough to CharFromCode slow case"); |
| 5001 | |
| 5002 | __ bind(&slow_case_); |
| 5003 | call_helper.BeforeCall(masm); |
| 5004 | __ push(code_); |
| 5005 | __ CallRuntime(Runtime::kCharFromCode, 1); |
| 5006 | __ Move(result_, r0); |
| 5007 | call_helper.AfterCall(masm); |
| 5008 | __ jmp(&exit_); |
| 5009 | |
| 5010 | __ Abort("Unexpected fallthrough from CharFromCode slow case"); |
| 5011 | } |
| 5012 | |
| 5013 | |
| 5014 | // ------------------------------------------------------------------------- |
| 5015 | // StringCharAtGenerator |
| 5016 | |
| 5017 | void StringCharAtGenerator::GenerateFast(MacroAssembler* masm) { |
| 5018 | char_code_at_generator_.GenerateFast(masm); |
| 5019 | char_from_code_generator_.GenerateFast(masm); |
| 5020 | } |
| 5021 | |
| 5022 | |
| 5023 | void StringCharAtGenerator::GenerateSlow( |
| 5024 | MacroAssembler* masm, const RuntimeCallHelper& call_helper) { |
| 5025 | char_code_at_generator_.GenerateSlow(masm, call_helper); |
| 5026 | char_from_code_generator_.GenerateSlow(masm, call_helper); |
| 5027 | } |
| 5028 | |
| 5029 | |
| 5030 | class StringHelper : public AllStatic { |
| 5031 | public: |
| 5032 | // Generate code for copying characters using a simple loop. This should only |
| 5033 | // be used in places where the number of characters is small and the |
| 5034 | // additional setup and checking in GenerateCopyCharactersLong adds too much |
| 5035 | // overhead. Copying of overlapping regions is not supported. |
| 5036 | // Dest register ends at the position after the last character written. |
| 5037 | static void GenerateCopyCharacters(MacroAssembler* masm, |
| 5038 | Register dest, |
| 5039 | Register src, |
| 5040 | Register count, |
| 5041 | Register scratch, |
| 5042 | bool ascii); |
| 5043 | |
| 5044 | // Generate code for copying a large number of characters. This function |
| 5045 | // is allowed to spend extra time setting up conditions to make copying |
| 5046 | // faster. Copying of overlapping regions is not supported. |
| 5047 | // Dest register ends at the position after the last character written. |
| 5048 | static void GenerateCopyCharactersLong(MacroAssembler* masm, |
| 5049 | Register dest, |
| 5050 | Register src, |
| 5051 | Register count, |
| 5052 | Register scratch1, |
| 5053 | Register scratch2, |
| 5054 | Register scratch3, |
| 5055 | Register scratch4, |
| 5056 | Register scratch5, |
| 5057 | int flags); |
| 5058 | |
| 5059 | |
| 5060 | // Probe the symbol table for a two character string. If the string is |
| 5061 | // not found by probing a jump to the label not_found is performed. This jump |
| 5062 | // does not guarantee that the string is not in the symbol table. If the |
| 5063 | // string is found the code falls through with the string in register r0. |
| 5064 | // Contents of both c1 and c2 registers are modified. At the exit c1 is |
| 5065 | // guaranteed to contain halfword with low and high bytes equal to |
| 5066 | // initial contents of c1 and c2 respectively. |
| 5067 | static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 5068 | Register c1, |
| 5069 | Register c2, |
| 5070 | Register scratch1, |
| 5071 | Register scratch2, |
| 5072 | Register scratch3, |
| 5073 | Register scratch4, |
| 5074 | Register scratch5, |
| 5075 | Label* not_found); |
| 5076 | |
| 5077 | // Generate string hash. |
| 5078 | static void GenerateHashInit(MacroAssembler* masm, |
| 5079 | Register hash, |
| 5080 | Register character); |
| 5081 | |
| 5082 | static void GenerateHashAddCharacter(MacroAssembler* masm, |
| 5083 | Register hash, |
| 5084 | Register character); |
| 5085 | |
| 5086 | static void GenerateHashGetHash(MacroAssembler* masm, |
| 5087 | Register hash); |
| 5088 | |
| 5089 | private: |
| 5090 | DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper); |
| 5091 | }; |
| 5092 | |
| 5093 | |
| 5094 | void StringHelper::GenerateCopyCharacters(MacroAssembler* masm, |
| 5095 | Register dest, |
| 5096 | Register src, |
| 5097 | Register count, |
| 5098 | Register scratch, |
| 5099 | bool ascii) { |
| 5100 | Label loop; |
| 5101 | Label done; |
| 5102 | // This loop just copies one character at a time, as it is only used for very |
| 5103 | // short strings. |
| 5104 | if (!ascii) { |
| 5105 | __ add(count, count, Operand(count), SetCC); |
| 5106 | } else { |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 5107 | __ cmp(count, Operand(0, RelocInfo::NONE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5108 | } |
| 5109 | __ b(eq, &done); |
| 5110 | |
| 5111 | __ bind(&loop); |
| 5112 | __ ldrb(scratch, MemOperand(src, 1, PostIndex)); |
| 5113 | // Perform sub between load and dependent store to get the load time to |
| 5114 | // complete. |
| 5115 | __ sub(count, count, Operand(1), SetCC); |
| 5116 | __ strb(scratch, MemOperand(dest, 1, PostIndex)); |
| 5117 | // last iteration. |
| 5118 | __ b(gt, &loop); |
| 5119 | |
| 5120 | __ bind(&done); |
| 5121 | } |
| 5122 | |
| 5123 | |
| 5124 | enum CopyCharactersFlags { |
| 5125 | COPY_ASCII = 1, |
| 5126 | DEST_ALWAYS_ALIGNED = 2 |
| 5127 | }; |
| 5128 | |
| 5129 | |
| 5130 | void StringHelper::GenerateCopyCharactersLong(MacroAssembler* masm, |
| 5131 | Register dest, |
| 5132 | Register src, |
| 5133 | Register count, |
| 5134 | Register scratch1, |
| 5135 | Register scratch2, |
| 5136 | Register scratch3, |
| 5137 | Register scratch4, |
| 5138 | Register scratch5, |
| 5139 | int flags) { |
| 5140 | bool ascii = (flags & COPY_ASCII) != 0; |
| 5141 | bool dest_always_aligned = (flags & DEST_ALWAYS_ALIGNED) != 0; |
| 5142 | |
| 5143 | if (dest_always_aligned && FLAG_debug_code) { |
| 5144 | // Check that destination is actually word aligned if the flag says |
| 5145 | // that it is. |
| 5146 | __ tst(dest, Operand(kPointerAlignmentMask)); |
| 5147 | __ Check(eq, "Destination of copy not aligned."); |
| 5148 | } |
| 5149 | |
| 5150 | const int kReadAlignment = 4; |
| 5151 | const int kReadAlignmentMask = kReadAlignment - 1; |
| 5152 | // Ensure that reading an entire aligned word containing the last character |
| 5153 | // of a string will not read outside the allocated area (because we pad up |
| 5154 | // to kObjectAlignment). |
| 5155 | STATIC_ASSERT(kObjectAlignment >= kReadAlignment); |
| 5156 | // Assumes word reads and writes are little endian. |
| 5157 | // Nothing to do for zero characters. |
| 5158 | Label done; |
| 5159 | if (!ascii) { |
| 5160 | __ add(count, count, Operand(count), SetCC); |
| 5161 | } else { |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 5162 | __ cmp(count, Operand(0, RelocInfo::NONE)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5163 | } |
| 5164 | __ b(eq, &done); |
| 5165 | |
| 5166 | // Assume that you cannot read (or write) unaligned. |
| 5167 | Label byte_loop; |
| 5168 | // Must copy at least eight bytes, otherwise just do it one byte at a time. |
| 5169 | __ cmp(count, Operand(8)); |
| 5170 | __ add(count, dest, Operand(count)); |
| 5171 | Register limit = count; // Read until src equals this. |
| 5172 | __ b(lt, &byte_loop); |
| 5173 | |
| 5174 | if (!dest_always_aligned) { |
| 5175 | // Align dest by byte copying. Copies between zero and three bytes. |
| 5176 | __ and_(scratch4, dest, Operand(kReadAlignmentMask), SetCC); |
| 5177 | Label dest_aligned; |
| 5178 | __ b(eq, &dest_aligned); |
| 5179 | __ cmp(scratch4, Operand(2)); |
| 5180 | __ ldrb(scratch1, MemOperand(src, 1, PostIndex)); |
| 5181 | __ ldrb(scratch2, MemOperand(src, 1, PostIndex), le); |
| 5182 | __ ldrb(scratch3, MemOperand(src, 1, PostIndex), lt); |
| 5183 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 5184 | __ strb(scratch2, MemOperand(dest, 1, PostIndex), le); |
| 5185 | __ strb(scratch3, MemOperand(dest, 1, PostIndex), lt); |
| 5186 | __ bind(&dest_aligned); |
| 5187 | } |
| 5188 | |
| 5189 | Label simple_loop; |
| 5190 | |
| 5191 | __ sub(scratch4, dest, Operand(src)); |
| 5192 | __ and_(scratch4, scratch4, Operand(0x03), SetCC); |
| 5193 | __ b(eq, &simple_loop); |
| 5194 | // Shift register is number of bits in a source word that |
| 5195 | // must be combined with bits in the next source word in order |
| 5196 | // to create a destination word. |
| 5197 | |
| 5198 | // Complex loop for src/dst that are not aligned the same way. |
| 5199 | { |
| 5200 | Label loop; |
| 5201 | __ mov(scratch4, Operand(scratch4, LSL, 3)); |
| 5202 | Register left_shift = scratch4; |
| 5203 | __ and_(src, src, Operand(~3)); // Round down to load previous word. |
| 5204 | __ ldr(scratch1, MemOperand(src, 4, PostIndex)); |
| 5205 | // Store the "shift" most significant bits of scratch in the least |
| 5206 | // signficant bits (i.e., shift down by (32-shift)). |
| 5207 | __ rsb(scratch2, left_shift, Operand(32)); |
| 5208 | Register right_shift = scratch2; |
| 5209 | __ mov(scratch1, Operand(scratch1, LSR, right_shift)); |
| 5210 | |
| 5211 | __ bind(&loop); |
| 5212 | __ ldr(scratch3, MemOperand(src, 4, PostIndex)); |
| 5213 | __ sub(scratch5, limit, Operand(dest)); |
| 5214 | __ orr(scratch1, scratch1, Operand(scratch3, LSL, left_shift)); |
| 5215 | __ str(scratch1, MemOperand(dest, 4, PostIndex)); |
| 5216 | __ mov(scratch1, Operand(scratch3, LSR, right_shift)); |
| 5217 | // Loop if four or more bytes left to copy. |
| 5218 | // Compare to eight, because we did the subtract before increasing dst. |
| 5219 | __ sub(scratch5, scratch5, Operand(8), SetCC); |
| 5220 | __ b(ge, &loop); |
| 5221 | } |
| 5222 | // There is now between zero and three bytes left to copy (negative that |
| 5223 | // number is in scratch5), and between one and three bytes already read into |
| 5224 | // scratch1 (eight times that number in scratch4). We may have read past |
| 5225 | // the end of the string, but because objects are aligned, we have not read |
| 5226 | // past the end of the object. |
| 5227 | // Find the minimum of remaining characters to move and preloaded characters |
| 5228 | // and write those as bytes. |
| 5229 | __ add(scratch5, scratch5, Operand(4), SetCC); |
| 5230 | __ b(eq, &done); |
| 5231 | __ cmp(scratch4, Operand(scratch5, LSL, 3), ne); |
| 5232 | // Move minimum of bytes read and bytes left to copy to scratch4. |
| 5233 | __ mov(scratch5, Operand(scratch4, LSR, 3), LeaveCC, lt); |
| 5234 | // Between one and three (value in scratch5) characters already read into |
| 5235 | // scratch ready to write. |
| 5236 | __ cmp(scratch5, Operand(2)); |
| 5237 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 5238 | __ mov(scratch1, Operand(scratch1, LSR, 8), LeaveCC, ge); |
| 5239 | __ strb(scratch1, MemOperand(dest, 1, PostIndex), ge); |
| 5240 | __ mov(scratch1, Operand(scratch1, LSR, 8), LeaveCC, gt); |
| 5241 | __ strb(scratch1, MemOperand(dest, 1, PostIndex), gt); |
| 5242 | // Copy any remaining bytes. |
| 5243 | __ b(&byte_loop); |
| 5244 | |
| 5245 | // Simple loop. |
| 5246 | // Copy words from src to dst, until less than four bytes left. |
| 5247 | // Both src and dest are word aligned. |
| 5248 | __ bind(&simple_loop); |
| 5249 | { |
| 5250 | Label loop; |
| 5251 | __ bind(&loop); |
| 5252 | __ ldr(scratch1, MemOperand(src, 4, PostIndex)); |
| 5253 | __ sub(scratch3, limit, Operand(dest)); |
| 5254 | __ str(scratch1, MemOperand(dest, 4, PostIndex)); |
| 5255 | // Compare to 8, not 4, because we do the substraction before increasing |
| 5256 | // dest. |
| 5257 | __ cmp(scratch3, Operand(8)); |
| 5258 | __ b(ge, &loop); |
| 5259 | } |
| 5260 | |
| 5261 | // Copy bytes from src to dst until dst hits limit. |
| 5262 | __ bind(&byte_loop); |
| 5263 | __ cmp(dest, Operand(limit)); |
| 5264 | __ ldrb(scratch1, MemOperand(src, 1, PostIndex), lt); |
| 5265 | __ b(ge, &done); |
| 5266 | __ strb(scratch1, MemOperand(dest, 1, PostIndex)); |
| 5267 | __ b(&byte_loop); |
| 5268 | |
| 5269 | __ bind(&done); |
| 5270 | } |
| 5271 | |
| 5272 | |
| 5273 | void StringHelper::GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 5274 | Register c1, |
| 5275 | Register c2, |
| 5276 | Register scratch1, |
| 5277 | Register scratch2, |
| 5278 | Register scratch3, |
| 5279 | Register scratch4, |
| 5280 | Register scratch5, |
| 5281 | Label* not_found) { |
| 5282 | // Register scratch3 is the general scratch register in this function. |
| 5283 | Register scratch = scratch3; |
| 5284 | |
| 5285 | // Make sure that both characters are not digits as such strings has a |
| 5286 | // different hash algorithm. Don't try to look for these in the symbol table. |
| 5287 | Label not_array_index; |
| 5288 | __ sub(scratch, c1, Operand(static_cast<int>('0'))); |
| 5289 | __ cmp(scratch, Operand(static_cast<int>('9' - '0'))); |
| 5290 | __ b(hi, ¬_array_index); |
| 5291 | __ sub(scratch, c2, Operand(static_cast<int>('0'))); |
| 5292 | __ cmp(scratch, Operand(static_cast<int>('9' - '0'))); |
| 5293 | |
| 5294 | // If check failed combine both characters into single halfword. |
| 5295 | // This is required by the contract of the method: code at the |
| 5296 | // not_found branch expects this combination in c1 register |
| 5297 | __ orr(c1, c1, Operand(c2, LSL, kBitsPerByte), LeaveCC, ls); |
| 5298 | __ b(ls, not_found); |
| 5299 | |
| 5300 | __ bind(¬_array_index); |
| 5301 | // Calculate the two character string hash. |
| 5302 | Register hash = scratch1; |
| 5303 | StringHelper::GenerateHashInit(masm, hash, c1); |
| 5304 | StringHelper::GenerateHashAddCharacter(masm, hash, c2); |
| 5305 | StringHelper::GenerateHashGetHash(masm, hash); |
| 5306 | |
| 5307 | // Collect the two characters in a register. |
| 5308 | Register chars = c1; |
| 5309 | __ orr(chars, chars, Operand(c2, LSL, kBitsPerByte)); |
| 5310 | |
| 5311 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5312 | // hash: hash of two character string. |
| 5313 | |
| 5314 | // Load symbol table |
| 5315 | // Load address of first element of the symbol table. |
| 5316 | Register symbol_table = c2; |
| 5317 | __ LoadRoot(symbol_table, Heap::kSymbolTableRootIndex); |
| 5318 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5319 | Register undefined = scratch4; |
| 5320 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 5321 | |
| 5322 | // Calculate capacity mask from the symbol table capacity. |
| 5323 | Register mask = scratch2; |
| 5324 | __ ldr(mask, FieldMemOperand(symbol_table, SymbolTable::kCapacityOffset)); |
| 5325 | __ mov(mask, Operand(mask, ASR, 1)); |
| 5326 | __ sub(mask, mask, Operand(1)); |
| 5327 | |
| 5328 | // Calculate untagged address of the first element of the symbol table. |
| 5329 | Register first_symbol_table_element = symbol_table; |
| 5330 | __ add(first_symbol_table_element, symbol_table, |
| 5331 | Operand(SymbolTable::kElementsStartOffset - kHeapObjectTag)); |
| 5332 | |
| 5333 | // Registers |
| 5334 | // chars: two character string, char 1 in byte 0 and char 2 in byte 1. |
| 5335 | // hash: hash of two character string |
| 5336 | // mask: capacity mask |
| 5337 | // first_symbol_table_element: address of the first element of |
| 5338 | // the symbol table |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5339 | // undefined: the undefined object |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5340 | // scratch: - |
| 5341 | |
| 5342 | // Perform a number of probes in the symbol table. |
| 5343 | static const int kProbes = 4; |
| 5344 | Label found_in_symbol_table; |
| 5345 | Label next_probe[kProbes]; |
| 5346 | for (int i = 0; i < kProbes; i++) { |
| 5347 | Register candidate = scratch5; // Scratch register contains candidate. |
| 5348 | |
| 5349 | // Calculate entry in symbol table. |
| 5350 | if (i > 0) { |
| 5351 | __ add(candidate, hash, Operand(SymbolTable::GetProbeOffset(i))); |
| 5352 | } else { |
| 5353 | __ mov(candidate, hash); |
| 5354 | } |
| 5355 | |
| 5356 | __ and_(candidate, candidate, Operand(mask)); |
| 5357 | |
| 5358 | // Load the entry from the symble table. |
| 5359 | STATIC_ASSERT(SymbolTable::kEntrySize == 1); |
| 5360 | __ ldr(candidate, |
| 5361 | MemOperand(first_symbol_table_element, |
| 5362 | candidate, |
| 5363 | LSL, |
| 5364 | kPointerSizeLog2)); |
| 5365 | |
| 5366 | // If entry is undefined no string with this hash can be found. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5367 | Label is_string; |
| 5368 | __ CompareObjectType(candidate, scratch, scratch, ODDBALL_TYPE); |
| 5369 | __ b(ne, &is_string); |
| 5370 | |
| 5371 | __ cmp(undefined, candidate); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5372 | __ b(eq, not_found); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5373 | // Must be null (deleted entry). |
| 5374 | if (FLAG_debug_code) { |
| 5375 | __ LoadRoot(ip, Heap::kNullValueRootIndex); |
| 5376 | __ cmp(ip, candidate); |
| 5377 | __ Assert(eq, "oddball in symbol table is not undefined or null"); |
| 5378 | } |
| 5379 | __ jmp(&next_probe[i]); |
| 5380 | |
| 5381 | __ bind(&is_string); |
| 5382 | |
| 5383 | // Check that the candidate is a non-external ASCII string. The instance |
| 5384 | // type is still in the scratch register from the CompareObjectType |
| 5385 | // operation. |
| 5386 | __ JumpIfInstanceTypeIsNotSequentialAscii(scratch, scratch, &next_probe[i]); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5387 | |
| 5388 | // If length is not 2 the string is not a candidate. |
| 5389 | __ ldr(scratch, FieldMemOperand(candidate, String::kLengthOffset)); |
| 5390 | __ cmp(scratch, Operand(Smi::FromInt(2))); |
| 5391 | __ b(ne, &next_probe[i]); |
| 5392 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5393 | // Check if the two characters match. |
| 5394 | // Assumes that word load is little endian. |
| 5395 | __ ldrh(scratch, FieldMemOperand(candidate, SeqAsciiString::kHeaderSize)); |
| 5396 | __ cmp(chars, scratch); |
| 5397 | __ b(eq, &found_in_symbol_table); |
| 5398 | __ bind(&next_probe[i]); |
| 5399 | } |
| 5400 | |
| 5401 | // No matching 2 character string found by probing. |
| 5402 | __ jmp(not_found); |
| 5403 | |
| 5404 | // Scratch register contains result when we fall through to here. |
| 5405 | Register result = scratch; |
| 5406 | __ bind(&found_in_symbol_table); |
| 5407 | __ Move(r0, result); |
| 5408 | } |
| 5409 | |
| 5410 | |
| 5411 | void StringHelper::GenerateHashInit(MacroAssembler* masm, |
| 5412 | Register hash, |
| 5413 | Register character) { |
| 5414 | // hash = character + (character << 10); |
| 5415 | __ add(hash, character, Operand(character, LSL, 10)); |
| 5416 | // hash ^= hash >> 6; |
| 5417 | __ eor(hash, hash, Operand(hash, ASR, 6)); |
| 5418 | } |
| 5419 | |
| 5420 | |
| 5421 | void StringHelper::GenerateHashAddCharacter(MacroAssembler* masm, |
| 5422 | Register hash, |
| 5423 | Register character) { |
| 5424 | // hash += character; |
| 5425 | __ add(hash, hash, Operand(character)); |
| 5426 | // hash += hash << 10; |
| 5427 | __ add(hash, hash, Operand(hash, LSL, 10)); |
| 5428 | // hash ^= hash >> 6; |
| 5429 | __ eor(hash, hash, Operand(hash, ASR, 6)); |
| 5430 | } |
| 5431 | |
| 5432 | |
| 5433 | void StringHelper::GenerateHashGetHash(MacroAssembler* masm, |
| 5434 | Register hash) { |
| 5435 | // hash += hash << 3; |
| 5436 | __ add(hash, hash, Operand(hash, LSL, 3)); |
| 5437 | // hash ^= hash >> 11; |
| 5438 | __ eor(hash, hash, Operand(hash, ASR, 11)); |
| 5439 | // hash += hash << 15; |
| 5440 | __ add(hash, hash, Operand(hash, LSL, 15), SetCC); |
| 5441 | |
| 5442 | // if (hash == 0) hash = 27; |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 5443 | __ mov(hash, Operand(27), LeaveCC, ne); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5444 | } |
| 5445 | |
| 5446 | |
| 5447 | void SubStringStub::Generate(MacroAssembler* masm) { |
| 5448 | Label runtime; |
| 5449 | |
| 5450 | // Stack frame on entry. |
| 5451 | // lr: return address |
| 5452 | // sp[0]: to |
| 5453 | // sp[4]: from |
| 5454 | // sp[8]: string |
| 5455 | |
| 5456 | // This stub is called from the native-call %_SubString(...), so |
| 5457 | // nothing can be assumed about the arguments. It is tested that: |
| 5458 | // "string" is a sequential string, |
| 5459 | // both "from" and "to" are smis, and |
| 5460 | // 0 <= from <= to <= string.length. |
| 5461 | // If any of these assumptions fail, we call the runtime system. |
| 5462 | |
| 5463 | static const int kToOffset = 0 * kPointerSize; |
| 5464 | static const int kFromOffset = 1 * kPointerSize; |
| 5465 | static const int kStringOffset = 2 * kPointerSize; |
| 5466 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5467 | // Check bounds and smi-ness. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5468 | Register to = r6; |
| 5469 | Register from = r7; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 5470 | |
| 5471 | if (FLAG_string_slices) { |
| 5472 | __ nop(0); // Jumping as first instruction would crash the code generation. |
| 5473 | __ jmp(&runtime); |
| 5474 | } |
| 5475 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5476 | __ Ldrd(to, from, MemOperand(sp, kToOffset)); |
| 5477 | STATIC_ASSERT(kFromOffset == kToOffset + 4); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5478 | STATIC_ASSERT(kSmiTag == 0); |
| 5479 | STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 5480 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5481 | // I.e., arithmetic shift right by one un-smi-tags. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5482 | __ mov(r2, Operand(to, ASR, 1), SetCC); |
| 5483 | __ mov(r3, Operand(from, ASR, 1), SetCC, cc); |
| 5484 | // If either to or from had the smi tag bit set, then carry is set now. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5485 | __ b(cs, &runtime); // Either "from" or "to" is not a smi. |
| 5486 | __ b(mi, &runtime); // From is negative. |
| 5487 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5488 | // Both to and from are smis. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5489 | __ sub(r2, r2, Operand(r3), SetCC); |
| 5490 | __ b(mi, &runtime); // Fail if from > to. |
| 5491 | // Special handling of sub-strings of length 1 and 2. One character strings |
| 5492 | // are handled in the runtime system (looked up in the single character |
| 5493 | // cache). Two character strings are looked for in the symbol cache. |
| 5494 | __ cmp(r2, Operand(2)); |
| 5495 | __ b(lt, &runtime); |
| 5496 | |
| 5497 | // r2: length |
| 5498 | // r3: from index (untaged smi) |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5499 | // r6 (a.k.a. to): to (smi) |
| 5500 | // r7 (a.k.a. from): from offset (smi) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5501 | |
| 5502 | // Make sure first argument is a sequential (or flat) string. |
| 5503 | __ ldr(r5, MemOperand(sp, kStringOffset)); |
| 5504 | STATIC_ASSERT(kSmiTag == 0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 5505 | __ JumpIfSmi(r5, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5506 | Condition is_string = masm->IsObjectStringType(r5, r1); |
| 5507 | __ b(NegateCondition(is_string), &runtime); |
| 5508 | |
| 5509 | // r1: instance type |
| 5510 | // r2: length |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5511 | // r3: from index (untagged smi) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5512 | // r5: string |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5513 | // r6 (a.k.a. to): to (smi) |
| 5514 | // r7 (a.k.a. from): from offset (smi) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5515 | Label seq_string; |
| 5516 | __ and_(r4, r1, Operand(kStringRepresentationMask)); |
| 5517 | STATIC_ASSERT(kSeqStringTag < kConsStringTag); |
| 5518 | STATIC_ASSERT(kConsStringTag < kExternalStringTag); |
| 5519 | __ cmp(r4, Operand(kConsStringTag)); |
| 5520 | __ b(gt, &runtime); // External strings go to runtime. |
| 5521 | __ b(lt, &seq_string); // Sequential strings are handled directly. |
| 5522 | |
| 5523 | // Cons string. Try to recurse (once) on the first substring. |
| 5524 | // (This adds a little more generality than necessary to handle flattened |
| 5525 | // cons strings, but not much). |
| 5526 | __ ldr(r5, FieldMemOperand(r5, ConsString::kFirstOffset)); |
| 5527 | __ ldr(r4, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 5528 | __ ldrb(r1, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 5529 | __ tst(r1, Operand(kStringRepresentationMask)); |
| 5530 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5531 | __ b(ne, &runtime); // Cons and External strings go to runtime. |
| 5532 | |
| 5533 | // Definitly a sequential string. |
| 5534 | __ bind(&seq_string); |
| 5535 | |
| 5536 | // r1: instance type. |
| 5537 | // r2: length |
| 5538 | // r3: from index (untaged smi) |
| 5539 | // r5: string |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5540 | // r6 (a.k.a. to): to (smi) |
| 5541 | // r7 (a.k.a. from): from offset (smi) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5542 | __ ldr(r4, FieldMemOperand(r5, String::kLengthOffset)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5543 | __ cmp(r4, Operand(to)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5544 | __ b(lt, &runtime); // Fail if to > length. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5545 | to = no_reg; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5546 | |
| 5547 | // r1: instance type. |
| 5548 | // r2: result string length. |
| 5549 | // r3: from index (untaged smi) |
| 5550 | // r5: string. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5551 | // r7 (a.k.a. from): from offset (smi) |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5552 | // Check for flat ASCII string. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5553 | Label non_ascii_flat; |
| 5554 | __ tst(r1, Operand(kStringEncodingMask)); |
| 5555 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5556 | __ b(eq, &non_ascii_flat); |
| 5557 | |
| 5558 | Label result_longer_than_two; |
| 5559 | __ cmp(r2, Operand(2)); |
| 5560 | __ b(gt, &result_longer_than_two); |
| 5561 | |
| 5562 | // Sub string of length 2 requested. |
| 5563 | // Get the two characters forming the sub string. |
| 5564 | __ add(r5, r5, Operand(r3)); |
| 5565 | __ ldrb(r3, FieldMemOperand(r5, SeqAsciiString::kHeaderSize)); |
| 5566 | __ ldrb(r4, FieldMemOperand(r5, SeqAsciiString::kHeaderSize + 1)); |
| 5567 | |
| 5568 | // Try to lookup two character string in symbol table. |
| 5569 | Label make_two_character_string; |
| 5570 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
| 5571 | masm, r3, r4, r1, r5, r6, r7, r9, &make_two_character_string); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5572 | Counters* counters = masm->isolate()->counters(); |
| 5573 | __ IncrementCounter(counters->sub_string_native(), 1, r3, r4); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5574 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 5575 | __ Ret(); |
| 5576 | |
| 5577 | // r2: result string length. |
| 5578 | // r3: two characters combined into halfword in little endian byte order. |
| 5579 | __ bind(&make_two_character_string); |
| 5580 | __ AllocateAsciiString(r0, r2, r4, r5, r9, &runtime); |
| 5581 | __ strh(r3, FieldMemOperand(r0, SeqAsciiString::kHeaderSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5582 | __ IncrementCounter(counters->sub_string_native(), 1, r3, r4); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5583 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 5584 | __ Ret(); |
| 5585 | |
| 5586 | __ bind(&result_longer_than_two); |
| 5587 | |
| 5588 | // Allocate the result. |
| 5589 | __ AllocateAsciiString(r0, r2, r3, r4, r1, &runtime); |
| 5590 | |
| 5591 | // r0: result string. |
| 5592 | // r2: result string length. |
| 5593 | // r5: string. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5594 | // r7 (a.k.a. from): from offset (smi) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5595 | // Locate first character of result. |
| 5596 | __ add(r1, r0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 5597 | // Locate 'from' character of string. |
| 5598 | __ add(r5, r5, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5599 | __ add(r5, r5, Operand(from, ASR, 1)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5600 | |
| 5601 | // r0: result string. |
| 5602 | // r1: first character of result string. |
| 5603 | // r2: result string length. |
| 5604 | // r5: first character of sub string to copy. |
| 5605 | STATIC_ASSERT((SeqAsciiString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 5606 | StringHelper::GenerateCopyCharactersLong(masm, r1, r5, r2, r3, r4, r6, r7, r9, |
| 5607 | COPY_ASCII | DEST_ALWAYS_ALIGNED); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5608 | __ IncrementCounter(counters->sub_string_native(), 1, r3, r4); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5609 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 5610 | __ Ret(); |
| 5611 | |
| 5612 | __ bind(&non_ascii_flat); |
| 5613 | // r2: result string length. |
| 5614 | // r5: string. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5615 | // r7 (a.k.a. from): from offset (smi) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5616 | // Check for flat two byte string. |
| 5617 | |
| 5618 | // Allocate the result. |
| 5619 | __ AllocateTwoByteString(r0, r2, r1, r3, r4, &runtime); |
| 5620 | |
| 5621 | // r0: result string. |
| 5622 | // r2: result string length. |
| 5623 | // r5: string. |
| 5624 | // Locate first character of result. |
| 5625 | __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 5626 | // Locate 'from' character of string. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5627 | __ add(r5, r5, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5628 | // As "from" is a smi it is 2 times the value which matches the size of a two |
| 5629 | // byte character. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5630 | __ add(r5, r5, Operand(from)); |
| 5631 | from = no_reg; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5632 | |
| 5633 | // r0: result string. |
| 5634 | // r1: first character of result. |
| 5635 | // r2: result length. |
| 5636 | // r5: first character of string to copy. |
| 5637 | STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5638 | StringHelper::GenerateCopyCharactersLong( |
| 5639 | masm, r1, r5, r2, r3, r4, r6, r7, r9, DEST_ALWAYS_ALIGNED); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5640 | __ IncrementCounter(counters->sub_string_native(), 1, r3, r4); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5641 | __ add(sp, sp, Operand(3 * kPointerSize)); |
| 5642 | __ Ret(); |
| 5643 | |
| 5644 | // Just jump to runtime to create the sub string. |
| 5645 | __ bind(&runtime); |
| 5646 | __ TailCallRuntime(Runtime::kSubString, 3, 1); |
| 5647 | } |
| 5648 | |
| 5649 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5650 | void StringCompareStub::GenerateFlatAsciiStringEquals(MacroAssembler* masm, |
| 5651 | Register left, |
| 5652 | Register right, |
| 5653 | Register scratch1, |
| 5654 | Register scratch2, |
| 5655 | Register scratch3) { |
| 5656 | Register length = scratch1; |
| 5657 | |
| 5658 | // Compare lengths. |
| 5659 | Label strings_not_equal, check_zero_length; |
| 5660 | __ ldr(length, FieldMemOperand(left, String::kLengthOffset)); |
| 5661 | __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 5662 | __ cmp(length, scratch2); |
| 5663 | __ b(eq, &check_zero_length); |
| 5664 | __ bind(&strings_not_equal); |
| 5665 | __ mov(r0, Operand(Smi::FromInt(NOT_EQUAL))); |
| 5666 | __ Ret(); |
| 5667 | |
| 5668 | // Check if the length is zero. |
| 5669 | Label compare_chars; |
| 5670 | __ bind(&check_zero_length); |
| 5671 | STATIC_ASSERT(kSmiTag == 0); |
| 5672 | __ tst(length, Operand(length)); |
| 5673 | __ b(ne, &compare_chars); |
| 5674 | __ mov(r0, Operand(Smi::FromInt(EQUAL))); |
| 5675 | __ Ret(); |
| 5676 | |
| 5677 | // Compare characters. |
| 5678 | __ bind(&compare_chars); |
| 5679 | GenerateAsciiCharsCompareLoop(masm, |
| 5680 | left, right, length, scratch2, scratch3, |
| 5681 | &strings_not_equal); |
| 5682 | |
| 5683 | // Characters are equal. |
| 5684 | __ mov(r0, Operand(Smi::FromInt(EQUAL))); |
| 5685 | __ Ret(); |
| 5686 | } |
| 5687 | |
| 5688 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5689 | void StringCompareStub::GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 5690 | Register left, |
| 5691 | Register right, |
| 5692 | Register scratch1, |
| 5693 | Register scratch2, |
| 5694 | Register scratch3, |
| 5695 | Register scratch4) { |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5696 | Label result_not_equal, compare_lengths; |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5697 | // Find minimum length and length difference. |
| 5698 | __ ldr(scratch1, FieldMemOperand(left, String::kLengthOffset)); |
| 5699 | __ ldr(scratch2, FieldMemOperand(right, String::kLengthOffset)); |
| 5700 | __ sub(scratch3, scratch1, Operand(scratch2), SetCC); |
| 5701 | Register length_delta = scratch3; |
| 5702 | __ mov(scratch1, scratch2, LeaveCC, gt); |
| 5703 | Register min_length = scratch1; |
| 5704 | STATIC_ASSERT(kSmiTag == 0); |
| 5705 | __ tst(min_length, Operand(min_length)); |
| 5706 | __ b(eq, &compare_lengths); |
| 5707 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5708 | // Compare loop. |
| 5709 | GenerateAsciiCharsCompareLoop(masm, |
| 5710 | left, right, min_length, scratch2, scratch4, |
| 5711 | &result_not_equal); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5712 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5713 | // Compare lengths - strings up to min-length are equal. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5714 | __ bind(&compare_lengths); |
| 5715 | ASSERT(Smi::FromInt(EQUAL) == static_cast<Smi*>(0)); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5716 | // Use length_delta as result if it's zero. |
| 5717 | __ mov(r0, Operand(length_delta), SetCC); |
| 5718 | __ bind(&result_not_equal); |
| 5719 | // Conditionally update the result based either on length_delta or |
| 5720 | // the last comparion performed in the loop above. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5721 | __ mov(r0, Operand(Smi::FromInt(GREATER)), LeaveCC, gt); |
| 5722 | __ mov(r0, Operand(Smi::FromInt(LESS)), LeaveCC, lt); |
| 5723 | __ Ret(); |
| 5724 | } |
| 5725 | |
| 5726 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5727 | void StringCompareStub::GenerateAsciiCharsCompareLoop( |
| 5728 | MacroAssembler* masm, |
| 5729 | Register left, |
| 5730 | Register right, |
| 5731 | Register length, |
| 5732 | Register scratch1, |
| 5733 | Register scratch2, |
| 5734 | Label* chars_not_equal) { |
| 5735 | // Change index to run from -length to -1 by adding length to string |
| 5736 | // start. This means that loop ends when index reaches zero, which |
| 5737 | // doesn't need an additional compare. |
| 5738 | __ SmiUntag(length); |
| 5739 | __ add(scratch1, length, |
| 5740 | Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 5741 | __ add(left, left, Operand(scratch1)); |
| 5742 | __ add(right, right, Operand(scratch1)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 5743 | __ rsb(length, length, Operand::Zero()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 5744 | Register index = length; // index = -length; |
| 5745 | |
| 5746 | // Compare loop. |
| 5747 | Label loop; |
| 5748 | __ bind(&loop); |
| 5749 | __ ldrb(scratch1, MemOperand(left, index)); |
| 5750 | __ ldrb(scratch2, MemOperand(right, index)); |
| 5751 | __ cmp(scratch1, scratch2); |
| 5752 | __ b(ne, chars_not_equal); |
| 5753 | __ add(index, index, Operand(1), SetCC); |
| 5754 | __ b(ne, &loop); |
| 5755 | } |
| 5756 | |
| 5757 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5758 | void StringCompareStub::Generate(MacroAssembler* masm) { |
| 5759 | Label runtime; |
| 5760 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5761 | Counters* counters = masm->isolate()->counters(); |
| 5762 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5763 | // Stack frame on entry. |
| 5764 | // sp[0]: right string |
| 5765 | // sp[4]: left string |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5766 | __ Ldrd(r0 , r1, MemOperand(sp)); // Load right in r0, left in r1. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5767 | |
| 5768 | Label not_same; |
| 5769 | __ cmp(r0, r1); |
| 5770 | __ b(ne, ¬_same); |
| 5771 | STATIC_ASSERT(EQUAL == 0); |
| 5772 | STATIC_ASSERT(kSmiTag == 0); |
| 5773 | __ mov(r0, Operand(Smi::FromInt(EQUAL))); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5774 | __ IncrementCounter(counters->string_compare_native(), 1, r1, r2); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5775 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 5776 | __ Ret(); |
| 5777 | |
| 5778 | __ bind(¬_same); |
| 5779 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5780 | // Check that both objects are sequential ASCII strings. |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5781 | __ JumpIfNotBothSequentialAsciiStrings(r1, r0, r2, r3, &runtime); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5782 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5783 | // Compare flat ASCII strings natively. Remove arguments from stack first. |
| 5784 | __ IncrementCounter(counters->string_compare_native(), 1, r2, r3); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5785 | __ add(sp, sp, Operand(2 * kPointerSize)); |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 5786 | GenerateCompareFlatAsciiStrings(masm, r1, r0, r2, r3, r4, r5); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5787 | |
| 5788 | // Call the runtime; it returns -1 (less), 0 (equal), or 1 (greater) |
| 5789 | // tagged as a small integer. |
| 5790 | __ bind(&runtime); |
| 5791 | __ TailCallRuntime(Runtime::kStringCompare, 2, 1); |
| 5792 | } |
| 5793 | |
| 5794 | |
| 5795 | void StringAddStub::Generate(MacroAssembler* masm) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5796 | Label string_add_runtime, call_builtin; |
| 5797 | Builtins::JavaScript builtin_id = Builtins::ADD; |
| 5798 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5799 | Counters* counters = masm->isolate()->counters(); |
| 5800 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5801 | // Stack on entry: |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5802 | // sp[0]: second argument (right). |
| 5803 | // sp[4]: first argument (left). |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5804 | |
| 5805 | // Load the two arguments. |
| 5806 | __ ldr(r0, MemOperand(sp, 1 * kPointerSize)); // First argument. |
| 5807 | __ ldr(r1, MemOperand(sp, 0 * kPointerSize)); // Second argument. |
| 5808 | |
| 5809 | // Make sure that both arguments are strings if not known in advance. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5810 | if (flags_ == NO_STRING_ADD_FLAGS) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5811 | __ JumpIfEitherSmi(r0, r1, &string_add_runtime); |
| 5812 | // Load instance types. |
| 5813 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5814 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 5815 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 5816 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 5817 | STATIC_ASSERT(kStringTag == 0); |
| 5818 | // If either is not a string, go to runtime. |
| 5819 | __ tst(r4, Operand(kIsNotStringMask)); |
| 5820 | __ tst(r5, Operand(kIsNotStringMask), eq); |
| 5821 | __ b(ne, &string_add_runtime); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5822 | } else { |
| 5823 | // Here at least one of the arguments is definitely a string. |
| 5824 | // We convert the one that is not known to be a string. |
| 5825 | if ((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) == 0) { |
| 5826 | ASSERT((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) != 0); |
| 5827 | GenerateConvertArgument( |
| 5828 | masm, 1 * kPointerSize, r0, r2, r3, r4, r5, &call_builtin); |
| 5829 | builtin_id = Builtins::STRING_ADD_RIGHT; |
| 5830 | } else if ((flags_ & NO_STRING_CHECK_RIGHT_IN_STUB) == 0) { |
| 5831 | ASSERT((flags_ & NO_STRING_CHECK_LEFT_IN_STUB) != 0); |
| 5832 | GenerateConvertArgument( |
| 5833 | masm, 0 * kPointerSize, r1, r2, r3, r4, r5, &call_builtin); |
| 5834 | builtin_id = Builtins::STRING_ADD_LEFT; |
| 5835 | } |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5836 | } |
| 5837 | |
| 5838 | // Both arguments are strings. |
| 5839 | // r0: first string |
| 5840 | // r1: second string |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5841 | // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 5842 | // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5843 | { |
| 5844 | Label strings_not_empty; |
| 5845 | // Check if either of the strings are empty. In that case return the other. |
| 5846 | __ ldr(r2, FieldMemOperand(r0, String::kLengthOffset)); |
| 5847 | __ ldr(r3, FieldMemOperand(r1, String::kLengthOffset)); |
| 5848 | STATIC_ASSERT(kSmiTag == 0); |
| 5849 | __ cmp(r2, Operand(Smi::FromInt(0))); // Test if first string is empty. |
| 5850 | __ mov(r0, Operand(r1), LeaveCC, eq); // If first is empty, return second. |
| 5851 | STATIC_ASSERT(kSmiTag == 0); |
| 5852 | // Else test if second string is empty. |
| 5853 | __ cmp(r3, Operand(Smi::FromInt(0)), ne); |
| 5854 | __ b(ne, &strings_not_empty); // If either string was empty, return r0. |
| 5855 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5856 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5857 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 5858 | __ Ret(); |
| 5859 | |
| 5860 | __ bind(&strings_not_empty); |
| 5861 | } |
| 5862 | |
| 5863 | __ mov(r2, Operand(r2, ASR, kSmiTagSize)); |
| 5864 | __ mov(r3, Operand(r3, ASR, kSmiTagSize)); |
| 5865 | // Both strings are non-empty. |
| 5866 | // r0: first string |
| 5867 | // r1: second string |
| 5868 | // r2: length of first string |
| 5869 | // r3: length of second string |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5870 | // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 5871 | // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5872 | // Look at the length of the result of adding the two strings. |
| 5873 | Label string_add_flat_result, longer_than_two; |
| 5874 | // Adding two lengths can't overflow. |
| 5875 | STATIC_ASSERT(String::kMaxLength < String::kMaxLength * 2); |
| 5876 | __ add(r6, r2, Operand(r3)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5877 | // Use the symbol table when adding two one character strings, as it |
| 5878 | // helps later optimizations to return a symbol here. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5879 | __ cmp(r6, Operand(2)); |
| 5880 | __ b(ne, &longer_than_two); |
| 5881 | |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5882 | // Check that both strings are non-external ASCII strings. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5883 | if (flags_ != NO_STRING_ADD_FLAGS) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5884 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5885 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 5886 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 5887 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 5888 | } |
| 5889 | __ JumpIfBothInstanceTypesAreNotSequentialAscii(r4, r5, r6, r7, |
| 5890 | &string_add_runtime); |
| 5891 | |
| 5892 | // Get the two characters forming the sub string. |
| 5893 | __ ldrb(r2, FieldMemOperand(r0, SeqAsciiString::kHeaderSize)); |
| 5894 | __ ldrb(r3, FieldMemOperand(r1, SeqAsciiString::kHeaderSize)); |
| 5895 | |
| 5896 | // Try to lookup two character string in symbol table. If it is not found |
| 5897 | // just allocate a new one. |
| 5898 | Label make_two_character_string; |
| 5899 | StringHelper::GenerateTwoCharacterSymbolTableProbe( |
| 5900 | masm, r2, r3, r6, r7, r4, r5, r9, &make_two_character_string); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5901 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5902 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 5903 | __ Ret(); |
| 5904 | |
| 5905 | __ bind(&make_two_character_string); |
| 5906 | // Resulting string has length 2 and first chars of two strings |
| 5907 | // are combined into single halfword in r2 register. |
| 5908 | // So we can fill resulting string without two loops by a single |
| 5909 | // halfword store instruction (which assumes that processor is |
| 5910 | // in a little endian mode) |
| 5911 | __ mov(r6, Operand(2)); |
| 5912 | __ AllocateAsciiString(r0, r6, r4, r5, r9, &string_add_runtime); |
| 5913 | __ strh(r2, FieldMemOperand(r0, SeqAsciiString::kHeaderSize)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5914 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5915 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 5916 | __ Ret(); |
| 5917 | |
| 5918 | __ bind(&longer_than_two); |
| 5919 | // Check if resulting string will be flat. |
| 5920 | __ cmp(r6, Operand(String::kMinNonFlatLength)); |
| 5921 | __ b(lt, &string_add_flat_result); |
| 5922 | // Handle exceptionally long strings in the runtime system. |
| 5923 | STATIC_ASSERT((String::kMaxLength & 0x80000000) == 0); |
| 5924 | ASSERT(IsPowerOf2(String::kMaxLength + 1)); |
| 5925 | // kMaxLength + 1 is representable as shifted literal, kMaxLength is not. |
| 5926 | __ cmp(r6, Operand(String::kMaxLength + 1)); |
| 5927 | __ b(hs, &string_add_runtime); |
| 5928 | |
| 5929 | // If result is not supposed to be flat, allocate a cons string object. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5930 | // If both strings are ASCII the result is an ASCII cons string. |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5931 | if (flags_ != NO_STRING_ADD_FLAGS) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5932 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5933 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 5934 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 5935 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 5936 | } |
| 5937 | Label non_ascii, allocated, ascii_data; |
| 5938 | STATIC_ASSERT(kTwoByteStringTag == 0); |
| 5939 | __ tst(r4, Operand(kStringEncodingMask)); |
| 5940 | __ tst(r5, Operand(kStringEncodingMask), ne); |
| 5941 | __ b(eq, &non_ascii); |
| 5942 | |
| 5943 | // Allocate an ASCII cons string. |
| 5944 | __ bind(&ascii_data); |
| 5945 | __ AllocateAsciiConsString(r7, r6, r4, r5, &string_add_runtime); |
| 5946 | __ bind(&allocated); |
| 5947 | // Fill the fields of the cons string. |
| 5948 | __ str(r0, FieldMemOperand(r7, ConsString::kFirstOffset)); |
| 5949 | __ str(r1, FieldMemOperand(r7, ConsString::kSecondOffset)); |
| 5950 | __ mov(r0, Operand(r7)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5951 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5952 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 5953 | __ Ret(); |
| 5954 | |
| 5955 | __ bind(&non_ascii); |
| 5956 | // At least one of the strings is two-byte. Check whether it happens |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 5957 | // to contain only ASCII characters. |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5958 | // r4: first instance type. |
| 5959 | // r5: second instance type. |
| 5960 | __ tst(r4, Operand(kAsciiDataHintMask)); |
| 5961 | __ tst(r5, Operand(kAsciiDataHintMask), ne); |
| 5962 | __ b(ne, &ascii_data); |
| 5963 | __ eor(r4, r4, Operand(r5)); |
| 5964 | STATIC_ASSERT(kAsciiStringTag != 0 && kAsciiDataHintTag != 0); |
| 5965 | __ and_(r4, r4, Operand(kAsciiStringTag | kAsciiDataHintTag)); |
| 5966 | __ cmp(r4, Operand(kAsciiStringTag | kAsciiDataHintTag)); |
| 5967 | __ b(eq, &ascii_data); |
| 5968 | |
| 5969 | // Allocate a two byte cons string. |
| 5970 | __ AllocateTwoByteConsString(r7, r6, r4, r5, &string_add_runtime); |
| 5971 | __ jmp(&allocated); |
| 5972 | |
| 5973 | // Handle creating a flat result. First check that both strings are |
| 5974 | // sequential and that they have the same encoding. |
| 5975 | // r0: first string |
| 5976 | // r1: second string |
| 5977 | // r2: length of first string |
| 5978 | // r3: length of second string |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5979 | // r4: first string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
| 5980 | // r5: second string instance type (if flags_ == NO_STRING_ADD_FLAGS) |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5981 | // r6: sum of lengths. |
| 5982 | __ bind(&string_add_flat_result); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 5983 | if (flags_ != NO_STRING_ADD_FLAGS) { |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 5984 | __ ldr(r4, FieldMemOperand(r0, HeapObject::kMapOffset)); |
| 5985 | __ ldr(r5, FieldMemOperand(r1, HeapObject::kMapOffset)); |
| 5986 | __ ldrb(r4, FieldMemOperand(r4, Map::kInstanceTypeOffset)); |
| 5987 | __ ldrb(r5, FieldMemOperand(r5, Map::kInstanceTypeOffset)); |
| 5988 | } |
| 5989 | // Check that both strings are sequential. |
| 5990 | STATIC_ASSERT(kSeqStringTag == 0); |
| 5991 | __ tst(r4, Operand(kStringRepresentationMask)); |
| 5992 | __ tst(r5, Operand(kStringRepresentationMask), eq); |
| 5993 | __ b(ne, &string_add_runtime); |
| 5994 | // Now check if both strings have the same encoding (ASCII/Two-byte). |
| 5995 | // r0: first string. |
| 5996 | // r1: second string. |
| 5997 | // r2: length of first string. |
| 5998 | // r3: length of second string. |
| 5999 | // r6: sum of lengths.. |
| 6000 | Label non_ascii_string_add_flat_result; |
| 6001 | ASSERT(IsPowerOf2(kStringEncodingMask)); // Just one bit to test. |
| 6002 | __ eor(r7, r4, Operand(r5)); |
| 6003 | __ tst(r7, Operand(kStringEncodingMask)); |
| 6004 | __ b(ne, &string_add_runtime); |
| 6005 | // And see if it's ASCII or two-byte. |
| 6006 | __ tst(r4, Operand(kStringEncodingMask)); |
| 6007 | __ b(eq, &non_ascii_string_add_flat_result); |
| 6008 | |
| 6009 | // Both strings are sequential ASCII strings. We also know that they are |
| 6010 | // short (since the sum of the lengths is less than kMinNonFlatLength). |
| 6011 | // r6: length of resulting flat string |
| 6012 | __ AllocateAsciiString(r7, r6, r4, r5, r9, &string_add_runtime); |
| 6013 | // Locate first character of result. |
| 6014 | __ add(r6, r7, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 6015 | // Locate first character of first argument. |
| 6016 | __ add(r0, r0, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 6017 | // r0: first character of first string. |
| 6018 | // r1: second string. |
| 6019 | // r2: length of first string. |
| 6020 | // r3: length of second string. |
| 6021 | // r6: first character of result. |
| 6022 | // r7: result string. |
| 6023 | StringHelper::GenerateCopyCharacters(masm, r6, r0, r2, r4, true); |
| 6024 | |
| 6025 | // Load second argument and locate first character. |
| 6026 | __ add(r1, r1, Operand(SeqAsciiString::kHeaderSize - kHeapObjectTag)); |
| 6027 | // r1: first character of second string. |
| 6028 | // r3: length of second string. |
| 6029 | // r6: next character of result. |
| 6030 | // r7: result string. |
| 6031 | StringHelper::GenerateCopyCharacters(masm, r6, r1, r3, r4, true); |
| 6032 | __ mov(r0, Operand(r7)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6033 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 6034 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6035 | __ Ret(); |
| 6036 | |
| 6037 | __ bind(&non_ascii_string_add_flat_result); |
| 6038 | // Both strings are sequential two byte strings. |
| 6039 | // r0: first string. |
| 6040 | // r1: second string. |
| 6041 | // r2: length of first string. |
| 6042 | // r3: length of second string. |
| 6043 | // r6: sum of length of strings. |
| 6044 | __ AllocateTwoByteString(r7, r6, r4, r5, r9, &string_add_runtime); |
| 6045 | // r0: first string. |
| 6046 | // r1: second string. |
| 6047 | // r2: length of first string. |
| 6048 | // r3: length of second string. |
| 6049 | // r7: result string. |
| 6050 | |
| 6051 | // Locate first character of result. |
| 6052 | __ add(r6, r7, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6053 | // Locate first character of first argument. |
| 6054 | __ add(r0, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6055 | |
| 6056 | // r0: first character of first string. |
| 6057 | // r1: second string. |
| 6058 | // r2: length of first string. |
| 6059 | // r3: length of second string. |
| 6060 | // r6: first character of result. |
| 6061 | // r7: result string. |
| 6062 | StringHelper::GenerateCopyCharacters(masm, r6, r0, r2, r4, false); |
| 6063 | |
| 6064 | // Locate first character of second argument. |
| 6065 | __ add(r1, r1, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 6066 | |
| 6067 | // r1: first character of second string. |
| 6068 | // r3: length of second string. |
| 6069 | // r6: next character of result (after copy of first string). |
| 6070 | // r7: result string. |
| 6071 | StringHelper::GenerateCopyCharacters(masm, r6, r1, r3, r4, false); |
| 6072 | |
| 6073 | __ mov(r0, Operand(r7)); |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6074 | __ IncrementCounter(counters->string_add_native(), 1, r2, r3); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 6075 | __ add(sp, sp, Operand(2 * kPointerSize)); |
| 6076 | __ Ret(); |
| 6077 | |
| 6078 | // Just jump to runtime to add the two strings. |
| 6079 | __ bind(&string_add_runtime); |
| 6080 | __ TailCallRuntime(Runtime::kStringAdd, 2, 1); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 6081 | |
| 6082 | if (call_builtin.is_linked()) { |
| 6083 | __ bind(&call_builtin); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6084 | __ InvokeBuiltin(builtin_id, JUMP_FUNCTION); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 6085 | } |
| 6086 | } |
| 6087 | |
| 6088 | |
| 6089 | void StringAddStub::GenerateConvertArgument(MacroAssembler* masm, |
| 6090 | int stack_offset, |
| 6091 | Register arg, |
| 6092 | Register scratch1, |
| 6093 | Register scratch2, |
| 6094 | Register scratch3, |
| 6095 | Register scratch4, |
| 6096 | Label* slow) { |
| 6097 | // First check if the argument is already a string. |
| 6098 | Label not_string, done; |
| 6099 | __ JumpIfSmi(arg, ¬_string); |
| 6100 | __ CompareObjectType(arg, scratch1, scratch1, FIRST_NONSTRING_TYPE); |
| 6101 | __ b(lt, &done); |
| 6102 | |
| 6103 | // Check the number to string cache. |
| 6104 | Label not_cached; |
| 6105 | __ bind(¬_string); |
| 6106 | // Puts the cached result into scratch1. |
| 6107 | NumberToStringStub::GenerateLookupNumberStringCache(masm, |
| 6108 | arg, |
| 6109 | scratch1, |
| 6110 | scratch2, |
| 6111 | scratch3, |
| 6112 | scratch4, |
| 6113 | false, |
| 6114 | ¬_cached); |
| 6115 | __ mov(arg, scratch1); |
| 6116 | __ str(arg, MemOperand(sp, stack_offset)); |
| 6117 | __ jmp(&done); |
| 6118 | |
| 6119 | // Check if the argument is a safe string wrapper. |
| 6120 | __ bind(¬_cached); |
| 6121 | __ JumpIfSmi(arg, slow); |
| 6122 | __ CompareObjectType( |
| 6123 | arg, scratch1, scratch2, JS_VALUE_TYPE); // map -> scratch1. |
| 6124 | __ b(ne, slow); |
| 6125 | __ ldrb(scratch2, FieldMemOperand(scratch1, Map::kBitField2Offset)); |
| 6126 | __ and_(scratch2, |
| 6127 | scratch2, Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 6128 | __ cmp(scratch2, |
| 6129 | Operand(1 << Map::kStringWrapperSafeForDefaultValueOf)); |
| 6130 | __ b(ne, slow); |
| 6131 | __ ldr(arg, FieldMemOperand(arg, JSValue::kValueOffset)); |
| 6132 | __ str(arg, MemOperand(sp, stack_offset)); |
| 6133 | |
| 6134 | __ bind(&done); |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 6135 | } |
| 6136 | |
| 6137 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6138 | void ICCompareStub::GenerateSmis(MacroAssembler* masm) { |
| 6139 | ASSERT(state_ == CompareIC::SMIS); |
| 6140 | Label miss; |
| 6141 | __ orr(r2, r1, r0); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6142 | __ JumpIfNotSmi(r2, &miss); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6143 | |
| 6144 | if (GetCondition() == eq) { |
| 6145 | // For equality we do not care about the sign of the result. |
| 6146 | __ sub(r0, r0, r1, SetCC); |
| 6147 | } else { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 6148 | // Untag before subtracting to avoid handling overflow. |
| 6149 | __ SmiUntag(r1); |
| 6150 | __ sub(r0, r1, SmiUntagOperand(r0)); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6151 | } |
| 6152 | __ Ret(); |
| 6153 | |
| 6154 | __ bind(&miss); |
| 6155 | GenerateMiss(masm); |
| 6156 | } |
| 6157 | |
| 6158 | |
| 6159 | void ICCompareStub::GenerateHeapNumbers(MacroAssembler* masm) { |
| 6160 | ASSERT(state_ == CompareIC::HEAP_NUMBERS); |
| 6161 | |
| 6162 | Label generic_stub; |
| 6163 | Label unordered; |
| 6164 | Label miss; |
| 6165 | __ and_(r2, r1, Operand(r0)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6166 | __ JumpIfSmi(r2, &generic_stub); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6167 | |
| 6168 | __ CompareObjectType(r0, r2, r2, HEAP_NUMBER_TYPE); |
| 6169 | __ b(ne, &miss); |
| 6170 | __ CompareObjectType(r1, r2, r2, HEAP_NUMBER_TYPE); |
| 6171 | __ b(ne, &miss); |
| 6172 | |
| 6173 | // Inlining the double comparison and falling back to the general compare |
| 6174 | // stub if NaN is involved or VFP3 is unsupported. |
Ben Murdoch | 8b112d2 | 2011-06-08 16:22:53 +0100 | [diff] [blame] | 6175 | if (CpuFeatures::IsSupported(VFP3)) { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6176 | CpuFeatures::Scope scope(VFP3); |
| 6177 | |
| 6178 | // Load left and right operand |
| 6179 | __ sub(r2, r1, Operand(kHeapObjectTag)); |
| 6180 | __ vldr(d0, r2, HeapNumber::kValueOffset); |
| 6181 | __ sub(r2, r0, Operand(kHeapObjectTag)); |
| 6182 | __ vldr(d1, r2, HeapNumber::kValueOffset); |
| 6183 | |
| 6184 | // Compare operands |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 6185 | __ VFPCompareAndSetFlags(d0, d1); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6186 | |
| 6187 | // Don't base result on status bits when a NaN is involved. |
| 6188 | __ b(vs, &unordered); |
| 6189 | |
| 6190 | // Return a result of -1, 0, or 1, based on status bits. |
| 6191 | __ mov(r0, Operand(EQUAL), LeaveCC, eq); |
| 6192 | __ mov(r0, Operand(LESS), LeaveCC, lt); |
| 6193 | __ mov(r0, Operand(GREATER), LeaveCC, gt); |
| 6194 | __ Ret(); |
| 6195 | |
| 6196 | __ bind(&unordered); |
| 6197 | } |
| 6198 | |
| 6199 | CompareStub stub(GetCondition(), strict(), NO_COMPARE_FLAGS, r1, r0); |
| 6200 | __ bind(&generic_stub); |
| 6201 | __ Jump(stub.GetCode(), RelocInfo::CODE_TARGET); |
| 6202 | |
| 6203 | __ bind(&miss); |
| 6204 | GenerateMiss(masm); |
| 6205 | } |
| 6206 | |
| 6207 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6208 | void ICCompareStub::GenerateSymbols(MacroAssembler* masm) { |
| 6209 | ASSERT(state_ == CompareIC::SYMBOLS); |
| 6210 | Label miss; |
| 6211 | |
| 6212 | // Registers containing left and right operands respectively. |
| 6213 | Register left = r1; |
| 6214 | Register right = r0; |
| 6215 | Register tmp1 = r2; |
| 6216 | Register tmp2 = r3; |
| 6217 | |
| 6218 | // Check that both operands are heap objects. |
| 6219 | __ JumpIfEitherSmi(left, right, &miss); |
| 6220 | |
| 6221 | // Check that both operands are symbols. |
| 6222 | __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 6223 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 6224 | __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6225 | __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6226 | STATIC_ASSERT(kSymbolTag != 0); |
| 6227 | __ and_(tmp1, tmp1, Operand(tmp2)); |
| 6228 | __ tst(tmp1, Operand(kIsSymbolMask)); |
| 6229 | __ b(eq, &miss); |
| 6230 | |
| 6231 | // Symbols are compared by identity. |
| 6232 | __ cmp(left, right); |
| 6233 | // Make sure r0 is non-zero. At this point input operands are |
| 6234 | // guaranteed to be non-zero. |
| 6235 | ASSERT(right.is(r0)); |
| 6236 | STATIC_ASSERT(EQUAL == 0); |
| 6237 | STATIC_ASSERT(kSmiTag == 0); |
| 6238 | __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq); |
| 6239 | __ Ret(); |
| 6240 | |
| 6241 | __ bind(&miss); |
| 6242 | GenerateMiss(masm); |
| 6243 | } |
| 6244 | |
| 6245 | |
| 6246 | void ICCompareStub::GenerateStrings(MacroAssembler* masm) { |
| 6247 | ASSERT(state_ == CompareIC::STRINGS); |
| 6248 | Label miss; |
| 6249 | |
| 6250 | // Registers containing left and right operands respectively. |
| 6251 | Register left = r1; |
| 6252 | Register right = r0; |
| 6253 | Register tmp1 = r2; |
| 6254 | Register tmp2 = r3; |
| 6255 | Register tmp3 = r4; |
| 6256 | Register tmp4 = r5; |
| 6257 | |
| 6258 | // Check that both operands are heap objects. |
| 6259 | __ JumpIfEitherSmi(left, right, &miss); |
| 6260 | |
| 6261 | // Check that both operands are strings. This leaves the instance |
| 6262 | // types loaded in tmp1 and tmp2. |
| 6263 | __ ldr(tmp1, FieldMemOperand(left, HeapObject::kMapOffset)); |
| 6264 | __ ldr(tmp2, FieldMemOperand(right, HeapObject::kMapOffset)); |
| 6265 | __ ldrb(tmp1, FieldMemOperand(tmp1, Map::kInstanceTypeOffset)); |
| 6266 | __ ldrb(tmp2, FieldMemOperand(tmp2, Map::kInstanceTypeOffset)); |
| 6267 | STATIC_ASSERT(kNotStringTag != 0); |
| 6268 | __ orr(tmp3, tmp1, tmp2); |
| 6269 | __ tst(tmp3, Operand(kIsNotStringMask)); |
| 6270 | __ b(ne, &miss); |
| 6271 | |
| 6272 | // Fast check for identical strings. |
| 6273 | __ cmp(left, right); |
| 6274 | STATIC_ASSERT(EQUAL == 0); |
| 6275 | STATIC_ASSERT(kSmiTag == 0); |
| 6276 | __ mov(r0, Operand(Smi::FromInt(EQUAL)), LeaveCC, eq); |
| 6277 | __ Ret(eq); |
| 6278 | |
| 6279 | // Handle not identical strings. |
| 6280 | |
| 6281 | // Check that both strings are symbols. If they are, we're done |
| 6282 | // because we already know they are not identical. |
| 6283 | ASSERT(GetCondition() == eq); |
| 6284 | STATIC_ASSERT(kSymbolTag != 0); |
| 6285 | __ and_(tmp3, tmp1, Operand(tmp2)); |
| 6286 | __ tst(tmp3, Operand(kIsSymbolMask)); |
| 6287 | // Make sure r0 is non-zero. At this point input operands are |
| 6288 | // guaranteed to be non-zero. |
| 6289 | ASSERT(right.is(r0)); |
| 6290 | __ Ret(ne); |
| 6291 | |
| 6292 | // Check that both strings are sequential ASCII. |
| 6293 | Label runtime; |
| 6294 | __ JumpIfBothInstanceTypesAreNotSequentialAscii(tmp1, tmp2, tmp3, tmp4, |
| 6295 | &runtime); |
| 6296 | |
| 6297 | // Compare flat ASCII strings. Returns when done. |
| 6298 | StringCompareStub::GenerateFlatAsciiStringEquals( |
| 6299 | masm, left, right, tmp1, tmp2, tmp3); |
| 6300 | |
| 6301 | // Handle more complex cases in runtime. |
| 6302 | __ bind(&runtime); |
| 6303 | __ Push(left, right); |
| 6304 | __ TailCallRuntime(Runtime::kStringEquals, 2, 1); |
| 6305 | |
| 6306 | __ bind(&miss); |
| 6307 | GenerateMiss(masm); |
| 6308 | } |
| 6309 | |
| 6310 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6311 | void ICCompareStub::GenerateObjects(MacroAssembler* masm) { |
| 6312 | ASSERT(state_ == CompareIC::OBJECTS); |
| 6313 | Label miss; |
| 6314 | __ and_(r2, r1, Operand(r0)); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 6315 | __ JumpIfSmi(r2, &miss); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6316 | |
| 6317 | __ CompareObjectType(r0, r2, r2, JS_OBJECT_TYPE); |
| 6318 | __ b(ne, &miss); |
| 6319 | __ CompareObjectType(r1, r2, r2, JS_OBJECT_TYPE); |
| 6320 | __ b(ne, &miss); |
| 6321 | |
| 6322 | ASSERT(GetCondition() == eq); |
| 6323 | __ sub(r0, r0, Operand(r1)); |
| 6324 | __ Ret(); |
| 6325 | |
| 6326 | __ bind(&miss); |
| 6327 | GenerateMiss(masm); |
| 6328 | } |
| 6329 | |
| 6330 | |
| 6331 | void ICCompareStub::GenerateMiss(MacroAssembler* masm) { |
| 6332 | __ Push(r1, r0); |
| 6333 | __ push(lr); |
| 6334 | |
| 6335 | // Call the runtime system in a fresh internal frame. |
Steve Block | 44f0eee | 2011-05-26 01:26:41 +0100 | [diff] [blame] | 6336 | ExternalReference miss = |
| 6337 | ExternalReference(IC_Utility(IC::kCompareIC_Miss), masm->isolate()); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 6338 | __ EnterInternalFrame(); |
| 6339 | __ Push(r1, r0); |
| 6340 | __ mov(ip, Operand(Smi::FromInt(op_))); |
| 6341 | __ push(ip); |
| 6342 | __ CallExternalReference(miss, 3); |
| 6343 | __ LeaveInternalFrame(); |
| 6344 | // Compute the entry point of the rewritten stub. |
| 6345 | __ add(r2, r0, Operand(Code::kHeaderSize - kHeapObjectTag)); |
| 6346 | // Restore registers. |
| 6347 | __ pop(lr); |
| 6348 | __ pop(r0); |
| 6349 | __ pop(r1); |
| 6350 | __ Jump(r2); |
| 6351 | } |
| 6352 | |
| 6353 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 6354 | void DirectCEntryStub::Generate(MacroAssembler* masm) { |
| 6355 | __ ldr(pc, MemOperand(sp, 0)); |
| 6356 | } |
| 6357 | |
| 6358 | |
| 6359 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 6360 | ExternalReference function) { |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 6361 | __ mov(r2, Operand(function)); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 6362 | GenerateCall(masm, r2); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 6363 | } |
| 6364 | |
| 6365 | |
| 6366 | void DirectCEntryStub::GenerateCall(MacroAssembler* masm, |
| 6367 | Register target) { |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 6368 | __ mov(lr, Operand(reinterpret_cast<intptr_t>(GetCode().location()), |
| 6369 | RelocInfo::CODE_TARGET)); |
| 6370 | // Push return address (accessible to GC through exit frame pc). |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 6371 | // Note that using pc with str is deprecated. |
| 6372 | Label start; |
| 6373 | __ bind(&start); |
| 6374 | __ add(ip, pc, Operand(Assembler::kInstrSize)); |
| 6375 | __ str(ip, MemOperand(sp, 0)); |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 6376 | __ Jump(target); // Call the C++ function. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 6377 | ASSERT_EQ(Assembler::kInstrSize + Assembler::kPcLoadDelta, |
| 6378 | masm->SizeOfCodeGeneratedSince(&start)); |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 6379 | } |
| 6380 | |
| 6381 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6382 | MaybeObject* StringDictionaryLookupStub::GenerateNegativeLookup( |
| 6383 | MacroAssembler* masm, |
| 6384 | Label* miss, |
| 6385 | Label* done, |
| 6386 | Register receiver, |
| 6387 | Register properties, |
| 6388 | String* name, |
| 6389 | Register scratch0) { |
| 6390 | // If names of slots in range from 1 to kProbes - 1 for the hash value are |
| 6391 | // not equal to the name and kProbes-th slot is not used (its name is the |
| 6392 | // undefined value), it guarantees the hash table doesn't contain the |
| 6393 | // property. It's true even if some slots represent deleted properties |
| 6394 | // (their names are the null value). |
| 6395 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6396 | // scratch0 points to properties hash. |
| 6397 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6398 | Register index = scratch0; |
| 6399 | // Capacity is smi 2^n. |
| 6400 | __ ldr(index, FieldMemOperand(properties, kCapacityOffset)); |
| 6401 | __ sub(index, index, Operand(1)); |
| 6402 | __ and_(index, index, Operand( |
| 6403 | Smi::FromInt(name->Hash() + StringDictionary::GetProbeOffset(i)))); |
| 6404 | |
| 6405 | // Scale the index by multiplying by the entry size. |
| 6406 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6407 | __ add(index, index, Operand(index, LSL, 1)); // index *= 3. |
| 6408 | |
| 6409 | Register entity_name = scratch0; |
| 6410 | // Having undefined at this place means the name is not contained. |
| 6411 | ASSERT_EQ(kSmiTagSize, 1); |
| 6412 | Register tmp = properties; |
| 6413 | __ add(tmp, properties, Operand(index, LSL, 1)); |
| 6414 | __ ldr(entity_name, FieldMemOperand(tmp, kElementsStartOffset)); |
| 6415 | |
| 6416 | ASSERT(!tmp.is(entity_name)); |
| 6417 | __ LoadRoot(tmp, Heap::kUndefinedValueRootIndex); |
| 6418 | __ cmp(entity_name, tmp); |
| 6419 | __ b(eq, done); |
| 6420 | |
| 6421 | if (i != kInlinedProbes - 1) { |
| 6422 | // Stop if found the property. |
| 6423 | __ cmp(entity_name, Operand(Handle<String>(name))); |
| 6424 | __ b(eq, miss); |
| 6425 | |
| 6426 | // Check if the entry name is not a symbol. |
| 6427 | __ ldr(entity_name, FieldMemOperand(entity_name, HeapObject::kMapOffset)); |
| 6428 | __ ldrb(entity_name, |
| 6429 | FieldMemOperand(entity_name, Map::kInstanceTypeOffset)); |
| 6430 | __ tst(entity_name, Operand(kIsSymbolMask)); |
| 6431 | __ b(eq, miss); |
| 6432 | |
| 6433 | // Restore the properties. |
| 6434 | __ ldr(properties, |
| 6435 | FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 6436 | } |
| 6437 | } |
| 6438 | |
| 6439 | const int spill_mask = |
| 6440 | (lr.bit() | r6.bit() | r5.bit() | r4.bit() | r3.bit() | |
| 6441 | r2.bit() | r1.bit() | r0.bit()); |
| 6442 | |
| 6443 | __ stm(db_w, sp, spill_mask); |
| 6444 | __ ldr(r0, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 6445 | __ mov(r1, Operand(Handle<String>(name))); |
| 6446 | StringDictionaryLookupStub stub(NEGATIVE_LOOKUP); |
| 6447 | MaybeObject* result = masm->TryCallStub(&stub); |
| 6448 | if (result->IsFailure()) return result; |
| 6449 | __ tst(r0, Operand(r0)); |
| 6450 | __ ldm(ia_w, sp, spill_mask); |
| 6451 | |
| 6452 | __ b(eq, done); |
| 6453 | __ b(ne, miss); |
| 6454 | return result; |
| 6455 | } |
| 6456 | |
| 6457 | |
| 6458 | // Probe the string dictionary in the |elements| register. Jump to the |
| 6459 | // |done| label if a property with the given name is found. Jump to |
| 6460 | // the |miss| label otherwise. |
| 6461 | // If lookup was successful |scratch2| will be equal to elements + 4 * index. |
| 6462 | void StringDictionaryLookupStub::GeneratePositiveLookup(MacroAssembler* masm, |
| 6463 | Label* miss, |
| 6464 | Label* done, |
| 6465 | Register elements, |
| 6466 | Register name, |
| 6467 | Register scratch1, |
| 6468 | Register scratch2) { |
| 6469 | // Assert that name contains a string. |
| 6470 | if (FLAG_debug_code) __ AbortIfNotString(name); |
| 6471 | |
| 6472 | // Compute the capacity mask. |
| 6473 | __ ldr(scratch1, FieldMemOperand(elements, kCapacityOffset)); |
| 6474 | __ mov(scratch1, Operand(scratch1, ASR, kSmiTagSize)); // convert smi to int |
| 6475 | __ sub(scratch1, scratch1, Operand(1)); |
| 6476 | |
| 6477 | // Generate an unrolled loop that performs a few probes before |
| 6478 | // giving up. Measurements done on Gmail indicate that 2 probes |
| 6479 | // cover ~93% of loads from dictionaries. |
| 6480 | for (int i = 0; i < kInlinedProbes; i++) { |
| 6481 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6482 | __ ldr(scratch2, FieldMemOperand(name, String::kHashFieldOffset)); |
| 6483 | if (i > 0) { |
| 6484 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 6485 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 6486 | // shifted in the following and instruction. |
| 6487 | ASSERT(StringDictionary::GetProbeOffset(i) < |
| 6488 | 1 << (32 - String::kHashFieldOffset)); |
| 6489 | __ add(scratch2, scratch2, Operand( |
| 6490 | StringDictionary::GetProbeOffset(i) << String::kHashShift)); |
| 6491 | } |
| 6492 | __ and_(scratch2, scratch1, Operand(scratch2, LSR, String::kHashShift)); |
| 6493 | |
| 6494 | // Scale the index by multiplying by the element size. |
| 6495 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6496 | // scratch2 = scratch2 * 3. |
| 6497 | __ add(scratch2, scratch2, Operand(scratch2, LSL, 1)); |
| 6498 | |
| 6499 | // Check if the key is identical to the name. |
| 6500 | __ add(scratch2, elements, Operand(scratch2, LSL, 2)); |
| 6501 | __ ldr(ip, FieldMemOperand(scratch2, kElementsStartOffset)); |
| 6502 | __ cmp(name, Operand(ip)); |
| 6503 | __ b(eq, done); |
| 6504 | } |
| 6505 | |
| 6506 | const int spill_mask = |
| 6507 | (lr.bit() | r6.bit() | r5.bit() | r4.bit() | |
| 6508 | r3.bit() | r2.bit() | r1.bit() | r0.bit()) & |
| 6509 | ~(scratch1.bit() | scratch2.bit()); |
| 6510 | |
| 6511 | __ stm(db_w, sp, spill_mask); |
| 6512 | __ Move(r0, elements); |
| 6513 | __ Move(r1, name); |
| 6514 | StringDictionaryLookupStub stub(POSITIVE_LOOKUP); |
| 6515 | __ CallStub(&stub); |
| 6516 | __ tst(r0, Operand(r0)); |
| 6517 | __ mov(scratch2, Operand(r2)); |
| 6518 | __ ldm(ia_w, sp, spill_mask); |
| 6519 | |
| 6520 | __ b(ne, done); |
| 6521 | __ b(eq, miss); |
| 6522 | } |
| 6523 | |
| 6524 | |
| 6525 | void StringDictionaryLookupStub::Generate(MacroAssembler* masm) { |
| 6526 | // Registers: |
| 6527 | // result: StringDictionary to probe |
| 6528 | // r1: key |
| 6529 | // : StringDictionary to probe. |
| 6530 | // index_: will hold an index of entry if lookup is successful. |
| 6531 | // might alias with result_. |
| 6532 | // Returns: |
| 6533 | // result_ is zero if lookup failed, non zero otherwise. |
| 6534 | |
| 6535 | Register result = r0; |
| 6536 | Register dictionary = r0; |
| 6537 | Register key = r1; |
| 6538 | Register index = r2; |
| 6539 | Register mask = r3; |
| 6540 | Register hash = r4; |
| 6541 | Register undefined = r5; |
| 6542 | Register entry_key = r6; |
| 6543 | |
| 6544 | Label in_dictionary, maybe_in_dictionary, not_in_dictionary; |
| 6545 | |
| 6546 | __ ldr(mask, FieldMemOperand(dictionary, kCapacityOffset)); |
| 6547 | __ mov(mask, Operand(mask, ASR, kSmiTagSize)); |
| 6548 | __ sub(mask, mask, Operand(1)); |
| 6549 | |
| 6550 | __ ldr(hash, FieldMemOperand(key, String::kHashFieldOffset)); |
| 6551 | |
| 6552 | __ LoadRoot(undefined, Heap::kUndefinedValueRootIndex); |
| 6553 | |
| 6554 | for (int i = kInlinedProbes; i < kTotalProbes; i++) { |
| 6555 | // Compute the masked index: (hash + i + i * i) & mask. |
| 6556 | // Capacity is smi 2^n. |
| 6557 | if (i > 0) { |
| 6558 | // Add the probe offset (i + i * i) left shifted to avoid right shifting |
| 6559 | // the hash in a separate instruction. The value hash + i + i * i is right |
| 6560 | // shifted in the following and instruction. |
| 6561 | ASSERT(StringDictionary::GetProbeOffset(i) < |
| 6562 | 1 << (32 - String::kHashFieldOffset)); |
| 6563 | __ add(index, hash, Operand( |
| 6564 | StringDictionary::GetProbeOffset(i) << String::kHashShift)); |
| 6565 | } else { |
| 6566 | __ mov(index, Operand(hash)); |
| 6567 | } |
| 6568 | __ and_(index, mask, Operand(index, LSR, String::kHashShift)); |
| 6569 | |
| 6570 | // Scale the index by multiplying by the entry size. |
| 6571 | ASSERT(StringDictionary::kEntrySize == 3); |
| 6572 | __ add(index, index, Operand(index, LSL, 1)); // index *= 3. |
| 6573 | |
| 6574 | ASSERT_EQ(kSmiTagSize, 1); |
| 6575 | __ add(index, dictionary, Operand(index, LSL, 2)); |
| 6576 | __ ldr(entry_key, FieldMemOperand(index, kElementsStartOffset)); |
| 6577 | |
| 6578 | // Having undefined at this place means the name is not contained. |
| 6579 | __ cmp(entry_key, Operand(undefined)); |
| 6580 | __ b(eq, ¬_in_dictionary); |
| 6581 | |
| 6582 | // Stop if found the property. |
| 6583 | __ cmp(entry_key, Operand(key)); |
| 6584 | __ b(eq, &in_dictionary); |
| 6585 | |
| 6586 | if (i != kTotalProbes - 1 && mode_ == NEGATIVE_LOOKUP) { |
| 6587 | // Check if the entry name is not a symbol. |
| 6588 | __ ldr(entry_key, FieldMemOperand(entry_key, HeapObject::kMapOffset)); |
| 6589 | __ ldrb(entry_key, |
| 6590 | FieldMemOperand(entry_key, Map::kInstanceTypeOffset)); |
| 6591 | __ tst(entry_key, Operand(kIsSymbolMask)); |
| 6592 | __ b(eq, &maybe_in_dictionary); |
| 6593 | } |
| 6594 | } |
| 6595 | |
| 6596 | __ bind(&maybe_in_dictionary); |
| 6597 | // If we are doing negative lookup then probing failure should be |
| 6598 | // treated as a lookup success. For positive lookup probing failure |
| 6599 | // should be treated as lookup failure. |
| 6600 | if (mode_ == POSITIVE_LOOKUP) { |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 6601 | __ mov(result, Operand::Zero()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6602 | __ Ret(); |
| 6603 | } |
| 6604 | |
| 6605 | __ bind(&in_dictionary); |
| 6606 | __ mov(result, Operand(1)); |
| 6607 | __ Ret(); |
| 6608 | |
| 6609 | __ bind(¬_in_dictionary); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 6610 | __ mov(result, Operand::Zero()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 6611 | __ Ret(); |
| 6612 | } |
| 6613 | |
| 6614 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 6615 | #undef __ |
| 6616 | |
| 6617 | } } // namespace v8::internal |
| 6618 | |
| 6619 | #endif // V8_TARGET_ARCH_ARM |