From owner-freebsd-arm@FreeBSD.ORG Mon May 4 07:27:04 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 5F1BA106566C for ; Mon, 4 May 2009 07:27:04 +0000 (UTC) (envelope-from venkiece2005@gmail.com) Received: from mail-gx0-f162.google.com (mail-gx0-f162.google.com [209.85.217.162]) by mx1.freebsd.org (Postfix) with ESMTP id DC4E78FC0C for ; Mon, 4 May 2009 07:27:03 +0000 (UTC) (envelope-from venkiece2005@gmail.com) Received: by gxk6 with SMTP id 6so763119gxk.19 for ; Mon, 04 May 2009 00:27:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:cc:content-type; bh=EumS6Zh+FqPcMCu9q5/DFbtlZg3Ou6T4fhOYmx6ezG8=; b=c/6nksYnaKGPyL3C0hzSNb27+HHVI38yWlbX/o8qYxu/vcY6toR5p37zn6+I+QpKmJ ISoirij1esn+deaFnolQlIACJxj/2hj2O0lHmf6Gl5wEZqSzpF9BiGzlsetYv0mnYVUY 1ykJFDE2F9y3iBKDZ/Uadn6t0lWR71peS5Kls= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:cc:content-type; b=VnGpijkY/81vVSwpQMIb/aKzC13LxLwchYUSXYcixXPrxT9/6zLQu5oiL21MkfHQDC 0mw8uJcaLv2HGs1RNdn7I0F027UD8/TZk0fmr2veGUMmk8pNI8Zco5Uv+1ClEJD0AERW /f11qyTGpW0Z+p2yODIkSzxL/VN51dl+XqXxw= MIME-Version: 1.0 Received: by 10.151.124.6 with SMTP id b6mr11372646ybn.160.1241420625269; Mon, 04 May 2009 00:03:45 -0700 (PDT) Date: Mon, 4 May 2009 12:33:45 +0530 Message-ID: <6d53329e0905040003sf72dddax16512347142ade3c@mail.gmail.com> From: venki kaps To: tinguely@casselton.net Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Cc: freebsd-arm@freebsd.org Subject: Regarding strncmp fix 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 07:27:05 -0000 Hi, This is my idea only. strncmp problem report: ======================== In the following below website: *http://archive.netbsd.se/?ml=freebsd-arm&a=2009-04&m=10547557* Hi, I am using the freebsd implementation of strncmp for ARM which is an assembly implementation. I have a small doubt, when i tested the strncmp by passing the third argument: 'n' as -1 the return values is '0' instead it should '-1'. When the third argument to strncmp is as below: ret = strncmp("a","b",-1) I think the assembly implementation in > src/lib/libc/arm/string/strncmp.S file needs to be modified to take care of the above condition. In the current implementation /* if ((len - 1) subs r2, r2, #1 movmi r0, #0 RETc(mi) This should be changed to check as below /* if ((len ) /* Assembly code here */ FreeBSD source: =============== ENTRY(strncmp) /* if ((len - 1) < 0) return 0 */ subs r2, r2, #1 movmi r0, #0 RETc(mi) /* 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 cmpcs r2, r3 beq 1b sub r0, r2, r3 RET Tinguely has given one solution for this: 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 The above fix is nice. But small change in the fix: 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 + cmp r2, #1 /* to igonre Carry falg set (unsigned higher or same) */ cmpcs r2, r3 beq 1b sub r0, r2, r3 RET Branch to 2f is not required since conditional assemblers automatically calls subroutine when compare fails. And also we can reduce no. of cycles(3 cycles) since 3 cycles required to branch. But I have one smaller query: Will it support the above code in the ARM-thumb mode? NOTE: Thumb mode and traditional mode instruction sets are different. Thumb mode implementation: /* if (len == 0) return 0 */ cmp r2, #0 bne 1f mov r0, #0 RET 1: /* ip == last src address to compare */ add ip, r0, r2 2: cmp ip, r0 beq 3f ldrb r2, [r0] add r0, r0, #1 ldrb r3, [r1] add r1, r1, #1 cmp r2, #0 beq 3f cmp r2, r3 beq 2b 3: sub r0, r2, r3 RET Will need to support both thumb mode as well as traditional mode? Example: #ifdef __thumb__ /* thumb code here */ #else /* traditional code here */ #endif Thanks & Regards, Venkappa