On Wed, 10 May 2023 18:29:32 +0200, Oswald Buddenhagen wrote: > > The idea to encode the bitfield manipulation in the register address is > quite clever, but doing that by hand is ugly and error-prone. So derive > it automatically from the mask instead. > > Macros cannot #define other macros, so we now declare enums instead. > > This also adds macros for decoding the register definitions. These will > be used by later commits. > > Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@xxxxxx> > --- > include/sound/emu10k1.h | 113 ++++++++++++++++++---------------------- > 1 file changed, 50 insertions(+), 63 deletions(-) > > diff --git a/include/sound/emu10k1.h b/include/sound/emu10k1.h > index 8fe80dcee71b..f4e05a2897e8 100644 > --- a/include/sound/emu10k1.h > +++ b/include/sound/emu10k1.h > @@ -38,6 +38,22 @@ > > #define IP_TO_CP(ip) ((ip == 0) ? 0 : (((0x00001000uL | (ip & 0x00000FFFL)) << (((ip >> 12) & 0x000FL) + 4)) & 0xFFFF0000uL)) > > +#define SUB_REG_NC(reg, field, mask) \ > + enum { \ > + field ## _MASK = mask, \ > + field = reg | \ > + (__builtin_ctz(mask) << 16) | \ > + (__builtin_popcount(mask) << 24), \ > + }; > +#define SUB_REG(reg, field, mask) SUB_REG_NC(reg, reg ## _ ## field, mask) This macro needs some more comments. It's a good opportunity to explain what's the real raw register and what's the sub(?) register, and which one is used for which helper, etc. thanks, Takashi