* [PATCH] sisfb: Replace creative use of the ternary operator
@ 2015-03-29 22:28 Ben Hutchings
0 siblings, 0 replies; only message in thread
From: Ben Hutchings @ 2015-03-29 22:28 UTC (permalink / raw)
To: linux-fbdev
[-- Attachment #1: Type: text/plain, Size: 3242 bytes --]
GETBITSTR() and related macros are defined in such a way that two of
the macro arguments must be pairs of integers joined with a ':',
selected between by prepending '1?' or '0?'. This is rather clever
but not very readable. Redefine the macros and change the users so
that each integer is a separate argument.
While we're at it, add a BUILD_BUG_ON_ZERO() to check that the
redundant first part of the 'to' argument is consistent with the
other arguments.
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
drivers/video/fbdev/sis/init.c | 32 +++++++++++++++-----------------
1 file changed, 15 insertions(+), 17 deletions(-)
diff --git a/drivers/video/fbdev/sis/init.c b/drivers/video/fbdev/sis/init.c
index dfe3eb7..d0c2e72 100644
--- a/drivers/video/fbdev/sis/init.c
+++ b/drivers/video/fbdev/sis/init.c
@@ -3320,11 +3320,9 @@ SiSSetMode(struct SiS_Private *SiS_Pr, unsigned short ModeNo)
return true;
}
-#ifndef GETBITSTR
-#define GENBITSMASK(mask) GENMASK(1?mask,0?mask)
-#define GETBITS(var,mask) (((var) & GENBITSMASK(mask)) >> (0?mask))
-#define GETBITSTR(val,from,to) ((GETBITS(val,from)) << (0?to))
-#endif
+#define GETBITSTR(val, fromhigh, fromlow, tohigh, tolow) \
+ (((((val) & GENMASK(fromhigh, fromlow)) >> (fromlow)) << (tolow)) + \
+ BUILD_BUG_ON_ZERO((fromhigh) - (fromlow) != (tohigh) - (tolow)))
void
SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth)
@@ -3363,23 +3361,23 @@ SiS_CalcCRRegisters(struct SiS_Private *SiS_Pr, int depth)
SiS_Pr->CCRT1CRTC[12] = (SiS_Pr->CVBlankEnd - 1) & 0xFF; /* CR16 */
SiS_Pr->CCRT1CRTC[13] = /* SRA */
- GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0) |
- GETBITSTR((SiS_Pr->CVDisplay -1), 10:10, 1:1) |
- GETBITSTR((SiS_Pr->CVBlankStart-1), 10:10, 2:2) |
- GETBITSTR((SiS_Pr->CVSyncStart -x), 10:10, 3:3) |
- GETBITSTR((SiS_Pr->CVBlankEnd -1), 8:8, 4:4) |
- GETBITSTR((SiS_Pr->CVSyncEnd ), 4:4, 5:5) ;
+ GETBITSTR((SiS_Pr->CVTotal -2), 10, 10, 0, 0) |
+ GETBITSTR((SiS_Pr->CVDisplay -1), 10, 10, 1, 1) |
+ GETBITSTR((SiS_Pr->CVBlankStart-1), 10, 10, 2, 2) |
+ GETBITSTR((SiS_Pr->CVSyncStart -x), 10, 10, 3, 3) |
+ GETBITSTR((SiS_Pr->CVBlankEnd -1), 8, 8, 4, 4) |
+ GETBITSTR((SiS_Pr->CVSyncEnd ), 4, 4, 5, 5) ;
SiS_Pr->CCRT1CRTC[14] = /* SRB */
- GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9:8, 1:0) |
- GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9:8, 3:2) |
- GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9:8, 5:4) |
- GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9:8, 7:6) ;
+ GETBITSTR((SiS_Pr->CHTotal >> 3) - 5, 9, 8, 1, 0) |
+ GETBITSTR((SiS_Pr->CHDisplay >> 3) - 1, 9, 8, 3, 2) |
+ GETBITSTR((SiS_Pr->CHBlankStart >> 3) - 1, 9, 8, 5, 4) |
+ GETBITSTR((SiS_Pr->CHSyncStart >> 3) + 3, 9, 8, 7, 6) ;
SiS_Pr->CCRT1CRTC[15] = /* SRC */
- GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7:6, 1:0) |
- GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5:5, 2:2) ;
+ GETBITSTR((SiS_Pr->CHBlankEnd >> 3) - 1, 7, 6, 1, 0) |
+ GETBITSTR((SiS_Pr->CHSyncEnd >> 3) + 3, 5, 5, 2, 2) ;
}
void
--
Ben Hutchings
Sturgeon's Law: Ninety percent of everything is crap.
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-03-29 22:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-29 22:28 [PATCH] sisfb: Replace creative use of the ternary operator Ben Hutchings
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).