tech-toolchain archive

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

why does "gcc -march=native" give a warning?



So I'm still using a somewhat antiquated -current, NetBSD-8.88.32.

This comes with "gcc (nb4 20181109) 6.5.0".

I was recently trying to test some code for performance and thought I'd
try cpuflags(1) (version 1.43 from pkgsrc) to get the best compiler
options (somewhat ignoring the advice of the comment in the package
description):

	$ cpuflags
	-mfpmath=sse -msse3 -march=native

However I think For my Xeon X5460 CPU ("Harpertown", a Yorkfield-based,
i.e. "core2", but with the "Penryn" microarchitecture) this should
really be:

	-msse4.1 -march=core2

CPU features:

	cpu0: "Intel(R) Xeon(R) CPU           X5460  @ 3.16GHz"
	cpu0: Intel Xeon 31xx, 33xx, 52xx, 54xx, Core 2 Quad 8xxx and 9xxx (686-class)
	cpu0: family 0x6 model 0x17 stepping 0x6 (id 0x10676)
	cpu0: features 0x1fc9cbf5<FPU,DE,TSC,MSR,PAE,MCE,CX8,APIC,SEP,MCA,CMOV,PAT>
	cpu0: features 0x1fc9cbf5<CLFLUSH,ACPI,MMX,FXSR,SSE,SSE2,SS,HTT>
	cpu0: features1 0x82201<SSE3,SSSE3,CX16,SSE41>
	cpu0: features2 0x20100800<SYSCALL/SYSRET,XD,EM64T>
	cpu0: features3 0x1<LAHF>


In any case the use of "-march=native" causes a warning from cc1:

	$ cc -O3 $(cpuflags) -o thello thello.c
	thello.c:1:0: error: bad value (native) for -march= switch
	 #include <stdio.h>
	 


Hmmmm....  This caused me a lot of deep dives down blind (and usually
dead-end) alleys, and I still don't quite see why this is happening.

From what I understand from elsewhere cc1 does not like/allow the
generic "native" CPU-type -- it seems to expect the front-end driver to
have figured out the exact CPU-type and to have passed that, but
apparently my front-end driver isn't doing that (though indeed I see in
the driver-i386.c source file the helpers to do exactly that).  (GCC
code is excessively complex, convoluted, and hard to read!)

From what I read elsewhere it seems somewhere between very hard and
impossible to tell exactly what a "normal" GCC will do with a CPU type
of "native" -- i.e. at runtime, for the current host CPU, even with the
help of the "-Q --help=target" option.  Well at least for me "cc
-march=native -Q --help-target" does still just show "-march=" (and thus
"-mtune=") as having been set to "native" (or whatever else is passed on
the command-line), so that's no help.

So, is this warning a bug?  Has it been fixed in more recent releases?

-- 
					Greg A. Woods <gwoods%acm.org@localhost>

Kelowna, BC     +1 250 762-7675           RoboHack <woods%robohack.ca@localhost>
Planix, Inc. <woods%planix.com@localhost>     Avoncote Farms <woods%avoncote.ca@localhost>

Attachment: pgp65aLrwp4FD.pgp
Description: OpenPGP Digital Signature



Home | Main Index | Thread Index | Old Index