[PATCH 04/16] bitfield: extract linearize_bitfield_insert()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



linearize_store_gen() is complex because it has to handle
the insertion of bitfields.

Isolate this operation in a separate function in order to
facilitate the incoming changes there.
---
 linearize.c | 30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/linearize.c b/linearize.c
index 273a534f2..c1e4498ea 100644
--- a/linearize.c
+++ b/linearize.c
@@ -973,6 +973,24 @@ static void add_store(struct entrypoint *ep, struct access_data *ad, pseudo_t va
 	add_one_insn(ep, store);
 }
 
+static pseudo_t linearize_bitfield_insert(struct entrypoint *ep,
+	pseudo_t ori, pseudo_t val, struct symbol *ctype, struct symbol *btype)
+{
+	unsigned int shift = ctype->bit_offset;
+	unsigned int size = ctype->bit_size;
+	unsigned long long mask = ((1ULL << size) - 1);
+
+	val = add_cast(ep, btype, ctype, OP_ZEXT, val);
+	if (shift) {
+		val = add_binary_op(ep, btype, OP_SHL, val, value_pseudo(shift));
+		mask <<= shift;
+	}
+	ori = add_binary_op(ep, btype, OP_AND, ori, value_pseudo(~mask));
+	val = add_binary_op(ep, btype, OP_OR, ori, val);
+
+	return val;
+}
+
 static pseudo_t linearize_store_gen(struct entrypoint *ep,
 		pseudo_t value,
 		struct access_data *ad)
@@ -985,18 +1003,8 @@ static pseudo_t linearize_store_gen(struct entrypoint *ep,
 		return VOID;
 
 	if (type_size(btype) != type_size(ctype)) {
-		unsigned int shift = ctype->bit_offset;
-		unsigned int size = ctype->bit_size;
 		pseudo_t orig = add_load(ep, ad);
-		unsigned long long mask = (1ULL << size) - 1;
-
-		store = add_cast(ep, btype, ctype, OP_ZEXT, store);
-		if (shift) {
-			store = add_binary_op(ep, btype, OP_SHL, store, value_pseudo(shift));
-			mask <<= shift;
-		}
-		orig = add_binary_op(ep, btype, OP_AND, orig, value_pseudo(~mask));
-		store = add_binary_op(ep, btype, OP_OR, orig, store);
+		store = linearize_bitfield_insert(ep, orig, value, ctype, btype);
 	}
 	add_store(ep, ad, store);
 	return value;
-- 
2.18.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux