linux-aspeed.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Kalle Valo <kvalo@codeaurora.org>
To: linux-aspeed@lists.ozlabs.org
Subject: [PATCH 01/17] bitfield: Add non-constant field_{prep, get}() helpers
Date: Wed, 24 Nov 2021 10:24:02 +0200	[thread overview]
Message-ID: <87sfvm55ct.fsf@codeaurora.org> (raw)
In-Reply-To: <CAMuHMdUnBgFpqhgjf5AA0LH9MZOFALeC=YinZ4Tv_V+Y9hkRSg@mail.gmail.com> (Geert Uytterhoeven's message of "Tue, 23 Nov 2021 09:30:14 +0100")

Geert Uytterhoeven <geert@linux-m68k.org> writes:

> Hi Johannes,
>
> On Mon, Nov 22, 2021 at 5:33 PM Johannes Berg <johannes@sipsolutions.net> wrote:
>> On Mon, 2021-11-22 at 16:53 +0100, Geert Uytterhoeven wrote:
>> > The existing FIELD_{GET,PREP}() macros are limited to compile-time
>> > constants.  However, it is very common to prepare or extract bitfield
>> > elements where the bitfield mask is not a compile-time constant.
>> >
>>
>> I'm not sure it's really a good idea to add a third API here?
>>
>> We have the upper-case (constant) versions, and already
>> {u32,...}_get_bits()/etc.
>
> These don't work for non-const masks.
>
>> Also, you're using __ffs(), which doesn't work for 64-bit on 32-bit
>> architectures (afaict), so that seems a bit awkward.
>
> That's a valid comment. Can be fixed by using a wrapper macro
> that checks if typeof(mask) == u64, and uses an __ffs64() version when
> needed.
>
>> Maybe we can make {u32,...}_get_bits() be doing compile-time only checks
>> if it is indeed a constant? The __field_overflow() usage is already only
>> done if __builtin_constant_p(v), so I guess we can do the same with
>> __bad_mask()?
>
> Are all compilers smart enough to replace the division by
> field_multiplier(field) by a shift?

It looks like the answer is no as few weeks back I received a comment
internally that a team is seeing a slow down with u32_get_bits():

"Time taken for executing both the macros/inline function (in terms of microseconds)
(out of 3 Trails)
FIELD_GET	: 32, 31, 32
u32_get_bits	: 6379, 6664, 6558"

Sadly I didn't realise to ask what compiler they were using. But I still
prefer {u32,...}_get_bits() over FIELD_GET(), they are just so much
cleaner to use.

-- 
https://patchwork.kernel.org/project/linux-wireless/list/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

  parent reply	other threads:[~2021-11-24  8:24 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-22 15:53 [PATCH 00/17] Non-const bitfield helper conversions Geert Uytterhoeven
2021-11-22 15:53 ` [PATCH 01/17] bitfield: Add non-constant field_{prep,get}() helpers Geert Uytterhoeven
2021-11-22 16:32   ` Johannes Berg
2021-11-23  1:17     ` Jakub Kicinski
2021-11-23  8:36       ` [PATCH 01/17] bitfield: Add non-constant field_{prep, get}() helpers Geert Uytterhoeven
2021-11-23 16:24         ` [PATCH 01/17] bitfield: Add non-constant field_{prep,get}() helpers Johannes Berg
2021-11-23 23:49           ` Jakub Kicinski
2021-11-24  8:03             ` Johannes Berg
2021-11-24 13:59               ` Jakub Kicinski
2021-11-24 14:07                 ` Johannes Berg
2021-11-23 23:39         ` Jakub Kicinski
2021-11-23  1:52     ` Alex Elder
2021-11-23  8:38       ` [PATCH 01/17] bitfield: Add non-constant field_{prep, get}() helpers Geert Uytterhoeven
2021-11-23  8:30     ` Geert Uytterhoeven
2021-11-23 16:21       ` [PATCH 01/17] bitfield: Add non-constant field_{prep,get}() helpers Johannes Berg
2021-11-23 16:31         ` [PATCH 01/17] bitfield: Add non-constant field_{prep, get}() helpers Geert Uytterhoeven
2021-11-24  8:24       ` Kalle Valo [this message]
2021-11-22 15:53 ` [PATCH 02/17] clk: renesas: Use bitfield helpers Geert Uytterhoeven
2021-11-22 15:53 ` [PATCH/RFC 03/17] soc: " Geert Uytterhoeven
2021-11-22 15:53 ` [PATCH/RFC 04/17] ARM: OMAP2+: " Geert Uytterhoeven
2021-11-22 15:53 ` [PATCH/RFC 05/17] bus: omap_l3_noc: " Geert Uytterhoeven
2021-11-22 15:53 ` [PATCH/RFC 06/17] clk: ti: " Geert Uytterhoeven
2021-11-22 15:54 ` [PATCH/RFC 07/17] iio: st_sensors: " Geert Uytterhoeven
2021-11-23 23:35   ` Linus Walleij
2021-11-22 15:54 ` [PATCH/RFC 08/17] iio: humidity: hts221: " Geert Uytterhoeven
2021-11-24 15:21   ` Jonathan Cameron
2021-11-22 15:54 ` [PATCH/RFC 09/17] iio: imu: st_lsm6dsx: " Geert Uytterhoeven
2021-11-22 15:54 ` [PATCH/RFC 10/17] media: ti-vpe: cal: " Geert Uytterhoeven
2021-11-22 15:54 ` [PATCH/RFC 11/17] mmc: sdhci-of-aspeed: " Geert Uytterhoeven
2021-11-22 15:54 ` [PATCH/RFC 12/17] pinctrl: aspeed: " Geert Uytterhoeven
2021-11-22 15:54 ` [PATCH/RFC 13/17] pinctl: ti: iodelay: " Geert Uytterhoeven
2021-11-22 17:52   ` Alexandre Belloni
2021-11-22 15:54 ` [PATCH/RFC 14/17] regulator: ti-abb: " Geert Uytterhoeven
2021-11-22 16:31   ` Mark Brown
2021-11-22 15:54 ` [PATCH/RFC 15/17] thermal/ti-soc-thermal: " Geert Uytterhoeven
2021-11-22 15:54 ` [PATCH/RFC 16/17] ALSA: ice1724: " Geert Uytterhoeven
2021-11-23 11:24   ` Takashi Iwai
2021-11-22 15:54 ` [PATCH/RFC 17/17] rtw89: " Geert Uytterhoeven
2021-11-22 18:38   ` Larry Finger
2021-11-22 17:50 ` [PATCH 00/17] Non-const bitfield helper conversions Alexandre Belloni
2021-11-23  8:20   ` Geert Uytterhoeven

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=87sfvm55ct.fsf@codeaurora.org \
    --to=kvalo@codeaurora.org \
    --cc=linux-aspeed@lists.ozlabs.org \
    /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;
as well as URLs for NNTP newsgroup(s).