This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Wrong inline assembler code generation (IMulL)



I've tried to compile this using -g and -O :
(under DJGPP 2.03, GCC 2.95.2 19991024 release)

(FixedPoint numbers using ASM)

// Result = A * B / C without loss of higher part of intermediate results
inline int Pm (int A, int B, int C)
 {
  int Result, temp;
  asm volatile ("IMulL %3\n\t"
                "IDivL %4\n\t"
                : "=a" (Result), "=d" (temp)
                : "0" (A), "r" (B), "r" (C)
                : "cc");
 }

...

int A, B, C, D;
A = 0x50000;
B = 0x30000;
C = 0x40000;
D = Pm (A, B, C);

...

And I have got SIGFPE (Division by zero). When I looked at the generated
code, it looked like this:

...

MovL  $0x50000, %EDI
MovL  $0x30000, %ESI
MovL  $0x40000, %EDX
MovL  %EDI, %EAX
IMulL %ESI, %EAX          // This will change EDX -> EDX:EAX = result of IMUL
IDiv  %EDX, %EAX          // Wrong divide

Did I something wrong ?

                                          Peter

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]