From owner-freebsd-arm@FreeBSD.ORG Thu Apr 30 17:06:02 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 69839106566C for ; Thu, 30 Apr 2009 17:06:02 +0000 (UTC) (envelope-from tinguely@casselton.net) Received: from casselton.net (casselton.net [63.165.140.2]) by mx1.freebsd.org (Postfix) with ESMTP id DA16A8FC15 for ; Thu, 30 Apr 2009 17:06:01 +0000 (UTC) (envelope-from tinguely@casselton.net) Received: from casselton.net (localhost [127.0.0.1]) by casselton.net (8.14.3/8.14.3) with ESMTP id n3UH5w3l057500; Thu, 30 Apr 2009 12:05:58 -0500 (CDT) (envelope-from tinguely@casselton.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=casselton.net; s=ccnMail; t=1241111158; bh=c8SPUKGIjFDRIICzJcjJB1XIuYSdIX5CzANxmwmh1Es=; h=Date:From:Message-Id:To:Subject:Cc:In-Reply-To; b=C7I72v5nBZxi4iv5rBpMYrtZ1WDRSu6iZ6jOoOIlw2VNXWdrRUXSA5cBO7gpMBmRm NM0oSiQ8vzDH5iCb+3kbqTA4jjXlhJ09n59d9BBsD3UGa+CZeM2ZO0AZQLtZbYh8Ce 6eLs1jl8eIJCTM/eF3qw2B0F3VNkZ7aB23AAXPI8= Received: (from tinguely@localhost) by casselton.net (8.14.3/8.14.2/Submit) id n3UH5wg2057498; Thu, 30 Apr 2009 12:05:58 -0500 (CDT) (envelope-from tinguely) Date: Thu, 30 Apr 2009 12:05:58 -0500 (CDT) From: Mark Tinguely Message-Id: <200904301705.n3UH5wg2057498@casselton.net> To: channa.kad@gmail.com, imp@bsdimp.com In-Reply-To: <20090430.000846.1484329326.imp@bsdimp.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.1.10 (casselton.net [127.0.0.1]); Thu, 30 Apr 2009 12:05:58 -0500 (CDT) 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: Thu, 30 Apr 2009 17:06:02 -0000 > Yes. We should get the following results: > > strncmp("a", "b", 0); 0 > strncmp("a", "b", *); < 0 > > where * is any other number :) > > Warner ENTRY(strncmp) /* if (len == 0) return 0 */ cmp r2, #0 moveq r0, #0 RETeq /* ip == last src address to compare */ add ip, r0, r2 1: ldrb r2, [r0], #1 ldrb r3, [r1], #1 cmp ip, r0 - cmpcs r2, #1 + beq 2f + cmp r2, #1 cmpcs r2, r3 beq 1b +2: sub r0, r2, r3 RET also ip < r0 if r2 = (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 noise. The above code, though, should work in all cases. strncmp("b", "a", 0) result is 0 strncmp("abcdef", "abcdef", n) result is 0 strncmp("abcde", "abcdef", n) 0 if 0 <= n < 6 neg if n < 0 or n > 5 strncmp("abcdef", "abcde", n) 0 if 0 <= n < 6 pos if n < 0 or n > 5 The "beq" will break out of the loop if we give a count <= the string length the first arguement. The next cmp looks for the NULL byte, and the last cmp checks the characters in the strings. --Mark.