From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21708 invoked by alias); 10 Aug 2002 16:54:06 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 21563 invoked from network); 10 Aug 2002 16:54:06 -0000 Received: from unknown (HELO Cantor.suse.de) (213.95.15.193) by sources.redhat.com with SMTP; 10 Aug 2002 16:54:06 -0000 Received: from Hermes.suse.de (Charybdis.suse.de [213.95.15.201]) by Cantor.suse.de (Postfix) with ESMTP id 8E127147A7 for ; Sat, 10 Aug 2002 18:54:05 +0200 (MEST) Received: from aj by arthur.inka.de with local (Exim 3.34 #1) id 17dZV5-0008DW-00 for libc-hacker@sources.redhat.com; Sat, 10 Aug 2002 18:54:03 +0200 To: GNU libc hacker Subject: i386/strchr.S broken? From: Andreas Jaeger Date: Sat, 10 Aug 2002 09:54:00 -0000 Message-ID: User-Agent: Gnus/5.090008 (Oort Gnus v0.08) XEmacs/21.4 (Artificial Intelligence, i386-suse-linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-SW-Source: 2002-08/txt/msg00109.txt.bz2 Looking at the i386/strchr.S file I noticed: L(7): testb %cl, %cl /* is first byte C? */ jz L(6) /* yes => return pointer */ cmpb %dl, %cl /* is first byte NUL? */ je L(2) /* yes => return NULL */ incl %eax /* it's not in the first byte */ This looks broken to me, IMO it should be: L(7): testb %cl, %cl /* is first byte NUL? */ jz L(2) /* yes => return NULL */ cmpb %dl, %cl /* is first byte C? */ je L(6) /* yes => return pointer */ incl %eax /* it's not in the first byte */ I'm appending an (untested) patch. Ok to commit for both branches? The i586 version looks fine, Andreas 2002-08-10 Andreas Jaeger * sysdeps/i386/strchr.S: Correct implementation. ============================================================ Index: sysdeps/i386/strchr.S --- sysdeps/i386/strchr.S 6 Jul 2001 04:55:52 -0000 1.11 +++ sysdeps/i386/strchr.S 10 Aug 2002 16:52:38 -0000 @@ -1,6 +1,6 @@ /* strchr (str, ch) -- Return pointer to first occurrence of CH in STR. For Intel 80x86, x>=3. - Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000 Free Software Foundation, Inc. + Copyright (C) 1994, 1995, 1996, 1997, 1999, 2000, 2002 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper Some optimisations by Alan Modra @@ -256,23 +256,23 @@ L(71): addl $4, %eax But we have to take care of the case that a NUL char is found before this in the dword. */ -L(7): testb %cl, %cl /* is first byte C? */ - jz L(6) /* yes => return pointer */ - cmpb %dl, %cl /* is first byte NUL? */ +L(7): testb %cl, %cl /* is first byte NUL? */ je L(2) /* yes => return NULL */ + cmpb %dl, %cl /* is first byte C? */ + jz L(6) /* yes => return pointer */ incl %eax /* it's not in the first byte */ - testb %ch, %ch /* is second byte C? */ - jz L(6) /* yes => return pointer */ - cmpb %dl, %ch /* is second byte NUL? */ + testb %ch, %ch /* is second byte NUL? */ je L(2) /* yes => return NULL? */ + cmpb %dl, %ch /* is second byte C? */ + jz L(6) /* yes => return pointer */ incl %eax /* it's not in the second byte */ shrl $16, %ecx /* make upper byte accessible */ - testb %cl, %cl /* is third byte C? */ - jz L(6) /* yes => return pointer */ - cmpb %dl, %cl /* is third byte NUL? */ + testb %cl, %cl /* is third byte NUL? */ je L(2) /* yes => return NULL */ + cmpb %dl, %cl /* is third byte C? */ + jz L(6) /* yes => return pointer */ /* It must be in the fourth byte and it cannot be NUL. */ incl %eax -- Andreas Jaeger SuSE Labs aj@suse.de private aj@arthur.inka.de http://www.suse.de/~aj