From owner-svn-src-all@FreeBSD.ORG Mon Apr 20 14:52:46 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C7EB6BE2; Mon, 20 Apr 2015 14:52:46 +0000 (UTC) Received: from mail110.syd.optusnet.com.au (mail110.syd.optusnet.com.au [211.29.132.97]) by mx1.freebsd.org (Postfix) with ESMTP id 8ABA8D73; Mon, 20 Apr 2015 14:52:45 +0000 (UTC) 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 mail110.syd.optusnet.com.au (Postfix) with ESMTPS id 498EC7814AC; Tue, 21 Apr 2015 00:52:36 +1000 (AEST) Date: Tue, 21 Apr 2015 00:52:35 +1000 (EST) From: Bruce Evans X-X-Sender: bde@besplex.bde.org To: Bruce Evans cc: Konstantin Belousov , Jung-uk Kim , Alan Cox , John Baldwin , src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r280279 - head/sys/sys In-Reply-To: <20150420220347.B9956@besplex.bde.org> Message-ID: <20150421003316.M10305@besplex.bde.org> References: <201503201027.t2KAR6Ze053047@svn.freebsd.org> <550DA656.5060004@FreeBSD.org> <20150322080015.O955@besplex.bde.org> <17035816.lxyzYKiOWV@ralph.baldwin.cx> <552BFEB2.8040407@rice.edu> <552C215D.8020107@FreeBSD.org> <20150420115351.GD2390@kib.kiev.ua> <20150420220347.B9956@besplex.bde.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=ZuzUdbLG c=1 sm=1 tr=0 a=KA6XNC2GZCFrdESI5ZmdjQ==:117 a=PO7r1zJSAAAA:8 a=kj9zAlcOel0A:10 a=JzwRw_2MAAAA:8 a=RFWfT8eTE1r12Y_Lx4gA:9 a=CjuIK1q_8ugA:10 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Apr 2015 14:52:46 -0000 On Tue, 21 Apr 2015, Bruce Evans wrote: > On Mon, 20 Apr 2015, Konstantin Belousov wrote: > >> On Mon, Apr 13, 2015 at 04:04:45PM -0400, Jung-uk Kim wrote: >>> Please try the attached patch. >>> ... >>> - __asm __volatile("xorl %k0,%k0;popcntq %1,%0" >>> - : "=&r" (result) : "rm" (elem)); >>> ... >>> + __asm __volatile("xorl %k0, %k0; popcntq %1, %0" >>> + : "=r" (count) : "m" (pc_map[field])); >> ... >> Yes, this worked for me the same way as for you, the argument is taken >> directly from memory, without temporary spill. Is this due to silly >> inliner ? Whatever the reason is, I think a comment should be added >> noting the subtlety. >> >> Otherwise, looks fine. > > Erm, this looks silly. It apparently works by making things too complicated > for the compiler to "optimize" (where one of the optimizations actually > gives pessimal spills). Its main changes are: > ... > It works better to change the constraint to "r": It's even sillier than that. The problem is not limited to this function. clang seems to prefer memory whenever you use the "rm" constraint. The silliest case is when you have a chain of simple asm functions. Say the original popcntq (without the xorl): return (popcntq(popcntq(popcntq(popcntq(popcntq(x)))))); gcc compiles this to 5 sequential popcntq instructions, but clang spills the results of the first 4. This is an old bug. clang does this on FreeBSD[9-11]. cc does this on FreeBSD[10-11] (not on FreeBSD-9 since cc = gcc there. Asms should always use "rm" if "m" works. Ones in cpufunc.h always do except for lidt(), lldt() and ltr(). These 3 are fixed in my version. So cpufunc.h almost always asks for the pessimization. Bruce