[GCC] x86 optimizer suggestion

Tom St Denis tomstdenis@iahu.ca
Tue Jun 17 08:26:00 GMT 2003


Code like

unsigned long long t, w;
unsigned long b;

        t = w / b;
        w = w % b;

Generates asm like

    movl    %esi, (%esp)
    movl    40(%esp), %eax
    movl    44(%esp), %ebx
    movl    %edi, 4(%esp)
    movl    %eax, 8(%esp)
    movl    %ebx, 12(%esp)
    call    ___udivdi3
    movl    40(%esp), %ecx
    movl    %esi, (%esp)
    movl    44(%esp), %esi
    movl    %edi, 4(%esp)
    movl    %eax, 56(%esp)
    movl    %esi, 12(%esp)
    movl    %edx, 60(%esp)
    movl    %ecx, 8(%esp)
    call    ___umoddi3
    movl    %eax, %esi
    movl    %edx, %edi

When call as "gcc -I./ -Wall -W -Wshadow -O3 -fomit-frame-pointer 
-funroll-loops -S bn_mp_div_d.c"  [in this case].

If I am not mistaken the x86 series [from 80386 and up] has a 64x32 
division instruction DIV which will divide EDX:EAX by another regmem 
value.  Couldn't this source code make only a single DIV opcode to get 
both results [or at the very least do two DIVs]?

Thanks,
Tom



More information about the Gcc mailing list