On Jul 30, 2013, at 16:09, Matthew Fleming <m...@freebsd.org> wrote:
> On Tue, Jul 30, 2013 at 5:33 AM, Dimitry Andric <d...@freebsd.org> 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_<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).
> 
> 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

_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to