performance - Why GCC does not generates assembly code with 1 **imul** instruction for 1 multiplication in C? -


i'm checking assembly code of following simple program on https://godbolt.org/ parameters -wall -m32 using gcc 6.3 , surprise generated assembly code takes 3 multiplications perform 1 multiplication in c shown below.

#include<stdio.h> #include<inttypes.h>  int main(void){      int32_t ax=-854763;      int32_t bx=586478;      int64_t cx= (int64_t)ax*bx;      printf("%lld\n", cx); } 

the generated assembly code statement int64_t cx= (int64_t)ax*bx; given below. there 2 imull , 1 mull instructions.

movl    -28(%ebp), %eax movl    %eax, %ecx movl    %eax, %ebx sarl    $31, %ebx movl    -32(%ebp), %eax cltd movl    %ebx, %edi imull   %eax, %edi movl    %edx, %esi imull   %ecx, %esi addl    %edi, %esi mull    %ecx leal    (%esi,%edx), %ecx movl    %ecx, %edx movl    %eax, -40(%ebp) movl    %edx, -36(%ebp) movl    %eax, -40(%ebp) movl    %edx, -36(%ebp)` 

is possible enforce gcc compiler/assembler 1 multiplication without using inline assembly? because in original code have perform many such multiplications within statement , in different statements.

why compiler not perform 1 imul instruction? have checked different versions of gcc on https://godbolt.org/ result same 3 multiplication instruction.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -