From: Ben Hutchings <ben@decadent.org.uk>
To: linux-fbdev@vger.kernel.org
Subject: [PATCH] sisfb: Replace creative use of the ternary operator
Date: Sun, 29 Mar 2015 22:28:28 +0000 [thread overview]
Message-ID: <1427668108.32382.106.camel@decadent.org.uk> (raw)
[-- 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 --]
reply other threads:[~2015-03-29 22:28 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1427668108.32382.106.camel@decadent.org.uk \
--to=ben@decadent.org.uk \
--cc=linux-fbdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).