GCC and the Multiply Instruction

I am using GCC in 32-bit mode on a Windows 7 machine under cygwin. I have the following function:

  unsigned f1(unsigned x, unsigned y)
  {
      return x*y;
  }

I want the code to do an unsigned multiply and as such I would expect it to generate the mul instruction, not the imul instruction. I compile the program with the following command:

 gcc -m32 -S t4.c

The generated assembly code is:

     .file   "t4.c"
     .text
     .globl  _f1
     .def    _f1;    .scl    2;  .type   32; .endef
_f1:
     pushl   %ebp
     movl    %esp, %ebp
     movl    8(%ebp), %eax
     imull   12(%ebp), %eax
     popl    %ebp
     ret
    .ident  "GCC: (GNU) 4.8.2"

I believe that the generated code has the wrong multiply instruction in it but I find it hard to believe that GCC has such a simple bug. Please comment.

Answers


The compiler relies on the "as-if" rule: No standard conforming program can detect a difference between what this program does and what the program should do, since the lowest 32 bits of the result are the same for both instructions.


Need Your Help

Removing every other character in a string using Java regex

java regex

I have this homework problem where I need to use regex to remove every other character in a string.

In jQuery what is the difference between using the dollar sign VS var?

jquery var dollar-sign

I'm working with a developer that never uses var when declaring variables in jQuery. Something like: