From owner-svn-src-head@freebsd.org Thu Aug 13 09:45:05 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B371799FABC; Thu, 13 Aug 2015 09:45:05 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail108.syd.optusnet.com.au (mail108.syd.optusnet.com.au [211.29.132.59]) by mx1.freebsd.org (Postfix) with ESMTP id 675D8F67; Thu, 13 Aug 2015 09:45:05 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from c211-30-166-197.carlnfd1.nsw.optusnet.com.au (c211-30-166-197.carlnfd1.nsw.optusnet.com.au [211.30.166.197]) by mail108.syd.optusnet.com.au (Postfix) with ESMTPS id C86A61A2DE9; Thu, 13 Aug 2015 19:44:54 +1000 (AEST) Date: Thu, 13 Aug 2015 19:44:53 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: David Chisnall cc: araujo@freebsd.org, "src-committers@freebsd.org" , "svn-src-all@freebsd.org" , "svn-src-head@freebsd.org" Subject: Re: svn commit: r286715 - head/lib/libc/string In-Reply-To: <0CFBA0CC-FEEE-40CE-BC47-065613C64293@FreeBSD.org> Message-ID: <20150813175120.F2152@besplex.bde.org> References: <201508130231.t7D2VOhc069855@repo.freebsd.org> <20150813134548.U1375@besplex.bde.org> <0CFBA0CC-FEEE-40CE-BC47-065613C64293@FreeBSD.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.1 cv=XMDNMlVE c=1 sm=1 tr=0 a=KA6XNC2GZCFrdESI5ZmdjQ==:117 a=PO7r1zJSAAAA:8 a=JzwRw_2MAAAA:8 a=kj9zAlcOel0A:10 a=pGLkceISAAAA:8 a=FXohseXW_oZzt_8xRucA:9 a=gdfBHrrxH7VcuoAt:21 a=Os2WNlZjV-2A-W07:21 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 13 Aug 2015 09:45:05 -0000 On Thu, 13 Aug 2015, David Chisnall wrote: > On 13 Aug 2015, at 08:11, Marcelo Araujo wrote: >> >> The bcopy() was removed in IEEE Std 1003.1-2008 and it is marked as LEGACY in IEEE Std 1003.1-2004. However, BSD has its implementation before IEEE Std 1003.1-2001. >> >> In my understood it is obsolete on POSIX, but not truly obsolete for FreeBSD. >> So I believe, this patch now address it in the correct way. > > Its use should be strongly discouraged in FreeBSD (or, ideally, replaced with the macro from the POSIX man page). LLVM does a load of optimisations for memmove and memcpy - using bcopy is a really good way of bypassing all of these. That is a good reason to use bcopy. Compilers are clueless about caches, so their optimizations tend to be negative. clang has a nice one now, not related to caches. It uses SSE if possible for small fixed-size memcpy's, so takes a few hundred cycles longer for the first memcpy per context switch if SSE would not have otherwise be used. Compilers cannot know if this is a good optimization. If this were important, then someone except me would have noticed that switching to -ffreestanding in the kernel turned off all builtins including the one for memcpy(). But it really is unimportant. Most copying in the kernel is done by pagecopy(), and the possible gains from optimizing that are on the order of 1% except in micro-benchmarks that arrange to do excessive pagecopy()s. The possible gains from optimizations in the memcpy() builtin are much smaller. The possible gains from restoring all builtins may be as much as 1%. I recently noticed bcmp() showing up in benchmarks. Only 1% for makeworld, but that is a lot for a single function. clang doesn't bother optimizing memcmp() and calls the library. gcc-4.2.1 pessimizes memcmp using "rep cmpsb" on x86 (gcc used to use a similar pessimization for memcpy(), but learned better. Strangely, "rep movsb" is now the best method on Haswell except for small counts where gcc used to use it). The library and kernel memcmp()s are not as bad as gcc's, but they still use "rep movs[lq]" and this is still slow on Haswell. Simple C code is more than 6 times faster in micro-benchmarks on Haswell. The FreeBSD library MI C code is a little too simple. It uses bytewise compares, so it it beats "rep cmpsb" but not "rep cmpsl". Bruce