[Issue 9920] [Optimizer] Use mul/imul for integer division by constant

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Apr 16 10:18:34 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9920



--- Comment #8 from bearophile_hugs at eml.cc 2013-04-16 10:18:30 PDT ---
(In reply to comment #5)

> Timings, n = 100_000_000:
>   GCC:  3.13 s
>   DMD: 11.69 s

The new timings are acceptable:

GCC: 3.03 s
DMD: 3.74 s


dmd -O -release -noboundscheck -inline
gcc -Ofast -flto -s

gcc V.4.8


The asm of the D version below seems to contains a bit too many "mov":

---------------------------------

New DMD inner loop:

L28:    lea    EBX, [EBX*4][EBX]
        mov    EAX, ESI
        mov    EDX, 0CCCCCCCDh
        mul    EDX
        shr    EDX, 3
        mov    ECX, ESI
        imul EAX, EDX, 0Ah
        sub    ECX, EAX
        mov    EAX, EDX
        add    EBX, EBX
        mov    EDX, ECX
        add    EBX, EDX
        test EAX, EAX
        mov    ESI, EAX
        jne    L28

---------------------------------

GCC:

L5:
    movl    %edi, %eax
    mull    %esi
    movl    %edx, %ebx
    shrl    $3, %ebx
    leal    (%ebx,%ebx,4), %eax
    movl    %ebx, %ecx
    addl    %eax, %eax
    movl    %edi, %ebx
    subl    %eax, %ebx
    testl    %ecx, %ecx
    je    L2
    .p2align 4,,7
L4:
    movl    %ecx, %eax
    mull    %esi
    leal    (%ebx,%ebx,4), %ebx
    shrl    $3, %edx
    leal    (%edx,%edx,4), %eax
    addl    %eax, %eax
    subl    %eax, %ecx
    testl    %edx, %edx
    leal    (%ecx,%ebx,2), %ebx
    movl    %edx, %ecx
    jne    L4
    addl    $1, %edi
    addl    %ebx, 12(%esp)
    cmpl    $100000000, %edi
    jne    L5

---------------------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list