From: Detlev Zundel <dzu@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RESEND PATCH v2 1/5] Tegra2: Add macros to calculate bitfield shifts and masks
Date: Wed, 13 Jul 2011 13:28:22 +0200 [thread overview]
Message-ID: <m262n6whbd.fsf@ohwell.denx.de> (raw)
In-Reply-To: <CAF6FioVOEuNcEsr=3jyxoVs__dO3Ox+q00PnDBRHdu+UmJZF2g@mail.gmail.com> (Anton Staaf's message of "Tue, 12 Jul 2011 16:11:08 -0700")
Hi Anton,
[...]
> The only problem with this is that there is one piece of missing
> information, which is how do you get the value of the field that is
> masked as if it were a 4-bit or 3-bit number. ?That is, if I want the
> IPS_DIV value, I probably want:
>
> ? ?(value & SCFR1_IPS_DIV_MASK) >> 20
>
> Likewise, if I want to set the IPS divisor to 5 say, I would have to do:
>
> ? ?(value & ~SCFR1_IPS_DIV_MASK) | (5 << 20)
>
> In both cases the value 20 needs to come from somewhere. ?So you would
> probably end up having:
>
> ? ?#define SCFR1_IPS_DIV_MASK ? ? ?0x03800000
> ? ?#define SCFR1_IPS_DIV_SHIFT ? ? ?20
>
> and
>
> ? ?(value & SCFR1_IPS_DIV_MASK) >> SCFR1_IPS_DIV_SHIFT
> ? ?(value & ~SCFR1_IPS_DIV_MASK) | (5 << SCFR1_IPS_DIV_SHIFT)
>
> And I think it would be great if these could turn into:
>
> ? ?field_value = GET_FIELD(register_value, SCFR1_IPS_DIV)
> ? ?register_value = SET_FIELD(register_value, SCFR1_IPS_DIV, 5)
Let me take this opportunity to once more explain why I don't like this.
As a big fan of functional programming, I personally have grown used to
code as explicit as possible. So _all_ arguments to a function should
be explicit in the call - reliance on state or such "hidden arguments"
violate this principle strongly. I learnt that code following these
principles written by other people is much easier for me to understand.
Cheers
Detlev
--
There are two hard things in computer science: cache invalidation,
naming things, and off-by-one errors.
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-40 Fax: (+49)-8142-66989-80 Email: dzu at denx.de
next prev parent reply other threads:[~2011-07-13 11:28 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-05 16:49 [U-Boot] [RESEND PATCH v2 0/5] Add basic clock and pinmux functions to the Tegra2 Simon Glass
2011-07-05 16:49 ` [U-Boot] [RESEND PATCH v2 1/5] Tegra2: Add macros to calculate bitfield shifts and masks Simon Glass
2011-07-09 13:56 ` Albert ARIBAUD
2011-07-11 4:34 ` Simon Glass
2011-07-11 6:16 ` Wolfgang Denk
2011-07-11 16:19 ` Anton Staaf
2011-07-12 15:29 ` Albert ARIBAUD
2011-07-12 16:48 ` Anton Staaf
2011-07-12 19:30 ` Wolfgang Denk
2011-07-12 20:59 ` Anton Staaf
2011-07-12 21:18 ` Wolfgang Denk
2011-07-12 23:11 ` Anton Staaf
2011-07-13 11:28 ` Detlev Zundel [this message]
2011-07-13 16:47 ` Anton Staaf
2011-07-14 16:00 ` Albert ARIBAUD
2011-07-14 17:29 ` Anton Staaf
2011-07-14 18:26 ` Albert ARIBAUD
2011-07-14 18:30 ` Wolfgang Denk
2011-07-14 18:42 ` Anton Staaf
2011-07-14 18:44 ` Wolfgang Denk
2011-07-14 20:06 ` Anton Staaf
2011-07-11 6:13 ` Wolfgang Denk
2011-07-05 16:49 ` [U-Boot] [RESEND PATCH v2 2/5] Tegra2: Add microsecond timer functions Simon Glass
2011-07-09 13:58 ` Albert ARIBAUD
2011-07-10 5:24 ` Graeme Russ
2011-07-10 6:14 ` Simon Glass
2011-07-10 6:54 ` Graeme Russ
2011-07-11 6:17 ` Wolfgang Denk
2011-07-11 6:20 ` Wolfgang Denk
2011-07-11 6:43 ` Graeme Russ
2011-07-11 19:58 ` Wolfgang Denk
2011-07-11 22:52 ` Graeme Russ
2011-07-05 16:49 ` [U-Boot] [RESEND PATCH v2 3/5] Tegra2: Add more clock support Simon Glass
2011-07-05 16:49 ` [U-Boot] [RESEND PATCH v2 4/5] Tegra2: add additional pin multiplexing features Simon Glass
2011-07-05 16:49 ` [U-Boot] [RESEND PATCH v2 5/5] Tegra2: Use clock and pinmux functions to simplify code Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m262n6whbd.fsf@ohwell.denx.de \
--to=dzu@denx.de \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox