Re: (x * x) % y

New Message Reply About this list Date view Thread view Subject view Author view

Ben Laurie (ben@algroup.co.uk)
Fri, 23 Apr 1999 11:38:38 +0100


Olivier Langlois wrote:
>
> -----Original Message-----
> From: Derek Atkins <warlord@MIT.EDU>
> To: Olivier Langlois <olanglois@sympatico.ca>
> Cc: CodherPlunks@toad.com <CodherPlunks@toad.com>
> Date: 22 avril, 1999 20:07
> Subject: Re: (x * x) % y
>
> >This would be a compiler bug, not a 'C' bug (assuming it is
> >a bug). What compiler are you using, and on what platform?
>
> The code was generated by VC++ on Windows.
> But I don't think it is a compiler bug. Like someone else said, 32 bits
> multiplication produce a 32 bits product.
>
> First I did a mistake. The correct assembler code would be:
>
> mov eax, DWORD PTR _i$[esp-4]
> mul eax
> div DWORD PTR _j$[esp-4]
> mov eax, edx
>
> The 1 operand version of the instruction mul multiply the operand (in that
> case eax) with the register eax. My first version result was unpredictable
> because eax wasn't initialized.
>
> The idea of my post is that the x86 processor can expand a 32 bits
> multiplication into a 64 bits value
> that it stores in a pair of registers (EDX:EAX). and the instruction DIV
> divide
> this value. So the x86 architecture would allow you to perform (i*i)%j for
> any value of i. But the compiler doesn't use this capability (or I don't
> know how to write correctly the C statement). It XOR the
> higher 32 bits in EDX and use a version of the MUL instruction (the 2
> operands
> version) that store the
> product in a 32 bits register.

But that is exactly what you asked it to do.

Cheers,

Ben.

--
http://www.apache-ssl.org/ben.html

"My grandfather once told me that there are two kinds of people: those who work and those who take the credit. He told me to try to be in the first group; there was less competition there." - Indira Gandhi


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Thu May 27 1999 - 23:44:22