This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Question about precise definition FLOOR_MOD_EXPR
- From: Geoffrey Keating <geoffk at geoffk dot org>
- To: kenner at vlsi1 dot ultra dot nyu dot edu (Richard Kenner)
- Cc: gcc at gcc dot gnu dot org
- Date: 01 Aug 2004 22:28:22 -0700
- Subject: Re: Question about precise definition FLOOR_MOD_EXPR
- References: <10408020131.AA28517@vlsi1.ultra.nyu.edu>
kenner@vlsi1.ultra.nyu.edu (Richard Kenner) writes:
> What should the result of <FLOOR_MOD_EXPR 11 -5> be?
>
> There is recent code added to fold that says that the negation can be ignored
> so this should be 1.
>
> However, if the "-5" is a variable and you let it be evaluated at runtime,
> the result is -4.
>
> I think it's a bad idea that folding produces a different result than
> executing the computation at run-time.
>
> Moreover, what *is* the result supposed to be? The Ada standard is clear
> that it should be -4. From looking at the online version of the C
> standard, I can't tell whether 1, -4 or choosing either at random is
> a valid result. Does anybody know? How about C++? Java? Does this
> come up in Fortran?
I believe that FLOOR_MOD_EXPR has the property that
x == (x FLOOR_DIV_EXPR y) * y + (x FLOOR_MOD_EXPR y)
just as TRUNC_MOD corresponds to TRUNC_DIV.
So, in this case, the result of the divide is -3, and so the result of
the modulo is -4, and fold() is wrong.