--- src.orig/gnu/usr.bin/gcc4/arch/i386/configargs.h	2010-05-08 12:00:12.000000000 +0900
+++ src/gnu/usr.bin/gcc4/arch/i386/configargs.h	2011-11-24 01:39:55.000000000 +0900
@@ -3,9 +3,9 @@
 /* Generated from: NetBSD: mknative.common,v 1.9 2007/02/05 18:26:01 apb Exp  */
 
 /* Generated automatically. */
-static const char configuration_arguments[] = "/usr/src/tools/gcc/../../gnu/dist/gcc4/configure --target=i486--netbsdelf --enable-long-long --enable-threads --enable-__cxa_atexit --with-arch=i486 --with-tune=nocona --disable-multilib --disable-symvers --build=x86_64-unknown-netbsd5.0. --host=i486--netbsdelf";
+static const char configuration_arguments[] = "/usr/src/tools/gcc/../../gnu/dist/gcc4/configure --target=i686--netbsdelf --enable-long-long --enable-threads --enable-__cxa_atexit --with-arch=i686 --with-tune=nocona --disable-multilib --disable-symvers --build=x86_64-unknown-netbsd5.0. --host=i686--netbsdelf";
 static const char thread_model[] = "posix";
 
 static const struct {
   const char *name, *value;
-} configure_default_options[] = { { "cpu", "i486" }, { "arch", "i486" }, { "tune", "nocona" } };
+} configure_default_options[] = { { "cpu", "i686" }, { "arch", "i686" }, { "tune", "nocona" } };
--- src.orig/external/gpl3/gcc/usr.bin/gcc/arch/i386/configargs.h	2011-12-15 15:35:45.000000000 +0900
+++ src/external/gpl3/gcc/usr.bin/gcc/arch/i386/configargs.h	2011-12-15 18:16:59.000000000 +0900
@@ -3,9 +3,9 @@
 /* Generated from: NetBSD: mknative.common,v 1.9 2007/02/05 18:26:01 apb Exp  */
 
 /* Generated automatically. */
-static const char configuration_arguments[] = "/usr/src2/tools/gcc/../../external/gpl3/gcc/dist/configure --target=i486--netbsdelf --enable-long-long --enable-threads --with-bugurl=http://www.NetBSD.org/Misc/send-pr.html --with-pkgversion='NetBSD nb2 20111202' --enable-__cxa_atexit --with-arch=i486 --with-tune=nocona --with-mpc=/var/obj/mknative/i386/usr/src2/destdir.i386/usr --with-mpfr=/var/obj/mknative/i386/usr/src2/destdir.i386/usr --with-gmp=/var/obj/mknative/i386/usr/src2/destdir.i386/usr --enable-tls --disable-multilib --disable-symvers --disable-libstdcxx-pch --build=x86_64-unknown-netbsd5.99.56 --host=i486--netbsdelf";
+static const char configuration_arguments[] = "/usr/src2/tools/gcc/../../external/gpl3/gcc/dist/configure --target=i686--netbsdelf --enable-long-long --enable-threads --with-bugurl=http://www.NetBSD.org/Misc/send-pr.html --with-pkgversion='NetBSD nb2 20111202' --enable-__cxa_atexit --with-arch=i686 --with-tune=nocona --with-mpc=/var/obj/mknative/i386/usr/src2/destdir.i386/usr --with-mpfr=/var/obj/mknative/i386/usr/src2/destdir.i386/usr --with-gmp=/var/obj/mknative/i386/usr/src2/destdir.i386/usr --enable-tls --disable-multilib --disable-symvers --disable-libstdcxx-pch --build=x86_64-unknown-netbsd5.99.56 --host=i686--netbsdelf";
 static const char thread_model[] = "posix";
 
 static const struct {
   const char *name, *value;
-} configure_default_options[] = { { "cpu", "i486" }, { "arch", "i486" }, { "tune", "nocona" } };
+} configure_default_options[] = { { "cpu", "i686" }, { "arch", "i686" }, { "tune", "nocona" } };
--- src.orig/external/lgpl3/gmp/lib/libgmp/arch/i386/config.h	2011-07-01 10:49:18.000000000 +0900
+++ src/external/lgpl3/gmp/lib/libgmp/arch/i386/config.h	2011-11-27 20:23:13.000000000 +0900
@@ -27,7 +27,7 @@
 
 /* The gmp-mparam.h file (a string) the tune program should suggest updating.
    */
-#define GMP_MPARAM_H_SUGGEST "/usr/src/external/lgpl3/gmp/dist/mpn/x86/i486/gmp-mparam.h"
+#define GMP_MPARAM_H_SUGGEST "/usr/src/external/lgpl3/gmp/dist/mpn/x86/p6/sse2/gmp-mparam.h"
 
 /* Define to 1 if you have the `alarm' function. */
 #define HAVE_ALARM 1
--- src.orig/external/lgpl3/gmp/lib/libgmp/arch/i386/config.m4	2011-07-07 15:30:02.000000000 +0900
+++ src/external/lgpl3/gmp/lib/libgmp/arch/i386/config.m4	2011-11-27 20:57:46.000000000 +0900
@@ -20,7 +20,7 @@
 define(<HAVE_COFF_TYPE>, <no>)
 define(<GOT_GSYM_PREFIX>, <>)
 define(<WANT_SHLDL_CL>, <1>)
-define(<SQR_TOOM2_THRESHOLD>,<49>)
+define(<SQR_TOOM2_THRESHOLD>,<52>)
 define(<SIZEOF_UNSIGNED>,<4>)
 define(<GMP_LIMB_BITS>,32)
 define(<GMP_NAIL_BITS>,0)
@@ -30,7 +30,7 @@
 ifdef(`__CONFIG_M4_INCLUDED__',,`
 include(CONFIG_TOP_SRCDIR`/mpn/asm-defs.m4')
 include_mpn(`x86/x86-defs.m4')
-define_not_for_expansion(`HAVE_HOST_CPU_i486')
+define_not_for_expansion(`HAVE_HOST_CPU_i686')
 define_not_for_expansion(`HAVE_ABI_32')
 define_not_for_expansion(`HAVE_LIMB_LITTLE_ENDIAN')
 define_not_for_expansion(`HAVE_DOUBLE_IEEE_LITTLE_ENDIAN')
--- src.orig/external/lgpl3/gmp/lib/libgmp/arch/i386/gmp-mparam.h	2011-06-29 17:06:47.000000000 +0900
+++ src/external/lgpl3/gmp/lib/libgmp/arch/i386/gmp-mparam.h	2011-11-27 20:57:21.000000000 +0900
@@ -1,6 +1,7 @@
-/* 80486 gmp-mparam.h -- Compiler/machine parameter header file.
+/* Intel P6 gmp-mparam.h -- Compiler/machine parameter header file.
 
-Copyright 2001, 2002, 2003 Free Software Foundation, Inc.
+Copyright 1991, 1993, 1994, 1999, 2000, 2001, 2002, 2003 Free Software
+Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -17,42 +18,49 @@
 You should have received a copy of the GNU Lesser General Public License
 along with the GNU MP Library.  If not, see http://www.gnu.org/licenses/.  */
 
+
 #define GMP_LIMB_BITS 32
 #define BYTES_PER_MP_LIMB 4
 
 
-/* 100MHz DX4 */
+/* NOTE: In a fat binary build SQR_TOOM2_THRESHOLD here cannot be smaller than
+   the value in mpn/x86/p6/mmx/gmp-mparam.h.  The former is used as a hard
+   limit in mpn/x86/p6/sqr_basecase.asm, and that file will be run by the
+   p6/mmx cpus (pentium2, pentium3).  */
+
+
+/* 200MHz Pentium Pro */
 
-/* Generated by tuneup.c, 2003-02-13, gcc 2.95 */
+/* Generated by tuneup.c, 2003-02-12, gcc 2.95 */
 
-#define MUL_TOOM22_THRESHOLD             18
-#define MUL_TOOM33_THRESHOLD            228
+#define MUL_TOOM22_THRESHOLD             23
+#define MUL_TOOM33_THRESHOLD            140
 
-#define SQR_BASECASE_THRESHOLD           13
-#define SQR_TOOM2_THRESHOLD              49
-#define SQR_TOOM3_THRESHOLD             238
+#define SQR_BASECASE_THRESHOLD            0  /* always */
+#define SQR_TOOM2_THRESHOLD              52
+#define SQR_TOOM3_THRESHOLD             189
 
-#define DIV_SB_PREINV_THRESHOLD       MP_SIZE_T_MAX  /* never */
-#define DIV_DC_THRESHOLD                 72
-#define POWM_THRESHOLD                   38
+#define DIV_SB_PREINV_THRESHOLD           0  /* always */
+#define DIV_DC_THRESHOLD                116
+#define POWM_THRESHOLD                  131
 
 #define GCD_ACCEL_THRESHOLD               3
-#define JACOBI_BASE_METHOD                2
+#define JACOBI_BASE_METHOD                1
 
 #define USE_PREINV_DIVREM_1               0
-#define USE_PREINV_MOD_1                  0
-#define DIVREM_2_THRESHOLD            MP_SIZE_T_MAX  /* never */
-#define DIVEXACT_1_THRESHOLD              0  /* always (native) */
-#define MODEXACT_1_ODD_THRESHOLD         17
-
-#define GET_STR_DC_THRESHOLD             32
-#define GET_STR_PRECOMPUTE_THRESHOLD     82
-#define SET_STR_THRESHOLD              3524
+#define USE_PREINV_MOD_1                  1  /* native */
+#define DIVREM_2_THRESHOLD                0  /* always */
+#define DIVEXACT_1_THRESHOLD              0  /* always */
+#define MODEXACT_1_ODD_THRESHOLD          0  /* always */
+
+#define GET_STR_DC_THRESHOLD             18
+#define GET_STR_PRECOMPUTE_THRESHOLD     23
+#define SET_STR_THRESHOLD              6093
 
-#define MUL_FFT_TABLE  { 464, 928, 1920, 4608, 10240, 40960, 0 }
-#define MUL_FFT_MODF_THRESHOLD          392
+#define MUL_FFT_TABLE  { 464, 928, 1920, 3584, 10240, 40960, 0 }
+#define MUL_FFT_MODF_THRESHOLD          360
 #define MUL_FFT_THRESHOLD              2816
 
-#define SQR_FFT_TABLE  { 432, 928, 1920, 4608, 14336, 40960, 0 }
-#define SQR_FFT_MODF_THRESHOLD          392
+#define SQR_FFT_TABLE  { 528, 1184, 1920, 4608, 14336, 40960, 0 }
+#define SQR_FFT_MODF_THRESHOLD          440
 #define SQR_FFT_THRESHOLD              2816
--- src.orig/external/lgpl3/gmp/lib/libgmp/arch/i386/gmp.h	2011-06-29 17:06:47.000000000 +0900
+++ src/external/lgpl3/gmp/lib/libgmp/arch/i386/gmp.h	2011-11-27 20:28:27.000000000 +0900
@@ -2268,7 +2268,7 @@
 
 /* Define CC and CFLAGS which were used to build this version of GMP */
 #define __GMP_CC "gcc -std=gnu99"
-#define __GMP_CFLAGS "-m32 -O2 -pedantic -fomit-frame-pointer -mtune=i486 -march=i486"
+#define __GMP_CFLAGS "-m32 -O2 -pedantic -fomit-frame-pointer -mtune=nocona -march=i686"
 
 /* Major version number is the value of __GNU_MP__ too, above and in mp.h. */
 #define __GNU_MP_VERSION 5
--- src.orig/lib/libc/arch/i386/SYS.h	2008-04-29 05:22:56.000000000 +0900
+++ src/lib/libc/arch/i386/SYS.h	2011-11-24 01:37:53.000000000 +0900
@@ -103,9 +103,9 @@
 
 #ifdef PIC
 #define _SYSCALL_ERR							\
-	PIC_PROLOGUE;							\
+	SYSCALL_PIC_PROLOGUE;						\
 	mov PIC_GOT(CERROR), %ecx;					\
-	PIC_EPILOGUE;							\
+	SYSCALL_PIC_EPILOGUE;						\
 	jmp *%ecx
 #else
 #define _SYSCALL_ERR							\
--- src.orig/sys/arch/i386/include/asm.h	2011-06-16 22:16:20.000000000 +0900
+++ src/sys/arch/i386/include/asm.h	2011-11-24 01:36:58.000000000 +0900
@@ -42,18 +42,48 @@
 #endif
 
 #ifdef PIC
+#define SYSCALL_PIC_PROLOGUE	\
+	pushl	%ebx;		\
+	call	1f;		\
+1:				\
+	popl	%ebx;		\
+	addl	$_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
+#define SYSCALL_PIC_EPILOGUE	\
+	popl	%ebx
+#ifdef __i686
+#undef __i686
+#define PIC_PROLOGUE							\
+	.ifndef __i686.get_pc_thunk.bx;					\
+	.section .text.__i686.get_pc_thunk.bx,"axG",@progbits,__i686.get_pc_thunk.bx,comdat; \
+.globl __i686.get_pc_thunk.bx;						\
+	.hidden	__i686.get_pc_thunk.bx;					\
+	.type	__i686.get_pc_thunk.bx,@function;			\
+__i686.get_pc_thunk.bx:							\
+	movl	(%esp), %ebx;						\
+	ret;								\
+	.size	__i686.get_pc_thunk.bx, . - __i686.get_pc_thunk.bx;	\
+	.previous;							\
+	.endif;								\
+	pushl	%ebx;							\
+	call	__i686.get_pc_thunk.bx;					\
+	addl	$_GLOBAL_OFFSET_TABLE_, %ebx
+#define	__i686	__i686
+#else	/* !__i686 */
 #define PIC_PROLOGUE	\
 	pushl	%ebx;	\
 	call	1f;	\
 1:			\
 	popl	%ebx;	\
 	addl	$_GLOBAL_OFFSET_TABLE_+[.-1b], %ebx
+#endif	/* __i686 */
 #define PIC_EPILOGUE	\
 	popl	%ebx
 #define PIC_PLT(x)	x@PLT
 #define PIC_GOT(x)	x@GOT(%ebx)
 #define PIC_GOTOFF(x)	x@GOTOFF(%ebx)
 #else
+#define SYSCALL_PIC_PROLOGUE
+#define SYSCALL_PIC_EPILOGUE
 #define PIC_PROLOGUE
 #define PIC_EPILOGUE
 #define PIC_PLT(x)	x
--- src.orig/common/lib/libc/arch/i386/string/ffs.S	2005-12-21 04:28:49.000000000 +0900
+++ src/common/lib/libc/arch/i386/string/ffs.S	2011-11-24 01:34:16.000000000 +0900
@@ -10,6 +10,12 @@
 #endif
 
 ENTRY(ffs)
+#ifdef __i686
+	bsfl	4(%esp),%eax
+	cmovel	-1,%eax			/* ZF is set if all bits are 0 */
+	incl	%eax			/* bits numbered from 1, not 0 */
+	ret
+#else
 	bsfl	4(%esp),%eax
 	jz	L1	 		/* ZF is set if all bits are 0 */
 	incl	%eax			/* bits numbered from 1, not 0 */
@@ -18,3 +24,4 @@
 	_ALIGN_TEXT
 L1:	xorl	%eax,%eax		/* clear result */
 	ret
+#endif
--- src.orig/share/mk/bsd.own.mk	2012-02-17 17:31:30.000000000 +0900
+++ src/share/mk/bsd.own.mk	2012-02-17 17:35:58.000000000 +0900
@@ -647,8 +647,8 @@
 # GNU sources and packages sometimes see architecture names differently.
 #
 GNU_ARCH.coldfire=m68k
-GNU_ARCH.i386=i486
-GCC_CONFIG_ARCH.i386=i486
+GNU_ARCH.i386=i686
+GCC_CONFIG_ARCH.i386=i686
 GCC_CONFIG_TUNE.i386=nocona
 GCC_CONFIG_TUNE.x86_64=nocona
 GNU_ARCH.m68000=m68010
--- src.orig/share/mk/bsd.kmodule.mk	2012-02-20 08:59:25.000000000 +0900
+++ src/share/mk/bsd.kmodule.mk	2012-02-20 09:03:03.000000000 +0900
@@ -30,6 +30,8 @@
 # resulting code would be much faster.
 .if ${MACHINE_CPU} == "arm"
 CFLAGS+=	-mlong-calls
+.elif ${MACHINE_CPU} == "i386"
+CFLAGS+=	-mno-sse -mno-sse2 -mno-sse3
 .elif ${MACHINE_CPU} == "powerpc"
 CFLAGS+=	-mlongcall
 .elif ${MACHINE_CPU} == "vax"
