[riot-devel] bitfeilds

Juergen Stuber juergen at jstuber.net
Fri Oct 28 10:03:17 CEST 2016

Hi Neil, hi everybody,

On Thu, 27 Oct 2016 11:33:57 +0100
Neil Jones <neiljay at gmail.com> wrote:
> are you suggesting the compiler generated code for accessing the
> bitfeilds is less size efficient than doing it manually? I would be
> suprised if that was the case ?

writing to a bitfield translates to a read followed by a write of the
updated value.  So if you write to multiple bitfields in a register you
have multiple read-write pairs.  These can't be combined when the
bitfields are volatile.  Similar for multiple reads of a register.

When you use shift and mask you usually do a single access for
all fields of a register.

IMHO it is also better to use shift and mask because a write to a
bitfield is actually a hidden non-atomic read-update-write, which
may become dangerous when you have concurrent access.


> On 27 Oct 2016 08:05, "Hauke Petersen" <hauke.petersen at fu-berlin.de>
> wrote:
> > Hi Neil, hi Kees,
> >
> > though named bitfields are kind of nice when it comes to code
> > readability, they behave very poorly when it comes to code size.
> > This is especially true for register maps, as these are typically
> > volatile. For this reason, we don't use them in RIOT and I strongly
> > advice not to use those.
> >
> > As example I was able to save several 100 bytes of ROM when
> > removing the named bitfield use from the samr21s peripheral drivers.
> >
> > Cheers,
> > Hauke

Jürgen Stuber <juergen at jstuber.net>
1B78 A579 E159 2A85 67BB  1314 C083 224B 0F9C DA21
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.riot-os.org/pipermail/devel/attachments/20161028/313edcb4/attachment.sig>

More information about the devel mailing list