David and others,

to my expreience arithemtics with signed bit fields produce much much larger
code, because the sign extension is very costly.

Try:

struct {
  int a:3;
} stest;

void test(void)
{
  if (a < 3)
     a++;
}

Same with unsigned produces much smaller code.

Moreover, fields of 1 bit width should lead to exactly the same code, no
matter if signed or unsigned. But they don't. Why?

Regards,
Ralf

"David Dyck" <david.d...@fluke.com> schrieb im Newsbeitrag
news:pine.lnx.4.51.0308261947450.23...@dd.tc.fluke.com...
> On Tue, 26 Aug 2003 at 18:05 -0700, Steve Underwood
<copp...@users.sourcefo...:
>
> > +<sect1 id="tips-and-tricks">
>
> > +
> > +<listitem><para>When defining bit fields, try to use signed integers.
This produces more compact code
> > +    that bit fields of unsigned integers.</para></listitem>
>
> I'd like to understand this suggestion a bit more, as if I want to store
0, 1, 2, or 3 in a bitfield,
> it seems like you are suggesting that I should use 3 bits instead of the
expected 2 bits that
> would be required in an unsigned bit field.  What can be done to make
msp430-gcc to generate better
> code for the unsigned integer bit field also?
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf




Reply via email to