iio: dac: ad5766: Convert GENMASK() to use static parameters
Subsystems (2)
PATCH v2 1/1 iio: dac: ad5766: Convert GENMASK() to use static parameters
There is no need to use run-time calculated masks in the code. Besides, GENMASK() over non-static parameters might lead compiler to generate much worse code.
---
v2: fixed typo
drivers/iio/dac/ad5766.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/dac/ad5766.c +2 -2
@@ -18,9 +18,9 @@#define AD5766_UPPER_WORD_SPI_MASK GENMASK(31, 16)#define AD5766_LOWER_WORD_SPI_MASK GENMASK(15, 0) -#define AD5766_DITHER_SOURCE_MASK (ch) GENMASK(((2 * ch) + 1), (2 * ch)) +#define AD5766_DITHER_SOURCE_MASK (ch) (GENMASK(1, 0) << ((ch) * 2))#define AD5766_DITHER_SOURCE (ch, source) BIT((ch * 2) + source) -#define AD5766_DITHER_SCALE_MASK (x) AD5766_DITHER_SOURCE_MASK(x) +#define AD5766_DITHER_SCALE_MASK (ch) (GENMASK(1, 0) << ((ch) * 2))#define AD5766_DITHER_SCALE (ch, scale) (scale << (ch * 2))#define AD5766_DITHER_ENABLE_MASK (ch) BIT(ch)#define AD5766_DITHER_ENABLE (ch, state) ((!state) << ch)
Signature · 1 line
2.50.1
Quoted 23 lines · Andy Shevchenko
There is no need to use run-time calculated masks in the code. Besides,
GENMASK()over non-static parameters might lead compiler to generate much worse code.Signed-off-by Andy Shevchenko <[email protected]>---
v2: fixed typo
drivers/iio/dac/ad5766.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)drivers/iio/dac/ad5766.c +0
-0@@ -18,9 +18,9 @@
#defineAD5766_UPPER_WORD_SPI_MASKGENMASK(31, 16)
#defineAD5766_LOWER_WORD_SPI_MASKGENMASK(15, 0)drivers/iio/dac/ad5766.c +1
-1-#define AD5766_DITHER_SOURCE_MASK (ch) GENMASK(((2 * ch) + 1), (2 * ch)) +#define AD5766_DITHER_SOURCE_MASK (ch) (GENMASK(1, 0) << ((ch) * 2))#define
AD5766_DITHER_SOURCE(ch, source)BIT((ch * 2) + source)
drivers/iio/dac/ad5766.c line 23
Quoted 2 lines
drivers/iio/dac/ad5766.c +1
-1-#define AD5766_DITHER_SCALE_MASK (x) AD5766_DITHER_SOURCE_MASK(x) +#define AD5766_DITHER_SCALE_MASK (ch) (GENMASK(1, 0) << ((ch) * 2))
This could have remained unchanged?
Quoted 3 lines
#define
AD5766_DITHER_SCALE(ch, scale)(scale << (ch * 2))
#defineAD5766_DITHER_ENABLE_MASK(ch)BIT(ch)
#defineAD5766_DITHER_ENABLE(ch, state)((!state) << ch)
Quoted 4 lines · Siratul Islam
Quoted 3 lines · Andy Shevchenko
There is no need to use run-time calculated masks in the code. Besides,
GENMASK()over non-static parameters might lead compiler to generate much worse code.
...
Quoted 8 lines
drivers/iio/dac/ad5766.c line 23
Quoted 7 lines
#define
AD5766_UPPER_WORD_SPI_MASKGENMASK(31, 16)
#defineAD5766_LOWER_WORD_SPI_MASKGENMASK(15, 0)drivers/iio/dac/ad5766.c +1
-1-#define AD5766_DITHER_SOURCE_MASK (ch) GENMASK(((2 * ch) + 1), (2 * ch)) +#define AD5766_DITHER_SOURCE_MASK (ch) (GENMASK(1, 0) << ((ch) * 2))#define
AD5766_DITHER_SOURCE(ch, source)BIT((ch * 2) + source)drivers/iio/dac/ad5766.c +1
-1-#define AD5766_DITHER_SCALE_MASK (x) AD5766_DITHER_SOURCE_MASK(x) +#define AD5766_DITHER_SCALE_MASK (ch) (GENMASK(1, 0) << ((ch) * 2))This could have remained unchanged?
Yes i could, but does it really show the tightness between two semantically? I believe it's not, that's why I explicitly put the numbers instead of indirection.
Quoted 3 lines
Quoted 3 lines
#define
AD5766_DITHER_SCALE(ch, scale)(scale << (ch * 2))
#defineAD5766_DITHER_ENABLE_MASK(ch)BIT(ch)
#defineAD5766_DITHER_ENABLE(ch, state)((!state) << ch)
Signature · 2 lines
With Best Regards, Andy Shevchenko
Siratul Islam
Reviewed-byQuoted 1 line · Andy Shevchenko
...
Quoted 7 lines
Quoted 4 lines
-#define
AD5766_DITHER_SCALE_MASK(x)AD5766_DITHER_SOURCE_MASK(x)+#defineAD5766_DITHER_SCALE_MASK(ch)(GENMASK(1, 0)<< ((ch) * 2)) This could have remained unchanged?Yes i could, but does it really show the tightness between two semantically? I believe it's not, that's why I explicitly put the numbers instead of indirection.
Thats fair.
Best regards,
Sirat
Quoted 7 lines · On Tue, 17 Nov 2026 17:08:43 +0100 Andy Shevchenko…
There is no need to use run-time calculated masks in the code. Besides,
GENMASK()over non-static parameters might lead compiler to generate much worse code.Signed-off-by Andy Shevchenko <[email protected]>---
I'm too lazy to find out what the compilers actually generate. Lots of options around code like this for what they might do. Anyhow, it is logically simpler so why not!
Applied.
Quoted 21 lines
v2: fixed typo
drivers/iio/dac/ad5766.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/iio/dac/ad5766.c +2
-2@@ -18,9 +18,9 @@#define AD5766_UPPER_WORD_SPI_MASK GENMASK(31, 16)#define AD5766_LOWER_WORD_SPI_MASK GENMASK(15, 0) -#define AD5766_DITHER_SOURCE_MASK (ch) GENMASK(((2 * ch) + 1), (2 * ch)) +#define AD5766_DITHER_SOURCE_MASK (ch) (GENMASK(1, 0) << ((ch) * 2))#define AD5766_DITHER_SOURCE (ch, source) BIT((ch * 2) + source) -#define AD5766_DITHER_SCALE_MASK (x) AD5766_DITHER_SOURCE_MASK(x) +#define AD5766_DITHER_SCALE_MASK (ch) (GENMASK(1, 0) << ((ch) * 2))#define AD5766_DITHER_SCALE (ch, scale) (scale << (ch * 2))#define AD5766_DITHER_ENABLE_MASK (ch) BIT(ch)#define AD5766_DITHER_ENABLE (ch, state) ((!state) << ch)