Re: "-march=native" possibly being misled on Debian i386?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Jun 11, 2017 at 1:33 PM, Xi Ruoyao <ryxi@xxxxxxxxxxxxxxxxx> wrote:
> On 2017-06-11 09:29 +0200, Toby Douglass wrote:

>> However, when I look in /usr/lib, I find this...
>>
>> /usr/lib/i386-linux-gnu
>
> This is just Debian multiarch hierarchy specification.
> Irrelevant with your issue.

Ah, so.  Yes.  I can install other archs, and they will turn up there
with their names

Stll, it indicates what the current system thinks it is, and I thought
that might relate in some way to what the GCC driver is doing, when it
guesses what the native system is.

>> But when I use "-march=native", like so; "gcc -march=native -dM -E - <
>> /dev/null | grep 86"
>>
>> I only get this!
>>
>> #define __i386 1
>> #define __i386__ 1
>> #define i386 1
>
> In the first case, the architecture is decided by "--with-arch=" when
> GCC was configured.

Yes.  When I make my own compiler, targetting i586, I get __586__.
When I do the same are target i686, I get __686__.

> In the second case, the architecture is guessed by GCC driver.

Right.

> Use "gcc [-march=native] -E -x c /dev/null -v".  And see the flag
> "-march=xxx" passed to `cc1` by `gcc` to figure out the real
> architecture GCC used.

Using the OS GCC (4.9.2, native build for i586-linux-gnu);

WIthout, I get arch i586, tune generic.

With, I get - ha! - "-march=native", and no tune.

>> Now, I may be completely wrong, but it looks to me where the OS is
>> pretending to be i386, it's actually misleading the mechanism behind
>> "-march=native".  There *is* no actual i686 Debian build, so I can't
>> just use that instead of the i386 Debian.
>
> No. I don't think so.  GCC is guessing the architecture for
> "-march=native" using "cpuid" instruction on x86.  GCC doesn't
> look at OS.

Hmm, that is very interesting.  I have an E640.  The result conflicts
with the Debian installer, which selected i686.  I wonder how the
Debian installer guesses.

> See the source code of
> gcc_source/gcc/config/i386/driver-i386.c: host_detect_local_cpu.

Huh.  I didn't know there was an instrinsic for "cpuid".  There's one
on Windows, too, actually.  Doesn't help me at compile time, unless I
run something to generate the makefile.

I've read through the code.  I'm thinking about compiling a debug
build and running it in the debugger to see what it does in
host_detect_local_cpu.  The processor here is a Atom E640, which may
just be confusing the compiler.  The processor was released in 2010.
GCC 4.8.5 and 4.9.2 both came out over five years later, though.

>> I want to use "-march=native" because it means the makefile selects
>> the correct target for whomever is building.
>
> I doubt it.  '__i386__' is defined for all 32-bit x86 architectures,
> but '__i686__' is only for "-march=i686", not its 'subsets'.

But that seems right, and it is what I expect.

> For example, on my laptop (x86-64, multilib), I can use
> "gcc -m32 -march=native". But then GCC guessed out
> "-
> march=ivybridge" and the macro "__corei7_avx__" was defined,
> instead of "__i686__".

Ooof.  That does not sound like what I'd want to have happen,
certainly from a compiler define point of view.

>> Any advice, insight, corrections, words of wisdom, etc?
>
> I think it's better to use configuration script (maybe generated
> by GNU autoconf) to get the architecture from several tests.

I was hoping never to use autconf.  Needing to learn a new language
(m4) to generate makefiles is not appealling! :-P :-)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux