From owner-svn-src-head@freebsd.org Sat Sep 9 07:14:44 2017 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 11177E07105; Sat, 9 Sep 2017 07:14:44 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from theravensnest.org (xvm-110-62.dc2.ghst.net [46.226.110.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "theravensnest.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8F27383508; Sat, 9 Sep 2017 07:14:42 +0000 (UTC) (envelope-from theraven@FreeBSD.org) Received: from [192.168.1.65] (host86-138-54-151.range86-138.btcentralplus.com [86.138.54.151]) (authenticated bits=0) by theravensnest.org (8.15.2/8.15.2) with ESMTPSA id v897EYm4084821 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 9 Sep 2017 07:14:35 GMT (envelope-from theraven@FreeBSD.org) X-Authentication-Warning: d60e724c-75b0-4b63-9702-f4a9d2bf6793: Host host86-138-54-151.range86-138.btcentralplus.com [86.138.54.151] claimed to be [192.168.1.65] Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: Re: svn commit: r323329 - head/sys/sys From: David Chisnall In-Reply-To: <201709082009.v88K9EGW006964@repo.freebsd.org> Date: Sat, 9 Sep 2017 08:14:30 +0100 Cc: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <9BE7B1BD-DE1A-48FE-B247-A3CE7674648E@FreeBSD.org> References: <201709082009.v88K9EGW006964@repo.freebsd.org> To: Mateusz Guzik X-Mailer: Apple Mail (2.3273) X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 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: Sat, 09 Sep 2017 07:14:44 -0000 On 8 Sep 2017, at 21:09, Mateusz Guzik wrote: >=20 > Author: mjg > Date: Fri Sep 8 20:09:14 2017 > New Revision: 323329 > URL: https://svnweb.freebsd.org/changeset/base/323329 >=20 > Log: > Allow __builtin_memset instead of bzero for small buffers of known = size This change seems redundant, because modern compilers already do this = optimisation. For example: #include =09 char buf[42]; =09 void bz(void) { bzero(buf, 42); } With clang 4.0 on x86 compiles to: pushq %rbp movq %rsp, %rbp xorps %xmm0, %xmm0 movups %xmm0, buf+26(%rip) movaps %xmm0, buf+16(%rip) movaps %xmm0, buf(%rip) popq %rbp retq On AArch64, it compiles to: adrp x8, buf add x8, x8, :lo12:buf strh wzr, [x8, #40] stp xzr, xzr, [x8, #24] stp xzr, xzr, [x8, #8] str xzr, [x8] ret Neither contains a call, both have inlined the zeroing. This change is = strictly worse, because the compiler has some carefully tuned heuristics = that are set per target for when to inline the memset / bzero and when = to call the function. These are based on both the size and the = alignment, including whether the target supports misaligned accesses and = whether misaligned accesses are cheap. None of this is captured by this = change. In the kernel, this optimisation is disabled by -ffreestanding, however = __builtin_memset will be turned into a memset call if the size is not = constant or if the memset call would be more efficient (as determined by = the aforementioned heuristics). Simply using __builtin_memset in all = cases should give better code, and is more likely to be forward = compatible with future ISAs where the arbitrary constant picked in this = patch may or may not be optimal. David