|16-bit integers on 32-bit machine(PowerPC) email@example.com (joshc) (2005-02-16)|
|Re: 16-bit integers on 32-bit machine(PowerPC) firstname.lastname@example.org (2005-02-18)|
|From:||email@example.com (Henry Spencer)|
|Date:||18 Feb 2005 22:49:51 -0500|
|Organization:||SP Systems, Toronto, Canada|
joshc <firstname.lastname@example.org> wrote:
>unsigned short int foo(unsigned short int x, unsigned short int y)
>(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...
Normally, the caller is required to do any type conversions as part of
the function call, so the function gets what it is expecting.
Probably the conventions used by this particular compiler say that
when a less-than-32-bits data type is held in a 32-bit register, the
unused upper bits may be trash, and anyone who needs them cleared must
clear them himself. This makes considerable sense if the instruction
set is such that (a) they are likely to contain trash, and (b) many
possible uses of the data won't be bothered by the trash.
But unless the instruction set can shift half a register -- which is pretty
rare -- a right shift is one case where you do need the upper bits clear.
"Think outside the box -- the box isn't our friend." | Henry Spencer
-- George Herbert | email@example.com
Return to the
Search the comp.compilers archives again.