🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1239

bitfields

#1239
From: Mark Bromley
Date: Wed, 30 Sep 1992 21:38
57 lines
2062 bytes
These are all questions/comments rather than bugs.  Is there a more
appropriate mailing list?

I'd like to see bitfields be efficient enough so that I could always use
them rather than doing manual packing/unpacking.  Unfortunately there are
still some big hits.

1) On the sparc bitfields seem to allocated in a big endian fashion.  There
is a competing concern in that the least significant 12 bits are faster to
access.  Its a little grotty to have to explicitly pad out the definition
so that important bits fall in the low 12 bits.

2) The compiler seems to always emit a read-modify-write for each
assignment to a bitfield.  When one has carefully aligned fields on word
boundaries it is possible to produce much better code when there are
successive assignments to all the fields in a word.  Eg

    typedef struct x {
      /* ... */
      signed int a	: 14;
      unsigned int b	:  6;
      unsigned int c	: 12;
    } HASH_ENTRY;

    struct x *p;

    p->a = aa;
    p->b = bb;
    p->c = cc;

The sequence of individual read-modify-writes takes 18 cycles on the
cypress sparc chip.  By taking advantage of the fact that the whole word is
being filled you can cut this in half.

3) Logical operations (bitwise and, xor, or) on a bitfield are done by
extracting the field, doing the operation and then reinserting the new
value.  Its possible to do these in place.  Eg

   struct flags {
     unsigned pad:31;
     unsigned turn:1;
   };

   struct flags f;

   f.turn ^= 1;

For this I see sparc code like:

	and %l0,1,%o0
	xor %o0,1,%o0
	and %l0,-2,%l0
	or %l0,%o0,%l0

It could be:

	xor %l1,1,%l1
Technical Details
Message-ID: <9209302138.AA26469@luna.think.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!think.com!bromley

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!convex!linac!pacific.mps.ohio-state.edu!cis.ohio-state.edu!think.com!bromley
From: bromley@think.com (Mark Bromley)
Subject: bitfields
Message-ID: <9209302138.AA26469@luna.think.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 30 Sep 1992 21:38:55 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 59