16-bit integers on 32-bit machine(PowerPC)

"joshc" <josh.curtz@gmail.com>
16 Feb 2005 20:53:00 -0500

          From comp.compilers

Related articles
16-bit integers on 32-bit machine(PowerPC) josh.curtz@gmail.com (joshc) (2005-02-16)
Re: 16-bit integers on 32-bit machine(PowerPC) henry@spsystems.net (2005-02-18)
| List of all articles for this month |

From: "joshc" <josh.curtz@gmail.com>
Newsgroups: comp.compilers
Date: 16 Feb 2005 20:53:00 -0500
Organization: http://groups.google.com
Keywords: C, question
Posted-Date: 16 Feb 2005 20:53:00 EST

I've got a question about the assembly generated for 16-bit integer
operations on a 32-bit PowerPC. I have a function in C that has
several 16-bit unsigned integer parameters(on my compiler unsigned
short int). Let's say the function is as below:

unsigned short int foo(unsigned short int x, unsigned short int y)
    return x >> y;

The arguments x and y are passed in register r3 and r4 respectively.
The first thing that is done in the aseembly listing for this function
is that r3 has its most significant 16 bits cleared. I am trying to
understand 2 things:
(1) Why is only 'x'(r3) being converted to an unsigned short int
whereas 'y' isn't?
(2) I also want to understand why it is necessary to clear the most
significant 16 bits of 16-bit variables when passed in 32-bit
registers. Is this because the caller could pass any data type as an
argument, i.e. a long int, and this is how the implicit casting that is
part of the C language is achieved?

[(1) most likely because the right shift instruction only looks at the
low bits of the shift count
(2) If it didn't clear the top half, what would get shifted into the result?

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.