1 /* 2 * String's indexOf. 3 * 4 * Requires r0 to have been previously checked for null. Will 5 * return index of match of r1 in r0. 6 * 7 * IMPORTANT NOTE: 8 * 9 * This code relies on hard-coded offsets for string objects, and must be 10 * kept in sync wth definitions in UtfString.h See asm-constants.h 11 * 12 * On entry: 13 * r0: string object pointer 14 * r1: char to match 15 * r2: Starting offset in string data 16 */ 17 18 ldr r3, [r0, #STRING_FIELDOFF_VALUE] 19 ldr r7, [r0, #STRING_FIELDOFF_OFFSET] 20 ldr r8, [r0, #STRING_FIELDOFF_COUNT] 21 22 23 /* 24 * At this point, we have: 25 * r1: char to match 26 * r2: starting offset 27 * r3: object pointer (final result -> r0) 28 * r7: offset 29 * r8: string length 30 */ 31 32 /* Build pointer to start of string data */ 33 add r3, #16 34 add r0, r3, r7, lsl #1 35 36 /* Save a copy of starting data in r7 */ 37 mov r7, r0 38 39 /* Clamp start to [0..count] */ 40 cmp r2, #0 41 movlt r2, #0 42 cmp r2, r8 43 movgt r2, r8 44 45 /* Build pointer to start of data to compare and pre-bias */ 46 add r0, r0, r2, lsl #1 47 sub r0, #2 48 49 /* Compute iteration count */ 50 sub r8, r2 51 52 /* 53 * At this point we have: 54 * r0: start of data to test 55 * r1: chat to compare 56 * r8: iteration count 57 * r7: original start of string 58 * r3, r4, r9, r10, r11, r12 available for loading string data 59 */ 60 61 subs r8, #4 62 blt indexof_remainder 63 64 indexof_loop4: 65 ldrh r3, [r0, #2]! 66 ldrh r4, [r0, #2]! 67 ldrh r10, [r0, #2]! 68 ldrh r11, [r0, #2]! 69 cmp r3, r1 70 beq match_0 71 cmp r4, r1 72 beq match_1 73 cmp r10, r1 74 beq match_2 75 cmp r11, r1 76 beq match_3 77 subs r8, #4 78 bge indexof_loop4 79 80 indexof_remainder: 81 adds r8, #4 82 beq indexof_nomatch 83 84 indexof_loop1: 85 ldrh r3, [r0, #2]! 86 cmp r3, r1 87 beq match_3 88 subs r8, #1 89 bne indexof_loop1 90 91 indexof_nomatch: 92 mov r0, #-1 93 bx lr 94 95 match_0: 96 sub r0, #6 97 sub r0, r7 98 asr r0, r0, #1 99 bx lr 100 match_1: 101 sub r0, #4 102 sub r0, r7 103 asr r0, r0, #1 104 bx lr 105 match_2: 106 sub r0, #2 107 sub r0, r7 108 asr r0, r0, #1 109 bx lr 110 match_3: 111 sub r0, r7 112 asr r0, r0, #1 113 bx lr 114