linux-acpi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Tony Luck <tony.luck@gmail.com>
Cc: Borislav Petkov <bp@alien8.de>,
	Chen Gong <gong.chen@linux.intel.com>,
	"Naveen N. Rao" <naveen.n.rao@linux.vnet.ibm.com>,
	m.chehab@samsung.com, arozansk@redhat.com,
	linux-acpi <linux-acpi@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Thomas Winischhofer <thomas@winischhofer.net>,
	Jean-Christophe Plagniol-Villard <plagnioj@jcrosoft.com>,
	Tomi Valkeinen <tomi.valkeinen@ti.com>
Subject: Re: [PATCH v2 3/9] bitops: Introduce a more generic BITMASK macro
Date: Thu, 17 Oct 2013 11:13:31 -0700	[thread overview]
Message-ID: <1382033611.22110.131.camel@joe-AO722> (raw)
In-Reply-To: <CA+8MBbLDVJgY9WWTY6vPeY7+L04-xDPofJ9eLwh7dJipBBh51w@mail.gmail.com>

On Thu, 2013-10-17 at 09:10 -0700, Tony Luck wrote:
> On Thu, Oct 17, 2013 at 1:55 AM, Joe Perches <joe@perches.com> wrote:
> > It's cost free to add the BUILD_BUG_ON
> > and perhaps you underestimate the runtime
> > bug checking effort,
> 
> This looks OK to me.  Gong: This doesn't stop people from using variables
> as arguments ... they just won't get a check for (h) < (l).

Another possibility is to swap high and low if necessary and
maybe warn when either is negative or too large for the bit width.

#define GENMASK(h, l)							\
({									\
	size_t high = h;						\
	size_t low = l;							\
	BUILD_BUG_ON(__builtin_constant_p(l) &&				\
		     __builtin_constant_p(h) &&				\
		     (l) > (h));					\
	BUILD_BUG_ON(__builtin_constant_p(l) &&				\
		     __builtin_constant_p(h) &&				\
		     ((l) >= BITS_PER_LONG ||				\
		      (h) >= BITS_PER_LONG));				\
	WARN_ONCE((!__builtin_constant_p(l) &&				\
		   ((l) < 0 || (l) > BITS_PER_LONG)) ||			\
		  (!__builtin_constant_p(h) &&				\
		   ((h) < 0 || (h) > BITS_PER_LONG)) ||			\
		  (l) > (h),						\
		  "GENMASK: invalid mask values: l: %u, h: %d\n",	\
		  (l), (h));						\
	if (low > high)							\
		swap(low, high);					\
	(((U32_C(1) << (high - low + 1)) - 1) << low);			\
})

And maybe this should be renamed something like
#define BIT_MASK_RANGE(h, l)
or
#define BIT_MASK_SHIFTED(h, l)



  reply	other threads:[~2013-10-17 18:13 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-16 14:55 [PATCH v2 0/9] Extended H/W error log driver Chen, Gong
2013-10-16 14:55 ` [PATCH v2 1/9] ACPI, APEI, CPER: Fix status check during error printing Chen, Gong
2013-10-16 16:53   ` Mauro Carvalho Chehab
2013-10-16 14:55 ` [PATCH v2 2/9] ACPI, CPER: Update cper info Chen, Gong
2013-10-16 16:28   ` Borislav Petkov
2013-10-16 16:52   ` Mauro Carvalho Chehab
2013-10-16 14:56 ` [PATCH v2 3/9] bitops: Introduce a more generic BITMASK macro Chen, Gong
2013-10-16 16:41   ` Borislav Petkov
2013-10-16 17:02   ` Mauro Carvalho Chehab
2013-10-17  2:31     ` Chen Gong
2013-10-17  2:59   ` Joe Perches
2013-10-17  6:30     ` Chen Gong
2013-10-17  6:58       ` Joe Perches
2013-10-17  7:38         ` Chen Gong
2013-10-17  8:32           ` Joe Perches
2013-10-17  8:40             ` Borislav Petkov
2013-10-17  8:55               ` Joe Perches
2013-10-17 16:10                 ` Tony Luck
2013-10-17 18:13                   ` Joe Perches [this message]
2013-10-16 14:56 ` [PATCH v2 4/9] ACPI, x86: Extended error log driver for x86 platform Chen, Gong
2013-10-16 17:02   ` Borislav Petkov
2013-10-16 14:56 ` [PATCH v2 5/9] DMI: Parse memory device (type 17) in SMBIOS Chen, Gong
2013-10-16 17:05   ` Borislav Petkov
2013-10-17 10:14   ` Mauro Carvalho Chehab
2013-10-16 14:56 ` [PATCH v2 6/9] ACPI, APEI, CPER: Add UEFI 2.4 support for memory error Chen, Gong
2013-10-16 16:43   ` Mauro Carvalho Chehab
2013-10-17 10:23   ` Mauro Carvalho Chehab
2013-10-17 12:16     ` Chen Gong
2013-10-17 12:23   ` Naveen N. Rao
2013-10-16 14:56 ` [PATCH v2 7/9] ACPI, APEI, CPER: Enhance memory reporting capability Chen, Gong
2013-10-16 17:11   ` Borislav Petkov
2013-10-17 10:24   ` Mauro Carvalho Chehab
2013-10-16 14:56 ` [PATCH v2 8/9] ACPI, APEI, CPER: Cleanup CPER memory error output format Chen, Gong
2013-10-16 17:24   ` Borislav Petkov
2013-10-17 10:27     ` Mauro Carvalho Chehab
2013-10-16 14:56 ` [PATCH v2 9/9] ACPI / trace: Add trace interface for eMCA driver Chen, Gong
2013-10-16 15:50   ` Mauro Carvalho Chehab
2013-10-16 17:29   ` Borislav Petkov
2013-10-16 15:06 ` [PATCH v2 0/9] Extended H/W error log driver Chen Gong
2013-10-16 16:05 ` Borislav Petkov
2013-10-16 16:49   ` Joe Perches
2013-10-16 16:56   ` Steven Rostedt
2013-10-16 18:00     ` Borislav Petkov
2013-10-16 18:11       ` Borislav Petkov
2013-10-17 14:33         ` Chen Gong
2013-10-17 15:25           ` Steven Rostedt
2013-10-17 15:35             ` 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=1382033611.22110.131.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=arozansk@redhat.com \
    --cc=bp@alien8.de \
    --cc=gong.chen@linux.intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m.chehab@samsung.com \
    --cc=naveen.n.rao@linux.vnet.ibm.com \
    --cc=plagnioj@jcrosoft.com \
    --cc=thomas@winischhofer.net \
    --cc=tomi.valkeinen@ti.com \
    --cc=tony.luck@gmail.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;
as well as URLs for NNTP newsgroup(s).