Re: C and side-effects

From: George Anzinger (george@pioneer.net)
Date: Fri May 05 2000 - 10:57:55 EST


Anton Altaparmakov wrote:
>
> At 10:50 04/05/2000, George Anzinger wrote:
> > I wrote:
> >
> >c = (c - d)>>n + d;
> >
> >and tested for values of 0 < c < 40, 1 < d < 40 and 0 < n < 80.
> >
> >Turns out that gcc (and the hardware) tend to give unexpected results
> >for n>32. I think the shift is done modulo 32. What does the standard
> >have to say about this?
>
> Aren't you thinking of: c = ((c - d) >> n) + d ? That would evaluate as d-1
> for n > 32 but what you said is actually:
> What you write would evaluate as: c = (c - d) >> (n + d) which obviously
> does something else...

Right! I should have cut the expression from my test program. The
problem I am trying to address is the test/jump around. Given current
machines just how much does a test/jump ( taken if) cost. For example,
the above expression (fixed of course) with the limits on its input:
a. Does nothing if n=0 and
b. Evaluates to d-1 for n>6

Clearly a test for n>6 is worth it to avoid the n>32 issue, but is the
n==0 test worth it, or is it faster to just evaluate the expression?

George

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Sun May 07 2000 - 21:00:17 EST