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

             Bug #: 50440
           Summary: 128 bit unsigned int subtraction generates too many
                    register moves
    Classification: Unclassified
           Product: gcc
           Version: 4.6.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: schnet...@gmail.com


I want to perform 128 bit integer arithmetic, and I am declaring my type like
this:

{{{
typedef unsigned int uint128_t __attribute__((mode(TI)));
uint128_t add (uint128_t x, uint128_t y) { return x+y; }
uint128_t sub (uint128_t x, uint128_t y) { return x-y; }
}}}

This is on an Intel Xeon processor in x86_64 mode. I build with the command

gcc-4.6.1 -O3 -march=native -S sub128.c

and I find that, while the "add" routine looks optimal, the "sub" routine has
several unnecessary register moves:

{{{
add:
    movq    %rdx, %rax
    movq    %rcx, %rdx
    addq    %rdi, %rax
    adcq    %rsi, %rdx
    ret
sub:
    movq    %rsi, %r10
    movq    %rdi, %rsi
    subq    %rdx, %rsi
    movq    %r10, %rdi
    sbbq    %rcx, %rdi
    movq    %rsi, %rax
    movq    %rdi, %rdx
    ret
}}}

Reply via email to