Lines Matching +full:1 +full:a

4  * A tnum tracks knowledge about the bits of a value.  Each bit can be either
5 * known (0 or 1), or unknown (x). Arithmetic operations on tnums will
13 /* A completely unknown value */
14 const struct tnum tnum_unknown = { .value = 0, .mask = -1 };
26 /* special case, needed because 1ULL << 64 is undefined */
29 /* e.g. if chi = 4, bits = 3, delta = (1<<3) - 1 = 7.
30 * if chi = 0, bits = 0, delta = (1<<0) - 1 = 0, so we return
33 delta = (1ULL << bits) - 1;
37 struct tnum tnum_lshift(struct tnum a, u8 shift)
39 return TNUM(a.value << shift, a.mask << shift);
42 struct tnum tnum_rshift(struct tnum a, u8 shift)
44 return TNUM(a.value >> shift, a.mask >> shift);
47 struct tnum tnum_arshift(struct tnum a, u8 min_shift, u8 insn_bitness)
49 /* if a.value is negative, arithmetic shifting by minimum shift
51 * If a.value is nonnegative, arithmetic shifting by minimum shift
55 return TNUM((u32)(((s32)a.value) >> min_shift),
56 (u32)(((s32)a.mask) >> min_shift));
58 return TNUM((s64)a.value >> min_shift,
59 (s64)a.mask >> min_shift);
62 struct tnum tnum_add(struct tnum a, struct tnum b)
66 sm = a.mask + b.mask;
67 sv = a.value + b.value;
70 mu = chi | a.mask | b.mask;
74 struct tnum tnum_sub(struct tnum a, struct tnum b)
78 dv = a.value - b.value;
79 alpha = dv + a.mask;
82 mu = chi | a.mask | b.mask;
86 struct tnum tnum_neg(struct tnum a)
88 return tnum_sub(TNUM(0, 0), a);
91 struct tnum tnum_and(struct tnum a, struct tnum b)
95 alpha = a.value | a.mask;
97 v = a.value & b.value;
101 struct tnum tnum_or(struct tnum a, struct tnum b)
105 v = a.value | b.value;
106 mu = a.mask | b.mask;
110 struct tnum tnum_xor(struct tnum a, struct tnum b)
114 v = a.value ^ b.value;
115 mu = a.mask | b.mask;
119 /* Perform long multiplication, iterating through the bits in a using rshift:
120 * - if LSB(a) is a known 0, keep current accumulator
121 * - if LSB(a) is a known 1, add b to current accumulator
122 * - if LSB(a) is unknown, take a union of the above cases.
136 struct tnum tnum_mul(struct tnum a, struct tnum b)
140 while (a.value || a.mask) {
141 /* LSB of tnum a is a certain 1 */
142 if (a.value & 1)
144 /* LSB of tnum a is uncertain */
145 else if (a.mask & 1) {
148 * LSB(a) = certain 0 and LSB(a) = certain 1.
150 * acc_1 = acc + 1 * b = tnum_add(acc, b).
156 a = tnum_rshift(a, 1);
157 b = tnum_lshift(b, 1);
162 bool tnum_overlap(struct tnum a, struct tnum b)
166 mu = ~a.mask & ~b.mask;
167 return (a.value & mu) == (b.value & mu);
170 /* Note that if a and b disagree - i.e. one has a 'known 1' where the other has
171 * a 'known 0' - this will return a 'known 1' for that bit.
173 struct tnum tnum_intersect(struct tnum a, struct tnum b)
177 v = a.value | b.value;
178 mu = a.mask & b.mask;
182 /* Returns a tnum with the uncertainty from both a and b, and in addition, new
183 * uncertainty at any position that a and b disagree. This represents a
184 * superset of the union of the concrete sets of both a and b. Despite the
187 struct tnum tnum_union(struct tnum a, struct tnum b)
189 u64 v = a.value & b.value;
190 u64 mu = (a.value ^ b.value) | a.mask | b.mask;
195 struct tnum tnum_cast(struct tnum a, u8 size)
197 a.value &= (1ULL << (size * 8)) - 1;
198 a.mask &= (1ULL << (size * 8)) - 1;
199 return a;
202 bool tnum_is_aligned(struct tnum a, u64 size)
206 return !((a.value | a.mask) & (size - 1));
209 bool tnum_in(struct tnum a, struct tnum b)
211 if (b.mask & ~a.mask)
213 b.value &= ~a.mask;
214 return a.value == b.value;
217 int tnum_sbin(char *str, size_t size, struct tnum a)
223 if (a.mask & 1)
224 str[n - 1] = 'x';
225 else if (a.value & 1)
226 str[n - 1] = '1';
228 str[n - 1] = '0';
230 a.mask >>= 1;
231 a.value >>= 1;
233 str[min(size - 1, (size_t)64)] = 0;
237 struct tnum tnum_subreg(struct tnum a)
239 return tnum_cast(a, 4);
242 struct tnum tnum_clear_subreg(struct tnum a)
244 return tnum_lshift(tnum_rshift(a, 32), 32);
252 struct tnum tnum_const_subreg(struct tnum a, u32 value)
254 return tnum_with_subreg(a, tnum_const(value));