From: Joe Perches <joe@perches.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-kernel@vger.kernel.org, Akinobu Mita <mita@miraclelinux.com>
Subject: Re: [PATCH] bitops: move BITS() macro to the bitops file
Date: Wed, 07 Aug 2013 03:33:34 -0700 [thread overview]
Message-ID: <1375871614.2424.103.camel@joe-AO722> (raw)
In-Reply-To: <1375866379-27504-1-git-send-email-linus.walleij@linaro.org>
On Wed, 2013-08-07 at 11:06 +0200, Linus Walleij wrote:
> This macro was invented by Mattias Nilsson for the usecase
> where you want to set a sequence of bits inside a n-bit
> word, while leaving the head and tail of the sequence all
> zeroes. For example:
>
> #include <linux/bitops.h>
BITS is a name that's not easily reused because it's
already in use in a few other places.
There are a few conflicts.
$ git grep -E "^\s*#\s*define\s+\bBITS\b"
arch/arc/include/asm/disasm.h:#define BITS(word, s, e) (((word) >> (s)) & (~((-2) << ((e) - (s)))))
drivers/input/keyboard/tnetv107x-keypad.c:#define BITS(x) (BIT(x) - 1)
drivers/mfd/dbx500-prcmu-regs.h:#define BITS(_start, _end) ((BIT(_end) - BIT(_start)) + BIT(_end))
drivers/net/wireless/iwlwifi/mvm/fw-api-bt-coex.h:#define BITS(nb) (BIT(nb) - 1)
fs/select.c:#define BITS(fds, n) (*FDS_IN(fds, n)|*FDS_OUT(fds, n)|*FDS_EX(fds, n))
lib/zlib_inflate/inflate.c:#define BITS(n) \
sound/core/oss/rate.c:#define BITS (1<<SHIFT)
> u16 mask = BITS(4, 12);
>
> Yields a mask like this:
>
> 0001111111110000
[]
> diff --git a/drivers/mfd/dbx500-prcmu-regs.h b/drivers/mfd/dbx500-prcmu-regs.h
[]
> @@ -13,8 +13,6 @@
[]
> -#define BITS(_start, _end) ((BIT(_end) - BIT(_start)) + BIT(_end))
> diff --git a/include/linux/bitops.h b/include/linux/bitops.h
[]
> @@ -6,6 +6,7 @@
[]
> +#define BITS(_start, _end) ((BIT(_end) - BIT(_start)) + BIT(_end))
Maybe use a statement expression to make sure
the start and end accesses are done only once.
#define BITS(start, end) \
({ \
unsigned long high = BIT(end); \
unsigned long low = BIT(start); \
unsigned long rtn = high + (high - low); \
rtn; \
})
I suggest | instead of + too.
Maybe add a WARN when low > high too.
Maybe make it a function to consolidate
any WARN instead of inline expansion.
next prev parent reply other threads:[~2013-08-07 10:33 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-07 9:06 Linus Walleij
2013-08-07 10:12 ` anish singh
2013-08-07 10:33 ` Joe Perches [this message]
2013-08-07 10:54 ` Borislav Petkov
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=1375871614.2424.103.camel@joe-AO722 \
--to=joe@perches.com \
--cc=linus.walleij@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mita@miraclelinux.com \
/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
all inboxes | Powered by JetHome®