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 r7, [r0, #STRING_FIELDOFF_OFFSET] 19 ldr r8, [r0, #STRING_FIELDOFF_COUNT] 20 ldr r0, [r0, #STRING_FIELDOFF_VALUE] 21 22 /* 23 * At this point, we have: 24 * r0: object pointer 25 * r1: char to match 26 * r2: starting offset 27 * r7: offset 28 * r8: string length 29 */ 30 31 /* Build pointer to start of string data */ 32 add r0, #16 33 add r0, r0, r7, lsl #1 34 35 /* Save a copy of starting data in r7 */ 36 mov r7, r0 37 38 /* Clamp start to [0..count] */ 39 cmp r2, #0 40 movlt r2, #0 41 cmp r2, r8 42 movgt r2, r8 43 44 /* Build pointer to start of data to compare and pre-bias */ 45 add r0, r0, r2, lsl #1 46 sub r0, #2 47 48 /* Compute iteration count */ 49 sub r8, r2 50 51 /* 52 * At this point we have: 53 * r0: start of data to test 54 * r1: chat to compare 55 * r8: iteration count 56 * r7: original start of string 57 * r3, r4, r9, r10, r11, r12 available for loading string data 58 */ 59 60 subs r8, #4 61 blt indexof_remainder 62 63 indexof_loop4: 64 ldrh r3, [r0, #2]! 65 ldrh r4, [r0, #2]! 66 ldrh r10, [r0, #2]! 67 ldrh r11, [r0, #2]! 68 cmp r3, r1 69 beq match_0 70 cmp r4, r1 71 beq match_1 72 cmp r10, r1 73 beq match_2 74 cmp r11, r1 75 beq match_3 76 subs r8, #4 77 bge indexof_loop4 78 79 indexof_remainder: 80 adds r8, #4 81 beq indexof_nomatch 82 83 indexof_loop1: 84 ldrh r3, [r0, #2]! 85 cmp r3, r1 86 beq match_3 87 subs r8, #1 88 bne indexof_loop1 89 90 indexof_nomatch: 91 mov r0, #-1 92 bx lr 93 94 match_0: 95 sub r0, #6 96 sub r0, r7 97 asr r0, r0, #1 98 bx lr 99 match_1: 100 sub r0, #4 101 sub r0, r7 102 asr r0, r0, #1 103 bx lr 104 match_2: 105 sub r0, #2 106 sub r0, r7 107 asr r0, r0, #1 108 bx lr 109 match_3: 110 sub r0, r7 111 asr r0, r0, #1 112 bx lr 113