From owner-freebsd-arm@FreeBSD.ORG Mon May 4 06:52:50 2009 Return-Path: Delivered-To: freebsd-arm@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DB68E1065673 for ; Mon, 4 May 2009 06:52:50 +0000 (UTC) (envelope-from channa.kad@gmail.com) Received: from yw-out-2324.google.com (yw-out-2324.google.com [74.125.46.30]) by mx1.freebsd.org (Postfix) with ESMTP id 9339D8FC0A for ; Mon, 4 May 2009 06:52:50 +0000 (UTC) (envelope-from channa.kad@gmail.com) Received: by yw-out-2324.google.com with SMTP id 9so2280623ywe.13 for ; Sun, 03 May 2009 23:52:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=mo7VdURgpXWc6IeHv9+TQpUdDvqO1ohZWrSkNA77jDM=; b=Z9YR0wBYiXKFi+Kpx7H3eBx9kjM8eyb48pDIm0gtYS8J4pnEiGJddl+MhNagbEE/FK FnT5G07kR5pdGL5sRfjPHrjcHodUhK96Mtrabj6zUc/TantfePaIrhwsHOpoLcF+Yn2P ZDLDL7/v8UYf4yItMNL677dMw+w85sulRYoZQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Hh5SptOR6qRR9kxFdWHUbeOh7pH6d5z5diWogEI6zZgMrqiJQi8vCedqMV8pyfld7+ y8RbsCMZNBKcwBkTXRawVWgikTfxTYgP/B1mtDYjhXb8wYZjtk5UuTwrW6e4q9V08kX0 HXS5LocdSZs2fTzuZcuXDdfxYGg3m0wd1RrDA= MIME-Version: 1.0 Received: by 10.100.197.3 with SMTP id u3mr12535061anf.20.1241419969713; Sun, 03 May 2009 23:52:49 -0700 (PDT) In-Reply-To: <200904301705.n3UH5wg2057498@casselton.net> References: <20090430.000846.1484329326.imp@bsdimp.com> <200904301705.n3UH5wg2057498@casselton.net> Date: Mon, 4 May 2009 12:22:49 +0530 Message-ID: <515c64960905032352j25edfbcajb3d146fa769b97bb@mail.gmail.com> From: Channa To: Mark Tinguely , Olivier Houchard Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: freebsd-arm@freebsd.org Subject: Re: strncmp issue X-BeenThere: freebsd-arm@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the StrongARM Processor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 May 2009 06:52:51 -0000 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 : > >> =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. >