Patchwork x86: emit tzcnt unconditionally

login
register
mail settings
Submitter Paolo Bonzini
Date April 27, 2012, 1:30 p.m.
Message ID <1335533422-11066-1-git-send-email-bonzini@gnu.org>
Download mbox | patch
Permalink /patch/155479/
State New
Headers show

Comments

Paolo Bonzini - April 27, 2012, 1:30 p.m.
tzcnt is encoded as "rep;bsf" and unlike lzcnt is a drop-in replacement
if we don't care about the flags (it has the same semantics for non-zero
values).

Since bsf is usually slower, just emit tzcnt unconditionally.  However,
write it as rep;bsf unless -mbmi is in use, to cater for old assemblers.

Bootstrapped on a non-BMI x86_64-linux host, regtest in progress.
Ok for mainline?

Paolo

2012-04-27  Paolo Bonzini  <bonzini@gnu.org>

        * config/i386/i386.md (ctz<mode>2): Emit tzcnt (as rep;bsf)
        instead of bsf.
Uros Bizjak - April 30, 2012, 8:09 a.m.
On Fri, Apr 27, 2012 at 3:30 PM, Paolo Bonzini <bonzini@gnu.org> wrote:
> tzcnt is encoded as "rep;bsf" and unlike lzcnt is a drop-in replacement
> if we don't care about the flags (it has the same semantics for non-zero
> values).
>
> Since bsf is usually slower, just emit tzcnt unconditionally.  However,
> write it as rep;bsf unless -mbmi is in use, to cater for old assemblers.

Please emit "rep;bsf" when optimize_insn_for_speed_p () is true.

> Bootstrapped on a non-BMI x86_64-linux host, regtest in progress.
> Ok for mainline?

OK with the optimize_insn_for_speed_p conditional.

Thanks,
Uros.

Patch

Index: i386/i386.md
===================================================================
--- i386/i386.md        (revisione 186904)
+++ i386/i386.md        (copia locale)
@@ -12082,14 +12082,15 @@  (define_insn "ctz<mode>2"
    (clobber (reg:CC FLAGS_REG))]
   ""
 {
+  /* tzcnt expands to rep;bsf and we can use it even if !TARGET_BMI.  */
   if (TARGET_BMI)
     return "tzcnt{<imodesuffix>}\t{%1, %0|%0, %1}";
   else
-    return "bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
+    return "rep;bsf{<imodesuffix>}\t{%1, %0|%0, %1}";
 }
   [(set_attr "type" "alu1")
    (set_attr "prefix_0f" "1")
-   (set (attr "prefix_rep") (symbol_ref "TARGET_BMI"))
+   (set_attr "prefix_rep" "1")
    (set_attr "mode" "<MODE>")])
 
 (define_expand "clz<mode>2"