From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111134 invoked by alias); 20 Dec 2016 17:19:10 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 111124 invoked by uid 89); 20 Dec 2016 17:19:09 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy=Hx-languages-length:1639 X-HELO: mail-qk0-f193.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=b3J8ci/ivA6yQrSdwtNhmZwnuGUPZNjJwWnzdM6cy5w=; b=E9RALQaMZm8q3j1XJRRgFavhF10EkVgmCB4YYFNFK3nTRQV1h9nIxIOvxUbrV5KZ+g PD41o3bMC1vMhb9NQLhJLELG8MZwCOpYmRI0T0SWQHQMWxqIPAGckri6OJo1tsjH9Sml 1cd62ay4G7vzjHNbuLy3ESpRPXUZVn7bSXbDzLSYlYXlH/WTR/aMqb13hWkjRo61Lri+ QWOdSWUk/zXEjOzjnGdoc6CkDm7TxlXWK14+Gw1P/hAKJ61ba+lWtTkvgfQiIz8dmxRc 7t2hycaOSpvtjJZqUmJeUxAHyd40KYDL2LmX1Db1gMguLTlxy9L1AoCjtjb+VDn4r9I4 nFKA== X-Gm-Message-State: AIkVDXLtny06hZWsgGTjZWiOLa78EfIkQ5oN5aClo8hdqcIPw1EvXVciXZJTamg/iOuZ3w== X-Received: by 10.55.165.129 with SMTP id o123mr473523qke.32.1482254346704; Tue, 20 Dec 2016 09:19:06 -0800 (PST) Subject: Re: [PATCH 06/11] Improve generic memrchr To: Adhemerval Zanella , libc-alpha@sourceware.org References: <20161217065729.28561-1-rth@twiddle.net> <20161217065729.28561-7-rth@twiddle.net> From: Richard Henderson Message-ID: <9ef65589-a3a6-7199-e713-53d4cd98a3cb@twiddle.net> Date: Tue, 20 Dec 2016 17:19:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2016-12/txt/msg00774.txt.bz2 On 12/20/2016 04:30 AM, Adhemerval Zanella wrote: > This implementation has a lot of issues, checking on both x86_64 and i386 > (by manually removing the assembly implementation to use the new default > one) I am seeing a lot of issues with string/testers and others. > Unfortunately the test-memrchr itself does not trigger most of the issues. I did notice problems by eye when going through the patch set for the second time. It is unfortunate that the tester doesn't trigger them. >> + align = (uintptr_t)char_ptr % sizeof(longword); >> + for (i = 0; i < align; ++i) >> if (*--char_ptr == c) >> - return (__ptr_t) char_ptr; >> + return (void *) char_ptr; > > We need to take care of 'n' while interacting over the string to align > it. It might the case where 's' is unaligned and 'n' is less than > the aligned value. As for memchr, I had intended if (align > n) align = n; >> + found: >> + i = whichzero (longword); >> + if (sizeof (longword) - 1 - i < n) >> + return (char *) longword_ptr + i; > > We need to check longword in reverse word since we are checking for last > occurrence. Well, yes and no. We check from reverse but want the last match. So it's still a forward search. What's needed is to mask out any match that is excluded by N. I currently have /* Handle any remaining portion of a word. */ if (n > 0) { word = *--word_ptr ^ repeated_c; /* Mask out the garbage bytes. */ op_t m = -1; if (__BYTE_ORDER == __LITTLE_ENDIAN) m <<= n * CHAR_BIT; else m >>= n * CHAR_BIT; word |= ~m; if (haszero (word)) { found: return (char *) word_ptr + findzero (word); } } r~