linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Dibyendu Majumdar <mobile@majumdar.org.uk>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v3 4/8] change the masking when loading bitfields
Date: Wed,  9 Aug 2017 01:06:30 +0200	[thread overview]
Message-ID: <20170808230634.16227-5-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170808230634.16227-1-luc.vanoostenryck@gmail.com>

To make some simplification easier, change the way the masking
is done when loading bitfields.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 linearize.c                | 15 +++++++++------
 validation/bitfield-size.c |  6 ++++--
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/linearize.c b/linearize.c
index ba76397ea..f833fd8d9 100644
--- a/linearize.c
+++ b/linearize.c
@@ -1000,14 +1000,17 @@ static pseudo_t linearize_load_gen(struct entrypoint *ep, struct access_data *ad
 {
 	struct symbol *ctype = ad->result_type;
 	pseudo_t new = add_load(ep, ad);
+	unsigned int off = ctype->bit_offset;
+	unsigned int siz = ctype->bit_size;
 
-	if (ctype->bit_offset) {
-		pseudo_t shift = value_pseudo(ctype->bit_offset);
-		pseudo_t newval = add_binary_op(ep, ad->source_type, OP_LSR, new, shift);
-		new = newval;
+	if (siz != type_size(ad->source_type)) {
+		pseudo_t mask = value_pseudo(((1ULL << siz) - 1) << off);
+		new = add_binary_op(ep, ad->source_type, OP_AND, new, mask);
+	}
+	if (off) {
+		pseudo_t shift = value_pseudo(off);
+		new = add_binary_op(ep, ad->source_type, OP_LSR, new, shift);
 	}
-	if (ctype->bit_size != type_size(ad->source_type))
-		new = cast_pseudo(ep, new, ad->source_type, ad->result_type);
 	return new;
 }
 
diff --git a/validation/bitfield-size.c b/validation/bitfield-size.c
index ce78ecf21..c8c94bb15 100644
--- a/validation/bitfield-size.c
+++ b/validation/bitfield-size.c
@@ -35,7 +35,9 @@ unsigned int get_pbfi_b(struct bfi *bf) { return bf->b; }
  * check-command: test-linearize -Wno-decl $file
  * check-output-ignore
  *
- * check-output-pattern-24-times: cast\\.
- * check-output-pattern-12-times: cast\\.4
+ * check-output-excludes: cast\\.4
+ * check-output-pattern-6-times: cast\\.
  * check-output-pattern-6-times: lsr\\..*\\$6
+ * check-output-pattern-6-times: and\\..*\\$15
+ * check-output-pattern-6-times: and\\..*\\$960
  */
-- 
2.13.2


  parent reply	other threads:[~2017-08-08 23:06 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08 23:06 [PATCH v3 0/8] fix loading of partially defined bitfield Luc Van Oostenryck
2017-08-08 23:06 ` [PATCH v3 1/8] Remove single-store shortcut Luc Van Oostenryck
2017-08-08 23:06 ` [PATCH v3 2/8] new helper: def_opcode() Luc Van Oostenryck
2017-08-08 23:06 ` [PATCH v3 3/8] reuse nbr_pseudo_users() Luc Van Oostenryck
2017-08-08 23:06 ` Luc Van Oostenryck [this message]
2017-08-08 23:06 ` [PATCH v3 5/8] simplify ((A & M') | B ) & M when M' & M == 0 Luc Van Oostenryck
2017-08-08 23:06 ` [PATCH v3 6/8] transform (A & M) >> S to (A >> S) & (M >> S) Luc Van Oostenryck
2017-08-08 23:06 ` [PATCH v3 7/8] transform (A << S) >> S into A & (-1 " Luc Van Oostenryck
2017-08-08 23:06 ` [PATCH v3 8/8] fix: cast of OP_AND only valid if it's an OP_CAST Luc Van Oostenryck
2017-08-09  5:52 ` [PATCH v3 0/8] fix loading of partially defined bitfield Christopher Li
2017-08-09 19:37   ` [PATCH v4 0/9] " Luc Van Oostenryck
2017-08-09 19:37     ` [PATCH v4 1/9] testsuite: add support for commands with timeout Luc Van Oostenryck
2017-08-09 19:37     ` [PATCH v4 2/9] Remove single-store shortcut Luc Van Oostenryck
2017-08-09 19:47       ` Dibyendu Majumdar
2017-08-09 20:02         ` Luc Van Oostenryck
2017-08-09 22:23           ` Dibyendu Majumdar
2017-08-09 23:15             ` Luc Van Oostenryck
2017-08-09 23:32               ` Dibyendu Majumdar
2017-08-09 23:51                 ` Luc Van Oostenryck
2017-08-12 18:51                   ` Dibyendu Majumdar
2017-08-12 19:28                     ` Luc Van Oostenryck
2017-08-12 19:55                       ` Dibyendu Majumdar
2017-08-12 20:14                         ` Luc Van Oostenryck
2017-08-09 19:38     ` [PATCH v4 3/9] new helper: def_opcode() Luc Van Oostenryck
2017-08-09 19:38     ` [PATCH v4 4/9] reuse nbr_pseudo_users() Luc Van Oostenryck
2017-08-09 19:38     ` [PATCH v4 5/9] change the masking when loading bitfields Luc Van Oostenryck
2017-08-09 19:38     ` [PATCH v4 6/9] simplify ((A & M') | B ) & M when M' & M == 0 Luc Van Oostenryck
2017-08-09 19:38     ` [PATCH v4 7/9] transform (A & M) >> S to (A >> S) & (M >> S) Luc Van Oostenryck
2017-08-10  1:16       ` Christopher Li
2017-08-10 23:41         ` Luc Van Oostenryck
2017-08-09 19:38     ` [PATCH v4 8/9] transform (A << S) >> S into A & (-1 " Luc Van Oostenryck
2017-08-09 19:38     ` [PATCH v4 9/9] fix: cast of OP_AND only valid if it's an OP_CAST Luc Van Oostenryck

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=20170808230634.16227-5-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=mobile@majumdar.org.uk \
    --cc=sparse@chrisli.org \
    --cc=torvalds@linux-foundation.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).