From nobody@FreeBSD.org  Sun Jul 25 12:24:47 2010
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id EC228106566B
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Jul 2010 12:24:47 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 1E70F8FC1F
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Jul 2010 12:24:48 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id o6PCOl1J059268
	for <freebsd-gnats-submit@FreeBSD.org>; Sun, 25 Jul 2010 12:24:47 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id o6PCOkSV059267;
	Sun, 25 Jul 2010 12:24:46 GMT
	(envelope-from nobody)
Message-Id: <201007251224.o6PCOkSV059267@www.freebsd.org>
Date: Sun, 25 Jul 2010 12:24:46 GMT
From: Yuri Karaban <tech@askold.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: make gcc generate i486 code by default
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         148926
>Category:       gnu
>Synopsis:       [patch] make gcc generate i486 code by default
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    tijl
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Jul 25 12:30:10 UTC 2010
>Closed-Date:    Tue Sep 21 15:13:06 CEST 2010
>Last-Modified:  Tue Sep 21 15:13:06 CEST 2010
>Originator:     Yuri Karaban
>Release:        8.1-RELEASE
>Organization:
>Environment:
>Description:
Since FreeBSD does not support a 80386 processor, and minimum supported system is i486 it is good idea to enable i486 code generation by default.

Standard C++ library (libstdc++) can benefit from this change. The library uses atomic operation for thread safety. Function which perform atomic operation may be either synthesized as inline functions in case if synthesized operations are supported, and as library functions (like __gnu_cxx::__exchange_and_add) otherwise.

The problem that libstdc++ ensures that synthesized operations are supported by compiler with default options and disable support if not. It is logical decision, because libstdc++ must be usable whenever source compiled with explicit -march or not.

Since FreeBSD gcc producing i386 code by default, libstdc++ can't use synthesized operations (because for example atomic exchange and add instruction "xadd" is not supported on i386).

So I think enabling i486 code generation by default, and enabling atomic builtins in libstdc++ can give good performance boost, because locking operation in libstdc++ is used extensively.

Default options for gcc is located in configargs.h, which is generated by /usr/src/gnu/usr.bin/cc/cc_tools/Makefile.

And can me changed like:

--- Makefile.orig
+++ Makefile
@@ -321,7 +321,7 @@
 	echo 'static const struct {'				>> ${.TARGET}
 	echo '	const char *name, *value;'			>> ${.TARGET}
 	echo '} configure_default_options[] = {'		>> ${.TARGET}
-	echo '	{ "NULL", "NULL" } };'				>> ${.TARGET}
+	echo '	{ "arch", "i486" } };'				>> ${.TARGET}
 
 GENSRCS+=	configargs.h
 
(of course this change must be applied only on i386 architecture)
>How-To-Repeat:

>Fix:


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-i386->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Jul 27 00:41:08 UTC 2010 
Responsible-Changed-Why:  
reclassify. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=148926 

From: Tijl Coosemans <tijl@coosemans.org>
To: bug-followup@freebsd.org, tech@askold.net
Cc:  
Subject: Re: gnu/148926: [patch] make gcc generate i486 code by default
Date: Tue, 31 Aug 2010 14:56:36 +0200

 Hi Yuri,
 
 On my system, it seems gcc already compiles for i486 by default. The
 output of "cc -E -dM - < /dev/null" shows that __i486__ is defined and
 atomic builtins such as __sync_fetch_and_add are defined and produce
 i486 instructions. Only when you explicitly specify -march=i386 does
 gcc produce i386 code.
 
 However, it does look like libstdc++ can be optimised somewhat now that
 FreeBSD doesn't support the 80386 anymore. Can you test the attached
 patch and verify that it accomplishes what you want?
 
 diff --git a/gnu/lib/libstdc++/Makefile b/gnu/lib/libstdc++/Makefile
 index e0a7bb2..56ca626 100644
 --- a/gnu/lib/libstdc++/Makefile
 +++ b/gnu/lib/libstdc++/Makefile
 @@ -83,7 +83,7 @@ ATOMICITY_H=	${SRCDIR}/config/cpu/${MARCHDIR}/atomicity.h
  ATOMICITY_H=	${SRCDIR}/config/cpu/generic/atomicity_mutex/atomicity.h
  .endif
  
 -.if ${MACHINE_ARCH} == "amd64"
 +.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
  .if exists(${SRCDIR}/config/cpu/generic/atomicity_builtins/atomicity.h)
  ATOMICITY_H=	${SRCDIR}/config/cpu/generic/atomicity_builtins/atomicity.h
  .endif
 diff --git a/gnu/lib/libstdc++/config.h b/gnu/lib/libstdc++/config.h
 index de4641d..8bc099f 100644
 --- a/gnu/lib/libstdc++/config.h
 +++ b/gnu/lib/libstdc++/config.h
 @@ -671,7 +671,7 @@
  /* #undef VERSION */
  
  /* Define if builtin atomic operations are supported on this host. */
 -#if defined(__amd64__)
 +#if defined(__amd64__) || defined(__i386__)
  #define _GLIBCXX_ATOMIC_BUILTINS 1
  #endif
  
State-Changed-From-To: open->feedback 
State-Changed-By: tijl 
State-Changed-When: Tue Aug 31 13:19:42 UTC 2010 
State-Changed-Why:  
Track. 


Responsible-Changed-From-To: freebsd-bugs->tijl 
Responsible-Changed-By: tijl 
Responsible-Changed-When: Tue Aug 31 13:19:42 UTC 2010 
Responsible-Changed-Why:  
Track. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=148926 
State-Changed-From-To: feedback->open 
State-Changed-By: tijl 
State-Changed-When: Thu Sep 2 15:01:30 UTC 2010 
State-Changed-Why:  
Submitter replied via email: 

I tested the patch. The synthesized function versions is actually used 
and object files does not contain references to __exchange_and_add and 
friends (some files contain references actually, but it is not the case 
because std::locale and std::tr1::shared_ptr calls __exchange_and_add 
explicitly). 

Applications compiled with synthesized functions are working stable. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=148926 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: gnu/148926: commit references a PR
Date: Tue,  7 Sep 2010 08:33:31 +0000 (UTC)

 Author: tijl
 Date: Tue Sep  7 08:33:17 2010
 New Revision: 212286
 URL: http://svn.freebsd.org/changeset/base/212286
 
 Log:
   GCC defines built-ins for atomic instructions found on i486 and higher.
   Because FreeBSD no longer supports the 80386 cpu all code targeting
   FreeBSD/i386 necessarily runs on i486 or higher so the compiler
   built-ins can be used by default inside libstdc++ and in C++ headers.
   This allows newly compiled C++ code to inline some atomic operations.
   Old binaries continue to use libstdc++ functions.
   
   PR:		148926
   Tested by:	Yuri Karaban <tech askold net>
   Reviewed by:	kan
   Approved by:	kib (mentor)
   MFC after:	2 weeks
 
 Modified:
   head/gnu/lib/libstdc++/Makefile
   head/gnu/lib/libstdc++/config.h
 
 Modified: head/gnu/lib/libstdc++/Makefile
 ==============================================================================
 --- head/gnu/lib/libstdc++/Makefile	Tue Sep  7 07:31:58 2010	(r212285)
 +++ head/gnu/lib/libstdc++/Makefile	Tue Sep  7 08:33:17 2010	(r212286)
 @@ -83,7 +83,7 @@ ATOMICITY_H=	${SRCDIR}/config/cpu/${MARC
  ATOMICITY_H=	${SRCDIR}/config/cpu/generic/atomicity_mutex/atomicity.h
  .endif
  
 -.if ${MACHINE_CPUARCH} == "amd64"
 +.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
  .if exists(${SRCDIR}/config/cpu/generic/atomicity_builtins/atomicity.h)
  ATOMICITY_H=	${SRCDIR}/config/cpu/generic/atomicity_builtins/atomicity.h
  .endif
 
 Modified: head/gnu/lib/libstdc++/config.h
 ==============================================================================
 --- head/gnu/lib/libstdc++/config.h	Tue Sep  7 07:31:58 2010	(r212285)
 +++ head/gnu/lib/libstdc++/config.h	Tue Sep  7 08:33:17 2010	(r212286)
 @@ -671,7 +671,7 @@
  /* #undef VERSION */
  
  /* Define if builtin atomic operations are supported on this host. */
 -#if defined(__amd64__)
 +#if defined(__amd64__) || defined(__i386__)
  #define _GLIBCXX_ATOMIC_BUILTINS 1
  #endif
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: open->patched 
State-Changed-By: tijl 
State-Changed-When: Tue Sep 7 08:44:26 UTC 2010 
State-Changed-Why:  
Patch committed to CURRENT 

http://www.freebsd.org/cgi/query-pr.cgi?pr=148926 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: gnu/148926: commit references a PR
Date: Tue, 21 Sep 2010 12:55:25 +0000 (UTC)

 Author: tijl
 Date: Tue Sep 21 12:55:20 2010
 New Revision: 212962
 URL: http://svn.freebsd.org/changeset/base/212962
 
 Log:
   MFC r212286:
   
   GCC defines built-ins for atomic instructions found on i486 and higher.
   Because FreeBSD no longer supports the 80386 cpu all code targeting
   FreeBSD/i386 necessarily runs on i486 or higher so the compiler
   built-ins can be used by default inside libstdc++ and in C++ headers.
   This allows newly compiled C++ code to inline some atomic operations.
   Old binaries continue to use libstdc++ functions.
   
   PR:		148926
   Tested by:	Yuri Karaban <tech askold net>
   Approved by:	kib (mentor)
 
 Modified:
   stable/8/gnu/lib/libstdc++/Makefile
   stable/8/gnu/lib/libstdc++/config.h
 Directory Properties:
   stable/8/gnu/lib/libstdc++/   (props changed)
 
 Modified: stable/8/gnu/lib/libstdc++/Makefile
 ==============================================================================
 --- stable/8/gnu/lib/libstdc++/Makefile	Tue Sep 21 10:22:29 2010	(r212961)
 +++ stable/8/gnu/lib/libstdc++/Makefile	Tue Sep 21 12:55:20 2010	(r212962)
 @@ -81,7 +81,7 @@ ATOMICITY_H=	${SRCDIR}/config/cpu/${MARC
  ATOMICITY_H=	${SRCDIR}/config/cpu/generic/atomicity_mutex/atomicity.h
  .endif
  
 -.if ${MACHINE_ARCH} == "amd64"
 +.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
  .if exists(${SRCDIR}/config/cpu/generic/atomicity_builtins/atomicity.h)
  ATOMICITY_H=	${SRCDIR}/config/cpu/generic/atomicity_builtins/atomicity.h
  .endif
 
 Modified: stable/8/gnu/lib/libstdc++/config.h
 ==============================================================================
 --- stable/8/gnu/lib/libstdc++/config.h	Tue Sep 21 10:22:29 2010	(r212961)
 +++ stable/8/gnu/lib/libstdc++/config.h	Tue Sep 21 12:55:20 2010	(r212962)
 @@ -671,7 +671,7 @@
  /* #undef VERSION */
  
  /* Define if builtin atomic operations are supported on this host. */
 -#if defined(__amd64__)
 +#if defined(__amd64__) || defined(__i386__)
  #define _GLIBCXX_ATOMIC_BUILTINS 1
  #endif
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: tijl 
State-Changed-When: Tue Sep 21 15:11:18 CEST 2010 
State-Changed-Why:  
Patch committed to 7-STABLE and 8-STABLE 

http://www.freebsd.org/cgi/query-pr.cgi?pr=148926 
>Unformatted:
