[Bug target/82418] Division on a constant is suboptimal because of not using imul instruction

plasmahh at gmx dot net gcc-bugzilla@gcc.gnu.org
Tue Jul 17 15:20:00 GMT 2018


Dennis Lubert <plasmahh at gmx dot net> changed:

           What    |Removed                     |Added
                 CC|                            |plasmahh at gmx dot net

--- Comment #5 from Dennis Lubert <plasmahh at gmx dot net> ---
Was about to open a bug for this very same thing myself.

I came from another route, noticing that our own implementation of /100 

uint32_t divx( uint32_t r)
    uint32_t u = r * 1374389535uLL;
    u >>= 5u;
    return u;


  imull   $1374389535, %edi, %eax
        shrl    $5, %eax

whereas the code generated by gcc above is (depending on actual circumstances)
making our int to string function run 13-15% slower.

I was hoping I could reduce the use of magic numbers and instead use readable

For some reason clang moves edi to eax and then calls imul, whereas the above
divx directly uses edi, this might be worth adding too.

More information about the Gcc-bugs mailing list