Rockbox mail archive
Subject: using bitwise shift operators on negative signed values
using bitwise shift operators on negative signed values
While reading the code in dsp.c, I was wondering what really was the result of
using bitwise shift operators (<< and >>) on negative signed values... It seems
from the rockbox code that we assume the sign bit is left untouched (am I right?).
I just took a look at the C99 standard, and it says (section 6.5.7):
"The result of E1 << E2 is E1 leftshifted E2 bit positions; vacated bits are
filled with zeros. If E1 has an unsigned type, the value of the result is
E1*2^E2, reduced modulo one more than the maximum value representable in the
result type. If E1 has a signed type and nonnegative value, and E1 *2^E2 is
representable in the result type, then that is the resulting value; otherwise,
the behavior is *undefined*.
The result of E1 >> E2 is E1 rightshifted E2 bit positions. If E1 has an
unsigned type or if E1 has a signed type and a nonnegative value, the value of
the result is the integral part of the quotient of E1 divided by the quantity, 2
raised to the power E2. If E1 has a signed type and a negative value, the
resulting value is *implementationdefined*."
This means that much of the code in dsp.c is probably nonportable and may break
when moving to another compiler or platform...
Any thoughts on that?
Fred
_______________________________________________
http://cool.haxx.se/mailman/listinfo/rockbox
Received on Thu Aug 11 17:33:06 2005
Page was last modified "Jan 10 2012" The Rockbox Crew
