This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Wrong inline assembler code generation (IMulL)
- To: gcc-bugs at gcc dot gnu dot org
- Subject: Wrong inline assembler code generation (IMulL)
- From: "Skvarenina Peter - 5ZA51/9" <skvaren at fred dot fri dot utc dot sk>
- Date: Fri, 12 May 2000 14:11:54 +0200 (MET DST)
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