Date: Mon, 4 May 2009 07:59:55 -0500 (CDT) From: Mark Tinguely <tinguely@casselton.net> To: channa.kad@gmail.com, mlfbsd@ci0.org, tinguely@casselton.net, venkiece2005@gmail.com Cc: freebsd-arm@freebsd.org Subject: Re: strncmp issue Message-ID: <200905041259.n44CxtV2077931@casselton.net> In-Reply-To: <515c64960905032352j25edfbcajb3d146fa769b97bb@mail.gmail.com>
index | next in thread | previous in thread | raw e-mail
Hi, the propose code by both of you two:
/* if (len == 0) return 0 */
cmp r2, #0
moveq r0, #0
moveq pc, lr
/* ip == last src address to compare */
add ip, r0, r2
1:
ldrb r2, [r0], #1
ldrb r3, [r1], #1
cmp ip, r0
cmp r2, #1
cmpcs r2, r3
beq 1b
sub r0, r2, r3
That was one of my failed attempts. I to was hoping to not add the branch
to cut down in cycles. A person has to test every possible call to strncmp.
This will fail on a positive string length less than strlen length of the
input strings:
strncmp("abcdefg", "abcdefh", 6)
Will return (-1) str1 < str2 at 6 characters which is wrong.
/* if (len == 0) return 0 */
cmp r2, #0
moveq r0, #0
moveq pc, lr
/* ip == last src address to compare */
add ip, r0, r2
1:
ldrb r2, [r0], #1
ldrb r3, [r1], #1
cmp ip, r0
beq 2f <- stops in the case where strlen(s1) > len
cmp r2, #1 <- stops thea NULL case, we can't just change
the comparison because below we loop on
an equality and can end up in a big loop
cmpcs r2, r3 <- compare characters.
beq 1b
2:
sub r0, r2, r3
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200905041259.n44CxtV2077931>
