OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #if V8_TARGET_ARCH_ARM | 5 #if V8_TARGET_ARCH_ARM |
6 | 6 |
7 #include "src/code-stubs.h" | 7 #include "src/code-stubs.h" |
8 #include "src/api-arguments.h" | 8 #include "src/api-arguments.h" |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 2106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2117 __ bind(&loop); | 2117 __ bind(&loop); |
2118 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt); | 2118 __ ldrb(scratch, MemOperand(src, 1, PostIndex), lt); |
2119 __ strb(scratch, MemOperand(dest, 1, PostIndex)); | 2119 __ strb(scratch, MemOperand(dest, 1, PostIndex)); |
2120 __ bind(&loop_entry); | 2120 __ bind(&loop_entry); |
2121 __ cmp(dest, Operand(limit)); | 2121 __ cmp(dest, Operand(limit)); |
2122 __ b(lt, &loop); | 2122 __ b(lt, &loop); |
2123 | 2123 |
2124 __ bind(&done); | 2124 __ bind(&done); |
2125 } | 2125 } |
2126 | 2126 |
| 2127 |
| 2128 void SubStringStub::Generate(MacroAssembler* masm) { |
| 2129 Label runtime; |
| 2130 |
| 2131 // Stack frame on entry. |
| 2132 // lr: return address |
| 2133 // sp[0]: to |
| 2134 // sp[4]: from |
| 2135 // sp[8]: string |
| 2136 |
| 2137 // This stub is called from the native-call %_SubString(...), so |
| 2138 // nothing can be assumed about the arguments. It is tested that: |
| 2139 // "string" is a sequential string, |
| 2140 // both "from" and "to" are smis, and |
| 2141 // 0 <= from <= to <= string.length. |
| 2142 // If any of these assumptions fail, we call the runtime system. |
| 2143 |
| 2144 const int kToOffset = 0 * kPointerSize; |
| 2145 const int kFromOffset = 1 * kPointerSize; |
| 2146 const int kStringOffset = 2 * kPointerSize; |
| 2147 |
| 2148 __ Ldrd(r2, r3, MemOperand(sp, kToOffset)); |
| 2149 STATIC_ASSERT(kFromOffset == kToOffset + 4); |
| 2150 STATIC_ASSERT(kSmiTag == 0); |
| 2151 STATIC_ASSERT(kSmiTagSize + kSmiShiftSize == 1); |
| 2152 |
| 2153 // Arithmetic shift right by one un-smi-tags. In this case we rotate right |
| 2154 // instead because we bail out on non-smi values: ROR and ASR are equivalent |
| 2155 // for smis but they set the flags in a way that's easier to optimize. |
| 2156 __ mov(r2, Operand(r2, ROR, 1), SetCC); |
| 2157 __ mov(r3, Operand(r3, ROR, 1), SetCC, cc); |
| 2158 // If either to or from had the smi tag bit set, then C is set now, and N |
| 2159 // has the same value: we rotated by 1, so the bottom bit is now the top bit. |
| 2160 // We want to bailout to runtime here if From is negative. In that case, the |
| 2161 // next instruction is not executed and we fall through to bailing out to |
| 2162 // runtime. |
| 2163 // Executed if both r2 and r3 are untagged integers. |
| 2164 __ sub(r2, r2, Operand(r3), SetCC, cc); |
| 2165 // One of the above un-smis or the above SUB could have set N==1. |
| 2166 __ b(mi, &runtime); // Either "from" or "to" is not an smi, or from > to. |
| 2167 |
| 2168 // Make sure first argument is a string. |
| 2169 __ ldr(r0, MemOperand(sp, kStringOffset)); |
| 2170 __ JumpIfSmi(r0, &runtime); |
| 2171 Condition is_string = masm->IsObjectStringType(r0, r1); |
| 2172 __ b(NegateCondition(is_string), &runtime); |
| 2173 |
| 2174 Label single_char; |
| 2175 __ cmp(r2, Operand(1)); |
| 2176 __ b(eq, &single_char); |
| 2177 |
| 2178 // Short-cut for the case of trivial substring. |
| 2179 Label return_r0; |
| 2180 // r0: original string |
| 2181 // r2: result string length |
| 2182 __ ldr(r4, FieldMemOperand(r0, String::kLengthOffset)); |
| 2183 __ cmp(r2, Operand(r4, ASR, 1)); |
| 2184 // Return original string. |
| 2185 __ b(eq, &return_r0); |
| 2186 // Longer than original string's length or negative: unsafe arguments. |
| 2187 __ b(hi, &runtime); |
| 2188 // Shorter than original string's length: an actual substring. |
| 2189 |
| 2190 // Deal with different string types: update the index if necessary |
| 2191 // and put the underlying string into r5. |
| 2192 // r0: original string |
| 2193 // r1: instance type |
| 2194 // r2: length |
| 2195 // r3: from index (untagged) |
| 2196 Label underlying_unpacked, sliced_string, seq_or_external_string; |
| 2197 // If the string is not indirect, it can only be sequential or external. |
| 2198 STATIC_ASSERT(kIsIndirectStringMask == (kSlicedStringTag & kConsStringTag)); |
| 2199 STATIC_ASSERT(kIsIndirectStringMask != 0); |
| 2200 __ tst(r1, Operand(kIsIndirectStringMask)); |
| 2201 __ b(eq, &seq_or_external_string); |
| 2202 |
| 2203 __ tst(r1, Operand(kSlicedNotConsMask)); |
| 2204 __ b(ne, &sliced_string); |
| 2205 // Cons string. Check whether it is flat, then fetch first part. |
| 2206 __ ldr(r5, FieldMemOperand(r0, ConsString::kSecondOffset)); |
| 2207 __ CompareRoot(r5, Heap::kempty_stringRootIndex); |
| 2208 __ b(ne, &runtime); |
| 2209 __ ldr(r5, FieldMemOperand(r0, ConsString::kFirstOffset)); |
| 2210 // Update instance type. |
| 2211 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 2212 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 2213 __ jmp(&underlying_unpacked); |
| 2214 |
| 2215 __ bind(&sliced_string); |
| 2216 // Sliced string. Fetch parent and correct start index by offset. |
| 2217 __ ldr(r5, FieldMemOperand(r0, SlicedString::kParentOffset)); |
| 2218 __ ldr(r4, FieldMemOperand(r0, SlicedString::kOffsetOffset)); |
| 2219 __ add(r3, r3, Operand(r4, ASR, 1)); // Add offset to index. |
| 2220 // Update instance type. |
| 2221 __ ldr(r1, FieldMemOperand(r5, HeapObject::kMapOffset)); |
| 2222 __ ldrb(r1, FieldMemOperand(r1, Map::kInstanceTypeOffset)); |
| 2223 __ jmp(&underlying_unpacked); |
| 2224 |
| 2225 __ bind(&seq_or_external_string); |
| 2226 // Sequential or external string. Just move string to the expected register. |
| 2227 __ mov(r5, r0); |
| 2228 |
| 2229 __ bind(&underlying_unpacked); |
| 2230 |
| 2231 if (FLAG_string_slices) { |
| 2232 Label copy_routine; |
| 2233 // r5: underlying subject string |
| 2234 // r1: instance type of underlying subject string |
| 2235 // r2: length |
| 2236 // r3: adjusted start index (untagged) |
| 2237 __ cmp(r2, Operand(SlicedString::kMinLength)); |
| 2238 // Short slice. Copy instead of slicing. |
| 2239 __ b(lt, ©_routine); |
| 2240 // Allocate new sliced string. At this point we do not reload the instance |
| 2241 // type including the string encoding because we simply rely on the info |
| 2242 // provided by the original string. It does not matter if the original |
| 2243 // string's encoding is wrong because we always have to recheck encoding of |
| 2244 // the newly created string's parent anyways due to externalized strings. |
| 2245 Label two_byte_slice, set_slice_header; |
| 2246 STATIC_ASSERT((kStringEncodingMask & kOneByteStringTag) != 0); |
| 2247 STATIC_ASSERT((kStringEncodingMask & kTwoByteStringTag) == 0); |
| 2248 __ tst(r1, Operand(kStringEncodingMask)); |
| 2249 __ b(eq, &two_byte_slice); |
| 2250 __ AllocateOneByteSlicedString(r0, r2, r6, r4, &runtime); |
| 2251 __ jmp(&set_slice_header); |
| 2252 __ bind(&two_byte_slice); |
| 2253 __ AllocateTwoByteSlicedString(r0, r2, r6, r4, &runtime); |
| 2254 __ bind(&set_slice_header); |
| 2255 __ mov(r3, Operand(r3, LSL, 1)); |
| 2256 __ str(r5, FieldMemOperand(r0, SlicedString::kParentOffset)); |
| 2257 __ str(r3, FieldMemOperand(r0, SlicedString::kOffsetOffset)); |
| 2258 __ jmp(&return_r0); |
| 2259 |
| 2260 __ bind(©_routine); |
| 2261 } |
| 2262 |
| 2263 // r5: underlying subject string |
| 2264 // r1: instance type of underlying subject string |
| 2265 // r2: length |
| 2266 // r3: adjusted start index (untagged) |
| 2267 Label two_byte_sequential, sequential_string, allocate_result; |
| 2268 STATIC_ASSERT(kExternalStringTag != 0); |
| 2269 STATIC_ASSERT(kSeqStringTag == 0); |
| 2270 __ tst(r1, Operand(kExternalStringTag)); |
| 2271 __ b(eq, &sequential_string); |
| 2272 |
| 2273 // Handle external string. |
| 2274 // Rule out short external strings. |
| 2275 STATIC_ASSERT(kShortExternalStringTag != 0); |
| 2276 __ tst(r1, Operand(kShortExternalStringTag)); |
| 2277 __ b(ne, &runtime); |
| 2278 __ ldr(r5, FieldMemOperand(r5, ExternalString::kResourceDataOffset)); |
| 2279 // r5 already points to the first character of underlying string. |
| 2280 __ jmp(&allocate_result); |
| 2281 |
| 2282 __ bind(&sequential_string); |
| 2283 // Locate first character of underlying subject string. |
| 2284 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqOneByteString::kHeaderSize); |
| 2285 __ add(r5, r5, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
| 2286 |
| 2287 __ bind(&allocate_result); |
| 2288 // Sequential acii string. Allocate the result. |
| 2289 STATIC_ASSERT((kOneByteStringTag & kStringEncodingMask) != 0); |
| 2290 __ tst(r1, Operand(kStringEncodingMask)); |
| 2291 __ b(eq, &two_byte_sequential); |
| 2292 |
| 2293 // Allocate and copy the resulting one-byte string. |
| 2294 __ AllocateOneByteString(r0, r2, r4, r6, r1, &runtime); |
| 2295 |
| 2296 // Locate first character of substring to copy. |
| 2297 __ add(r5, r5, r3); |
| 2298 // Locate first character of result. |
| 2299 __ add(r1, r0, Operand(SeqOneByteString::kHeaderSize - kHeapObjectTag)); |
| 2300 |
| 2301 // r0: result string |
| 2302 // r1: first character of result string |
| 2303 // r2: result string length |
| 2304 // r5: first character of substring to copy |
| 2305 STATIC_ASSERT((SeqOneByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 2306 StringHelper::GenerateCopyCharacters( |
| 2307 masm, r1, r5, r2, r3, String::ONE_BYTE_ENCODING); |
| 2308 __ jmp(&return_r0); |
| 2309 |
| 2310 // Allocate and copy the resulting two-byte string. |
| 2311 __ bind(&two_byte_sequential); |
| 2312 __ AllocateTwoByteString(r0, r2, r4, r6, r1, &runtime); |
| 2313 |
| 2314 // Locate first character of substring to copy. |
| 2315 STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0); |
| 2316 __ add(r5, r5, Operand(r3, LSL, 1)); |
| 2317 // Locate first character of result. |
| 2318 __ add(r1, r0, Operand(SeqTwoByteString::kHeaderSize - kHeapObjectTag)); |
| 2319 |
| 2320 // r0: result string. |
| 2321 // r1: first character of result. |
| 2322 // r2: result length. |
| 2323 // r5: first character of substring to copy. |
| 2324 STATIC_ASSERT((SeqTwoByteString::kHeaderSize & kObjectAlignmentMask) == 0); |
| 2325 StringHelper::GenerateCopyCharacters( |
| 2326 masm, r1, r5, r2, r3, String::TWO_BYTE_ENCODING); |
| 2327 |
| 2328 __ bind(&return_r0); |
| 2329 Counters* counters = isolate()->counters(); |
| 2330 __ IncrementCounter(counters->sub_string_native(), 1, r3, r4); |
| 2331 __ Drop(3); |
| 2332 __ Ret(); |
| 2333 |
| 2334 // Just jump to runtime to create the sub string. |
| 2335 __ bind(&runtime); |
| 2336 __ TailCallRuntime(Runtime::kSubString); |
| 2337 |
| 2338 __ bind(&single_char); |
| 2339 // r0: original string |
| 2340 // r1: instance type |
| 2341 // r2: length |
| 2342 // r3: from index (untagged) |
| 2343 __ SmiTag(r3, r3); |
| 2344 StringCharAtGenerator generator(r0, r3, r2, r0, &runtime, &runtime, &runtime, |
| 2345 RECEIVER_IS_STRING); |
| 2346 generator.GenerateFast(masm); |
| 2347 __ Drop(3); |
| 2348 __ Ret(); |
| 2349 generator.SkipSlow(masm, &runtime); |
| 2350 } |
| 2351 |
2127 void ToStringStub::Generate(MacroAssembler* masm) { | 2352 void ToStringStub::Generate(MacroAssembler* masm) { |
2128 // The ToString stub takes one argument in r0. | 2353 // The ToString stub takes one argument in r0. |
2129 Label is_number; | 2354 Label is_number; |
2130 __ JumpIfSmi(r0, &is_number); | 2355 __ JumpIfSmi(r0, &is_number); |
2131 | 2356 |
2132 __ CompareObjectType(r0, r1, r1, FIRST_NONSTRING_TYPE); | 2357 __ CompareObjectType(r0, r1, r1, FIRST_NONSTRING_TYPE); |
2133 // r0: receiver | 2358 // r0: receiver |
2134 // r1: receiver instance type | 2359 // r1: receiver instance type |
2135 __ Ret(lo); | 2360 __ Ret(lo); |
2136 | 2361 |
(...skipping 2815 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4952 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, | 5177 CallApiFunctionAndReturn(masm, api_function_address, thunk_ref, |
4953 kStackUnwindSpace, NULL, return_value_operand, NULL); | 5178 kStackUnwindSpace, NULL, return_value_operand, NULL); |
4954 } | 5179 } |
4955 | 5180 |
4956 #undef __ | 5181 #undef __ |
4957 | 5182 |
4958 } // namespace internal | 5183 } // namespace internal |
4959 } // namespace v8 | 5184 } // namespace v8 |
4960 | 5185 |
4961 #endif // V8_TARGET_ARCH_ARM | 5186 #endif // V8_TARGET_ARCH_ARM |
OLD | NEW |