1/* Copyright (c) 2009 Nick Clifton <nickc@redhat.com> */ 2 .file "memchr.S" 3 4 .section .text 5 6 .global _memchr 7 .type _memchr,@function 8_memchr: 9 ;; R1: string pointer 10 ;; R2: byte sought 11 ;; R3: max number to scan 12#ifdef __RX_DISALLOW_STRING_INSNS__ 13 mov.b r2, r2 ; The mov.b below sign extends as it loads, so make sure that r2 is sign-extended as well. 142: cmp #0, r3 15 beq 1f 16 sub #1, r3 17 mov.b [r1+], r5 18 cmp r5, r2 19 bne 2b 20 21 sub #1, r1 ; We have found a match, bit now R1 points to the byte after the match. 221: rts 23#else 24 cmp #0, r3 ; If r3 is 0 suntil.b will do nothing and not set any flags... 25 stz #1, r1 ; ...so store 1 into r1. It will be decremented by the SUB later. 26 suntil.b ; Search until *r1 == r2 or r3 bytes have been examined. 27 stnz #1, r1 ; If no match was found return NULL. 28 sub #1, r1 ; suntil.b leaves r1 pointing at the address *after* the match. 29 rts 30#endif 31 32 .size _memchr, . - _memchr 33 34