From owner-svn-src-head@FreeBSD.ORG Tue Jul 30 16:18:46 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id A5552E7; Tue, 30 Jul 2013 16:18:46 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 628132D5A; Tue, 30 Jul 2013 16:18:46 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 15BFFB977; Tue, 30 Jul 2013 12:18:45 -0400 (EDT) From: John Baldwin To: Matthew Fleming Subject: Re: svn commit: r253802 - head/contrib/llvm/tools/clang/lib/Headers Date: Tue, 30 Jul 2013 12:16:15 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p28; KDE/4.5.5; amd64; ; ) References: <201307301233.r6UCXLT8012177@svn.freebsd.org> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-15" Content-Transfer-Encoding: 7bit Message-Id: <201307301216.15235.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 30 Jul 2013 12:18:45 -0400 (EDT) Cc: "svn-src-head@freebsd.org" , "svn-src-all@freebsd.org" , "src-committers@freebsd.org" , Dimitry Andric X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 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: Tue, 30 Jul 2013 16:18:46 -0000 On Tuesday, July 30, 2013 10:09:35 am Matthew Fleming wrote: > On Tue, Jul 30, 2013 at 5:33 AM, Dimitry Andric wrote: > > > Author: dim > > Date: Tue Jul 30 12:33:21 2013 > > New Revision: 253802 > > URL: http://svnweb.freebsd.org/changeset/base/253802 > > > > Log: > > Pull in r186696 from upstream clang trunk: > > > > This patch implements __get_cpuid_max() as an inline and __cpuid() > > and __cpuid_count() as macros to be compatible with GCC's cpuid.h. > > It also adds bit_ constants for the various feature bits as > > described in version 039 (May 2011) of Intel's SDM Volume 2 in the > > description of the CPUID instruction. The list of bit_ > > constants is a bit exhaustive (GCC doesn't do near this many). More > > bits could be added from a newer version of SDM if desired. > > > > Patch by John Baldwin! > > > > This should fix several ports which depend on this functionality being > > available. > > > > MFC after: 1 week > > > > Modified: > > head/contrib/llvm/tools/clang/lib/Headers/cpuid.h > > > > Modified: head/contrib/llvm/tools/clang/lib/Headers/cpuid.h > > > > ============================================================================== > > --- head/contrib/llvm/tools/clang/lib/Headers/cpuid.h Tue Jul 30 > > 12:17:45 2013 (r253801) > > +++ head/contrib/llvm/tools/clang/lib/Headers/cpuid.h Tue Jul 30 > > 12:33:21 2013 (r253802) > > +/* PIC on i386 uses %ebx, so preserve it. */ > > +#if __i386__ > > +#define __cpuid(__level, __eax, __ebx, __ecx, __edx) \ > > + __asm(" pushl %%ebx\n" \ > > + " cpuid\n" \ > > + " mov %%ebx,%1\n" \ > > + " popl %%ebx" \ > > + : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \ > > + : "0"(__level)) > > + > > +#define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \ > > + __asm(" pushl %%ebx\n" \ > > + " cpuid\n" \ > > + " mov %%ebx,%1\n" \ > > + " popl %%ebx" \ > > + : "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \ > > + : "0"(__level), "2"(__count)) > > +#else > > +#define __cpuid(__level, __eax, __ebx, __ecx, __edx) \ > > + __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \ > > + : "0"(__level)) > > + > > +#define __cpuid_count(__level, __count, __eax, __ebx, __ecx, __edx) \ > > + __asm("cpuid" : "=a"(__eax), "=b" (__ebx), "=c"(__ecx), "=d"(__edx) \ > > + : "0"(__level), "2"(__count)) > > +#endif > > > > PIC mode on amd64 also uses %ebx. The difference is that FreeBSD makefiles > set -fPIC for i386 kernel compile but not amd64. Locally we use -fPIC for > amd64 (it was added 6 years ago to our environment because it gave better > kernel debugging). Note that this is used in userland and the kernel. > Anyways, is there some way to detect PIC mode and use that to decide > whether to use %ebx for the cpuid instruction, rather than using i386? Does clang supply a reliable #define to indicate that PIC is in use? If not, then this should use the PIC path always to be safe. -- John Baldwin