This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] x86: use 'rep bsf' syntax when assembler supports it


The GNU assembler now (just as of today) accepts 'rep bsf ...' or 'rep bsr ...'
syntax.  It's always better to put a prefix on the instruction itself
rather than to write 'rep; ...'.  This changes 'rep; bsf ...' to 'rep bsf ...'
when the assembler accepts the latter.


Thanks,
Roland


gcc/
2012-06-22  Roland McGrath  <mcgrathr@google.com>

	* configure.ac (HAVE_AS_IX86_REP_BSFBSR): New test.
	* configure: Regenerate.
	* config.in: Regenerate.
	* config/i386/i386.h (REP_BEFORE_BSF): New macro.
	* config/i386/i386.md (ctz<mode>2): Use it.

diff --git a/gcc/config.in b/gcc/config.in
index 7b12b4b..be7271f 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -345,6 +345,12 @@
 #endif
 
 
+/* Define if the assembler supports 'rep bsf' and 'rep bsr'. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_AS_IX86_REP_BSFBSR
+#endif
+
+
 /* Define if the assembler supports 'rep <insn>, lock <insn>'. */
 #ifndef USED_FOR_TARGET
 #undef HAVE_AS_IX86_REP_LOCK_PREFIX
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index f7f13d2..90eaf95 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -1,6 +1,6 @@
 /* Definitions of target machine for GCC for IA-32.
    Copyright (C) 1988, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
 This file is part of GCC.
@@ -2030,6 +2030,12 @@ do {									\
    asm (SECTION_OP "\n\t"					\
 	"call " CRT_MKSTR(__USER_LABEL_PREFIX__) #FUNC "\n"	\
 	TEXT_SECTION_ASM_OP);
+
+#ifdef HAVE_AS_IX86_REP_BSFBSR
+#define REP_BEFORE_BSF "rep "
+#else
+#define REP_BEFORE_BSF "rep; "
+#endif
 
 /* Which processor to tune code generation for.  */
 
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index 879b87b..4a1cbbe 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -12235,7 +12235,7 @@
     ;
   else if (TARGET_GENERIC)
     /* tzcnt expands to rep;bsf and we can use it even if !TARGET_BMI.  */
-    return "rep; bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
+    return REP_BEFORE_BSF "bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
 
   return "bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
 }
diff --git a/gcc/configure b/gcc/configure
index 1fdf0af..c5039d0 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -24815,6 +24815,38 @@ $as_echo "#define HAVE_AS_IX86_REP_LOCK_PREFIX 1" >>confdefs.h
 
 fi
 
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for rep prefix on bsf/bsr" >&5
+$as_echo_n "checking assembler for rep prefix on bsf/bsr... " >&6; }
+if test "${gcc_cv_as_ix86_rep_bsf+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  gcc_cv_as_ix86_rep_bsf=no
+  if test x$gcc_cv_as != x; then
+    $as_echo 'rep bsf %ecx, %eax
+	 rep bsr %ecx, %eax' > conftest.s
+    if { ac_try='$gcc_cv_as $gcc_cv_as_flags  -o conftest.o conftest.s >&5'
+  { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
+  test $ac_status = 0; }; }
+    then
+	gcc_cv_as_ix86_rep_bsf=yes
+    else
+      echo "configure: failed program was" >&5
+      cat conftest.s >&5
+    fi
+    rm -f conftest.o conftest.s
+  fi
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_ix86_rep_bsf" >&5
+$as_echo "$gcc_cv_as_ix86_rep_bsf" >&6; }
+if test $gcc_cv_as_ix86_rep_bsf = yes; then
+
+$as_echo "#define HAVE_AS_IX86_REP_BSFBSR 1" >>confdefs.h
+
+fi
+
     { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for R_386_TLS_GD_PLT reloc" >&5
 $as_echo_n "checking assembler for R_386_TLS_GD_PLT reloc... " >&6; }
 if test "${gcc_cv_as_ix86_tlsgdplt+set}" = set; then :
@@ -28698,4 +28730,3 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
 fi
 
-
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 22dab55..c366181 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -3646,6 +3646,13 @@ foo:	nop
         [AC_DEFINE(HAVE_AS_IX86_REP_LOCK_PREFIX, 1,
           [Define if the assembler supports 'rep <insn>, lock <insn>'.])])
 
+    gcc_GAS_CHECK_FEATURE([rep prefix on bsf/bsr],
+        gcc_cv_as_ix86_rep_bsf,,,
+	[rep bsf %ecx, %eax
+	 rep bsr %ecx, %eax],,
+        [AC_DEFINE(HAVE_AS_IX86_REP_BSFBSR, 1,
+          [Define if the assembler supports 'rep bsf' and 'rep bsr'.])])
+
     gcc_GAS_CHECK_FEATURE([R_386_TLS_GD_PLT reloc],
         gcc_cv_as_ix86_tlsgdplt,,,
 	[call    tls_gd@tlsgdplt],


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]