My question is, within C++, is the following code defined? Some of it? And if it is, what’s it supposed to do in these four scenarios?
word << 100;
word >> 100;
word << -100;
word >> -100;
word is a uint32_t
(This is for a bottleneck in a 3d lighting renderer. One of the more minor improvements in the inner most loop I wanna make is eliminating needless conditional forks. One of those forks is checking to see if a left shift should be done on several 32 bit words as part of a hamming weight count. If the left shift accepts absurd values, the checks don’t need done at all)
In the C++0X draft N3290, §5.8:
Note: the above paragraph is identical in the C++03 standard.
So the last two are undefined. The others, I believe depend on whether
wordis signed or not, ifwordis at least 101bits long. Ifwordis “smaller” than 101bits, the above applies and the behavior is undefined.Here are the next two sections of that paragraph in C++0X (these do differ in C++03):