Date: Mon, 4 May 2009 12:22:49 +0530 From: Channa <channa.kad@gmail.com> To: Mark Tinguely <tinguely@casselton.net>, Olivier Houchard <mlfbsd@ci0.org> Cc: freebsd-arm@freebsd.org Subject: Re: strncmp issue Message-ID: <515c64960905032352j25edfbcajb3d146fa769b97bb@mail.gmail.com> In-Reply-To: <200904301705.n3UH5wg2057498@casselton.net> References: <20090430.000846.1484329326.imp@bsdimp.com> <200904301705.n3UH5wg2057498@casselton.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Hi, Thanks for the fix. I used your code and tested it works fine. But i have one doubt in the code below you have added : - cmpcs r2, #1 + beq 2f + cmp r2, #1 : Instead of the branch instruction above replace the instruction 'cmpcs' with 'cmp' since we are comparing unsigned value in 'r2' with a constant. So the code looks as below : - cmpcs r2, #1 + cmp r2, #1 : I have tested the above fix it works good for me. Please let me know your views. Thanks & Regards, Channa 2009/4/30 Mark Tinguely <tinguely@casselton.net>: > >> =A0Yes. =A0We should get the following results: >> >> =A0 =A0 =A0 strncmp("a", "b", 0); =A0 =A0 0 >> =A0 =A0 =A0 strncmp("a", "b", *); =A0 =A0 < 0 >> >> =A0where * is any other number :) >> >> =A0Warner > > ENTRY(strncmp) > /* if (len =3D=3D 0) return 0 */ > =A0 =A0 =A0 =A0cmp =A0 =A0 r2, #0 > =A0 =A0 =A0 =A0moveq =A0 r0, #0 > =A0 =A0 =A0 =A0RETeq > > /* ip =3D=3D last src address to compare */ > =A0 =A0 =A0 =A0add =A0 =A0 ip, r0, r2 > 1: > =A0 =A0 =A0 =A0ldrb =A0 =A0r2, [r0], #1 > =A0 =A0 =A0 =A0ldrb =A0 =A0r3, [r1], #1 > =A0 =A0 =A0 =A0cmp =A0 =A0 ip, r0 > - =A0 =A0 =A0 cmpcs =A0 r2, #1 > + =A0 =A0 =A0 beq =A0 =A0 2f > + =A0 =A0 =A0 cmp =A0 =A0 r2, #1 > =A0 =A0 =A0 =A0cmpcs =A0 r2, r3 > =A0 =A0 =A0 =A0beq =A0 =A0 1b > +2: > =A0 =A0 =A0 =A0sub =A0 =A0 r0, r2, r3 > =A0 =A0 =A0 =A0RET > > also ip < r0 if r2 =3D (unsigned int) -1 using 32 bit math. so original > loop will terminate and compare the first characters. For example > strncmp("ab", "aa", -1) will result is 0. > > I sent Olivier a couple patches, both wrong. Again, sorry for all the noi= se. > > The above code, though, should work in all cases. > > =A0 =A0 =A0 =A0strncmp("b", "a", 0) =A0result is 0 > =A0 =A0 =A0 =A0strncmp("abcdef", "abcdef", n) =A0result is 0 > =A0 =A0 =A0 =A0strncmp("abcde", "abcdef", n) =A0 0 if 0 <=3D n < 6 =A0neg= if n < 0 or n > 5 > =A0 =A0 =A0 =A0strncmp("abcdef", "abcde", n) =A0 0 if 0 <=3D n < 6 =A0pos= if n < 0 or n > 5 > > > The "beq" will break out of the loop if we give a count <=3D the string > length the first arguement. > > The next cmp looks for the NULL byte, and the last cmp checks the charact= ers > in the strings. > > --Mark. >
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?515c64960905032352j25edfbcajb3d146fa769b97bb>