Hello,
when performing (int64_t) foo / (int32_t) bar in gcc under x86, a call to
__divdi3 is always output, even though it seems the use of the idiv
instruction could be faster.
This seems to remain even under -Ofast and other available options.

To illustrate, this godbolt link: https://godbolt.org/z/hq4GKb
With code

#include <stdint.h>
int32_t d(int64_t a, int32_t b) {
    return a / b;
}

Compiles to

d(long long, int):
        sub     esp, 12
        mov     eax, DWORD PTR [esp+24]
        cdq
        push    edx
        push    eax
        push    DWORD PTR [esp+28]
        push    DWORD PTR [esp+28]
        call    __divdi3
        add     esp, 28
        ret

Why is this?

-- 
Lucas de Almeida

Reply via email to