1/* 2Copyright (c) 2009 Nick Clifton <nickc@redhat.com> 3 */ 4#include <picolibc.h> 5 6 .file "strncmp.S" 7 8 .section .text 9 .global _strncmp 10 .type _strncmp,@function 11_strncmp: 12 ;; R1: string1 13 ;; R2: string2 14 ;; R3: max number of bytes to compare 15#ifdef __RX_DISALLOW_STRING_INSNS__ 16 cmp #0, r3 ; For a length of zero, return zero 17 beq 4f 18 192: mov.b [r1+], r4 20 mov.b [r2+], r5 21 cmp #0, r4 22 beq 3f 23 cmp #0, r5 24 beq 3f 25 sub #1, r3 26 beq 3f 27 cmp r4, r5 28 beq 2b 29 303: and #0xff, r4 ; We need to perform an unsigned comparison of the bytes. 31 and #0xff, r5 32 sub r5, r4, r1 33 rts 34 354: mov #0, r1 36 rts 37#else 38 scmpu ; Perform the string comparison 39 bnc 1f ; If Carry is not set skip over 40 scne.L r1 ; Set result based on Z flag 41 rts ; 421: ; 43 mov #-1,r1 ; Carry not set, result should be negative 44 rts ; 45#endif 46 .size _strncmp, . - _strncmp 47