--- cpuinfo.sh.orig	2012-06-08 19:49:47.000000000 +0800
+++ cpuinfo.sh	2022-10-30 09:07:30.000000000 +0800
@@ -37,12 +37,13 @@
 extcheck()
 {
 cat > conftest.c <<EOF
+#include <stdlib.h>
 #include <signal.h>
 void catch() { exit(1); }
 int main(void){
   signal(SIGILL, catch);
-  __asm__ __volatile__ ("$1":::"memory");
-  exit(0);
+  __asm__ volatile ("$1":::"memory");
+  return 0;
 }
 EOF
 
@@ -109,10 +110,10 @@
 case "$pvendor" in
 	AuthenticAMD)
 		case "$pfamily" in
-			3)proc=i386
-			  ;;
-			4) proc=i486
-			  ;;
+			3) proc=i386 iproc=386
+			   ;;
+			4) proc=i486 iproc=486
+			   ;;
 			5) iproc=586
 			# models are: K5/SSA5 K5 K5 K5 ? ? K6 K6 K6-2 K6-3
 			# K6 model 13 are the K6-2+ and K6-III+
@@ -141,7 +142,7 @@
 				proc=athlon
 			   fi
 			   ;;
-			15) 
+			15) iproc=686
 			    # Despite what the gcc into says 'athlon64' is not accepted as 
 			    # synonym for 'k8'
 			   proc=k8
@@ -152,9 +153,9 @@
 		;;
 	GenuineIntel)
 		case "$pfamily" in
-			3) proc=i386
+			3) proc=i386 iproc=386
 			   ;;
-			4) proc=i486
+			4) proc=i486 iproc=486
 			   ;;
 			5) iproc=586
 			   if test "$pmodel" -eq 4 || test "$pmodel" -eq 8; then
@@ -164,10 +165,16 @@
 			   fi
 			   ;;
 			6) iproc=686
-                           if test "$pmodel" -ge 15; then
-                                proc=nocona
-                           elif test "$pmodel" -ge 13; then
-                                proc=pentium-m
+			   if test "$pmodel" -eq 28 -o "$pmodel" -eq 38 -o "$pmodel" -eq 54; then
+				proc=atom
+			   elif test "$pmodel" -ge 42; then
+				proc=corei7-avx
+			   elif test "$pmodel" -ge 26; then
+				proc=corei7
+			   elif test "$pmodel" -ge 15; then
+				proc=core2
+			   elif test "$pmodel" -eq 9 -o "$pmodel" -ge 13; then
+				proc=pentium-m
 			   elif test "$pmodel" -ge 7; then
 				proc=pentium3
 			   elif test "$pmodel" -ge 3; then
@@ -175,7 +182,7 @@
 			   else
 				proc=i686
 			   fi
-                           ;;
+			   ;;
 			15) proc=pentium4
 			   ;;
 			*) proc=pentium4
@@ -225,6 +232,18 @@
     fi
 fi
 
+if test "$proc" = "atom" || test "$proc" = "corei7-avx" || test "$proc" = "corei7"; then
+	do_cc -march=$proc $cpuopt=$proc || proc=core2
+fi
+if test "$proc" = "core2"; then
+	do_cc -march=$proc $cpuopt=$proc || proc=x86-64
+fi
+if test "$proc" = "x86-64"; then
+	do_cc -march=$proc $cpuopt=$proc || proc=nocona
+fi
+if test "$proc" = "nocona"; then
+	do_cc -march=$proc $cpuopt=$proc || proc=pentium4
+fi
 if test "$proc" = "pentium4" || test "$proc" = "pentium3" || test "$proc" = "pentium2" || test "$proc" = "athlon"; then
 	do_cc -march=$proc $_opt_mcpu=$proc || proc=i686
 fi
@@ -248,8 +267,8 @@
 	_march="-march=i586"
 	_mcpu="$_opt_mcpu=i686"
 else
-      _march="-march=$proc"
-      _mcpu="$_opt_mcpu=$proc"
+	_march="-march=$proc"
+	_mcpu="$_opt_mcpu=$proc"
 fi
 
 if test $_cc_major -ge 3; then
@@ -334,5 +353,5 @@
 if test $target = x86; then
 	do_x86
 elif test $target = ppc; then
-        do_ppc
+	do_ppc
 fi
