From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10501 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: memchr() performance Date: Mon, 19 Sep 2016 09:37:35 -0400 Message-ID: <20160919133735.GD15995@brightrain.aerifal.cx> References: <20160918185422.GA2577@dell12.lru.li> <20160918204036.GZ1280@port70.net> <20160919132953.GA8375@dell12.lru.li> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1474292290 2435 195.159.176.226 (19 Sep 2016 13:38:10 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 19 Sep 2016 13:38:10 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-10514-gllmg-musl=m.gmane.org@lists.openwall.com Mon Sep 19 15:38:02 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1blylb-0006v6-DF for gllmg-musl@m.gmane.org; Mon, 19 Sep 2016 15:37:51 +0200 Original-Received: (qmail 3650 invoked by uid 550); 19 Sep 2016 13:37:51 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 3629 invoked from network); 19 Sep 2016 13:37:50 -0000 Content-Disposition: inline In-Reply-To: <20160919132953.GA8375@dell12.lru.li> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:10501 Archived-At: On Mon, Sep 19, 2016 at 03:29:53PM +0200, Georg Sauthoff wrote: > On Sun, Sep 18, 2016 at 10:40:36PM +0200, Szabolcs Nagy wrote: > > Hello, > > > * Georg Sauthoff [2016-09-18 20:54:22 +0200]: > > [..] > > > > On recent Intel CPUs it is even slower than a naive implementation: > > > > > > https://gms.tf/stdfind-and-memchr-optimizations.html#measurements > > > https://gms.tf/sparc-and-ppc-find-benchmark-results.html > > > > > > Of course, on x86, other implementations that use SIMD instructions > > > perform even better. > > > yes simd is expected to be faster. > > > but that needs asm which is expensive to maintain (there is no > > portable simd language extension for c and there is the aliasing > > issue: the reinterpret_cast in your code is formally ub). > > you mean because the vector-word pointer returned by reinterpret_cast is > used to access vector-words in the memory passed via a char pointer and > this is not covered by the ISO C++ strict aliasing rules? > > Yes. Sure, ub means that anything can happen, but this case should be ok > with GCC - if the function is compiled in isolation in its own > translation unit. > > I mean, there isn't much possibiltiy for reordering due to the > application of strict-aliasing-rules that would yield a different > result. > > There are no aliased write accesses. > > Btw, the current musl memchr() implementation has similar aliased > accesses - there, unsigned characters are aliased via a size_t pointer. Yes, that's a known bug with a pending patch - see: http://www.openwall.com/lists/musl/2016/04/27/8 Rich