Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 30 Jul 2013 16:16:58 +0200
From:      Dimitry Andric <dim@freebsd.org>
To:        Matthew Fleming <mdf@freebsd.org>
Cc:        "svn-src-head@FreeBSD.org" <svn-src-head@freebsd.org>, "svn-src-all@FreeBSD.org" <svn-src-all@freebsd.org>, "src-committers@FreeBSD.org" <src-committers@freebsd.org>
Subject:   Re: svn commit: r253802 - head/contrib/llvm/tools/clang/lib/Headers
Message-ID:  <2DE35C45-B110-4D93-BFA7-542A3D1EE902@freebsd.org>
In-Reply-To: <CAMBSHm8xDvWsKJiLAzPF8azMKLHq3WWWQ3X1d6-6nJSAppux9Q@mail.gmail.com>
References:  <201307301233.r6UCXLT8012177@svn.freebsd.org> <CAMBSHm8xDvWsKJiLAzPF8azMKLHq3WWWQ3X1d6-6nJSAppux9Q@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Jul 30, 2013, at 16:09, Matthew Fleming <mdf@freebsd.org> wrote:
> On Tue, Jul 30, 2013 at 5:33 AM, Dimitry Andric <dim@freebsd.org> =
wrote:
> Author: dim
> Date: Tue Jul 30 12:33:21 2013
> New Revision: 253802
> URL: http://svnweb.freebsd.org/changeset/base/253802
>=20
> Log:
>   Pull in r186696 from upstream clang trunk:
>=20
>     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_<foo> 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_<foo>
>     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.
...
> +/* 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" \
...
> 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).
>=20
> 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?

Upstream gcc checks this with:

#if defined(__i386__) && defined(__PIC__)
...
#elif defined(__x86_64__) && (defined(__code_model_medium__) || =
defined(__code_model_large__)) && defined(__PIC__)
...

and it exchanges ebx or rbx with %k1 or %q1, respectively, instead of =
push/pop.  That might be a little more efficient.

I guess the defined(__PIC__) should be enough for us, in most cases.  =
The code_model stuff is for x32 support, which we do not have yet.

-Dimitry




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2DE35C45-B110-4D93-BFA7-542A3D1EE902>