A question about the data type of rtems
Ralf Corsepius
ralf.corsepius at rtems.org
Mon Oct 13 13:25:17 UTC 2008
On Mon, 2008-10-13 at 15:09 +0200, Thomas Doerfler wrote:
> PowerMan wrote:
> >
> > 3. If so, I found some driver uses "int",
> > Would that make some problems to portability?
>
> It depends. "int" should the the integral data type that the target CPU
> can process as fast as possible (more or less). So it makes sense to use
> the type "int" for "small" counter loops and similar things.
Not necessarily:
- there are cases when counter loops need to have different sizes than
"ints", e.g. "unsigned ints" or iterations over array indexes (These
internally are size_t or ssize_t).
- there are cases when using smaller types than int's can provide faster
iterations/better code (Nowadays, GCC often does this kind of
optimization by itself)
- All [u]int<size>_t types are typedefs to ordinal types. I.e. compiler
optimization-wise using them instead of "ordinal types" rarely make a
difference.
> E.g: PowerPC has 32 bit internal registers. there are no arithmetic
> operations for smaller portions than 32 bit.
Conversely on the SHes. Some variants of them have very fast 8bit and/or
16bit operations, which take less cpu-cycles than 32bit operations.
Fortunately, in many cases (e.g. loops with constant bounds) GCC is able
to optimize them to efficient asm.
Ralf
More information about the users
mailing list