Missed opportunity: quotient and remainder down to 60 times slower than necessary

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Missed opportunity: quotient and remainder down to 60 times slower than necessary

Hubert Tong via cfe-dev
Spoiler alert: this is not the demonstration of the factor 30 achievable
with a properly coded SINGLE 128/128-bit division ... although it can
show even a factor 60!

--- bugs-bunny.c ---
// Copyleft © 2014-2020, Stefan Kanthak <[hidden email]>

__uint128_t udivmodti4(__uint128_t dividend, __uint128_t divisor, __uint128_t *remainder) {
    if (remainder != 0)
        *remainder = dividend % divisor;
    return dividend / divisor;
}
--- EOF ---

clang -c -o- -O3 -S -target amd64-pc-windows bugs-bunny.c

udivmodti4:     # @udivmodti4
# %bb.0:
[...]
        testq   %r8, %r8
        je      .LBB0_2
# %bb.1:
        movq    %r8, %rbx
        movq    %r13, %rdi
        movq    %r12, %rsi
        movq    %r15, %rdx
        movq    %r14, %rcx
        callq   __umodti3
        movq    %rdx, 8(%rbx)
        movq    %rax, (%rbx)
.LBB0_2:
        movq    %r13, %rdi
        movq    %r12, %rsi
        movq    %r15, %rdx
        movq    %r14, %rcx
        callq   __udivti3
[...]


OOPS!
Instead to generate a single call of the library function __udivmodti4()
which returns both quotient and remainder, even with the option -O3
specified clang generates two separate calls of the library functions
__umodti3() and __udivti3() -- which is especially "funny", since both
call the library function __udivmodti4() in turn!

_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: Missed opportunity: quotient and remainder down to 60 times slower than necessary

Hubert Tong via cfe-dev
Stefan, what is the point of these mails, what do you hope to achieve with them?

Roman

> _______________________________________________
> cfe-dev mailing list
> [hidden email]
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
_______________________________________________
cfe-dev mailing list
[hidden email]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev