I'm wondering about the assembly generated by my compiler for a 32-bit PowerPC processor. I have some code(in C) that deals with 16 bit unsigned integer types(unsigned short int on my compiler) and I have some questions about the assembly that is generated for some of the code.
If I have a function such as the following:
unsigned short int foo(unsigned short int x, unsigned short int y) { return x >> y; }
I compile this without optimizations and I get assembly such as the following(x is passed in r31, y in r30):
rlwinm r12, r31, 0, 16, 31 srw r29, r12, r30
What I want to understand is why 'x' is effectively cast to an unsigned short int but 'y' is not. Is this because the ANSI C standard states that shifting a 16-bit value by more than 15 results in undefined behavior?
I am basically trying to get a grasp of the overhead involved with dealing with 16-bit integers on a 32-bit machine. BTW, I tried posting this to comp.compilers but apparently it might take a few days for the moderator to accept my message so I posted here due to urgency.
Thanks!