RFC: size-saving boolean type for busybox
Denis Vlasenko
vda.linux at googlemail.com
Tue Jan 2 22:11:32 UTC 2007
On Tuesday 02 January 2007 18:40, David Daney wrote:
> Denis Vlasenko wrote:
> > Hi people,
> >
> > I am thinking about introducing a boolean type for busybox.
> > In C people usually use int, but it takes 4 bytes of data
> > or bss when you have global flag variable.
> >
> > C99 has _Bool and on i386 it really takes 1 byte,
> > at least with gcc 4.1.1 -Os, but I am hot sure about
> > other versions and especially other arches.
> >
> > OTOH, there are CPUs which _really_ have hard time
> > dealing with 1-byte integers (generated code is much bigger),
> > so using uint8_t as "standard" type for a flag variable isn't ok.
> >
> > How about this?
> >
> > #if defined(i386) /* || defined(...) as needed */
> > typedef unsigned char bbool;
> > #else
> > typedef unsigned bbool;
> > #endif
>
> Did you do a size comparison?
Not yet.
> How about adding a check for C99 and if true, just use _Bool?
I do not trust that gcc's _Bool is 1 byte on all arches where it
makes sense. I want busybox's headers to be in control whether bbool
is a char or an int, not gcc's developer.
Why gcc should not be trusted (yet):
unsigned f(unsigned v) { return v/10; }
gcc 4.1.1 -O2:
movl $-858993459, %eax
mull 4(%esp)
shrl $3, %edx
movl %edx, %eax
ret
gcc 4.1.1 -Os:
movl 4(%esp), %eax
movl $10, %edx
movl %edx, %ecx
xorl %edx, %edx
divl %ecx
ret
gcc -O2 is not just faster - it's SMALLER too. !??
> Also MIPS can efficiently access bytes, so you could add mips to the test.
Will do.
--
vda
More information about the busybox
mailing list