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

henry@spsystems.net (Henry Spencer)
18 Feb 2005 22:49:51 -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: henry@spsystems.net (Henry Spencer)
Newsgroups: comp.compilers
Date: 18 Feb 2005 22:49:51 -0500
Organization: SP Systems, Toronto, Canada
References: 05-02-072
Keywords: C, architecture
Posted-Date: 18 Feb 2005 22:49:50 EST



joshc <josh.curtz@gmail.com> 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 | henry@spsystems.net


Post a followup to this message

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