mirror of
https://github.com/torvalds/linux.git
synced 2026-05-27 00:22:00 +02:00
drm/i915/reg: make masked field helpers constexpr
Make it possible to use _MASKED_FIELD(), _MASKED_BIT_ENABLE() and _MASKED_BIT_DISABLE() in contexts that require integer constant expressions. This increases their usefulness at the small cost of making the warnings from build time checks less helpful. Reviewed-by: Michał Grzelak <michal.grzelak@intel.com> Acked-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Link: https://patch.msgid.link/788f538cc71dec0db25e0c768e8945bef6f9701c.1772042022.git.jani.nikula@intel.com Signed-off-by: Jani Nikula <jani.nikula@intel.com>
This commit is contained in:
parent
f5c8f824a4
commit
b6d558af2d
|
|
@ -106,17 +106,17 @@
|
|||
BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0))))
|
||||
|
||||
#define __MASKED_FIELD(mask, value) ((mask) << 16 | (value))
|
||||
#define _MASKED_FIELD(mask, value) ({ \
|
||||
if (__builtin_constant_p(mask)) \
|
||||
BUILD_BUG_ON_MSG(((mask) & 0xffff0000), "Incorrect mask"); \
|
||||
if (__builtin_constant_p(value)) \
|
||||
BUILD_BUG_ON_MSG((value) & 0xffff0000, "Incorrect value"); \
|
||||
if (__builtin_constant_p(mask) && __builtin_constant_p(value)) \
|
||||
BUILD_BUG_ON_MSG((value) & ~(mask), \
|
||||
"Incorrect value for mask"); \
|
||||
__MASKED_FIELD(mask, value); })
|
||||
#define _MASKED_BIT_ENABLE(a) ({ typeof(a) _a = (a); _MASKED_FIELD(_a, _a); })
|
||||
#define _MASKED_BIT_DISABLE(a) (_MASKED_FIELD((a), 0))
|
||||
#define _MASKED_FIELD(mask, value) \
|
||||
(BUILD_BUG_ON_ZERO(__builtin_choose_expr(__builtin_constant_p(mask), (mask) & 0xffff0000, 0)) + \
|
||||
BUILD_BUG_ON_ZERO(__builtin_choose_expr(__builtin_constant_p(value), (value) & 0xffff0000, 0)) + \
|
||||
BUILD_BUG_ON_ZERO(__builtin_choose_expr(__builtin_constant_p(mask) && __builtin_constant_p(value), (value) & ~(mask), 0)) + \
|
||||
__MASKED_FIELD(mask, value))
|
||||
|
||||
#define _MASKED_BIT_ENABLE(a) \
|
||||
(__builtin_choose_expr(__builtin_constant_p(a), _MASKED_FIELD((a), (a)), ({ typeof(a) _a = (a); _MASKED_FIELD(_a, _a); })))
|
||||
|
||||
#define _MASKED_BIT_DISABLE(a) \
|
||||
(_MASKED_FIELD((a), 0))
|
||||
|
||||
/*
|
||||
* Given the first two numbers __a and __b of arbitrarily many evenly spaced
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user