Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Apr 1997 14:09:09 +0200
From:      j@uriah.heep.sax.de (J Wunsch)
To:        freebsd-hackers@freebsd.org
Subject:   Re: How to declare device driver variables and data structures ?
Message-ID:  <19970406140909.UB47399@uriah.heep.sax.de>
In-Reply-To: <m0wDonp-00002GC@ernie.kts.org>; from Hellmuth Michaelis on Apr 6, 1997 12:04:01 %2B0200
References:  <m0wDonp-00002GC@ernie.kts.org>

next in thread | previous in thread | raw e-mail | index | archive | help
As Hellmuth Michaelis wrote:

> i.e. if i know a variable can only have values 0 ... 32, shall i make it
> an unsigned char ? Is it slower to make such variables an unsigned int
> or an unsigned short ? What are the space vs. speed considerations ?

You should probably only use shorter values than plain int or unsigned
if either the hardware enforces a particular size (since it's a mirror
of a hardware register or such), or if you pack a bunch of them
beneath, and they are static/extern/bss.  For automatic variables, i
think it's better to stick with the default size for your machine.
I'm not sure, but if it has an effect at all, restraining the size
will make the access slower.

> another i.e. for boolean variables, is it better to make them chars, shorts
> or ints ? signed or unsigned ?

int's, unless you have many of them in static storage.  But then, you
want to make them flag bits, and store them temporarily in ints
locally if you need them a lot.

> What is the speed of unsigned variables vs. signed variables ?

No difference, at least not on the ix86.

> What is with future ports to other architectures ?

Do you wanna predict the future? :-)

Generally, using variables of a non-default size is likely to make the
code slower.  Other machines have a lot more of registers, so there's
nothing wrong to store temp values in registers.  Don't use `register'
declarations, the compiler is usually better in knowing what should go
into a register.

> How does this all apply to variables being part of structures ?

Alignment problems...  see also style(9).

-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19970406140909.UB47399>