http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54115

             Bug #: 54115
           Summary: Unnecessary sign extensions for __builtin_ctz et al.
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: nel...@seznam.cz


Instructions bsf,bsr,bsfq... return integer in range 0..63. 
When used in 64 bit computations an unnecessary sign extension is emitted as
following example shows:

#include <stdint.h>
uint64_t foo(long x){
 return __builtin_ctzl(x);
}

Output:

  .file "exa.c"
  .text
  .p2align 4,,15
  .globl  foo
  .type foo, @function
foo:
.LFB0:
  .cfi_startproc
  bsfq  %rdi, %rax
  cltq
  ret
  .cfi_endproc
.LFE0:
  .size foo, .-foo
  .ident  "GCC: (Debian 4.7.1-2) 4.7.1"
  .section  .note.GNU-stack,"",@progbits

Reply via email to