[vox-tech] appropriate variable size in driver

Eric Nelson vox-tech@lists.lugod.org
Fri, 13 Sep 2002 20:07:40 -0700


On Wednesday 11 September 2002 20:03, you wrote:
> begin Eric Nelson <en77@attbi.com>
>
> > I am porting a driver from an 8 bit processer to a linux driver.
>
> heh.  you mean rewrite, right?   :-)
>
Well, the hw part is new, and the interrupts, etc.  But that's the fun=20
part.  It's the C code that does the processing that concerns me. =20
It's one of those things, the boss thinks it's just a few hours work=20
because it's existing code, but, you and I know, soon as you rebuild=20
it, especially on a new processor, all bets are off.

> > Many
> > counters and other variables are unsigned char, because they
> > don't get big, do it works, kind of the embedded thing to do -
> > keep small. The target is a 32 bit geode.  It seems like I should
> > generalize these variables to 16 bit or 32 bit.  What works
> > better?  What is more 'appropriate'.  It seems kind of old
> > fashioned to leave them at 8 bit.
>
> eric, i found that kernelnewbies.org is a good place for questions
> like this.  among other people, rik van riel hangs out on that
> mailing list, (although he mainly answers MM questions).  they've
> got some really good people there!

Thanks, pete, that's a good suggestion.  And, that's what I am, a=20
newbie.  I'll try to filter the questions I send here.
>
> pete

(I'm trying to answer all at once)
---------------------------------------------------------------------
from Jeff Newmiller   =20

Processing 8-bit integers tends to be slightly slower on 32-bit
processors, and in some architectures is considerably slower. =20
I would widen them.

As to whether signed or unsigned is slower, that is architecturally
dependent too. AFAIK signed is slightly faster on x86, but Linux is
multiplatform so that is probably not a good justification for =20
decisions.

I would use "int" unless I needed something more specific for a=20
reason.
--------------------------------------------------------------------
Eric Nelson:

Well, I guess I'll widen them, execpt part of it is processed as a=20
char array, so, I don't want to change how it operates, so I'll leave=20
that. =20
It's is easy just to say int.  But, I guess I'm old fashioned, I keep=20
wanting to use short int over int, save some cycles, but I guess the=20
processer has to do about the same work.

----------------------------------------------------------------------
Mark Kim:
I'd test the unsigned char first to make sure the code works.  There=20
could be other issues that are more important to address.  After=20
verifying the code does work and has no other issues, then move onto=20
int-fying variables.

If you int-fied everything first, and if the code didn't work, you
wouldn't know if the int-fying broke the code, if there are other=20
issues, or both.

Just my $0.03... (inflation)
-------------------------------------------------------------------------=
-
Eric Nelson:
Good suggestions.  I'll test thoroughly. =20
I've had problems in the past w/ unsigned variables, you do have to be=20
careful.  And, the problems don't show up until certain=20
situations....  ;>).

By the way, something maybe you guys didn't know, I just found out,=20
there are some types, I think in types.h,
u8,
u16,
u32,
If you want to specify exactly what size you want.
Thanks.