x86 MUL Instruction from VS 2008/2010

后端 未结 6 1601
鱼传尺愫
鱼传尺愫 2020-11-29 09:29

Will modern (2008/2010) incantations of Visual Studio or Visual C++ Express produce x86 MUL instructions (unsigned multiply) in the compiled code? I cannot seem to find or

6条回答
  •  盖世英雄少女心
    2020-11-29 09:51

    According to http://gmplib.org/~tege/x86-timing.pdf, the IMUL instruction has a lower latency and higher throughput (if I'm reading the table correctly). Perhaps VS is simply using the faster instruction (that's assuming that IMUL and MUL always produce the same output).

    I don't have Visual Studio handy, so I tried to get something else with GCC. I also always get some variation of IMUL.

    This:

    unsigned int func(unsigned int a, unsigned int b)
    { 
        return a * b;
    }
    

    Assembles to this (with -O2):

    _func:
    LFB2:
            pushq   %rbp
    LCFI0:
            movq    %rsp, %rbp
    LCFI1:
            movl    %esi, %eax
            imull   %edi, %eax
            movzbl  %al, %eax
            leave
            ret
    

提交回复
热议问题