1#ifndef BITWISE_BOUNDS_H_INCLUDED
2#define BITWISE_BOUNDS_H_INCLUDED
24 while (cand_bits != 0)
28 UINT_X least_bit = cand_bits & (-cand_bits);
33 UINT_X alternate_b = (b - least_bit) | (least_bit - 1);
34 UINT_X alternate_d = (d - least_bit) | (least_bit - 1);
37 if (alternate_b < a && alternate_d < c)
42 extra_bits |= (least_bit - 1);
45 cand_bits &= (cand_bits - 1);
50 return b | d | extra_bits;
71 while (cand_bits != 0)
75 UINT_X least_bit = cand_bits & (-cand_bits);
80 UINT_X alternate_a = (a | least_bit) & (-least_bit);
90 cand_bits &= (cand_bits - 1);
95 while (cand_bits != 0)
97 UINT_X least_bit = cand_bits & (-cand_bits);
98 UINT_X alternate_c = (c | least_bit) & (-least_bit);
101 best_c = alternate_c;
102 cand_bits &= (cand_bits - 1);
108 UINT_X min_1 = best_a | c;
109 UINT_X min_2 = a | best_c;
112 return (min_1 < min_2) ? min_1 : min_2;
270 UINT_X sign_bit = 1 << (n - 1);
271 UINT_X mask = sign_bit | (sign_bit - 1);
289 UINT_X sign_bit = 1 << (n - 1);
290 UINT_X mask = sign_bit | (sign_bit - 1);
348 UINT_X sign_bit = 1 << (n - 1);
351 UINT_X mask = sign_bit | (sign_bit - 1);
354 if ((a & sign_bit) != 0 && (b & sign_bit) == 0)
373 UINT_X sign_bit = 1 << (n - 1);
376 UINT_X mask = sign_bit | (sign_bit - 1);
379 if ((a & sign_bit) != 0 && (b & sign_bit) == 0)
501 return (a < c) ? a : c;
608 return (e > f) ? e : f;
683 return (e < f) ? e : f;
820 UINT_X sign_bit = 1 << (n - 1);
823 UINT_X mask = sign_bit | (sign_bit - 1);
826 if ((x & sign_bit) == 0)
827 return (
INT_X)x & mask;
831 INT_X positive_x = (~x & mask) + 1;
847 UINT_X sign_bit = 1 << (n - 1);
852 UINT_X cand_bits = b & (-sign_bit);
856 UINT_X least_bit = cand_bits & (-cand_bits);
861 UINT_X alternate_b = (b - least_bit) | (least_bit - 1);
865 UINT_X positive_b = alternate_b & ~sign_bit;
868 if (positive_b >= a && positive_b <= b)
872 if ((b & sign_bit) == 0)
876 if (alternate_b >= a && alternate_b <= b)
895 UINT_X sign_bit = 1 << (n - 1);
900 UINT_X cand_bits = ~a & (-sign_bit);
904 UINT_X least_bit = cand_bits & (-cand_bits);
909 UINT_X alternate_a = (a | least_bit) & (-least_bit);
913 UINT_X negative_a = alternate_a | sign_bit;
916 if (negative_a >= a && negative_a <= b)
920 if ((a & sign_bit) != 0)
924 if (alternate_a >= a && alternate_a <= b)
947 return (c > d) ? c : d;
970 return (c < d) ? c : d;
989 UINT_X sign_bit = 1 << (n - 1);
992 if ((b & sign_bit) != 0)
994 if ((a & sign_bit) == 0)
1017 UINT_X sign_bit = 1 << (n - 1);
1020 if ((b & sign_bit) != 0)
1022 if ((a & sign_bit) == 0)
1033#define UINT_FUNC(FUNC, LHS, RHS) \
1035 LHS.get_lower().to_uint64(), \
1036 LHS.get_upper().to_uint64(), \
1037 RHS.get_lower().to_uint64(), \
1038 RHS.get_upper().to_uint64())
1040#define INT_FUNC(FUNC, LHS, RHS) \
1042 LHS.get_lower().to_int64(), \
1043 LHS.get_upper().to_int64(), \
1044 RHS.get_lower().to_int64(), \
1045 RHS.get_upper().to_int64())
1047#define GET_BIT_INTERVALS(NAME, MIN_UFUNC, MAX_UFUNC, MIN_FUNC, MAX_FUNC) \
1049 interval_templatet<BigInt> interval_templatet<BigInt>::NAME( \
1050 const interval_templatet<BigInt> &lhs, \
1051 const interval_templatet<BigInt> &rhs) const \
1053 interval_templatet<BigInt> result; \
1054 if (!lhs.lower || !lhs.upper || !rhs.lower || !rhs.upper) \
1056 if (is_unsignedbv_type(lhs.type) && is_unsignedbv_type(rhs.type)) \
1058 result.set_lower(UINT_FUNC(MIN_UFUNC, lhs, rhs)); \
1059 result.set_upper(UINT_FUNC(MAX_UFUNC, lhs, rhs)); \
1061 else if (is_signedbv_type(lhs.type) && is_signedbv_type(rhs.type)) \
1063 result.set_lower(INT_FUNC(MIN_FUNC, lhs, rhs)); \
1064 result.set_upper(INT_FUNC(MAX_FUNC, lhs, rhs)); \
1093 interval_logical_right_shift,
1106 if (!lhs.lower || !lhs.upper || !rhs.lower || !rhs.upper)
1108 if (!is_signedbv_type(lhs.type) || !is_signedbv_type(rhs.type))
1111 if (rhs.get_lower() < 0 || rhs.get_upper() >=
BigInt(lhs.type->get_width()))
1119 interval_left_shift,
1127#undef GET_BIT_INTERVALS
INT_X unsigned_2_signed_max_truncate(UINT_X a, UINT_X b, UINT_X n)
Upper bound on unsigned to signed interval truncation.
Definition bitwise_bounds.h:844
#define UINT_X
Definition bitwise_bounds.h:4
UINT_X unsigned_min_left_shift(UINT_X a, UINT_X, UINT_X c, UINT_X)
Lower bound on interval left shift.
Definition bitwise_bounds.h:225
UINT_X unsigned_max_left_shift(UINT_X, UINT_X b, UINT_X, UINT_X d)
Upper bound on interval left shift.
Definition bitwise_bounds.h:211
UINT_X unsigned_min_not(UINT_X, UINT_X b)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:197
unsigned_max_or
Definition bitwise_bounds.h:1081
signed_max_or signed_min_right_shift
Definition bitwise_bounds.h:1096
signed_max_or unsigned_max_right_shift
Definition bitwise_bounds.h:1095
UINT_X signed_2_unsigned_max_extend(INT_X a, INT_X b, UINT_X n)
Upper bound on the unsigned extension of an n bit signed interval.
Definition bitwise_bounds.h:345
INT_X signed_max_and(INT_X a, INT_X b, INT_X c, INT_X d)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:541
#define INT_FUNC(FUNC, LHS, RHS)
Definition bitwise_bounds.h:1040
INT_X signed_min_not(INT_X, INT_X b)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:733
UINT_X signed_2_unsigned_min_extend(INT_X a, INT_X b, UINT_X n)
Lower bound on the unsigned extension of an n bit signed interval.
Definition bitwise_bounds.h:370
INT_X signed_max_not(INT_X a, INT_X)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:720
unsigned_min_or
Definition bitwise_bounds.h:1080
UINT_X unsigned_max_and(UINT_X a, UINT_X b, UINT_X c, UINT_X d)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:125
INT_X signed_max_right_shift(INT_X, INT_X b, UINT_X c, UINT_X d)
Upper bound on interval right shift.
Definition bitwise_bounds.h:784
INT_X signed_2_signed_min_truncate(INT_X a, INT_X b, UINT_X n)
Lower bound on signed to signed interval truncation.
Definition bitwise_bounds.h:963
UINT_X signed_2_unsigned_min_truncate(INT_X a, INT_X b, UINT_X n)
Lower bound on signed to unsigned interval truncation.
Definition bitwise_bounds.h:325
UINT_X signed_2_unsigned_max_truncate(INT_X a, INT_X b, UINT_X n)
Upper bound on signed to unsigned interval truncation.
Definition bitwise_bounds.h:305
INT_X unsigned_2_signed(UINT_X x, UINT_X n)
Cast a limited-width unsigned integer to signed integer.
Definition bitwise_bounds.h:817
INT_X signed_2_signed_max_truncate(INT_X a, INT_X b, UINT_X n)
Upper bound on signed to signed interval truncation.
Definition bitwise_bounds.h:940
INT_X unsigned_2_signed_max_extend(UINT_X a, UINT_X b, UINT_X n)
Upper bound on the signed extension of an n bit unsigned interval.
Definition bitwise_bounds.h:986
UINT_X unsigned_min_xor(UINT_X a, UINT_X b, UINT_X c, UINT_X d)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:171
signed_max_or unsigned_min_right_shift
Definition bitwise_bounds.h:1094
UINT_X unsigned_max_not(UINT_X a, UINT_X)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:184
UINT_X unsigned_2_unsigned_min_truncate(UINT_X a, UINT_X b, UINT_X n)
Lower bound on unsigned to unsigned interval truncation.
Definition bitwise_bounds.h:286
UINT_X unsigned_max_xor(UINT_X a, UINT_X b, UINT_X c, UINT_X d)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:155
#define GET_BIT_INTERVALS(NAME, MIN_UFUNC, MAX_UFUNC, MIN_FUNC, MAX_FUNC)
Definition bitwise_bounds.h:1047
#define INT_X
Definition bitwise_bounds.h:5
INT_X signed_min_and(INT_X a, INT_X b, INT_X c, INT_X d)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:557
INT_X signed_min_left_shift(INT_X a, INT_X, UINT_X c, UINT_X d)
Lower bound on interval left shift.
Definition bitwise_bounds.h:766
INT_X signed_max_or(INT_X a, INT_X b, INT_X c, INT_X d)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:397
INT_X signed_max_left_shift(INT_X, INT_X b, UINT_X c, UINT_X d)
Upper bound on interval left shift.
Definition bitwise_bounds.h:748
INT_X signed_max_xor(INT_X a, INT_X b, INT_X c, INT_X d)
Original upper bound on signed interval XOR, inspired by the case-based algorithm for signed interval...
Definition bitwise_bounds.h:574
INT_X unsigned_2_signed_min_truncate(UINT_X a, UINT_X b, UINT_X n)
Lower bound on unsigned to signed interval truncation.
Definition bitwise_bounds.h:892
INT_X unsigned_2_signed_min_extend(UINT_X a, UINT_X b, UINT_X n)
Lower bound on the signed extension of an n bit unsigned interval.
Definition bitwise_bounds.h:1014
UINT_X unsigned_min_and(UINT_X a, UINT_X b, UINT_X c, UINT_X d)
Implementation of the algorithm in Henry S.
Definition bitwise_bounds.h:140
signed_min_or
Definition bitwise_bounds.h:1082
INT_X signed_min_xor(INT_X a, INT_X b, INT_X c, INT_X d)
Original lower bound on signed interval XOR, inspired by the case-based algorithm for signed interval...
Definition bitwise_bounds.h:649
UINT_X unsigned_2_unsigned_max_truncate(UINT_X a, UINT_X b, UINT_X n)
Upper bound on unsigned to unsigned interval truncation.
Definition bitwise_bounds.h:267
This class is used to store intervals in the form of lower <= upper.
Definition interval_template.h:20
void set_lower(const T &b)
Definition interval_template.h:75
void set_upper(const T &b)
Definition interval_template.h:71
interval_templatet< BigInt > interval_arithmetic_right_shift(const interval_templatet< BigInt > &, const interval_templatet< BigInt > &) const
Definition interval_template.h:531
interval_templatet()=default