From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11733 invoked by alias); 30 May 2016 09:37:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 11191 invoked by uid 89); 30 May 2016 09:37:14 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.3 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=tricky, Bernd, bernd, encountered X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 30 May 2016 09:37:13 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0903B63147 for ; Mon, 30 May 2016 09:37:12 +0000 (UTC) Received: from oldenburg.str.redhat.com (dhcp-192-212.str.redhat.com [10.33.192.212]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u4U9bAmV032359 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 30 May 2016 05:37:11 -0400 Subject: Re: Thoughts on memcmp expansion (PR43052) To: Bernd Schmidt , GCC Patches , Nick Clifton References: <56992541.3090402@redhat.com> From: Florian Weimer Message-ID: <55238d87-b52b-b743-5a5f-5afb43355b26@redhat.com> Date: Mon, 30 May 2016 11:29:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <56992541.3090402@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2016-05/txt/msg02323.txt.bz2 On 01/15/2016 05:58 PM, Bernd Schmidt wrote: > One question Richard posed in the comments: why aren't we optimizing > small constant size memcmps other than size 1 to *s == *q? The reason is > the return value of memcmp, which implies byte-sized operation > (incidentally, the use of SImode in the cmpmem/cmpstr patterns is really > odd). It's possible to work around this, but expansion becomes a little > more tricky (subtract after bswap, maybe). When I did this (big-endian conversion, wide substract, sign) to the tail difference check in glibc's x86_64 memcmp, it was actually a bit faster than isolating the differing byte and returning its difference, even for non-random data such as encountered during qsort: > * Expand __memcmp_eq for small constant sizes with loads and > comparison, fall back to a memcmp call. Should we export such a function from glibc? I expect it's fairly common. Computing the tail difference costs a few cycles. It may also make sense to call a streamlined implementation if you have interesting alignment information (for x86_64, that would be at least 16 on one or both inputs, so it's perhaps not easy to come by). Florian