Re: Subtraction + comparison in one asm instruction?

"Vincent Lefevre" <vincent+news@vinc17.org>
23 Aug 2002 11:03:47 -0400

          From comp.compilers

Related articles
Subtraction + comparison in one asm instruction? vincent+news@vinc17.org (Vincent Lefevre) (2002-08-10)
Re: Subtraction + comparison in one asm instruction? Peter-Lawrence.Montgomery@cwi.nl (Peter L. Montgomery) (2002-08-14)
Re: Subtraction + comparison in one asm instruction? iddw@hotmail.com (Dave Hansen) (2002-08-14)
Re: Subtraction + comparison in one asm instruction? walter@bytecraft.com (Walter Banks) (2002-08-23)
Re: Subtraction + comparison in one asm instruction? vincent+news@vinc17.org (Vincent Lefevre) (2002-08-23)
Re: Subtraction + comparison in one asm instruction? gdr@soliton.integrable-solutions.net (Gabriel Dos Reis) (2002-09-03)
Re: Subtraction + comparison in one asm instruction? vincent+news@vinc17.org (Vincent Lefevre) (2002-09-08)
Re: Subtraction + comparison in one asm instruction? gdr@integrable-solutions.net (Gabriel Dos Reis) (2002-09-12)
Re: Subtraction + comparison in one asm instruction? vbdis@aol.com (VBDis) (2002-09-12)
Re: Subtraction + comparison in one asm instruction? gdr@integrable-solutions.net (Gabriel Dos Reis) (2002-09-12)
Re: Subtraction + comparison in one asm instruction? vincent+news@vinc17.org (Vincent Lefevre) (2002-09-12)
[8 later articles]
| List of all articles for this month |

From: "Vincent Lefevre" <vincent+news@vinc17.org>
Newsgroups: comp.compilers
Date: 23 Aug 2002 11:03:47 -0400
Organization: a training zoo
References: 02-08-033 02-08-044
Keywords: architecture
Posted-Date: 23 Aug 2002 11:03:47 EDT

In article 02-08-044,
    Peter L. Montgomery <Peter-Lawrence.Montgomery@cwi.nl> wrote:


> /*
> Be careful while implementing this optimization.
> While trying to do the modular multiplication (a * b) mod p,
> where a, b, p are close to the machine word size,
> I have experienced bad code for the following sequence,
> using one Fortran and one C compiler:


> Assume we have a 32-bit machine.
> */


> unsigned int a, b, p, q;
> signed int rem;


> (initialize a, b, p, with 0 <= a,b < p < 2^31);


> q = (estimate of a*b/p)
> rem = a*b - q*p;
> if (rem < 0) rem += p;
> return (unsigned)rem;


OK, but this is not the same code. Here you have a conversion
unsigned -> signed, and if the value is not representable in a
signed int, the result is implementation-defined, and depending
on what the implementation decides, you can have several
behaviours.


In my code, if c - 1 is not representable, this is an undefined
behaviour. Thus the compiler could choose to do anything in this
case and the optimization would be valid (if there are problems
with some codes, the compiler could still provide switches to
disable the optimization for such broken codes).


Vincent Lefèvre.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.