Right-shift of a signed 64-bit value by 64 bits produces the original input when the shift amount is a constant, but the signed value when it's a variable. Left shift produces zero for both constant and variable shift amounts.
Shifts of 16, and 32-bit values by the value size in bits consistently produce zero. (8-bit values are promoted to int, so left shift does not produce zero.)
The behavior of these operations is supposed to be undefined, but it would be nice if it were consistent.
commit 129e28e96694452e76d573053f3ec7b920504432
Author: Peter A. Bigot <pabigot@users.sourceforge.net>
Date: Sat Aug 20 19:53:15 2011 -0500
SF 3237002 implement 430x multi-bit shift/rotate
Major rework of all shift operations. Instructions have been added to
consistently optimize 48-bit, 32-bit, 16-bit, and 8-bit constant shifts on
all word sizes. Where feasible, the multi-bit shift operations of CPUX are
used, as is the unsigned right shift instruction.
libgcc has been extended with hand-optimized functions to perform shift
operations with runtime-determined shift counts. While fast, in the common
case of few non-constant multi-word shifts the presence of these functions
increases code size significantly. Use of them requires
-menable-libcall-shift, and will be inhibited if -Os is also specified.
This commit also addresses:
SF 3250822 inconsistent results shifting by bit-size of value
in that shifts of an N-bit value by N or higher has no effect on the value.
In previous implementations, such a shift would sometimes result in zero (or
all ones for ashr).