Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+11 -11
+11 -11
drivers/gpu/drm/i915/i915_reg_defs.h
··· 106 106 BUILD_BUG_ON_ZERO(__builtin_choose_expr(__is_constexpr(__val), (~((__mask) >> __bf_shf(__mask)) & (__val)), 0)))) 107 107 108 108 #define __MASKED_FIELD(mask, value) ((mask) << 16 | (value)) 109 - #define _MASKED_FIELD(mask, value) ({ \ 110 - if (__builtin_constant_p(mask)) \ 111 - BUILD_BUG_ON_MSG(((mask) & 0xffff0000), "Incorrect mask"); \ 112 - if (__builtin_constant_p(value)) \ 113 - BUILD_BUG_ON_MSG((value) & 0xffff0000, "Incorrect value"); \ 114 - if (__builtin_constant_p(mask) && __builtin_constant_p(value)) \ 115 - BUILD_BUG_ON_MSG((value) & ~(mask), \ 116 - "Incorrect value for mask"); \ 117 - __MASKED_FIELD(mask, value); }) 118 - #define _MASKED_BIT_ENABLE(a) ({ typeof(a) _a = (a); _MASKED_FIELD(_a, _a); }) 119 - #define _MASKED_BIT_DISABLE(a) (_MASKED_FIELD((a), 0)) 109 + #define _MASKED_FIELD(mask, value) \ 110 + (BUILD_BUG_ON_ZERO(__builtin_choose_expr(__builtin_constant_p(mask), (mask) & 0xffff0000, 0)) + \ 111 + BUILD_BUG_ON_ZERO(__builtin_choose_expr(__builtin_constant_p(value), (value) & 0xffff0000, 0)) + \ 112 + BUILD_BUG_ON_ZERO(__builtin_choose_expr(__builtin_constant_p(mask) && __builtin_constant_p(value), (value) & ~(mask), 0)) + \ 113 + __MASKED_FIELD(mask, value)) 114 + 115 + #define _MASKED_BIT_ENABLE(a) \ 116 + (__builtin_choose_expr(__builtin_constant_p(a), _MASKED_FIELD((a), (a)), ({ typeof(a) _a = (a); _MASKED_FIELD(_a, _a); }))) 117 + 118 + #define _MASKED_BIT_DISABLE(a) \ 119 + (_MASKED_FIELD((a), 0)) 120 120 121 121 /* 122 122 * Given the first two numbers __a and __b of arbitrarily many evenly spaced