joakim.nohlgard at eistec.se
Fri Oct 28 11:11:25 CEST 2016
Thank you Juergen, this was a very comprehensive answer, in my opinion. I
have been watching this thread to understand bitfields better :)
On Oct 28, 2016 10:04 AM, "Juergen Stuber" <juergen at jstuber.net> wrote:
> 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
> devel mailing list
> devel at riot-os.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the devel