From nobody@FreeBSD.org  Fri May 25 15:15:23 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 9DE5C16A421
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 25 May 2007 15:15:23 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id 8B84913C44B
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 25 May 2007 15:15:23 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l4PFFNMe028895
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 25 May 2007 15:15:23 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l4PFFM9Q028894;
	Fri, 25 May 2007 15:15:22 GMT
	(envelope-from nobody)
Message-Id: <200705251515.l4PFFM9Q028894@www.freebsd.org>
Date: Fri, 25 May 2007 15:15:22 GMT
From: Scot Hetzel<swhetzel@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Add note about the 'native' mtune option to share/examples/etc/make.conf
X-Send-Pr-Version: www-3.0

>Number:         112997
>Category:       misc
>Synopsis:       [bsd.cpu.mk] [patch] Add note about the 'native' mtune option
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri May 25 15:20:02 GMT 2007
>Closed-Date:    
>Last-Modified:  Sun May 04 04:21:21 UTC 2014
>Originator:     Scot Hetzel
>Release:        7.0-CURRENT
>Organization:
>Environment:
FreeBSD hp010.hetzel.org 7.0-CURRENT FreeBSD 7.0-CURRENT #0: Thu May 24 21:37:39 CDT 2007     root@hp010.hetzel.org:/usr/src/7x/sys-p4/amd64/compile/GENERIC.debug  amd64

>Description:
On the AMD64 mailing list there was a discussion on what to set CPUTYPE
to for a users system.  During the discussion, the new 'native' mtune
option for gcc 4.2 was brought up.  This option allows gcc to automatically
tune the compile for the processor that the machine is being built on for
the x86 and AMD64 architectures.

We need to warn users to not set CPUTYPE to 'native' in /etc/make.conf,
as CPUTYPE is used to determine the value of MACHINE_CPU. But instead to use:

gcc -v -x c -E -mtune=native /dev/null -o /dev/null 2>&1 | grep mtune | sed -e 's/.*mtune=//'

to determine the value of CPUTYPE for their system.
>How-To-Repeat:

>Fix:
apply attached patch to share/examples/etc/make.conf

Patch attached with submission follows:

Index: make.conf
===================================================================
RCS file: /home/ncvs/src/share/examples/etc/make.conf,v
retrieving revision 1.279
diff -u -r1.279 make.conf
--- make.conf	17 Jan 2007 12:43:06 -0000	1.279
+++ make.conf	25 May 2007 15:08:52 -0000
@@ -40,6 +40,17 @@
 #   AMD64 architecture: opteron, athlon64, nocona, prescott, core2
 #   Intel ia64 architecture: itanium2, itanium
 #
+# On the Intel x86 and AMD architectures, you can use gcc to determine
+# determine the processor type of the compiling machine by using the
+# following command:
+#
+# gcc -v -x c -E -mtune=native /dev/null -o /dev/null 2>&1 | grep mtune | sed -e 's/.*mtune=//'
+#
+# set CPUTYPE to the value returned for mtune.
+#
+# NOTE: DO NOT set CPUTYPE to 'native' in make.conf, as CPUTYPE is used to
+#       set MACHINE_CPU in share/mk/bsd.cpu.mk.
+#
 # (?= allows to buildworld for a different CPUTYPE.)
 #
 #CPUTYPE?=pentium3


>Release-Note:
>Audit-Trail:

From: "Scot Hetzel" <swhetzel@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org, freebsd-bugs@freebsd.org
Cc:  
Subject: Re: conf/112997: Add note about the 'native' mtune option to share/examples/etc/make.conf
Date: Fri, 25 May 2007 10:37:37 -0500

 The patch has one error, remove the second '-e' from the sed command.
 
 [linimon note: I have gone ahead and done this in the above code]
 
 -- 
 DISCLAIMER:
 No electrons were mamed while sending this message. Only slightly bruised.

From: "Scot Hetzel" <swhetzel@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:  
Subject: Re: conf/112997: Add note about the 'native' mtune option to share/examples/etc/make.conf
Date: Tue, 28 Aug 2007 01:04:24 -0500

 ------=_Part_6081_32633261.1188281064325
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 I found another solution to this problem by patching share/mk/bsd.cpu.mk.
 
 This patch adds code to share/mk/bsd.cpu.mk which uses gcc to change
 the 'native' cpu_type to the a CPUTYPE that can be used to set the
 correct MACHINE_CPU.
 
 Scot
 
 -- 
 DISCLAIMER:
 No electrons were mamed while sending this message. Only slightly bruised.
 
 ------=_Part_6081_32633261.1188281064325
 Content-Type: text/x-diff; name=gcc_native.patch; charset=ANSI_X3.4-1968
 Content-Transfer-Encoding: base64
 X-Attachment-Id: file0
 Content-Disposition: attachment; filename="gcc_native.patch"
 
 SW5kZXg6IHNoYXJlL21rL2JzZC5jcHUubWsKPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTogL2hvbWUvbmN2
 cy9zcmMvc2hhcmUvbWsvYnNkLmNwdS5tayx2CnJldHJpZXZpbmcgcmV2aXNpb24gMS42MgpkaWZm
 IC11IC1yMS42MiBic2QuY3B1Lm1rCi0tLSBzaGFyZS9tay9ic2QuY3B1Lm1rCTIxIE1heSAyMDA3
 IDA4OjM5OjQ0IC0wMDAwCTEuNjIKKysrIHNoYXJlL21rL2JzZC5jcHUubWsJMjggQXVnIDIwMDcg
 MDU6NTA6MDkgLTAwMDAKQEAgLTE4LDYgKzE4LDE0IEBACiAuIGVuZGlmCiAuZWxzZQogCisjIEhh
 bmRsZSAnbmF0aXZlJyBieSBjb252ZXJ0aW5nIGl0IHRvIHRoZSBhcHByb3ByaWF0ZSBDUFVUWVBF
 CisKKy5pZiAke01BQ0hJTkVfQVJDSH0gPT0gImkzODYiIHx8ICR7TUFDSElORV9BUkNIfSA9PSAi
 YW1kNjQiCisuIGlmICR7Q1BVVFlQRX0gPT0gIm5hdGl2ZSIKK0NQVVRZUEUgIT0gZ2NjIC12IC14
 IGMgLUUgLW10dW5lPW5hdGl2ZSAvZGV2L251bGwgLW8gL2Rldi9udWxsIDI+JjEgfCBncmVwIG10
 dW5lIHwgc2VkIC1lICdzLy4qbXR1bmU9Ly8nCisuIGVuZGlmCisuZW5kaWYKKwogIyBIYW5kbGUg
 YWxpYXNlcyAobm90IGRvY3VtZW50ZWQgaW4gbWFrZS5jb25mIHRvIGF2b2lkIHVzZXIgY29uZnVz
 aW9uCiAjIGJldHdlZW4gZS5nLiBpNTg2IGFuZCBwZW50aXVtKQogCg==
 ------=_Part_6081_32633261.1188281064325--

From: "Remko Lodder" <remko@FreeBSD.org>
To: "Scot Hetzel" <swhetzel@gmail.com>
Cc: freebsd-bugs@freebsd.org,
 bug-followup@FreeBSD.org
Subject: Re: conf/112997: Add note about the 'native' mtune option to 
     share/examples/etc/make.conf
Date: Tue, 28 Aug 2007 08:49:25 +0200 (CEST)

 Hello,
 
 The attached patch was unreadable, can you perhaps copy paste it in, or
 attach it as .txt file?
 
 Thanks!
 
 
 
 -- 
 Kind regards,
 
      Remko Lodder               ** remko@elvandar.org
      FreeBSD                    ** remko@FreeBSD.org
 
      /* Quis custodiet ipsos custodes */
 

From: "Scot Hetzel" <swhetzel@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:  
Subject: Re: conf/112997: Add note about the 'native' mtune option to share/examples/etc/make.conf
Date: Tue, 28 Aug 2007 01:58:03 -0500

 ------=_Part_6217_7670961.1188284283612
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 On 8/28/07, Remko Lodder <remko@freebsd.org> wrote:
 >
 > Hello,
 >
 > The attached patch was unreadable, can you perhaps copy paste it in, or
 > attach it as .txt file?
 >
 I have to remember to add .txt when sending patches thru gmail.
 
 Scot
 
 ------=_Part_6217_7670961.1188284283612
 Content-Type: text/plain; name=gcc_native.txt; charset=ANSI_X3.4-1968
 Content-Transfer-Encoding: base64
 X-Attachment-Id: f_f5w1pd55
 Content-Disposition: attachment; filename="gcc_native.txt"
 
 SW5kZXg6IHNoYXJlL21rL2JzZC5jcHUubWsKPT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
 PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQpSQ1MgZmlsZTogL2hvbWUvbmN2
 cy9zcmMvc2hhcmUvbWsvYnNkLmNwdS5tayx2CnJldHJpZXZpbmcgcmV2aXNpb24gMS42MgpkaWZm
 IC11IC1yMS42MiBic2QuY3B1Lm1rCi0tLSBzaGFyZS9tay9ic2QuY3B1Lm1rCTIxIE1heSAyMDA3
 IDA4OjM5OjQ0IC0wMDAwCTEuNjIKKysrIHNoYXJlL21rL2JzZC5jcHUubWsJMjggQXVnIDIwMDcg
 MDU6NTA6MDkgLTAwMDAKQEAgLTE4LDYgKzE4LDE0IEBACiAuIGVuZGlmCiAuZWxzZQogCisjIEhh
 bmRsZSAnbmF0aXZlJyBieSBjb252ZXJ0aW5nIGl0IHRvIHRoZSBhcHByb3ByaWF0ZSBDUFVUWVBF
 CisKKy5pZiAke01BQ0hJTkVfQVJDSH0gPT0gImkzODYiIHx8ICR7TUFDSElORV9BUkNIfSA9PSAi
 YW1kNjQiCisuIGlmICR7Q1BVVFlQRX0gPT0gIm5hdGl2ZSIKK0NQVVRZUEUgIT0gZ2NjIC12IC14
 IGMgLUUgLW10dW5lPW5hdGl2ZSAvZGV2L251bGwgLW8gL2Rldi9udWxsIDI+JjEgfCBncmVwIG10
 dW5lIHwgc2VkIC1lICdzLy4qbXR1bmU9Ly8nCisuIGVuZGlmCisuZW5kaWYKKwogIyBIYW5kbGUg
 YWxpYXNlcyAobm90IGRvY3VtZW50ZWQgaW4gbWFrZS5jb25mIHRvIGF2b2lkIHVzZXIgY29uZnVz
 aW9uCiAjIGJldHdlZW4gZS5nLiBpNTg2IGFuZCBwZW50aXVtKQogCg==
 ------=_Part_6217_7670961.1188284283612--

From: "Scot Hetzel" <swhetzel@gmail.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:  
Subject: Re: conf/112997: Add note about the 'native' mtune option to share/examples/etc/make.conf
Date: Tue, 28 Aug 2007 02:24:07 -0500

 On 8/28/07, Scot Hetzel <swhetzel@gmail.com> wrote:
 > On 8/28/07, Remko Lodder <remko@freebsd.org> wrote:
 > >
 > > Hello,
 > >
 > > The attached patch was unreadable, can you perhaps copy paste it in, or
 > > attach it as .txt file?
 > >
 > I have to remember to add .txt when sending patches thru gmail.
 >
 I give up, no ideal as to why gnats/gmail is converting the attachment
 to base64 encoding, the patch is available in this post:
 
 http://lists.freebsd.org/pipermail/freebsd-current/2007-August/076503.html
 
 Scot
 -- 
 DISCLAIMER:
 No electrons were mamed while sending this message. Only slightly bruised.

From: Anonymous <swell.k@gmail.com>
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: conf/112997: [patch] Add note about the 'native' mtune option to share/examples/etc/make.conf
Date: Mon, 03 May 2010 15:18:33 +0400

 I disagree, native and ${YOUR_CPU} aren't equivalent. Here is what I get
 on gcc45 + core2@amd64 system:
 
   $ cc -E -v -march=core2 - </dev/null |& fgrep cc1
   .../cc1 -E -quiet -v - -march=core2
 
   $ cc -E -v -mtune=core2 - </dev/null |& fgrep cc1
   .../cc1 -E -quiet -v - -mtune=core2 -march=x86-64
 
   $ cc -E -v -march=native - </dev/null |& fgrep cc1
   .../cc1 -E -quiet -v - -march=core2 -mcx16 -msahf -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -mtune=core2
 
   $ cc -E -v -mtune=native - </dev/null |& fgrep cc1
   .../cc1 -E -quiet -v - --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=6144 -mtune=core2 -march=x86-64
 
 And bsd.cpu.mk is oblivious about gcc43+. It will degrade native to
 nocona even though core2 is supported. Good example that overriding
 CPUTYPE is bad idea.
 
 Better leave CPUTYPE as is and populate MACHINE_CPU directly, smth like
 
   $ cat a.mk
   CPUTYPE = ${MACHINE_ARCH}
   MACHINE_CPU != echo ${MACHINE_ARCH}; ${CC} -E -dM -v -march=${CPUTYPE:S/amd64/x86-64/:S/i386/i486/} - </dev/null 2>&1 \
           | awk '/SSE|MMX/ && !/MATH/ { FS="__"; gsub("_",".",$$2); print tolower($$2) }'
 
   $ make -f a.mk -V MACHINE_CPU
   amd64 mmx sse2 sse
   $ make -f a.mk -V MACHINE_CPU CPUTYPE=native
   amd64 sse4.1 mmx sse2 ssse3 sse sse3
   $ make -f a.mk -V MACHINE_CPU CPUTYPE=native CC=/usr/bin/cc
   amd64 mmx sse sse2 sse3

From: "b. f." <bf1783@googlemail.com>
To: bug-followup@FreeBSD.org
Cc: Scot Hetzel <swhetzel@gmail.com>
Subject: Re: conf/112997: [patch] Add note about the 'native' mtune option to share/examples/etc/make.conf
Date: Sun, 5 Sep 2010 01:22:03 +0000

 It is very inefficient to invoke gcc, grep, and/or awk every time this
 makefile is processed.  (In the past, we've gone to a great deal of
 trouble to avoid this kind of thing:
 
 http://lists.freebsd.org/pipermail/freebsd-ports/2008-July/049777.html
 http://lists.freebsd.org/pipermail/cvs-ports/2008-July/153224.html
 
 )  Instead, I think that comments in /etc/make.conf instructing users
 to how to correctly specify their CPUTYPE would be appropriate.  The
 list of overrides for the base system compiler should be expanded, and
 perhaps relaxed if CC != cc.  But _all_ overrides cannot be removed,
 and MACHINE_CPU cannot be expanded to include all features recognized
 by compilers from ports, because the kernel lacks the necessary
 support for things like SSE5/XOP+FMA4+CVT16, LWP, AVX, etc.
 
 b.
>Unformatted:
